Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language selector to change the app language #2921

Merged
merged 24 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dea1e0d
Update localizations settings
B0pol Jan 4, 2020
3ad0e31
changed the way to change language, now is «NewPipe's language» selector
B0pol Jan 9, 2020
e0a39ef
Merge branch 'dev' into dev
B0pol Jan 9, 2020
ed9a351
removed unused imports
B0pol Jan 9, 2020
b32935a
app language now changes time formatting (3hrs ago), was system langu…
B0pol Jan 9, 2020
8f46432
fixed some activities where the wrong languages would be set
B0pol Jan 10, 2020
11d06dc
remove todo as it's already done
B0pol Jan 10, 2020
382e692
Merge branch 'dev' into dev
B0pol Jan 14, 2020
f8a7aac
fixed indonesian, see https://stackoverflow.com/questions/13291578/ho…
B0pol Jan 14, 2020
055365a
added Occitan to the selector
B0pol Jan 14, 2020
105981b
made system translatable + renamed it to system's language
B0pol Jan 14, 2020
9d8fcbb
fix: wrong language shown when rotating screen in popup player
B0pol Jan 15, 2020
0cd9fb3
Merge branch 'dev' into dev
B0pol Jan 17, 2020
b155f23
fix: wrong language shown in playback parameters dialog
B0pol Jan 18, 2020
e08e724
upload date in description now matches newpipe's language
B0pol Jan 18, 2020
e58088d
Merge branch 'dev' into dev
B0pol Jan 19, 2020
489420e
Merge branch 'dev' into dev
B0pol Jan 24, 2020
e94981e
Merge branch 'dev' into dev
B0pol Jan 27, 2020
156a2eb
update prettytime dependency
B0pol Jan 27, 2020
edc9d47
app language: refactoring
B0pol Jan 28, 2020
6be23a0
fix wrong language shown many popup dialogs
B0pol Jan 31, 2020
c5e6bb5
Merge remote-tracking branch 'upstream/dev' into dev
B0pol Feb 1, 2020
55a138e
fix toast on app language change
B0pol Feb 1, 2020
d36ac7a
Improve formatting
TobiGr Feb 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,7 +55,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;
Expand All @@ -67,6 +65,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;
Expand All @@ -78,6 +77,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
Expand Down Expand Up @@ -113,9 +114,9 @@ protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
TLSSocketFactoryCompat.setAsDefault();
}

ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));

assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Expand Down Expand Up @@ -419,6 +420,8 @@ protected void onDestroy() {

@Override
protected void onResume() {
assureCorrectAppLanguage(this);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

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.assureCorrectAppLanguage;

public class AboutActivity extends AppCompatActivity {

/**
Expand Down Expand Up @@ -62,8 +63,10 @@ public class AboutActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this);
this.setTitle(getString(R.string.title_activity_about));

setContentView(R.layout.activity_about);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object, Void, Integer> {

final WeakReference<Activity> weakReference;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
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.assureCorrectAppLanguage;

public class DownloadActivity extends AppCompatActivity {

private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag";
Expand All @@ -29,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
i.setClass(this, DownloadManagerService.class);
startService(i);

assureCorrectAppLanguage(this);
ThemeHelper.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader);
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.schabi.newpipe.util.ThemeHelper;

import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

/**
* Base players joining the common properties
Expand Down Expand Up @@ -115,7 +115,7 @@ public void onCreate() {
notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
lockManager = new LockManager(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

assureCorrectAppLanguage(this);
ThemeHelper.setTheme(this);
basePlayerImpl = new BasePlayerImpl(this);
basePlayerImpl.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +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.assureCorrectAppLanguage;
import static org.schabi.newpipe.util.StateSaver.KEY_SAVED_STATE;

/**
Expand Down Expand Up @@ -125,6 +126,7 @@ public final class MainVideoPlayer extends AppCompatActivity

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState);
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -192,6 +194,7 @@ protected void onNewIntent(Intent intent) {
@Override
protected void onResume() {
if (DEBUG) Log.d(TAG, "onResume() called");
assureCorrectAppLanguage(this);
super.onResume();

if (globalScreenOrientationLocked()) {
Expand Down Expand Up @@ -222,6 +225,7 @@ protected void onResume() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
assureCorrectAppLanguage(this);

if (playerImpl.isSomePopupMenuVisible()) {
playerImpl.getQualityPopupMenu().dismiss();
Expand Down Expand Up @@ -366,8 +370,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +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.assureCorrectAppLanguage;

/**
* Service Popup Player implementing VideoPlayer
Expand Down Expand Up @@ -142,6 +143,7 @@ public final class PopupVideoPlayer extends Service {

@Override
public void onCreate() {
assureCorrectAppLanguage(this);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));

Expand Down Expand Up @@ -169,6 +171,7 @@ public int onStartCommand(final Intent intent, int flags, int startId) {

@Override
public void onConfigurationChanged(Configuration newConfig) {
assureCorrectAppLanguage(this);
if (DEBUG) Log.d(TAG, "onConfigurationChanged() called with: newConfig = [" + newConfig + "]");
updateScreenSize();
updatePopupSize(popupLayoutParams.width, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +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.assureCorrectAppLanguage;

public abstract class ServicePlayerActivity extends AppCompatActivity
implements PlayerEventListener, SeekBar.OnSeekBarChangeListener,
Expand Down Expand Up @@ -116,6 +117,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this);
setContentView(R.layout.activity_player_queue_control);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.schabi.newpipe.util.SliderStrategy;

import static org.schabi.newpipe.player.BasePlayer.DEBUG;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

public class PlaybackParameterDialog extends DialogFragment {
@NonNull private static final String TAG = "PlaybackParameterDialog";
Expand Down Expand Up @@ -108,6 +109,7 @@ public void onAttach(Context context) {

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
assureCorrectAppLanguage(getContext());
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO);
Expand Down Expand Up @@ -137,6 +139,7 @@ public void onSaveInstanceState(Bundle outState) {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
assureCorrectAppLanguage(getContext());
final View view = View.inflate(getContext(), R.layout.dialog_playback_parameter, null);
setupControlViews(view);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.util.TimeZone;
import java.util.Vector;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

/*
* Created by Christian Schabesberger on 24.10.15.
*
Expand Down Expand Up @@ -171,6 +173,7 @@ private static String[] elToSl(List<Throwable> stackTraces) {

@Override
protected void onCreate(Bundle savedInstanceState) {
assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this);
setContentView(R.layout.activity_error);
Expand Down
Loading