mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-04 23:45:14 +00:00
1ad54e7b88
PassphraseRequiredMixin might check for a bound service at a time where the bind has been requested but the service connection has not been established yet, and therefore fail to call unbindService, leading to a leaked service connection. This fixes #1518.
53 lines
1.9 KiB
Java
53 lines
1.9 KiB
Java
package org.thoughtcrime.securesms.util;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.preference.PreferenceManager;
|
|
|
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|
import org.thoughtcrime.securesms.ConversationActivity;
|
|
import org.thoughtcrime.securesms.ConversationListActivity;
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
public class DynamicTheme {
|
|
|
|
private int currentTheme;
|
|
|
|
public void onCreate(Activity activity) {
|
|
currentTheme = getSelectedTheme(activity);
|
|
activity.setTheme(currentTheme);
|
|
}
|
|
|
|
public void onResume(Activity activity) {
|
|
if (currentTheme != getSelectedTheme(activity)) {
|
|
Intent intent = activity.getIntent();
|
|
activity.finish();
|
|
OverridePendingTransition.invoke(activity);
|
|
activity.startActivity(intent);
|
|
OverridePendingTransition.invoke(activity);
|
|
}
|
|
}
|
|
|
|
private static int getSelectedTheme(Activity activity) {
|
|
String theme = TextSecurePreferences.getTheme(activity);
|
|
|
|
if (theme.equals("light")) {
|
|
if (activity instanceof ConversationListActivity) return R.style.TextSecure_LightTheme_NavigationDrawer;
|
|
else if (activity instanceof ConversationActivity) return R.style.TextSecure_LightTheme_ConversationActivity;
|
|
else return R.style.TextSecure_LightTheme;
|
|
} else if (theme.equals("dark")) {
|
|
if (activity instanceof ConversationListActivity) return R.style.TextSecure_DarkTheme_NavigationDrawer;
|
|
else if (activity instanceof ConversationActivity) return R.style.TextSecure_DarkTheme_ConversationActivity;
|
|
else return R.style.TextSecure_DarkTheme;
|
|
}
|
|
|
|
return R.style.TextSecure_LightTheme;
|
|
}
|
|
|
|
private static final class OverridePendingTransition {
|
|
static void invoke(Activity activity) {
|
|
activity.overridePendingTransition(0, 0);
|
|
}
|
|
}
|
|
}
|