app language now changes time formatting (3hrs ago), was system language b4
This commit is contained in:
parent
ed9a3517c6
commit
b32935a1b0
|
@ -99,7 +99,7 @@ public class App extends Application {
|
|||
NewPipe.init(getDownloader(),
|
||||
Localization.getPreferredLocalization(this),
|
||||
Localization.getPreferredContentCountry(this));
|
||||
Localization.init();
|
||||
Localization.init(getApplicationContext());
|
||||
|
||||
StateSaver.init(this);
|
||||
initNotificationChannel();
|
||||
|
|
|
@ -66,6 +66,7 @@ import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
|||
import org.schabi.newpipe.report.ErrorActivity;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.KioskTranslator;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.PeertubeHelper;
|
||||
import org.schabi.newpipe.util.PermissionHelper;
|
||||
|
@ -78,7 +79,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLocale;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static final String TAG = "MainActivity";
|
||||
|
@ -117,7 +118,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
|
||||
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
@ -422,7 +423,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
Localization.init(getApplicationContext()); //change the date format to match the selected language on resume
|
||||
super.onResume();
|
||||
|
||||
// close drawer on return, and don't show animation, so its looks like the drawer isn't open
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.schabi.newpipe.util.NavigationHelper;
|
|||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLocale;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class AboutActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeHelper.setTheme(this);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import us.shandian.giga.service.DownloadManagerService;
|
|||
import us.shandian.giga.ui.fragment.MissionsFragment;
|
||||
|
||||
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLocale;
|
||||
|
||||
public class DownloadActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class DownloadActivity extends AppCompatActivity {
|
|||
i.setClass(this, DownloadManagerService.class);
|
||||
startService(i);
|
||||
|
||||
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
ThemeHelper.setTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_downloader);
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.schabi.newpipe.R;
|
|||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import static org.schabi.newpipe.util.Localization.changeAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLanguage;
|
||||
import static org.schabi.newpipe.util.Localization.getAppLocale;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -47,7 +47,7 @@ public class SettingsActivity extends AppCompatActivity implements BasePreferenc
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
setTheme(ThemeHelper.getSettingsThemeStyle(this));
|
||||
changeAppLanguage(getAppLanguage(getApplicationContext()), getResources());
|
||||
changeAppLanguage(getAppLocale(getApplicationContext()), getResources());
|
||||
super.onCreate(savedInstanceBundle);
|
||||
setContentView(R.layout.settings_layout);
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import android.content.res.Resources;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.PluralsRes;
|
||||
|
@ -54,8 +53,8 @@ public class Localization {
|
|||
private Localization() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
initPrettyTime();
|
||||
public static void init(Context context) {
|
||||
initPrettyTime(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -203,17 +202,17 @@ public class Localization {
|
|||
// Pretty Time
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
private static void initPrettyTime() {
|
||||
prettyTime = new PrettyTime(Locale.getDefault());
|
||||
private static void initPrettyTime(Context context) {
|
||||
prettyTime = new PrettyTime(getAppLocale(context));
|
||||
// Do not use decades as YouTube doesn't either.
|
||||
prettyTime.removeUnit(Decade.class);
|
||||
}
|
||||
|
||||
private static PrettyTime getPrettyTime() {
|
||||
// If pretty time's Locale is different, init again with the new one.
|
||||
if (!prettyTime.getLocale().equals(Locale.getDefault())) {
|
||||
initPrettyTime();
|
||||
}
|
||||
// if (!prettyTime.getLocale().equals(Locale.getDefault())) {
|
||||
// initPrettyTime();
|
||||
// }
|
||||
return prettyTime;
|
||||
}
|
||||
|
||||
|
@ -228,7 +227,7 @@ public class Localization {
|
|||
res.updateConfiguration(conf, dm);
|
||||
}
|
||||
|
||||
public static Locale getAppLanguage(Context context) {
|
||||
public static Locale getAppLocale(Context context) {
|
||||
SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String lang = prefs.getString("newpipes_language_key", "en");
|
||||
Locale loc;
|
||||
|
|
Loading…
Reference in New Issue