Last active
July 20, 2019 13:29
-
-
Save zmdominguez/6eaa2788c16988d391f45d8445d561f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun showThemeSwitcher(activity: Activity, prefs: SharedPreferences) { | |
val builder = AlertDialog.Builder(activity) | |
val names = mutableListOf<String>() | |
var selectedTheme = getSelectedTheme(activity, prefs).ordinal | |
builder.setTitle("Choose theme to apply") | |
builder.setSingleChoiceItems(SwitchableThemes.values().mapTo(names) { | |
it.label | |
}.toTypedArray(), selectedTheme) { _, which -> | |
selectedTheme = which | |
}.setPositiveButton(R.string.ok) { dialog, which -> | |
prefs.edit { | |
putInt(activity.getString(R.string.debug_switch_theme), selectedTheme) | |
} | |
activity.recreate() | |
dialog.dismiss() | |
}.show() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getSelectedTheme(context: Context, prefs: SharedPreferences): SwitchableThemes { | |
val themePos = prefs.getInt(context.getString(R.string.debug_switch_theme), 0) | |
return SwitchableThemes.values()[themePos] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class SwitchableThemes(val label: String, @StyleRes val id: Int) { | |
DEFAULT("WOW", R.style.Theme_Wow), | |
REWARDS("Variant 1", R.style.Theme_Variant_1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment