Not using static app context wherever possible
This commit is contained in:
parent
904dd748cb
commit
5ff4438a42
15 changed files with 107 additions and 71 deletions
|
@ -6,6 +6,7 @@ import android.net.ConnectivityManager
|
|||
import androidx.core.content.edit
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.content.res.use
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
|
@ -98,10 +99,10 @@ object PreferenceUtil {
|
|||
|
||||
val languageCode: String get() = sharedPreferences.getString(LANGUAGE_NAME, "auto") ?: "auto"
|
||||
|
||||
var userName
|
||||
var Fragment.userName
|
||||
get() = sharedPreferences.getString(
|
||||
USER_NAME,
|
||||
App.getContext().getString(R.string.user_name)
|
||||
getString(R.string.user_name)
|
||||
)
|
||||
set(value) = sharedPreferences.edit {
|
||||
putString(USER_NAME, value)
|
||||
|
|
|
@ -1,31 +1,28 @@
|
|||
package code.name.monkey.retromusic.util.theme
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.generalThemeValue
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.theme.ThemeMode.*
|
||||
|
||||
object ThemeManager {
|
||||
|
||||
@StyleRes
|
||||
fun getThemeResValue(): Int =
|
||||
if (PreferenceUtil.materialYou) {
|
||||
R.style.Theme_RetroMusic_MD3
|
||||
} else {
|
||||
when (App.getContext().generalThemeValue) {
|
||||
LIGHT -> R.style.Theme_RetroMusic_Light
|
||||
DARK -> R.style.Theme_RetroMusic_Base
|
||||
BLACK -> R.style.Theme_RetroMusic_Black
|
||||
AUTO -> R.style.Theme_RetroMusic_FollowSystem
|
||||
}
|
||||
@StyleRes
|
||||
fun Context.getThemeResValue(): Int =
|
||||
if (PreferenceUtil.materialYou) {
|
||||
R.style.Theme_RetroMusic_MD3
|
||||
} else {
|
||||
when (generalThemeValue) {
|
||||
LIGHT -> R.style.Theme_RetroMusic_Light
|
||||
DARK -> R.style.Theme_RetroMusic_Base
|
||||
BLACK -> R.style.Theme_RetroMusic_Black
|
||||
AUTO -> R.style.Theme_RetroMusic_FollowSystem
|
||||
}
|
||||
|
||||
fun getNightMode(): Int = when (App.getContext().generalThemeValue) {
|
||||
LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
|
||||
fun Context.getNightMode(): Int = when (generalThemeValue) {
|
||||
LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue