mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Support localization in passphrase activity and lock notification.
// FREEBIE Closes #1328
This commit is contained in:
parent
e5e5b93884
commit
4e98c350a5
@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.StoragePreferenceFragment;
|
||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.Dialogs;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
@ -136,6 +137,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
dynamicTheme.onResume(this);
|
||||
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
|
||||
dynamicLanguage.onResume(this);
|
||||
|
||||
Intent intent = new Intent(this, KeyCachingService.class);
|
||||
intent.setAction(KeyCachingService.LOCALE_CHANGE_EVENT);
|
||||
startService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
@ -52,16 +53,25 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
*/
|
||||
public class PassphrasePromptActivity extends PassphraseActivity {
|
||||
|
||||
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private EditText passphraseText;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
dynamicLanguage.onCreate(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.prompt_passphrase_activity);
|
||||
initializeResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
dynamicLanguage.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
|
@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.ParcelUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.jobqueue.EncryptionKeys;
|
||||
@ -63,6 +64,9 @@ public class KeyCachingService extends Service {
|
||||
public static final String DISABLE_ACTION = "org.thoughtcrime.securesms.service.action.DISABLE";
|
||||
public static final String ACTIVITY_START_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_START_EVENT";
|
||||
public static final String ACTIVITY_STOP_EVENT = "org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT";
|
||||
public static final String LOCALE_CHANGE_EVENT = "org.thoughtcrime.securesms.service.action.LOCALE_CHANGE_EVENT";
|
||||
|
||||
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private PendingIntent pending;
|
||||
private int activitiesRunning = 0;
|
||||
@ -101,7 +105,6 @@ public class KeyCachingService extends Service {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (!DatabaseUpgradeActivity.isUpdate(KeyCachingService.this)) {
|
||||
// DecryptingQueue.schedulePendingDecrypts(KeyCachingService.this, masterSecret);
|
||||
ApplicationContext.getInstance(KeyCachingService.this)
|
||||
.getJobManager()
|
||||
.setEncryptionKeys(new EncryptionKeys(ParcelUtil.serialize(masterSecret)));
|
||||
@ -117,16 +120,16 @@ public class KeyCachingService extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent == null) return START_NOT_STICKY;
|
||||
|
||||
if (intent.getAction() != null && intent.getAction().equals(CLEAR_KEY_ACTION))
|
||||
handleClearKey();
|
||||
else if (intent.getAction() != null && intent.getAction().equals(ACTIVITY_START_EVENT))
|
||||
handleActivityStarted();
|
||||
else if (intent.getAction() != null && intent.getAction().equals(ACTIVITY_STOP_EVENT))
|
||||
handleActivityStopped();
|
||||
else if (intent.getAction() != null && intent.getAction().equals(PASSPHRASE_EXPIRED_EVENT))
|
||||
handleClearKey();
|
||||
else if (intent.getAction() != null && intent.getAction().equals(DISABLE_ACTION))
|
||||
handleDisableService();
|
||||
if (intent.getAction() != null) {
|
||||
switch (intent.getAction()) {
|
||||
case CLEAR_KEY_ACTION: handleClearKey(); break;
|
||||
case ACTIVITY_START_EVENT: handleActivityStarted(); break;
|
||||
case ACTIVITY_STOP_EVENT: handleActivityStopped(); break;
|
||||
case PASSPHRASE_EXPIRED_EVENT: handleClearKey(); break;
|
||||
case DISABLE_ACTION: handleDisableService(); break;
|
||||
case LOCALE_CHANGE_EVENT: handleLocaleChanged(); break;
|
||||
}
|
||||
}
|
||||
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
@ -203,6 +206,11 @@ public class KeyCachingService extends Service {
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
private void handleLocaleChanged() {
|
||||
dynamicLanguage.updateServiceLocale(this);
|
||||
foregroundService();
|
||||
}
|
||||
|
||||
private void startTimeoutIfAppropriate() {
|
||||
boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.TextUtils;
|
||||
@ -15,7 +17,7 @@ public class DynamicLanguage {
|
||||
|
||||
public void onCreate(Activity activity) {
|
||||
currentLocale = getSelectedLocale(activity);
|
||||
setActivityLocale(activity, currentLocale);
|
||||
setContextLocale(activity, currentLocale);
|
||||
}
|
||||
|
||||
public void onResume(Activity activity) {
|
||||
@ -28,13 +30,18 @@ public class DynamicLanguage {
|
||||
}
|
||||
}
|
||||
|
||||
private static void setActivityLocale(Activity activity, Locale selectedLocale) {
|
||||
Configuration configuration = activity.getResources().getConfiguration();
|
||||
public void updateServiceLocale(Service service) {
|
||||
currentLocale = getSelectedLocale(service);
|
||||
setContextLocale(service, currentLocale);
|
||||
}
|
||||
|
||||
private static void setContextLocale(Context context, Locale selectedLocale) {
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
|
||||
if (!configuration.locale.equals(selectedLocale)) {
|
||||
configuration.locale = selectedLocale;
|
||||
activity.getResources().updateConfiguration(configuration,
|
||||
activity.getResources().getDisplayMetrics());
|
||||
context.getResources().updateConfiguration(configuration,
|
||||
context.getResources().getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,8 +49,8 @@ public class DynamicLanguage {
|
||||
return activity.getResources().getConfiguration().locale;
|
||||
}
|
||||
|
||||
private static Locale getSelectedLocale(Activity activity) {
|
||||
String language[] = TextUtils.split(TextSecurePreferences.getLanguage(activity), "_");
|
||||
private static Locale getSelectedLocale(Context context) {
|
||||
String language[] = TextUtils.split(TextSecurePreferences.getLanguage(context), "_");
|
||||
|
||||
if (language[0].equals(DEFAULT)) {
|
||||
return Locale.getDefault();
|
||||
|
Loading…
x
Reference in New Issue
Block a user