Skip to content

Instantly share code, notes, and snippets.

@alirezanazari
Created April 24, 2020 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezanazari/5ee9a04153b2214a301c494c90c1efce to your computer and use it in GitHub Desktop.
Save alirezanazari/5ee9a04153b2214a301c494c90c1efce to your computer and use it in GitHub Desktop.
Theme in Android
package com.moviom.internal
import android.content.Context
import android.util.TypedValue
import com.moviom.R
import com.moviom.data.provider.PreferencesProvider
class Theme(
private val preferences: PreferencesProvider
) {
fun getTheme() : Int{
return when(ThemeType.valueOf(preferences.getTheme())){
ThemeType.LIGHT -> R.style.LightTheme
ThemeType.DARK -> R.style.DarkTheme
}
}
fun setTheme(theme : ThemeType){
preferences.setTheme(theme.name)
}
fun getCurrentTheme(): ThemeType{
return ThemeType.valueOf(preferences.getTheme())
}
enum class ThemeType(val typeName: String){
LIGHT("LIGHT") , DARK("DARK")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment