app language: refactoring
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.
This commit is contained in:
parent
156a2eb4ff
commit
edc9d47da7
|
@ -31,7 +31,6 @@ import android.preference.PreferenceManager;
|
|||
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 org.schabi.newpipe.util.ThemeHelper;
|
|||
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 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
assureCorrectAppLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
@ -422,7 +420,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@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();
|
||||
|
||||
|
|
|
@ -22,11 +22,9 @@ import android.widget.TextView;
|
|||
|
||||
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));
|
||||
|
|
|
@ -12,14 +12,12 @@ import android.view.MenuItem;
|
|||
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 @@ public class DownloadActivity extends AppCompatActivity {
|
|||
i.setClass(this, DownloadManagerService.class);
|
||||
startService(i);
|
||||
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
assureCorrectAppLanguage(this);
|
||||
ThemeHelper.setTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_downloader);
|
||||
|
|
|
@ -58,9 +58,7 @@ import org.schabi.newpipe.util.NavigationHelper;
|
|||
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 final class BackgroundPlayer extends Service {
|
|||
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();
|
||||
|
|
|
@ -95,8 +95,7 @@ import static org.schabi.newpipe.util.AnimationUtils.Type.SCALE_AND_ALPHA;
|
|||
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 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||
@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 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
assureCorrectAppLanguage(this);
|
||||
|
||||
if (playerImpl.isSomePopupMenuVisible()) {
|
||||
playerImpl.getQualityPopupMenu().dismiss();
|
||||
|
|
|
@ -80,8 +80,7 @@ import static org.schabi.newpipe.player.BasePlayer.STATE_PLAYING;
|
|||
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 final class PopupVideoPlayer extends Service {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -46,8 +46,7 @@ import java.util.List;
|
|||
|
||||
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);
|
||||
|
|
|
@ -17,8 +17,7 @@ import org.schabi.newpipe.R;
|
|||
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 class PlaybackParameterDialog extends DialogFragment {
|
|||
|
||||
@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 class PlaybackParameterDialog extends DialogFragment {
|
|||
@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);
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ import java.util.List;
|
|||
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 @@ public class ErrorActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
assureCorrectAppLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeHelper.setTheme(this);
|
||||
setContentView(R.layout.activity_error);
|
||||
|
|
|
@ -14,9 +14,7 @@ import android.view.MenuItem;
|
|||
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 class SettingsActivity extends AppCompatActivity implements BasePreferenc
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
setTheme(ThemeHelper.getSettingsThemeStyle(this));
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
assureCorrectAppLanguage(this);
|
||||
super.onCreate(savedInstanceBundle);
|
||||
setContentView(R.layout.settings_layout);
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ public class Localization {
|
|||
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 class Localization {
|
|||
|
||||
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 class Localization {
|
|||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
public static void assureCorrectAppLanguage(Context c) {
|
||||
changeAppLanguage(getAppLocale(c), c.getResources());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@
|
|||
<string name="enable_playback_resume_key" translatable="false">enable_playback_resume</string>
|
||||
<string name="enable_playback_state_lists_key" translatable="false">enable_playback_state_lists</string>
|
||||
|
||||
<string name="newpipes_language_key" translatable="false">newpipes_language_key</string>
|
||||
<string name="app_language_key" translatable="false">app_language_key</string>
|
||||
<string name="enable_lock_screen_video_thumbnail_key" translatable="false">enable_lock_screen_video_thumbnail</string>
|
||||
|
||||
<string name="import_data" translatable="false">import_data</string>
|
||||
|
@ -926,8 +926,8 @@
|
|||
<item>ZW</item>
|
||||
</string-array>
|
||||
|
||||
<!--The next two arrays are set to change the NewPipe language-->
|
||||
<string-array name="language_code_np" translatable="false">
|
||||
<!--The next two arrays are set to change the app language-->
|
||||
<string-array name="app_language_code" translatable="false">
|
||||
<item>system</item>
|
||||
<item>ar</item>
|
||||
<item>az</item>
|
||||
|
@ -992,7 +992,7 @@
|
|||
<item>zh-hans</item>
|
||||
<item>zh-tw</item>
|
||||
</string-array>
|
||||
<string-array name="language_name_np" translatable="false">
|
||||
<string-array name="app_language_name" translatable="false">
|
||||
<item>@string/systems_language</item>
|
||||
<item>العربية</item>
|
||||
<item>Azərbaycan dili</item>
|
||||
|
|
|
@ -589,6 +589,6 @@
|
|||
<string name="downloads_storage_use_saf_title">Use SAF</string>
|
||||
<string name="downloads_storage_use_saf_summary">The Storage Access Framework allows downloads to an external SD card.\nNote: some devices are not compatible</string>
|
||||
<string name="choose_instance_prompt">Choose an instance</string>
|
||||
<string name="newpipes_language_title">NewPipe\'s language</string>
|
||||
<string name="systems_language">System\'s language</string>
|
||||
<string name="app_language_title">App language</string>
|
||||
<string name="systems_language">System default</string>
|
||||
</resources>
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<ListPreference
|
||||
app:iconSpaceReserved="false"
|
||||
android:defaultValue="system"
|
||||
android:entries="@array/language_name_np"
|
||||
android:entryValues="@array/language_code_np"
|
||||
android:key="@string/newpipes_language_key"
|
||||
android:entries="@array/app_language_name"
|
||||
android:entryValues="@array/app_language_code"
|
||||
android:key="@string/app_language_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/newpipes_language_title"/>
|
||||
android:title="@string/app_language_title"/>
|
||||
|
||||
<ListPreference
|
||||
app:iconSpaceReserved="false"
|
||||
|
|
Loading…
Reference in New Issue