2013-06-21 18:56:59 +00:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
2014-03-04 09:47:27 +00:00
|
|
|
import org.thoughtcrime.securesms.ConversationActivity;
|
2013-06-23 04:44:12 +00:00
|
|
|
import org.thoughtcrime.securesms.ConversationListActivity;
|
2013-06-21 18:56:59 +00:00
|
|
|
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)) {
|
2014-05-23 20:22:23 +00:00
|
|
|
Intent intent = activity.getIntent();
|
|
|
|
activity.finish();
|
|
|
|
OverridePendingTransition.invoke(activity);
|
|
|
|
activity.startActivity(intent);
|
|
|
|
OverridePendingTransition.invoke(activity);
|
2013-06-21 18:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 04:44:12 +00:00
|
|
|
private static int getSelectedTheme(Activity activity) {
|
2013-07-11 21:58:40 +00:00
|
|
|
String theme = TextSecurePreferences.getTheme(activity);
|
2013-06-21 18:56:59 +00:00
|
|
|
|
|
|
|
if (theme.equals("light")) {
|
2014-08-15 06:11:06 +00:00
|
|
|
if (activity instanceof ConversationActivity) return R.style.TextSecure_LightTheme_ConversationActivity;
|
|
|
|
else return R.style.TextSecure_LightTheme;
|
2013-06-21 18:56:59 +00:00
|
|
|
} else if (theme.equals("dark")) {
|
2014-08-15 06:11:06 +00:00
|
|
|
if (activity instanceof ConversationActivity) return R.style.TextSecure_DarkTheme_ConversationActivity;
|
|
|
|
else return R.style.TextSecure_DarkTheme;
|
2013-06-21 18:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return R.style.TextSecure_LightTheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final class OverridePendingTransition {
|
|
|
|
static void invoke(Activity activity) {
|
|
|
|
activity.overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|