You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Cleanup RvItems
This commit is contained in:
@@ -6,11 +6,15 @@ import androidx.core.view.updateLayoutParams
|
||||
import androidx.databinding.ViewDataBinding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.databinding.DiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.LenientRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvContainer
|
||||
import kotlin.math.max
|
||||
|
||||
class ConsoleItem(val item: String) : ComparableRvItem<ConsoleItem>(), LenientRvItem {
|
||||
class ConsoleItem(
|
||||
override val item: String
|
||||
) : DiffRvItem<ConsoleItem>(), LenientRvItem,
|
||||
RvContainer<String> {
|
||||
override val layoutRes = R.layout.item_console_md2
|
||||
|
||||
private var parentWidth = -1
|
||||
@@ -31,7 +35,4 @@ class ConsoleItem(val item: String) : ComparableRvItem<ConsoleItem>(), LenientRv
|
||||
recyclerView.requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
override fun contentSameAs(other: ConsoleItem) = itemSameAs(other)
|
||||
override fun itemSameAs(other: ConsoleItem) = item == other.item
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import android.view.ViewGroup
|
||||
import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.databinding.ComparableRv
|
||||
import com.topjohnwu.magisk.databinding.ObservableDiffRvItem
|
||||
import com.topjohnwu.magisk.ktx.startAnimations
|
||||
import com.topjohnwu.magisk.utils.addOnPropertyChangedCallback
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
@@ -14,7 +15,7 @@ import kotlin.math.roundToInt
|
||||
|
||||
class HideRvItem(
|
||||
val info: HideAppInfo
|
||||
) : ObservableItem<HideRvItem>(), Comparable<HideRvItem> {
|
||||
) : ObservableDiffRvItem<HideRvItem>(), ComparableRv<HideRvItem> {
|
||||
|
||||
override val layoutRes get() = R.layout.item_hide_md2
|
||||
|
||||
@@ -89,7 +90,7 @@ class HideRvItem(
|
||||
|
||||
class HideProcessRvItem(
|
||||
val process: HideProcessInfo
|
||||
) : ObservableItem<HideProcessRvItem>() {
|
||||
) : ObservableDiffRvItem<HideProcessRvItem>() {
|
||||
|
||||
override val layoutRes get() = R.layout.item_hide_process_md2
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@ import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.model.su.SuLog
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableDiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvContainer
|
||||
import com.topjohnwu.magisk.ktx.timeDateFormat
|
||||
import com.topjohnwu.magisk.ktx.toTime
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
|
||||
class LogRvItem(val item: SuLog) : ObservableItem<LogRvItem>() {
|
||||
class LogRvItem(
|
||||
override val item: SuLog
|
||||
) : ObservableDiffRvItem<LogRvItem>(), RvContainer<SuLog> {
|
||||
|
||||
override val layoutRes = R.layout.item_log_access_md2
|
||||
|
||||
@@ -24,14 +27,4 @@ class LogRvItem(val item: SuLog) : ObservableItem<LogRvItem>() {
|
||||
set(value) = set(value, field, { field = it }, BR.bottom)
|
||||
|
||||
override fun itemSameAs(other: LogRvItem) = item.appName == other.item.appName
|
||||
|
||||
override fun contentSameAs(other: LogRvItem) = item.fromUid == other.item.fromUid &&
|
||||
item.toUid == other.item.toUid &&
|
||||
item.fromPid == other.item.fromPid &&
|
||||
item.packageName == other.item.packageName &&
|
||||
item.command == other.item.command &&
|
||||
item.action == other.item.action &&
|
||||
item.time == other.item.time &&
|
||||
isTop == other.isTop &&
|
||||
isBottom == other.isBottom
|
||||
}
|
||||
|
||||
@@ -5,22 +5,20 @@ import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.databinding.DiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableDiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvContainer
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
|
||||
object InstallModule : ComparableRvItem<InstallModule>() {
|
||||
object InstallModule : DiffRvItem<InstallModule>() {
|
||||
override val layoutRes = R.layout.item_module_download
|
||||
|
||||
override fun contentSameAs(other: InstallModule) = this == other
|
||||
override fun itemSameAs(other: InstallModule) = this === other
|
||||
}
|
||||
|
||||
class SectionTitle(
|
||||
val title: Int,
|
||||
_button: Int = 0,
|
||||
_icon: Int = 0
|
||||
) : ObservableItem<SectionTitle>() {
|
||||
) : ObservableDiffRvItem<SectionTitle>() {
|
||||
override val layoutRes = R.layout.item_section_md2
|
||||
|
||||
@get:Bindable
|
||||
@@ -34,12 +32,11 @@ class SectionTitle(
|
||||
@get:Bindable
|
||||
var hasButton = _button != 0 && _icon != 0
|
||||
set(value) = set(value, field, { field = it }, BR.hasButton)
|
||||
|
||||
override fun itemSameAs(other: SectionTitle): Boolean = this === other
|
||||
override fun contentSameAs(other: SectionTitle): Boolean = this === other
|
||||
}
|
||||
|
||||
class OnlineModuleRvItem(val item: OnlineModule) : ObservableItem<OnlineModuleRvItem>() {
|
||||
class OnlineModuleRvItem(
|
||||
override val item: OnlineModule
|
||||
) : ObservableDiffRvItem<OnlineModuleRvItem>(), RvContainer<OnlineModule> {
|
||||
override val layoutRes: Int = R.layout.item_repo_md2
|
||||
|
||||
@get:Bindable
|
||||
@@ -48,12 +45,12 @@ class OnlineModuleRvItem(val item: OnlineModule) : ObservableItem<OnlineModuleRv
|
||||
|
||||
var hasUpdate = false
|
||||
|
||||
override fun contentSameAs(other: OnlineModuleRvItem): Boolean = item == other.item
|
||||
override fun itemSameAs(other: OnlineModuleRvItem): Boolean = item.id == other.item.id
|
||||
|
||||
}
|
||||
|
||||
class LocalModuleRvItem(val item: LocalModule) : ObservableItem<LocalModuleRvItem>() {
|
||||
class LocalModuleRvItem(
|
||||
override val item: LocalModule
|
||||
) : ObservableDiffRvItem<LocalModuleRvItem>(), RvContainer<LocalModule> {
|
||||
|
||||
override val layoutRes = R.layout.item_module_md2
|
||||
|
||||
@@ -81,10 +78,5 @@ class LocalModuleRvItem(val item: LocalModule) : ObservableItem<LocalModuleRvIte
|
||||
viewModel.updateActiveState()
|
||||
}
|
||||
|
||||
override fun contentSameAs(other: LocalModuleRvItem): Boolean = item.version == other.item.version
|
||||
&& item.versionCode == other.item.versionCode
|
||||
&& item.description == other.item.description
|
||||
&& item.name == other.item.name
|
||||
|
||||
override fun itemSameAs(other: LocalModuleRvItem): Boolean = item.id == other.item.id
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.topjohnwu.magisk.arch.*
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.databinding.AnyDiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvItem
|
||||
import com.topjohnwu.magisk.events.OpenReadmeEvent
|
||||
import com.topjohnwu.magisk.events.SelectModuleEvent
|
||||
@@ -44,8 +44,8 @@ class ModuleViewModel : BaseViewModel(), Queryable {
|
||||
var searchLoading = false
|
||||
set(value) = set(value, field, { field = it }, BR.searchLoading)
|
||||
|
||||
val itemsSearch = diffListOf<ComparableRvItem<*>>()
|
||||
val itemSearchBinding = itemBindingOf<ComparableRvItem<*>> {
|
||||
val itemsSearch = diffListOf<AnyDiffRvItem>()
|
||||
val itemSearchBinding = itemBindingOf<AnyDiffRvItem> {
|
||||
it.bindExtra(BR.viewModel, this)
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class ModuleViewModel : BaseViewModel(), Queryable {
|
||||
|
||||
// ---
|
||||
|
||||
private suspend fun queryInternal(query: String): List<ComparableRvItem<*>> {
|
||||
private suspend fun queryInternal(query: String): List<AnyDiffRvItem> {
|
||||
return if (query.isBlank()) {
|
||||
itemsSearch.clear()
|
||||
listOf()
|
||||
|
||||
@@ -7,12 +7,12 @@ import androidx.annotation.CallSuper
|
||||
import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableRvItem
|
||||
import com.topjohnwu.magisk.utils.TextHolder
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
|
||||
sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() {
|
||||
sealed class BaseSettingsItem : ObservableRvItem() {
|
||||
|
||||
override val layoutRes get() = R.layout.item_settings
|
||||
|
||||
@@ -42,9 +42,6 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() {
|
||||
|
||||
open fun refresh() {}
|
||||
|
||||
override fun itemSameAs(other: BaseSettingsItem) = this === other
|
||||
override fun contentSameAs(other: BaseSettingsItem) = itemSameAs(other)
|
||||
|
||||
// ---
|
||||
|
||||
interface Callback {
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.BuildConfig
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.BaseViewModel
|
||||
import com.topjohnwu.magisk.arch.adapterOf
|
||||
import com.topjohnwu.magisk.arch.diffListOf
|
||||
import com.topjohnwu.magisk.arch.itemBindingOf
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
@@ -32,7 +31,7 @@ class SettingsViewModel(
|
||||
|
||||
val adapter = adapterOf<BaseSettingsItem>()
|
||||
val itemBinding = itemBindingOf<BaseSettingsItem> { it.bindExtra(BR.callback, this) }
|
||||
val items = diffListOf(createItems())
|
||||
val items = createItems()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -5,14 +5,15 @@ import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.model.su.SuPolicy
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.databinding.ObservableDiffRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvContainer
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
|
||||
class PolicyRvItem(
|
||||
val item: SuPolicy,
|
||||
override val item: SuPolicy,
|
||||
val icon: Drawable,
|
||||
val viewModel: SuperuserViewModel
|
||||
) : ObservableItem<PolicyRvItem>() {
|
||||
) : ObservableDiffRvItem<PolicyRvItem>(), RvContainer<SuPolicy> {
|
||||
override val layoutRes = R.layout.item_policy_md2
|
||||
|
||||
@get:Bindable
|
||||
@@ -64,7 +65,6 @@ class PolicyRvItem(
|
||||
viewModel.deletePressed(this)
|
||||
}
|
||||
|
||||
override fun contentSameAs(other: PolicyRvItem) = itemSameAs(other)
|
||||
override fun itemSameAs(other: PolicyRvItem) = item.uid == other.item.uid
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.topjohnwu.magisk.core.magiskdb.PolicyDao
|
||||
import com.topjohnwu.magisk.core.model.su.SuPolicy
|
||||
import com.topjohnwu.magisk.core.utils.BiometricHelper
|
||||
import com.topjohnwu.magisk.core.utils.currentLocale
|
||||
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.databinding.AnyDiffRvItem
|
||||
import com.topjohnwu.magisk.events.SnackbarEvent
|
||||
import com.topjohnwu.magisk.events.dialog.BiometricEvent
|
||||
import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
|
||||
@@ -35,13 +35,13 @@ class SuperuserViewModel(
|
||||
private val itemsPolicies = diffListOf<PolicyRvItem>()
|
||||
private val itemsHelpers = ObservableArrayList<TextItem>()
|
||||
|
||||
val adapter = adapterOf<ComparableRvItem<*>>()
|
||||
val items = MergeObservableList<ComparableRvItem<*>>().apply {
|
||||
val adapter = adapterOf<AnyDiffRvItem>()
|
||||
val items = MergeObservableList<AnyDiffRvItem>().apply {
|
||||
if (Config.magiskHide)
|
||||
insertItem(TappableHeadlineItem.Hide)
|
||||
}.insertList(itemsHelpers)
|
||||
.insertList(itemsPolicies)
|
||||
val itemBinding = itemBindingOf<ComparableRvItem<*>> {
|
||||
val itemBinding = itemBindingOf<AnyDiffRvItem> {
|
||||
it.bindExtra(BR.listener, this)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class SuperuserViewModel(
|
||||
fun deletePressed(item: PolicyRvItem) {
|
||||
fun updateState() = viewModelScope.launch {
|
||||
db.delete(item.item.uid)
|
||||
itemsPolicies.removeAll { it.genericItemSameAs(item) }
|
||||
itemsPolicies.removeAll { it.itemSameAs(item) }
|
||||
if (itemsPolicies.isEmpty() && itemsHelpers.isEmpty()) {
|
||||
itemsHelpers.add(itemNoData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user