parent
1efd73af5e
commit
5cd00ccbb5
|
@ -33,6 +33,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
|||
|
||||
|
||||
public abstract class AbstractGBActivity extends AppCompatActivity implements GBActivity {
|
||||
private boolean isLanguageInvalid = false;
|
||||
|
||||
public static final int NONE = 0;
|
||||
public static final int NO_ACTIONBAR = 1;
|
||||
|
@ -52,8 +53,11 @@ public abstract class AbstractGBActivity extends AppCompatActivity implements GB
|
|||
}
|
||||
};
|
||||
|
||||
public void setLanguage(Locale language, boolean recreate) {
|
||||
AndroidUtils.setLanguage(this, language, recreate);
|
||||
public void setLanguage(Locale language, boolean invalidateLanguage) {
|
||||
if (invalidateLanguage) {
|
||||
isLanguageInvalid = true;
|
||||
}
|
||||
AndroidUtils.setLanguage(this, language);
|
||||
}
|
||||
|
||||
public static void init(GBActivity activity) {
|
||||
|
@ -88,6 +92,15 @@ public abstract class AbstractGBActivity extends AppCompatActivity implements GB
|
|||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isLanguageInvalid) {
|
||||
isLanguageInvalid = false;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
|
|
|
@ -49,6 +49,8 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractSettingsActivity.class);
|
||||
|
||||
private boolean isLanguageInvalid = false;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -152,6 +154,15 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isLanguageInvalid) {
|
||||
isLanguageInvalid = false;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
|
@ -210,7 +221,10 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void setLanguage(Locale language, boolean recreate) {
|
||||
AndroidUtils.setLanguage(this, language, recreate);
|
||||
public void setLanguage(Locale language, boolean invalidateLanguage) {
|
||||
if (invalidateLanguage) {
|
||||
isLanguageInvalid = true;
|
||||
}
|
||||
AndroidUtils.setLanguage(this, language);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,8 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||
private GBDeviceAdapterv2 mGBDeviceAdapter;
|
||||
private RecyclerView deviceListView;
|
||||
|
||||
private boolean isLanguageInvalid = false;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -206,6 +208,15 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isLanguageInvalid) {
|
||||
isLanguageInvalid = false;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unregisterForContextMenu(deviceListView);
|
||||
|
@ -311,7 +322,10 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0);
|
||||
}
|
||||
|
||||
public void setLanguage(Locale language, boolean recreate) {
|
||||
AndroidUtils.setLanguage(this, language, recreate);
|
||||
public void setLanguage(Locale language, boolean invalidateLanguage) {
|
||||
if (invalidateLanguage) {
|
||||
isLanguageInvalid = true;
|
||||
}
|
||||
AndroidUtils.setLanguage(this, language);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
|||
import java.util.Locale;
|
||||
|
||||
public interface GBActivity {
|
||||
void setLanguage(Locale language, boolean recreate);
|
||||
void setLanguage(Locale language, boolean invalidateLanguage);
|
||||
void setTheme(int themeId);
|
||||
|
||||
}
|
||||
|
|
|
@ -159,6 +159,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||
String newLang = newVal.toString();
|
||||
try {
|
||||
GBApplication.setLanguage(newLang);
|
||||
recreate();
|
||||
} catch (Exception ex) {
|
||||
GB.toast(getApplicationContext(),
|
||||
"Error setting language: " + ex.getLocalizedMessage(),
|
||||
|
|
|
@ -70,14 +70,6 @@ public class AndroidUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setLanguage(Activity activity, Locale language, boolean recreate) {
|
||||
setLanguage(activity.getBaseContext(), language);
|
||||
|
||||
if (recreate) {
|
||||
activity.recreate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLanguage(Context context, Locale language) {
|
||||
Configuration config = new Configuration();
|
||||
config.setLocale(language);
|
||||
|
|
Loading…
Reference in New Issue