Update implementation to use new methods

This commit is contained in:
topjohnwu 2020-07-12 14:35:21 -07:00
parent 45fabf8e03
commit 7cf3da1b3b
3 changed files with 18 additions and 45 deletions

View File

@ -7,24 +7,17 @@ import com.topjohnwu.magisk.databinding.ObservableItem
import com.topjohnwu.magisk.ktx.timeDateFormat import com.topjohnwu.magisk.ktx.timeDateFormat
import com.topjohnwu.magisk.ktx.toTime import com.topjohnwu.magisk.ktx.toTime
import com.topjohnwu.magisk.model.entity.MagiskLog import com.topjohnwu.magisk.model.entity.MagiskLog
import com.topjohnwu.magisk.utils.observable
class LogItem(val item: MagiskLog) : ObservableItem<LogItem>() { class LogItem(val item: MagiskLog) : ObservableItem<LogItem>() {
override val layoutRes = R.layout.item_log_access_md2 override val layoutRes = R.layout.item_log_access_md2
val date = item.time.toTime(timeDateFormat) val date = item.time.toTime(timeDateFormat)
var isTop = false @get:Bindable
@Bindable get var isTop by observable(false, BR.top)
set(value) { @get:Bindable
field = value var isBottom by observable(false, BR.bottom)
notifyPropertyChanged(BR.top)
}
var isBottom = false
@Bindable get
set(value) {
field = value
notifyPropertyChanged(BR.bottom)
}
override fun itemSameAs(other: LogItem) = item.appName == other.item.appName override fun itemSameAs(other: LogItem) = item.appName == other.item.appName

View File

@ -2,7 +2,6 @@ package com.topjohnwu.magisk.model.entity.recycler
import androidx.databinding.Bindable import androidx.databinding.Bindable
import androidx.databinding.Observable import androidx.databinding.Observable
import androidx.databinding.ObservableField
import androidx.databinding.ViewDataBinding import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.StaggeredGridLayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.topjohnwu.magisk.BR 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.ComparableRvItem
import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.databinding.ObservableItem
import com.topjohnwu.magisk.ui.module.ModuleViewModel import com.topjohnwu.magisk.ui.module.ModuleViewModel
import com.topjohnwu.magisk.utils.observable
object InstallModule : ComparableRvItem<InstallModule>() { object InstallModule : ComparableRvItem<InstallModule>() {
override val layoutRes = R.layout.item_module_download override val layoutRes = R.layout.item_module_download
@ -33,24 +33,12 @@ class SectionTitle(
) : ObservableItem<SectionTitle>() { ) : ObservableItem<SectionTitle>() {
override val layoutRes = R.layout.item_section_md2 override val layoutRes = R.layout.item_section_md2
var button = _button @get:Bindable
@Bindable get var button by observable(_button, BR.button)
set(value) { @get:Bindable
field = value var icon by observable(_icon, BR.icon)
notifyPropertyChanged(BR.button) @get:Bindable
} var hasButton by observable(_button != 0 && _icon != 0, BR.hasButton)
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)
}
override fun onBindingBound(binding: ViewDataBinding) { override fun onBindingBound(binding: ViewDataBinding) {
super.onBindingBound(binding) super.onBindingBound(binding)
@ -65,13 +53,10 @@ class SectionTitle(
sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() { sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() {
override val layoutRes: Int = R.layout.item_repo_md2 override val layoutRes: Int = R.layout.item_repo_md2
val progress = ObservableField(0) @get:Bindable
var isUpdate = false var progress by observable(0, BR.progress)
@Bindable get @get:Bindable
protected set(value) { var isUpdate by observable(false, BR.update)
field = value
notifyPropertyChanged(BR.update)
}
override fun contentSameAs(other: RepoItem): Boolean = item == other.item override fun contentSameAs(other: RepoItem): Boolean = item == other.item
override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id
@ -90,11 +75,7 @@ class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {
override val layoutRes = R.layout.item_module_md2 override val layoutRes = R.layout.item_module_md2
@get:Bindable @get:Bindable
var repo: Repo? = null var repo: Repo? by observable(null, BR.repo)
set(value) {
field = value
notifyPropertyChanged(BR.repo)
}
@get:Bindable @get:Bindable
var isEnabled var isEnabled

View File

@ -15,7 +15,6 @@ import com.topjohnwu.magisk.data.database.RepoByUpdatedDao
import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.databinding.ComparableRvItem
import com.topjohnwu.magisk.ktx.addOnListChangedCallback import com.topjohnwu.magisk.ktx.addOnListChangedCallback
import com.topjohnwu.magisk.ktx.reboot 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.internal.DownloadSubject
import com.topjohnwu.magisk.model.entity.recycler.* import com.topjohnwu.magisk.model.entity.recycler.*
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
@ -276,7 +275,7 @@ class ModuleViewModel(
itemsRemote.filter(predicate) + itemsRemote.filter(predicate) +
itemsSearch.filter(predicate) itemsSearch.filter(predicate)
} }
items.forEach { it.progress.value = progress } items.forEach { it.progress = progress }
} }
// --- // ---