From 7cf3da1b3b6a6300d5bd5b4fbab1383e01c39a1f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 12 Jul 2020 14:35:21 -0700 Subject: [PATCH] Update implementation to use new methods --- .../magisk/model/entity/recycler/LogRvItem.kt | 17 +++----- .../model/entity/recycler/ModuleRvItem.kt | 43 ++++++------------- .../magisk/ui/module/ModuleViewModel.kt | 3 +- 3 files changed, 18 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt index 8ea52474d..5059ad34c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/LogRvItem.kt @@ -7,24 +7,17 @@ import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.ktx.timeDateFormat import com.topjohnwu.magisk.ktx.toTime import com.topjohnwu.magisk.model.entity.MagiskLog +import com.topjohnwu.magisk.utils.observable class LogItem(val item: MagiskLog) : ObservableItem() { override val layoutRes = R.layout.item_log_access_md2 val date = item.time.toTime(timeDateFormat) - var isTop = false - @Bindable get - set(value) { - field = value - notifyPropertyChanged(BR.top) - } - var isBottom = false - @Bindable get - set(value) { - field = value - notifyPropertyChanged(BR.bottom) - } + @get:Bindable + var isTop by observable(false, BR.top) + @get:Bindable + var isBottom by observable(false, BR.bottom) override fun itemSameAs(other: LogItem) = item.appName == other.item.appName diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt index 59e484b5d..2fa90a0f9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt @@ -2,7 +2,6 @@ package com.topjohnwu.magisk.model.entity.recycler import androidx.databinding.Bindable import androidx.databinding.Observable -import androidx.databinding.ObservableField import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.StaggeredGridLayoutManager import com.topjohnwu.magisk.BR @@ -12,6 +11,7 @@ import com.topjohnwu.magisk.core.model.module.Repo import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.ui.module.ModuleViewModel +import com.topjohnwu.magisk.utils.observable object InstallModule : ComparableRvItem() { override val layoutRes = R.layout.item_module_download @@ -33,24 +33,12 @@ class SectionTitle( ) : ObservableItem() { override val layoutRes = R.layout.item_section_md2 - var button = _button - @Bindable get - set(value) { - field = value - notifyPropertyChanged(BR.button) - } - var icon = _icon - @Bindable get - set(value) { - field = value - notifyPropertyChanged(BR.icon) - } - var hasButton = button != 0 || icon != 0 - @Bindable get - set(value) { - field = value - notifyPropertyChanged(BR.hasButton) - } + @get:Bindable + var button by observable(_button, BR.button) + @get:Bindable + var icon by observable(_icon, BR.icon) + @get:Bindable + var hasButton by observable(_button != 0 && _icon != 0, BR.hasButton) override fun onBindingBound(binding: ViewDataBinding) { super.onBindingBound(binding) @@ -65,13 +53,10 @@ class SectionTitle( sealed class RepoItem(val item: Repo) : ObservableItem() { override val layoutRes: Int = R.layout.item_repo_md2 - val progress = ObservableField(0) - var isUpdate = false - @Bindable get - protected set(value) { - field = value - notifyPropertyChanged(BR.update) - } + @get:Bindable + var progress by observable(0, BR.progress) + @get:Bindable + var isUpdate by observable(false, BR.update) override fun contentSameAs(other: RepoItem): Boolean = item == other.item override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id @@ -90,11 +75,7 @@ class ModuleItem(val item: Module) : ObservableItem(), Observable { override val layoutRes = R.layout.item_module_md2 @get:Bindable - var repo: Repo? = null - set(value) { - field = value - notifyPropertyChanged(BR.repo) - } + var repo: Repo? by observable(null, BR.repo) @get:Bindable var isEnabled diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 4168443a5..f016d6ab8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -15,7 +15,6 @@ import com.topjohnwu.magisk.data.database.RepoByUpdatedDao import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.ktx.addOnListChangedCallback import com.topjohnwu.magisk.ktx.reboot -import com.topjohnwu.magisk.ktx.value import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.recycler.* import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent @@ -276,7 +275,7 @@ class ModuleViewModel( itemsRemote.filter(predicate) + itemsSearch.filter(predicate) } - items.forEach { it.progress.value = progress } + items.forEach { it.progress = progress } } // ---