From b32935a1b087bbc6d19fb7e50493273796d2ffb4 Mon Sep 17 00:00:00 2001 From: bopol Date: Thu, 9 Jan 2020 15:51:41 +0100 Subject: [PATCH] app language now changes time formatting (3hrs ago), was system language b4 --- app/src/main/java/org/schabi/newpipe/App.java | 2 +- .../java/org/schabi/newpipe/MainActivity.java | 8 +++++--- .../org/schabi/newpipe/about/AboutActivity.java | 4 ++-- .../newpipe/download/DownloadActivity.java | 4 ++-- .../newpipe/settings/SettingsActivity.java | 4 ++-- .../org/schabi/newpipe/util/Localization.java | 17 ++++++++--------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 7f050e6c7..dae143b6c 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -99,7 +99,7 @@ public class App extends Application { NewPipe.init(getDownloader(), Localization.getPreferredLocalization(this), Localization.getPreferredContentCountry(this)); - Localization.init(); + Localization.init(getApplicationContext()); StateSaver.init(this); initNotificationChannel(); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index eb5f11987..d48db1035 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -66,6 +66,7 @@ import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; +import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PeertubeHelper; import org.schabi.newpipe.util.PermissionHelper; @@ -78,7 +79,7 @@ import java.util.ArrayList; import java.util.List; import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @@ -117,7 +118,7 @@ public class MainActivity extends AppCompatActivity { } ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); - changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -422,7 +423,8 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { - changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + Localization.init(getApplicationContext()); //change the date format to match the selected language on resume super.onResume(); // close drawer on return, and don't show animation, so its looks like the drawer isn't open diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java index 3555ecefe..795feceb0 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -26,7 +26,7 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ThemeHelper; import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; public class AboutActivity extends AppCompatActivity { @@ -65,7 +65,7 @@ public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index bf546bf85..fd0d28a0e 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -19,7 +19,7 @@ import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.ui.fragment.MissionsFragment; import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; public class DownloadActivity extends AppCompatActivity { @@ -32,7 +32,7 @@ public class DownloadActivity extends AppCompatActivity { i.setClass(this, DownloadManagerService.class); startService(i); - changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); ThemeHelper.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_downloader); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java index 781c033b8..6804f9831 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -15,7 +15,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.util.ThemeHelper; import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; /* @@ -47,7 +47,7 @@ public class SettingsActivity extends AppCompatActivity implements BasePreferenc @Override protected void onCreate(Bundle savedInstanceBundle) { setTheme(ThemeHelper.getSettingsThemeStyle(this)); - changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceBundle); setContentView(R.layout.settings_layout); diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 7d742b04a..695a73295 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -7,7 +7,6 @@ import android.content.res.Resources; import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.DisplayMetrics; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.PluralsRes; @@ -54,8 +53,8 @@ public class Localization { private Localization() { } - public static void init() { - initPrettyTime(); + public static void init(Context context) { + initPrettyTime(context); } @NonNull @@ -203,17 +202,17 @@ public class Localization { // Pretty Time //////////////////////////////////////////////////////////////////////////*/ - private static void initPrettyTime() { - prettyTime = new PrettyTime(Locale.getDefault()); + private static void initPrettyTime(Context context) { + prettyTime = new PrettyTime(getAppLocale(context)); // Do not use decades as YouTube doesn't either. prettyTime.removeUnit(Decade.class); } private static PrettyTime getPrettyTime() { // If pretty time's Locale is different, init again with the new one. - if (!prettyTime.getLocale().equals(Locale.getDefault())) { - initPrettyTime(); - } +// if (!prettyTime.getLocale().equals(Locale.getDefault())) { +// initPrettyTime(); +// } return prettyTime; } @@ -228,7 +227,7 @@ public class Localization { res.updateConfiguration(conf, dm); } - public static Locale getAppLanguage(Context context) { + public static Locale getAppLocale(Context context) { SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context); String lang = prefs.getString("newpipes_language_key", "en"); Locale loc;