Refactor theme preference values into constants

Also explicitly set a theme via preference updating to the default.
This commit is contained in:
Thialfihar
2015-07-04 19:30:25 +02:00
parent 8d2cd33339
commit 86d95e4d40
4 changed files with 14 additions and 4 deletions

View File

@@ -104,6 +104,11 @@ public final class Constants {
public static final String PROXY_PORT = "proxyPort";
public static final String PROXY_TYPE = "proxyType";
public static final String THEME = "theme";
public static final class Theme {
public static final String LIGHT = "light";
public static final String DARK = "dark";
}
}
/**
@@ -117,7 +122,7 @@ public final class Constants {
public static final class Defaults {
public static final String KEY_SERVERS = "hkps://hkps.pool.sks-keyservers.net, hkps://pgp.mit.edu";
public static final int PREF_VERSION = 4;
public static final int PREF_VERSION = 5;
}
public static final class key {

View File

@@ -136,7 +136,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
int themeId = R.style.LightTheme;
if ("dark".equals(newTheme)) {
if (Constants.Pref.Theme.DARK.equals(newTheme)) {
themeId = R.style.DarkTheme;
}

View File

@@ -30,6 +30,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -76,7 +77,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
int themeId = R.style.LightTheme;
if ("dark".equals(newTheme)) {
if (Constants.Pref.Theme.DARK.equals(newTheme)) {
themeId = R.style.DarkTheme;
}

View File

@@ -221,7 +221,7 @@ public class Preferences {
}
public String getTheme() {
return mSharedPreferences.getString(Pref.THEME, "light");
return mSharedPreferences.getString(Pref.THEME, Pref.Theme.LIGHT);
}
public void setTheme(String value) {
@@ -390,6 +390,10 @@ public class Preferences {
}
// fall through
case 4: {
// fall through
}
case 5: {
setTheme(Constants.Pref.Theme.LIGHT);
}
}