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.toTime
import com.topjohnwu.magisk.model.entity.MagiskLog
import com.topjohnwu.magisk.utils.observable
class LogItem(val item: MagiskLog) : ObservableItem<LogItem>() {
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

View File

@ -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<InstallModule>() {
override val layoutRes = R.layout.item_module_download
@ -33,24 +33,12 @@ class SectionTitle(
) : ObservableItem<SectionTitle>() {
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<RepoItem>() {
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<ModuleItem>(), 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

View File

@ -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 }
}
// ---