mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-30 23:18:13 +00:00
Updated action cards to be more colorful
This commit is contained in:
@@ -24,7 +24,7 @@ val redesignModule = module {
|
||||
viewModel { RequestViewModel() }
|
||||
viewModel { SafetynetViewModel(get()) }
|
||||
viewModel { SettingsViewModel() }
|
||||
viewModel { SuperuserViewModel(get(), get(), get(), get()) }
|
||||
viewModel { SuperuserViewModel(get(), get(), get()) }
|
||||
viewModel { ThemeViewModel() }
|
||||
viewModel { InstallViewModel() }
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.topjohnwu.magisk.model.entity.recycler
|
||||
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
|
||||
sealed class TappableHeadlineItem : ComparableRvItem<TappableHeadlineItem>() {
|
||||
|
||||
abstract val title: Int
|
||||
abstract val icon: Int
|
||||
|
||||
override val layoutRes = R.layout.item_tappable_headline
|
||||
|
||||
override fun itemSameAs(other: TappableHeadlineItem) =
|
||||
this === other
|
||||
|
||||
override fun contentSameAs(other: TappableHeadlineItem) =
|
||||
title == other.title && icon == other.icon
|
||||
|
||||
// --- listener
|
||||
|
||||
interface Listener {
|
||||
|
||||
fun onItemPressed(item: TappableHeadlineItem)
|
||||
|
||||
}
|
||||
|
||||
// --- objects
|
||||
|
||||
object Hide : TappableHeadlineItem() {
|
||||
override val title = R.string.magisk_hide_md2
|
||||
override val icon = R.drawable.ic_hide_md2
|
||||
}
|
||||
|
||||
object Safetynet : TappableHeadlineItem() {
|
||||
override val title = R.string.safetyNet
|
||||
override val icon = R.drawable.ic_safetynet_md2
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.topjohnwu.magisk.extensions.subscribeK
|
||||
import com.topjohnwu.magisk.extensions.toggle
|
||||
import com.topjohnwu.magisk.model.entity.MagiskPolicy
|
||||
import com.topjohnwu.magisk.model.entity.recycler.PolicyItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem
|
||||
import com.topjohnwu.magisk.model.events.PolicyUpdateEvent
|
||||
import com.topjohnwu.magisk.model.events.SnackbarEvent
|
||||
import com.topjohnwu.magisk.model.events.dialog.BiometricDialog
|
||||
@@ -20,26 +21,26 @@ import com.topjohnwu.magisk.redesign.compat.CompatViewModel
|
||||
import com.topjohnwu.magisk.redesign.home.itemBindingOf
|
||||
import com.topjohnwu.magisk.utils.BiometricHelper
|
||||
import com.topjohnwu.magisk.utils.DiffObservableList
|
||||
import com.topjohnwu.magisk.utils.RxBus
|
||||
import com.topjohnwu.magisk.utils.currentLocale
|
||||
import io.reactivex.Single
|
||||
|
||||
class SuperuserViewModel(
|
||||
private val rxBus: RxBus,
|
||||
private val db: PolicyDao,
|
||||
private val packageManager: PackageManager,
|
||||
private val resources: Resources
|
||||
) : CompatViewModel() {
|
||||
) : CompatViewModel(), TappableHeadlineItem.Listener {
|
||||
|
||||
val items = diffListOf<PolicyItem>()
|
||||
val itemBinding = itemBindingOf<PolicyItem> {
|
||||
val items = diffListOf<ComparableRvItem<*>>()
|
||||
val itemBinding = itemBindingOf<ComparableRvItem<*>> {
|
||||
it.bindExtra(BR.viewModel, this)
|
||||
it.bindExtra(BR.listener, this)
|
||||
}
|
||||
|
||||
init {
|
||||
rxBus.register<PolicyUpdateEvent>()
|
||||
.subscribeK { updatePolicy(it) }
|
||||
.add()
|
||||
companion object {
|
||||
private val menuOptions = listOf(
|
||||
TappableHeadlineItem.Hide,
|
||||
TappableHeadlineItem.Safetynet
|
||||
)
|
||||
}
|
||||
|
||||
// ---
|
||||
@@ -56,6 +57,7 @@ class SuperuserViewModel(
|
||||
).compare(o1, o2)
|
||||
}
|
||||
.toList()
|
||||
.map { menuOptions + it }
|
||||
.map { it to items.calculateDiff(it) }
|
||||
.applySchedulers()
|
||||
.applyViewModel(this)
|
||||
@@ -63,12 +65,19 @@ class SuperuserViewModel(
|
||||
|
||||
// ---
|
||||
|
||||
fun safetynetPressed() = Navigation.safetynet().publish()
|
||||
fun hidePressed() = Navigation.hide().publish()
|
||||
@Suppress("REDUNDANT_ELSE_IN_WHEN")
|
||||
override fun onItemPressed(item: TappableHeadlineItem) = when (item) {
|
||||
TappableHeadlineItem.Hide -> hidePressed()
|
||||
TappableHeadlineItem.Safetynet -> safetynetPressed()
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
private fun safetynetPressed() = Navigation.safetynet().publish()
|
||||
private fun hidePressed() = Navigation.hide().publish()
|
||||
|
||||
fun deletePressed(item: PolicyItem) {
|
||||
fun updateState() = deletePolicy(item.item)
|
||||
.subscribeK { items.removeAll { it.itemSameAs(item) } }
|
||||
.subscribeK { items.removeAll { it.genericItemSameAs(item) } }
|
||||
.add()
|
||||
|
||||
if (BiometricHelper.isEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user