mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-11 18:54:21 +00:00
fb9ba8cb8d
Fixes #4353 Closes #4466 // FREEBIE
44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package org.thoughtcrime.securesms.util;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
public class DynamicTheme {
|
|
|
|
public static final String DARK = "dark";
|
|
public static final String LIGHT = "light";
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
protected int getSelectedTheme(Activity activity) {
|
|
String theme = TextSecurePreferences.getTheme(activity);
|
|
|
|
if (theme.equals(DARK)) return R.style.TextSecure_DarkTheme;
|
|
|
|
return R.style.TextSecure_LightTheme;
|
|
}
|
|
|
|
private static final class OverridePendingTransition {
|
|
static void invoke(Activity activity) {
|
|
activity.overridePendingTransition(0, 0);
|
|
}
|
|
}
|
|
}
|