Created
April 24, 2020 09:02
-
-
Save alirezanazari/5ee9a04153b2214a301c494c90c1efce to your computer and use it in GitHub Desktop.
Theme in Android
This file contains 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
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