Added themes

All files (that used styles) were refactored to use styles directly so themes can only actually adjust colors
 - Elaborate themes would be super hard to maintain and would certainly break over time
This commit is contained in:
Viktor De Pasquale
2019-11-22 19:29:53 +01:00
parent 42606162b2
commit cc7e47bbb6
49 changed files with 799 additions and 409 deletions

View File

@@ -13,6 +13,7 @@ import com.topjohnwu.magisk.di.Protected
import com.topjohnwu.magisk.extensions.get
import com.topjohnwu.magisk.extensions.inject
import com.topjohnwu.magisk.model.preference.PreferenceModel
import com.topjohnwu.magisk.redesign.theme.Theme
import com.topjohnwu.magisk.utils.BiometricHelper
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.superuser.Shell
@@ -52,6 +53,7 @@ object Config : PreferenceModel, DBConfig {
const val DOWNLOAD_PATH = "download_path"
const val REDESIGN = "redesign"
const val SAFETY = "safety_notice"
const val THEME_ORDINAL = "theme_ordinal"
// system state
const val MAGISKHIDE = "magiskhide"
@@ -125,6 +127,7 @@ object Config : PreferenceModel, DBConfig {
Key.DARK_THEME_EXTENDED,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
)
var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal)
var suReAuth by preference(Key.SU_REAUTH, false)
var checkUpdate by preference(Key.CHECK_UPDATES, true)
var magiskHide by preference(Key.MAGISKHIDE, true)

View File

@@ -0,0 +1,14 @@
package com.topjohnwu.magisk.model.entity.recycler
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ComparableRvItem
import com.topjohnwu.magisk.redesign.theme.Theme
class ThemeItem(val theme: Theme) : ComparableRvItem<ThemeItem>() {
override val layoutRes = R.layout.item_theme
override fun contentSameAs(other: ThemeItem) = itemSameAs(other)
override fun itemSameAs(other: ThemeItem) = theme == other.theme
}

View File

@@ -8,6 +8,7 @@ import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.intent
import com.topjohnwu.magisk.redesign.install.InstallFragment
import com.topjohnwu.magisk.redesign.safetynet.SafetynetFragment
import com.topjohnwu.magisk.redesign.theme.ThemeFragment
import com.topjohnwu.magisk.ui.MainActivity
import com.topjohnwu.magisk.ui.hide.MagiskHideFragment
import com.topjohnwu.magisk.ui.home.HomeFragment
@@ -98,6 +99,10 @@ object Navigation {
navDirections { destination = InstallFragment::class }
}
fun theme() = MagiskNavigationEvent {
navDirections { destination = ThemeFragment::class }
}
fun fromSection(section: String) = when (section) {
"superuser" -> superuser()
"modules" -> modules()

View File

@@ -10,7 +10,6 @@ import androidx.core.content.getSystemService
import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.base.BaseActivity
import com.topjohnwu.magisk.extensions.snackbar
import com.topjohnwu.magisk.extensions.startAnimations
@@ -18,13 +17,14 @@ import com.topjohnwu.magisk.model.events.SnackbarEvent
import com.topjohnwu.magisk.model.events.ViewEvent
import com.topjohnwu.magisk.model.navigation.MagiskNavigationEvent
import com.topjohnwu.magisk.model.navigation.Navigator
import com.topjohnwu.magisk.redesign.theme.Theme
import kotlin.reflect.KClass
abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBinding> :
BaseActivity<ViewModel, Binding>(), CompatView<ViewModel>, Navigator {
override val themeRes = R.style.Foundation_Default
override val themeRes = Theme.selected.themeRes
override val viewRoot: View get() = binding.root
override val navigation: CompatNavigationDelegate<CompatActivity<ViewModel, Binding>>? by lazy {
CompatNavigationDelegate(this)

View File

@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback
import com.topjohnwu.magisk.extensions.toggle
import com.topjohnwu.magisk.model.events.DieEvent
import com.topjohnwu.magisk.model.events.dialog.DarkThemeDialog
import com.topjohnwu.magisk.model.navigation.Navigation
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
import com.topjohnwu.magisk.utils.KObservableField
@@ -21,6 +21,6 @@ class SettingsViewModel : CompatViewModel() {
}
fun toggle(item: KObservableField<Boolean>) = item.toggle()
fun darkModePressed() = DarkThemeDialog().publish()
fun themePressed() = Navigation.theme().publish()
}

View File

@@ -0,0 +1,50 @@
package com.topjohnwu.magisk.redesign.theme
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.R
enum class Theme(
val themeName: String,
val themeRes: Int
) {
Piplup(
themeName = "Piplup",
themeRes = R.style.ThemeFoundationMD2_Piplup
),
PiplupAmoled(
themeName = "AMOLED",
themeRes = R.style.ThemeFoundationMD2_Amoled
),
Rayquaza(
themeName = "Rayquaza",
themeRes = R.style.ThemeFoundationMD2_Rayquaza
),
Zapdos(
themeName = "Zapdos",
themeRes = R.style.ThemeFoundationMD2_Zapdos
),
Charmeleon(
themeName = "Charmeleon",
themeRes = R.style.ThemeFoundationMD2_Charmeleon
),
Mew(
themeName = "Mew",
themeRes = R.style.ThemeFoundationMD2_Mew
),
Salamence(
themeName = "Salamence",
themeRes = R.style.ThemeFoundationMD2_Salamence
);
val isSelected get() = Config.themeOrdinal == ordinal
fun select() {
Config.themeOrdinal = ordinal
}
companion object {
val selected get() = values().getOrNull(Config.themeOrdinal) ?: Piplup
}
}

View File

@@ -1,5 +1,6 @@
package com.topjohnwu.magisk.redesign.theme
import android.graphics.Insets
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentThemeMd2Binding
import com.topjohnwu.magisk.redesign.compat.CompatFragment
@@ -10,4 +11,12 @@ class ThemeFragment : CompatFragment<ThemeViewModel, FragmentThemeMd2Binding>()
override val layoutRes = R.layout.fragment_theme_md2
override val viewModel by viewModel<ThemeViewModel>()
override fun consumeSystemWindowInsets(insets: Insets) = insets
override fun onStart() {
super.onStart()
activity.title = getString(R.string.section_theme)
}
}

View File

@@ -1,5 +1,23 @@
package com.topjohnwu.magisk.redesign.theme
import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.model.entity.recycler.ThemeItem
import com.topjohnwu.magisk.model.events.RecreateEvent
import com.topjohnwu.magisk.model.events.dialog.DarkThemeDialog
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
import com.topjohnwu.magisk.redesign.home.itemBindingOf
import com.topjohnwu.magisk.redesign.superuser.diffListOf
class ThemeViewModel : CompatViewModel()
class ThemeViewModel : CompatViewModel() {
val items = diffListOf(*Theme.values().map { ThemeItem(it) }.toTypedArray())
val itemBinding = itemBindingOf<ThemeItem> { it.bindExtra(BR.viewModel, this) }
fun saveTheme(theme: Theme) {
theme.select()
RecreateEvent().publish()
}
fun darkModePressed() = DarkThemeDialog().publish()
}

View File

@@ -455,4 +455,9 @@ fun View.setRotationNotAnimated(rotation: Int) {
@BindingAdapter("android:text")
fun TextView.setTextSafe(text: Int) {
if (text == 0) this.text = null else setText(text)
}
@BindingAdapter("android:theme")
fun View.setThemeCompat(theme: Int) {
}