From dea1e0dcb9652dbaddcd1f1de68d8a5d340426a2 Mon Sep 17 00:00:00 2001 From: bopol Date: Sat, 4 Jan 2020 21:38:27 +0100 Subject: [PATCH 01/17] Update localizations settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) now, on « content language » change, it will also change the app language 2) added Esperanto to the list of language in content language --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 5 +++++ .../java/org/schabi/newpipe/util/Localization.java | 10 ++++++++++ app/src/main/res/values/settings_keys.xml | 2 ++ 3 files changed, 17 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 90d299c7fc9..cac81408513 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -67,6 +67,7 @@ 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,6 +79,8 @@ import java.util.ArrayList; import java.util.List; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; + public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); @@ -116,6 +119,8 @@ protected void onCreate(Bundle savedInstanceState) { ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); + changeAppLanguage(Localization.getPreferredLocale(getApplicationContext()), getResources()); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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 9274df848a2..6b0b4cd0c69 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -2,8 +2,11 @@ import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.DisplayMetrics; import org.ocpsoft.prettytime.PrettyTime; import org.ocpsoft.prettytime.units.Decade; @@ -216,4 +219,11 @@ private static PrettyTime getPrettyTime() { public static String relativeTime(Calendar calendarTime) { return getPrettyTime().formatUnrounded(calendarTime); } + + public static void changeAppLanguage(Locale loc, Resources res) { + DisplayMetrics dm = res.getDisplayMetrics(); + Configuration conf = res.getConfiguration(); + conf.setLocale(loc); + res.updateConfiguration(conf, dm); + } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 6aaaa063044..3f361226d02 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -272,6 +272,7 @@ cs da de + eo et en-GB en @@ -351,6 +352,7 @@ Čeština Dansk Deutsch + Esperanto Eesti English (UK) English (US) From 3ad0e313caee037d42ea9a4ef89e80fbd04d9a2f Mon Sep 17 00:00:00 2001 From: bopol Date: Thu, 9 Jan 2020 09:40:05 +0100 Subject: [PATCH 02/17] =?UTF-8?q?changed=20the=20way=20to=20change=20langu?= =?UTF-8?q?age,=20now=20is=20=C2=ABNewPipe's=20language=C2=BB=20selector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/schabi/newpipe/MainActivity.java | 8 +- .../schabi/newpipe/about/AboutActivity.java | 6 + .../newpipe/download/DownloadActivity.java | 6 + .../settings/ContentSettingsFragment.java | 5 +- .../newpipe/settings/SettingsActivity.java | 7 +- .../org/schabi/newpipe/util/Localization.java | 26 ++- app/src/main/res/values-ur/strings.xml | 10 +- app/src/main/res/values/settings_keys.xml | 159 ++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/content_settings.xml | 10 ++ 10 files changed, 209 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index cac81408513..05e22401322 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -56,7 +56,6 @@ import com.google.android.material.navigation.NavigationView; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance; @@ -67,7 +66,6 @@ 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,8 +76,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLanguage; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @@ -116,10 +116,9 @@ protected void onCreate(Bundle savedInstanceState) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { TLSSocketFactoryCompat.setAsDefault(); } - ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); - changeAppLanguage(Localization.getPreferredLocale(getApplicationContext()), getResources()); + changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -424,6 +423,7 @@ protected void onDestroy() { @Override protected void onResume() { + changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); 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 2326e795ef1..4da1611d348 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -25,6 +25,11 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ThemeHelper; +import java.util.Locale; + +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLanguage; + public class AboutActivity extends AppCompatActivity { /** @@ -62,6 +67,7 @@ public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + changeAppLanguage(getAppLanguage(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 449a790e842..b8bfcf48066 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -15,9 +15,14 @@ import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.ThemeHelper; +import java.util.Locale; + 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; + public class DownloadActivity extends AppCompatActivity { private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag"; @@ -29,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) { i.setClass(this, DownloadManagerService.class); startService(i); + changeAppLanguage(getAppLanguage(getApplicationContext()), getResources()); ThemeHelper.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_downloader); diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 0c7a4b46e62..88c70058220 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -56,6 +56,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { private Localization initialSelectedLocalization; private ContentCountry initialSelectedContentCountry; + private String initialLanguage; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -64,6 +65,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { initialSelectedLocalization = org.schabi.newpipe.util.Localization.getPreferredLocalization(requireContext()); initialSelectedContentCountry = org.schabi.newpipe.util.Localization.getPreferredContentCountry(requireContext()); + initialLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en"); } @Override @@ -125,9 +127,10 @@ public void onDestroy() { .getPreferredLocalization(requireContext()); final ContentCountry selectedContentCountry = org.schabi.newpipe.util.Localization .getPreferredContentCountry(requireContext()); + final String selectedLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en"); if (!selectedLocalization.equals(initialSelectedLocalization) - || !selectedContentCountry.equals(initialSelectedContentCountry)) { + || !selectedContentCountry.equals(initialSelectedContentCountry) || !selectedLanguage.equals(initialLanguage)) { Toast.makeText(requireContext(), R.string.localization_changes_requires_app_restart, Toast.LENGTH_LONG).show(); NewPipe.setupLocalization(selectedLocalization, selectedContentCountry); 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 a3f218074dc..40af9f46099 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -14,6 +14,11 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.util.ThemeHelper; +import java.util.Locale; + +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLanguage; + /* * Created by Christian Schabesberger on 31.08.15. @@ -44,7 +49,7 @@ public static void initSettings(Context context) { @Override protected void onCreate(Bundle savedInstanceBundle) { setTheme(ThemeHelper.getSettingsThemeStyle(this)); - + changeAppLanguage(getAppLanguage(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 6b0b4cd0c69..7d742b04a51 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -7,6 +7,11 @@ import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.PluralsRes; +import androidx.annotation.StringRes; import org.ocpsoft.prettytime.PrettyTime; import org.ocpsoft.prettytime.units.Decade; @@ -21,10 +26,6 @@ import java.util.List; import java.util.Locale; -import androidx.annotation.NonNull; -import androidx.annotation.PluralsRes; -import androidx.annotation.StringRes; - /* * Created by chschtsch on 12/29/15. * @@ -226,4 +227,21 @@ public static void changeAppLanguage(Locale loc, Resources res) { conf.setLocale(loc); res.updateConfiguration(conf, dm); } + + public static Locale getAppLanguage(Context context) { + SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context); + String lang = prefs.getString("newpipes_language_key", "en"); + Locale loc; + if (lang.equals("system")) { + loc = Locale.getDefault(); + } else if (lang.matches(".*-.*")) { + String[] localisation = lang.split("-"); + lang = localisation[0]; + String country = localisation[1]; + loc = new Locale(lang, country); + } else { + loc = new Locale(lang); + } + return loc; + } } diff --git a/app/src/main/res/values-ur/strings.xml b/app/src/main/res/values-ur/strings.xml index 089b793c8d0..ce6f3f65165 100644 --- a/app/src/main/res/values-ur/strings.xml +++ b/app/src/main/res/values-ur/strings.xml @@ -193,13 +193,13 @@ بی کوئی صارفین نہیں - % s صارف - % s صارفین + %s صارف + %s صارفین کوئی مناظر نہیں - % s منظر - % s مناظر + %s منظر + %s مناظر ویڈیوز دستیاب نہیں @@ -388,7 +388,7 @@ کوئی حد نہیں موبائل ڈیٹا کا استعمال کرتے وقت ریذولوشن کو محدود کریں ایپ سوئچ کو کم سے کم کریں - اہم ویڈیو پلیئر سے دوسرے ایپ میں سوئچنگ کرتے وقت کارروائی-% s + اہم ویڈیو پلیئر سے دوسرے ایپ میں سوئچنگ کرتے وقت کارروائی-s% کوئی نہیں پس منظری پلیر میں کم کریں پاپ اپ پلیر میں کم کریں diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 3f361226d02..299803a4325 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -31,20 +31,20 @@ seek_duration 10000 - 5 seconds - 10 seconds - 15 seconds - 20 seconds - 25 seconds - 30 seconds + 5 seconds + 10 seconds + 15 seconds + 20 seconds + 25 seconds + 30 seconds - 5000 - 10000 - 15000 - 20000 - 25000 - 30000 + 5000 + 10000 + 15000 + 20000 + 25000 + 30000 minimize_on_exit_key @@ -175,6 +175,7 @@ main_page_content enable_playback_resume enable_playback_state_lists + newpipes_language_key import_data export_data @@ -272,7 +273,6 @@ cs da de - eo et en-GB en @@ -352,7 +352,6 @@ Čeština Dansk Deutsch - Esperanto Eesti English (UK) English (US) @@ -925,6 +924,137 @@ ZW + + + system + ar + az + ast + be + bg-bd + bn + ca + cs + da + de + el + en + eo + es + et + eu + fa + fi + fil + fr + gl + he + hi + hr + hu + hy + ia + ind + it + ja + ko + ku + lt + mk + ms + nb-no + ne + nl + nl-be + pa + pl + pr + pt + pt-br + ro + ru + sk + sl + sq + sr + sv + ta + te + th + tr + uk + ur + vi + zh + zh-hans + zh-tw + + + @string/system + العربية + Azərbaycan dili + Asturianu + Беларуская + български език + বাংলা + Català + Čeština + Dansk + Deutsch + Ελληνικά + English + Esperanto + Español + Eesti keel + Euskara + فارسی + Suomen kieli + Wikang Filipino + Français + Galego + עברית + हिन्दी + Hrvatski + magyar + Հայերեն + Interlingua + Bahasa Indonesia + Italiano + 日本語 + 한국어 + کوردی + Lietuvių kalba + македонски јазик + Bahasa Melayu + Norsk bokmål + Nनेपाली + Nederlands (NL) + Nederlands (BE) + ਪੰਜਾਬੀ + Polski + Pirate Language + Português (PT) + Português (BR) + Română + русский язык + Slovenčina + Slovenščina + Shqip + Српски + Svenska + தமிழ் + తెలుగు + ไทย + Türkçe + українська мова + اردو + Tiếng Việt + 官话 + 简化字 + 臺灣華語 + + + limit_mobile_data_usage limit_data_usage_none @@ -943,6 +1073,7 @@ list_view_mode auto + System auto diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6021df15ef8..12a96fe741d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -585,5 +585,6 @@ Use SAF The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible Choose an instance + NewPipe\'s language diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 4044e92d80b..ab9896cdede 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -3,6 +3,16 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:title="@string/content"> + + + Date: Thu, 9 Jan 2020 12:15:01 +0100 Subject: [PATCH 03/17] removed unused imports --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 1 - app/src/main/java/org/schabi/newpipe/about/AboutActivity.java | 2 -- .../main/java/org/schabi/newpipe/download/DownloadActivity.java | 2 -- .../main/java/org/schabi/newpipe/settings/SettingsActivity.java | 2 -- 4 files changed, 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 05e22401322..eb5f11987ac 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -76,7 +76,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Locale; import static org.schabi.newpipe.util.Localization.changeAppLanguage; import static org.schabi.newpipe.util.Localization.getAppLanguage; 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 4da1611d348..3555ecefe48 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -25,8 +25,6 @@ import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ThemeHelper; -import java.util.Locale; - import static org.schabi.newpipe.util.Localization.changeAppLanguage; import static org.schabi.newpipe.util.Localization.getAppLanguage; 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 b8bfcf48066..bf546bf858b 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -15,8 +15,6 @@ import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.ThemeHelper; -import java.util.Locale; - import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.ui.fragment.MissionsFragment; 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 40af9f46099..781c033b886 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -14,8 +14,6 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.util.ThemeHelper; -import java.util.Locale; - import static org.schabi.newpipe.util.Localization.changeAppLanguage; import static org.schabi.newpipe.util.Localization.getAppLanguage; From b32935a1b087bbc6d19fb7e50493273796d2ffb4 Mon Sep 17 00:00:00 2001 From: bopol Date: Thu, 9 Jan 2020 15:51:41 +0100 Subject: [PATCH 04/17] 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 7f050e6c7c4..dae143b6cd0 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 void onCreate() { 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 eb5f11987ac..d48db1035de 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.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.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 @@ protected void onCreate(Bundle savedInstanceState) { } 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 @@ protected void onDestroy() { @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 3555ecefe48..795feceb033 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.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 bf546bf858b..fd0d28a0e4e 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.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 @@ protected void onCreate(Bundle savedInstanceState) { 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 781c033b886..6804f9831ad 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.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 static void initSettings(Context context) { @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 7d742b04a51..695a73295bd 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.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 static String getDurationString(long duration) { // 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 static void changeAppLanguage(Locale loc, Resources res) { 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; From 8f46432391578b6602cea69ef344817857f75a7e Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 10 Jan 2020 15:50:15 +0100 Subject: [PATCH 05/17] fixed some activities where the wrong languages would be set --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 1 - .../java/org/schabi/newpipe/about/AboutActivity.java | 1 + .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 4 +++- .../java/org/schabi/newpipe/player/MainVideoPlayer.java | 9 +++++++-- .../java/org/schabi/newpipe/player/PopupVideoPlayer.java | 3 +++ .../org/schabi/newpipe/player/ServicePlayerActivity.java | 3 +++ .../java/org/schabi/newpipe/report/ErrorActivity.java | 4 ++++ .../main/java/org/schabi/newpipe/util/Localization.java | 4 ---- 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index d48db1035de..c5aedb85b00 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -119,7 +119,6 @@ protected void onCreate(Bundle savedInstanceState) { ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); - super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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 795feceb033..c8c62bbe771 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -68,6 +68,7 @@ protected void onCreate(Bundle savedInstanceState) { changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); + this.setTitle(getString(R.string.title_activity_about)); setContentView(R.layout.activity_about); diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 76da7da3676..c748821616f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -58,6 +58,8 @@ import org.schabi.newpipe.util.ThemeHelper; import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; /** @@ -115,7 +117,7 @@ public void onCreate() { notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); lockManager = new LockManager(this); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); ThemeHelper.setTheme(this); basePlayerImpl = new BasePlayerImpl(this); basePlayerImpl.setup(); diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 7a3e60c660e..284d10b4248 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -93,6 +93,8 @@ import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA; import static org.schabi.newpipe.util.AnimationUtils.animateRotation; import static org.schabi.newpipe.util.AnimationUtils.animateView; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; import static org.schabi.newpipe.util.StateSaver.KEY_SAVED_STATE; /** @@ -123,6 +125,7 @@ public final class MainVideoPlayer extends AppCompatActivity @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -190,6 +193,7 @@ protected void onNewIntent(Intent intent) { @Override protected void onResume() { if (DEBUG) Log.d(TAG, "onResume() called"); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onResume(); if (globalScreenOrientationLocked()) { @@ -220,6 +224,7 @@ protected void onResume() { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); if (playerImpl.isSomePopupMenuVisible()) { playerImpl.getQualityPopupMenu().dismiss(); @@ -364,8 +369,8 @@ private void setLandscape(boolean v) { } private boolean globalScreenOrientationLocked() { - // 1: Screen orientation changes using acelerometer - // 0: Screen orientatino is locked + // 1: Screen orientation changes using accelerometer + // 0: Screen orientation is locked return !(android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1); } diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 969c479906d..b173448d0dc 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -80,6 +80,8 @@ import static org.schabi.newpipe.player.VideoPlayer.DEFAULT_CONTROLS_DURATION; import static org.schabi.newpipe.player.VideoPlayer.DEFAULT_CONTROLS_HIDE_TIME; import static org.schabi.newpipe.util.AnimationUtils.animateView; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; /** * Service Popup Player implementing VideoPlayer @@ -142,6 +144,7 @@ public final class PopupVideoPlayer extends Service { @Override public void onCreate() { + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 2207808ac04..d5ee59a7e4d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -46,6 +46,8 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatPitch; import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; public abstract class ServicePlayerActivity extends AppCompatActivity implements PlayerEventListener, SeekBar.OnSeekBarChangeListener, @@ -116,6 +118,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); setContentView(R.layout.activity_player_queue_control); diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java index e7a6319e36a..05dfe33ca88 100644 --- a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java @@ -46,6 +46,9 @@ import java.util.TimeZone; import java.util.Vector; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; + /* * Created by Christian Schabesberger on 24.10.15. * @@ -171,6 +174,7 @@ private static String[] elToSl(List stackTraces) { @Override protected void onCreate(Bundle savedInstanceState) { + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); setContentView(R.layout.activity_error); 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 695a73295bd..3f555fcfdd3 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -209,10 +209,6 @@ private static void initPrettyTime(Context context) { } private static PrettyTime getPrettyTime() { - // If pretty time's Locale is different, init again with the new one. -// if (!prettyTime.getLocale().equals(Locale.getDefault())) { -// initPrettyTime(); -// } return prettyTime; } From 11d06dc86d8e1f0e2614251a1359e36dd537a81c Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 10 Jan 2020 16:03:24 +0100 Subject: [PATCH 06/17] remove todo as it's already done --- app/src/main/res/values/settings_keys.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 4bb66bf627e..18f42fe4603 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -1054,7 +1054,6 @@ 官话 简化字 臺灣華語 - From f8a7aac40d0e7e1a6558753e012dabd6f97d7df7 Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 14 Jan 2020 14:15:42 +0100 Subject: [PATCH 07/17] fixed indonesian, see https://stackoverflow.com/questions/13291578/how-to-localize-an-android-app-in-indonesian-language --- app/src/main/res/{values-id => values-in}/strings.xml | 0 app/src/main/res/values/settings_keys.xml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename app/src/main/res/{values-id => values-in}/strings.xml (100%) diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-in/strings.xml similarity index 100% rename from app/src/main/res/values-id/strings.xml rename to app/src/main/res/values-in/strings.xml diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 18f42fe4603..88da3afe53a 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -956,7 +956,7 @@ hu hy ia - ind + in it ja ko From 055365a44931b65e9fffd0d5d57595fe3be40abb Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 14 Jan 2020 14:26:53 +0100 Subject: [PATCH 08/17] added Occitan to the selector --- app/src/main/res/values/settings_keys.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 88da3afe53a..08b18f49b96 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -968,6 +968,7 @@ ne nl nl-be + oc pa pl pr @@ -1032,6 +1033,7 @@ Nनेपाली Nederlands (NL) Nederlands (BE) + Occitan ਪੰਜਾਬੀ Polski Pirate Language From 105981b2eb426b598f81694442621e8b695a642e Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 14 Jan 2020 19:11:46 +0100 Subject: [PATCH 09/17] made system translatable + renamed it to system's language --- app/src/main/res/values/settings_keys.xml | 3 +-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 08b18f49b96..ed3c454b830 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -993,7 +993,7 @@ zh-tw - @string/system + @string/systems_language العربية Azərbaycan dili Asturianu @@ -1076,7 +1076,6 @@ list_view_mode auto - System auto diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8a44fdc64c5..c5a59abe773 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -590,4 +590,5 @@ The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible Choose an instance NewPipe\'s language + System\'s language From 9d8fcbbffe7ade9e662ab94e1a5a539a7e4e7d04 Mon Sep 17 00:00:00 2001 From: B0pol Date: Wed, 15 Jan 2020 08:33:57 +0100 Subject: [PATCH 10/17] fix: wrong language shown when rotating screen in popup player --- .../main/java/org/schabi/newpipe/player/PopupVideoPlayer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index b173448d0dc..c0ac9544512 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -172,6 +172,7 @@ public int onStartCommand(final Intent intent, int flags, int startId) { @Override public void onConfigurationChanged(Configuration newConfig) { + changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); if (DEBUG) Log.d(TAG, "onConfigurationChanged() called with: newConfig = [" + newConfig + "]"); updateScreenSize(); updatePopupSize(popupLayoutParams.width, -1); From b155f23d276ebc48ffe5fe86759320b6751ac512 Mon Sep 17 00:00:00 2001 From: bopol Date: Sat, 18 Jan 2020 09:46:38 +0100 Subject: [PATCH 11/17] fix: wrong language shown in playback parameters dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hardly reproduceable bug that I hopefully fixed. After a long time of watching videos, you could have your system language shown in playback parameters dialog. Calling changeAppLanguage(getAppLocale(…),…) onCreate will most certainly fix this bug --- .../schabi/newpipe/player/helper/PlaybackParameterDialog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 4feed74fee9..2aefa675e3d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -17,6 +17,8 @@ import org.schabi.newpipe.util.SliderStrategy; import static org.schabi.newpipe.player.BasePlayer.DEBUG; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; +import static org.schabi.newpipe.util.Localization.getAppLocale; public class PlaybackParameterDialog extends DialogFragment { @NonNull private static final String TAG = "PlaybackParameterDialog"; @@ -108,6 +110,7 @@ public void onAttach(Context context) { @Override public void onCreate(@Nullable Bundle savedInstanceState) { + changeAppLanguage(getAppLocale(getContext()), getResources()); super.onCreate(savedInstanceState); if (savedInstanceState != null) { initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO); @@ -137,6 +140,7 @@ public void onSaveInstanceState(Bundle outState) { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + changeAppLanguage(getAppLocale(getContext()), getResources()); final View view = View.inflate(getContext(), R.layout.dialog_playback_parameter, null); setupControlViews(view); From e08e7245738ca8ee5dab4dc5801dc6d35399873a Mon Sep 17 00:00:00 2001 From: bopol Date: Sat, 18 Jan 2020 10:46:53 +0100 Subject: [PATCH 12/17] upload date in description now matches newpipe's language --- .../main/java/org/schabi/newpipe/util/Localization.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 3f555fcfdd3..d2fbd3a6511 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.util; +import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -118,12 +119,13 @@ public static String localizeNumber(Context context, long number) { return nf.format(number); } - public static String formatDate(Date date) { - return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(date); + public static String formatDate(Date date, Context context) { + return DateFormat.getDateInstance(DateFormat.MEDIUM, getAppLocale(context)).format(date); } + @SuppressLint("StringFormatInvalid") public static String localizeUploadDate(Context context, Date date) { - return context.getString(R.string.upload_date_text, formatDate(date)); + return context.getString(R.string.upload_date_text, formatDate(date, context)); } public static String localizeViewCount(Context context, long viewCount) { From 156a2eb4ffe7479333536f3195ed3ceee63fa7f1 Mon Sep 17 00:00:00 2001 From: bopol Date: Mon, 27 Jan 2020 19:32:40 +0100 Subject: [PATCH 13/17] update prettytime dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see https://github.com/TeamNewPipe/NewPipe/pull/2921#issuecomment-572601812 It will add Esperanto, add bengali, update vietnamese pretty time is the library used in the home page: … days ago --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 0ca03f158fd..f8fc1565fcf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -94,7 +94,7 @@ dependencies { implementation 'io.reactivex.rxjava2:rxjava:2.2.2' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1' - implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final' + implementation 'org.ocpsoft.prettytime:prettytime:4.0.3.Final' implementation "androidx.room:room-runtime:${roomDbLibVersion}" implementation "androidx.room:room-rxjava2:${roomDbLibVersion}" From edc9d47da795efbc1606efae50788bdc81f4468b Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 28 Jan 2020 20:48:42 +0100 Subject: [PATCH 14/17] app language: refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renamed NewPipe's language into App language, and same for all the concerning thing (keys, comments…) we now call assureCorrectAppLanguage(CONTEXT) in activities needing it instead of changeAppLanguage(getAppLocale(CONTEXT), RESOURCES) changeAppLanguage becomes private. --- app/src/main/java/org/schabi/newpipe/MainActivity.java | 8 +++----- .../java/org/schabi/newpipe/about/AboutActivity.java | 6 ++---- .../org/schabi/newpipe/download/DownloadActivity.java | 6 ++---- .../org/schabi/newpipe/player/BackgroundPlayer.java | 6 ++---- .../org/schabi/newpipe/player/MainVideoPlayer.java | 9 ++++----- .../org/schabi/newpipe/player/PopupVideoPlayer.java | 7 +++---- .../schabi/newpipe/player/ServicePlayerActivity.java | 5 ++--- .../newpipe/player/helper/PlaybackParameterDialog.java | 7 +++---- .../java/org/schabi/newpipe/report/ErrorActivity.java | 5 ++--- .../org/schabi/newpipe/settings/SettingsActivity.java | 6 ++---- .../java/org/schabi/newpipe/util/Localization.java | 10 ++++++++-- app/src/main/res/values/settings_keys.xml | 8 ++++---- app/src/main/res/values/strings.xml | 4 ++-- app/src/main/res/xml/content_settings.xml | 8 ++++---- 14 files changed, 43 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 63bc8df15c8..7cd620faa2e 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -31,7 +31,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.Window; @@ -78,8 +77,7 @@ import java.util.ArrayList; import java.util.List; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @@ -118,7 +116,7 @@ protected void onCreate(Bundle savedInstanceState) { } ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -422,7 +420,7 @@ protected void onDestroy() { @Override protected void onResume() { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); Localization.init(getApplicationContext()); //change the date format to match the selected language on resume super.onResume(); 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 4d9cfc7e142..9e23d9d3d7d 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -22,11 +22,9 @@ import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; -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.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; public class AboutActivity extends AppCompatActivity { @@ -65,7 +63,7 @@ public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); this.setTitle(getString(R.string.title_activity_about)); 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 7aaaeeb174c..00dd45ac90d 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -12,14 +12,12 @@ import android.view.ViewTreeObserver; import org.schabi.newpipe.R; -import org.schabi.newpipe.settings.SettingsActivity; import org.schabi.newpipe.util.ThemeHelper; 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.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; public class DownloadActivity extends AppCompatActivity { @@ -32,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) { i.setClass(this, DownloadManagerService.class); startService(i); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); ThemeHelper.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_downloader); diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index c748821616f..9e23d9145f2 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -58,9 +58,7 @@ import org.schabi.newpipe.util.ThemeHelper; import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; - +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; /** * Base players joining the common properties @@ -117,7 +115,7 @@ public void onCreate() { notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); lockManager = new LockManager(this); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); ThemeHelper.setTheme(this); basePlayerImpl = new BasePlayerImpl(this); basePlayerImpl.setup(); diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 487629c126a..31f7dd74a63 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -95,8 +95,7 @@ import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA; import static org.schabi.newpipe.util.AnimationUtils.animateRotation; import static org.schabi.newpipe.util.AnimationUtils.animateView; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import static org.schabi.newpipe.util.StateSaver.KEY_SAVED_STATE; /** @@ -127,7 +126,7 @@ public final class MainVideoPlayer extends AppCompatActivity @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -195,7 +194,7 @@ protected void onNewIntent(Intent intent) { @Override protected void onResume() { if (DEBUG) Log.d(TAG, "onResume() called"); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onResume(); if (globalScreenOrientationLocked()) { @@ -226,7 +225,7 @@ protected void onResume() { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); if (playerImpl.isSomePopupMenuVisible()) { playerImpl.getQualityPopupMenu().dismiss(); diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 96bc606cc39..fc14e8d5102 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -80,8 +80,7 @@ import static org.schabi.newpipe.player.VideoPlayer.DEFAULT_CONTROLS_DURATION; import static org.schabi.newpipe.player.VideoPlayer.DEFAULT_CONTROLS_HIDE_TIME; import static org.schabi.newpipe.util.AnimationUtils.animateView; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; /** * Service Popup Player implementing VideoPlayer @@ -144,7 +143,7 @@ public final class PopupVideoPlayer extends Service { @Override public void onCreate() { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); @@ -172,7 +171,7 @@ public int onStartCommand(final Intent intent, int flags, int startId) { @Override public void onConfigurationChanged(Configuration newConfig) { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); if (DEBUG) Log.d(TAG, "onConfigurationChanged() called with: newConfig = [" + newConfig + "]"); updateScreenSize(); updatePopupSize(popupLayoutParams.width, -1); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 1c6d786cd37..669d1c16c0b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -46,8 +46,7 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatPitch; import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; public abstract class ServicePlayerActivity extends AppCompatActivity implements PlayerEventListener, SeekBar.OnSeekBarChangeListener, @@ -118,7 +117,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); setContentView(R.layout.activity_player_queue_control); diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 2aefa675e3d..3ada3a6be85 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -17,8 +17,7 @@ import org.schabi.newpipe.util.SliderStrategy; import static org.schabi.newpipe.player.BasePlayer.DEBUG; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; public class PlaybackParameterDialog extends DialogFragment { @NonNull private static final String TAG = "PlaybackParameterDialog"; @@ -110,7 +109,7 @@ public void onAttach(Context context) { @Override public void onCreate(@Nullable Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getContext()), getResources()); + assureCorrectAppLanguage(getContext()); super.onCreate(savedInstanceState); if (savedInstanceState != null) { initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO); @@ -140,7 +139,7 @@ public void onSaveInstanceState(Bundle outState) { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getContext()), getResources()); + assureCorrectAppLanguage(getContext()); final View view = View.inflate(getContext(), R.layout.dialog_playback_parameter, null); setupControlViews(view); diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java index 05dfe33ca88..4512ab3a610 100644 --- a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java @@ -46,8 +46,7 @@ import java.util.TimeZone; import java.util.Vector; -import static org.schabi.newpipe.util.Localization.changeAppLanguage; -import static org.schabi.newpipe.util.Localization.getAppLocale; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; /* * Created by Christian Schabesberger on 24.10.15. @@ -174,7 +173,7 @@ private static String[] elToSl(List stackTraces) { @Override protected void onCreate(Bundle savedInstanceState) { - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this); setContentView(R.layout.activity_error); 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 6804f9831ad..53d60f86cc8 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -14,9 +14,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.getAppLocale; - +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; /* * Created by Christian Schabesberger on 31.08.15. @@ -47,7 +45,7 @@ public static void initSettings(Context context) { @Override protected void onCreate(Bundle savedInstanceBundle) { setTheme(ThemeHelper.getSettingsThemeStyle(this)); - changeAppLanguage(getAppLocale(getApplicationContext()), getResources()); + assureCorrectAppLanguage(this); 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 d2fbd3a6511..6149118cc36 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -218,7 +218,7 @@ public static String relativeTime(Calendar calendarTime) { return getPrettyTime().formatUnrounded(calendarTime); } - public static void changeAppLanguage(Locale loc, Resources res) { + private static void changeAppLanguage(Locale loc, Resources res) { DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.setLocale(loc); @@ -227,11 +227,13 @@ public static void changeAppLanguage(Locale loc, Resources res) { public static Locale getAppLocale(Context context) { SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context); - String lang = prefs.getString("newpipes_language_key", "en"); + String lang = prefs.getString("app_language_key", "en"); Locale loc; if (lang.equals("system")) { loc = Locale.getDefault(); } else if (lang.matches(".*-.*")) { + //to differentiate different versions of the language + //for example, pt (portuguese in Portugal) and pt-br (portuguese in Brazil) String[] localisation = lang.split("-"); lang = localisation[0]; String country = localisation[1]; @@ -241,4 +243,8 @@ public static Locale getAppLocale(Context context) { } return loc; } + + public static void assureCorrectAppLanguage(Context c) { + changeAppLanguage(getAppLocale(c), c.getResources()); + } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index ed3c454b830..1a7d61daed6 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -176,7 +176,7 @@ enable_playback_resume enable_playback_state_lists - newpipes_language_key + app_language_key enable_lock_screen_video_thumbnail import_data @@ -926,8 +926,8 @@ ZW - - + + system ar az @@ -992,7 +992,7 @@ zh-hans zh-tw - + @string/systems_language العربية Azərbaycan dili diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5a59abe773..29864963f14 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -589,6 +589,6 @@ Use SAF The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible Choose an instance - NewPipe\'s language - System\'s language + App language + System default diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index ab9896cdede..197c144873b 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -7,11 +7,11 @@ + android:title="@string/app_language_title"/> Date: Fri, 31 Jan 2020 22:49:43 +0100 Subject: [PATCH 15/17] fix wrong language shown many popup dialogs Changed android.R.string.ok, which is "OK", into R.string.finish, which is also OK, but from our strings Then for a small amount of languages that don't have Android translation, it will show the good string. --- .../newpipe/about/LicenseFragmentHelper.java | 15 +++++++----- .../newpipe/download/DownloadDialog.java | 24 +++++++++++-------- .../ImportConfirmationDialog.java | 5 +++- .../settings/ContentSettingsFragment.java | 12 ++++++---- .../settings/DownloadSettingsFragment.java | 10 +++++--- .../giga/ui/adapter/MissionAdapter.java | 2 +- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java index eeafc1f57b6..9a11b19cc6c 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.content.res.Resources; import android.os.AsyncTask; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -14,6 +15,8 @@ import java.io.InputStreamReader; import java.lang.ref.WeakReference; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class LicenseFragmentHelper extends AsyncTask { final WeakReference weakReference; @@ -55,15 +58,15 @@ protected void onPostExecute(Integer result) { wv.loadData(webViewData, "text/html; charset=UTF-8", null); alert.setView(wv); - alert.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); + assureCorrectAppLanguage(activity.getApplicationContext()); + alert.setNegativeButton(getFinishString(activity), (dialog, which) -> dialog.dismiss()); alert.show(); } + private static String getFinishString(Activity activity) { + return activity.getApplicationContext().getResources().getString(R.string.finish); + } + /** * @param context the context to use * @param license the license diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 44966744be4..c78e68597d7 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -11,15 +11,6 @@ import android.os.Environment; import android.os.IBinder; import android.preference.PreferenceManager; -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.fragment.app.DialogFragment; -import androidx.documentfile.provider.DocumentFile; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.view.menu.ActionMenuItemView; -import androidx.appcompat.widget.Toolbar; import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; @@ -34,6 +25,16 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.IdRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.menu.ActionMenuItemView; +import androidx.appcompat.widget.Toolbar; +import androidx.documentfile.provider.DocumentFile; +import androidx.fragment.app.DialogFragment; + import com.nononsenseapps.filepicker.Utils; import org.schabi.newpipe.MainActivity; @@ -78,6 +79,8 @@ import us.shandian.giga.service.DownloadManagerService.DownloadManagerBinder; import us.shandian.giga.service.MissionState; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheckedChangeListener, AdapterView.OnItemSelectedListener { private static final String TAG = "DialogFragment"; private static final boolean DEBUG = MainActivity.DEBUG; @@ -527,10 +530,11 @@ private String getNameEditText() { } private void showFailedDialog(@StringRes int msg) { + assureCorrectAppLanguage(getContext()); new AlertDialog.Builder(context) .setTitle(R.string.general_error) .setMessage(msg) - .setNegativeButton(android.R.string.ok, null) + .setNegativeButton(getString(R.string.finish), null) .create() .show(); } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java b/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java index fbcf5d70e36..a44efa1d3ba 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/ImportConfirmationDialog.java @@ -15,6 +15,8 @@ import icepick.Icepick; import icepick.State; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class ImportConfirmationDialog extends DialogFragment { @State protected Intent resultServiceIntent; @@ -34,11 +36,12 @@ public static void show(@NonNull Fragment fragment, @NonNull Intent resultServic @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + assureCorrectAppLanguage(getContext()); return new AlertDialog.Builder(getContext(), ThemeHelper.getDialogTheme(getContext())) .setMessage(R.string.import_network_expensive_warning) .setCancelable(true) .setNegativeButton(R.string.cancel, null) - .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + .setPositiveButton(R.string.finish, (dialogInterface, i) -> { if (resultServiceIntent != null && getContext() != null) { getContext().startService(resultServiceIntent); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 88c70058220..dc6ccb0a02c 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -7,11 +7,12 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; -import android.util.Log; -import android.widget.Toast; import com.nononsenseapps.filepicker.Utils; import com.nostra13.universalimageloader.core.ImageLoader; @@ -40,6 +41,8 @@ import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class ContentSettingsFragment extends BasePreferenceFragment { private static final int REQUEST_IMPORT_PATH = 8945; @@ -139,6 +142,7 @@ public void onDestroy() { @Override public void onActivityResult(int requestCode, int resultCode, @NonNull Intent data) { + assureCorrectAppLanguage(getContext()); super.onActivityResult(requestCode, resultCode, data); if (DEBUG) { Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); @@ -153,7 +157,7 @@ public void onActivityResult(int requestCode, int resultCode, @NonNull Intent da } else { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(R.string.override_current_data) - .setPositiveButton(android.R.string.ok, + .setPositiveButton(getString(R.string.finish), (DialogInterface d, int id) -> importDatabase(path)) .setNegativeButton(android.R.string.cancel, (DialogInterface d, int id) -> d.cancel()); @@ -248,7 +252,7 @@ private void importDatabase(String filePath) { // restart app to properly load db System.exit(0); }); - alert.setPositiveButton(android.R.string.yes, (dialog, which) -> { + alert.setPositiveButton(getString(R.string.finish), (dialog, which) -> { dialog.dismiss(); loadSharedPreferences(newpipe_settings); // restart app to properly load db diff --git a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java index 8becc79a8d2..b8ce0ec184a 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DownloadSettingsFragment.java @@ -8,11 +8,12 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.preference.Preference; -import android.util.Log; -import android.widget.Toast; import com.nononsenseapps.filepicker.Utils; @@ -28,6 +29,8 @@ import us.shandian.giga.io.StoredDirectoryHelper; +import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; + public class DownloadSettingsFragment extends BasePreferenceFragment { private static final int REQUEST_DOWNLOAD_VIDEO_PATH = 0x1235; private static final int REQUEST_DOWNLOAD_AUDIO_PATH = 0x1236; @@ -159,7 +162,7 @@ private void showMessageDialog(@StringRes int title, @StringRes int message) { AlertDialog.Builder msg = new AlertDialog.Builder(ctx); msg.setTitle(title); msg.setMessage(message); - msg.setPositiveButton(android.R.string.ok, null); + msg.setPositiveButton(getString(R.string.finish), null); msg.show(); } @@ -202,6 +205,7 @@ public boolean onPreferenceTreeClick(Preference preference) { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + assureCorrectAppLanguage(getContext()); super.onActivityResult(requestCode, resultCode, data); if (DEBUG) { Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], " + diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index aaf7826ef0a..852c29835b0 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -534,7 +534,7 @@ private void showError(@NonNull DownloadMission mission) { ); } - builder.setNegativeButton(android.R.string.ok, (dialog, which) -> dialog.cancel()) + builder.setNegativeButton(R.string.finish, (dialog, which) -> dialog.cancel()) .setTitle(mission.storage.getName()) .create() .show(); From 55a138e8da10ffb7b9a18b9ee602c20f2ef4b307 Mon Sep 17 00:00:00 2001 From: bopol Date: Sat, 1 Feb 2020 15:30:51 +0100 Subject: [PATCH 16/17] fix toast on app language change I forgot to change the key here when I renamed it --- .../org/schabi/newpipe/settings/ContentSettingsFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index dc6ccb0a02c..5abdd680621 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -68,7 +68,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { initialSelectedLocalization = org.schabi.newpipe.util.Localization.getPreferredLocalization(requireContext()); initialSelectedContentCountry = org.schabi.newpipe.util.Localization.getPreferredContentCountry(requireContext()); - initialLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en"); + initialLanguage = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("app_language_key", "en"); } @Override @@ -130,7 +130,7 @@ public void onDestroy() { .getPreferredLocalization(requireContext()); final ContentCountry selectedContentCountry = org.schabi.newpipe.util.Localization .getPreferredContentCountry(requireContext()); - final String selectedLanguage = androidx.preference.PreferenceManager.getDefaultSharedPreferences(getContext()).getString("newpipes_language_key", "en"); + final String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("app_language_key", "en"); if (!selectedLocalization.equals(initialSelectedLocalization) || !selectedContentCountry.equals(initialSelectedContentCountry) || !selectedLanguage.equals(initialLanguage)) { From d36ac7a5dee1c460e5bf06dd291f292830e77dd4 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sat, 1 Feb 2020 15:35:33 +0100 Subject: [PATCH 17/17] Improve formatting --- .../schabi/newpipe/settings/ContentSettingsFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 5abdd680621..03d48ca5b5f 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -196,7 +196,7 @@ private void saveSharedPreferencesToFile(File dst) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - }finally { + } finally { try { if (output != null) { output.flush(); @@ -243,7 +243,7 @@ private void importDatabase(String filePath) { } //If settings file exist, ask if it should be imported. - if(ZipHelper.extractFileFromZip(filePath, newpipe_settings.getPath(), "newpipe.settings")) { + if (ZipHelper.extractFileFromZip(filePath, newpipe_settings.getPath(), "newpipe.settings")) { AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); alert.setTitle(R.string.import_settings); @@ -298,7 +298,7 @@ else if (v instanceof String) e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); - }finally { + } finally { try { if (input != null) { input.close();