mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 12:17:38 +00:00
Added division of the modules section to updatable, installed and not installed
This commit is contained in:
parent
761a8bf2a9
commit
2de984ae24
@ -15,6 +15,6 @@ val viewModelModules = module {
|
||||
viewModel { HomeViewModel(get(), get()) }
|
||||
viewModel { SuperuserViewModel(get(), get(), get(), get()) }
|
||||
viewModel { HideViewModel(get(), get()) }
|
||||
viewModel { ModuleViewModel(get()) }
|
||||
viewModel { ModuleViewModel(get(), get()) }
|
||||
viewModel { LogViewModel(get(), get()) }
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.topjohnwu.magisk.model.entity.recycler
|
||||
|
||||
import com.skoumal.teanity.databinding.ComparableRvItem
|
||||
import com.topjohnwu.magisk.R
|
||||
|
||||
class SectionRvItem(val text: String) : ComparableRvItem<SectionRvItem>() {
|
||||
override val layoutRes: Int = R.layout.item_section
|
||||
|
||||
override fun contentSameAs(other: SectionRvItem) = itemSameAs(other)
|
||||
override fun itemSameAs(other: SectionRvItem) = text == other.text
|
||||
}
|
@ -1,17 +1,21 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.database.Cursor
|
||||
import androidx.annotation.StringRes
|
||||
import com.skoumal.teanity.databinding.ComparableRvItem
|
||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||
import com.skoumal.teanity.extensions.subscribeK
|
||||
import com.skoumal.teanity.util.DiffObservableList
|
||||
import com.skoumal.teanity.util.KObservableField
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||
import com.topjohnwu.magisk.model.entity.Module
|
||||
import com.topjohnwu.magisk.model.entity.Repo
|
||||
import com.topjohnwu.magisk.model.entity.recycler.ModuleRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.RepoRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.SectionRvItem
|
||||
import com.topjohnwu.magisk.model.events.InstallModuleEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenChangelogEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenFilePickerEvent
|
||||
@ -25,7 +29,8 @@ import io.reactivex.Single
|
||||
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||
|
||||
class ModuleViewModel(
|
||||
private val repoDatabase: RepoDatabaseHelper
|
||||
private val repoDatabase: RepoDatabaseHelper,
|
||||
private val resources: Resources
|
||||
) : MagiskViewModel() {
|
||||
|
||||
val query = KObservableField("")
|
||||
@ -94,8 +99,34 @@ class ModuleViewModel(
|
||||
it.item.description.contains(query, ignoreCase = true)
|
||||
}
|
||||
.toList()
|
||||
.map { if (query.isEmpty()) it.divide() else it }
|
||||
.map { it to itemsRemote.calculateDiff(it) }
|
||||
|
||||
private fun List<RepoRvItem>.divide(): List<ComparableRvItem<*>> {
|
||||
val installed = itemsInstalled.filterIsInstance<ModuleRvItem>()
|
||||
val installedModules = filter { installed.any { item -> it.item.id == item.item.id } }
|
||||
|
||||
fun installedByID(id: String) = installed.firstOrNull { it.item.id == id }
|
||||
|
||||
fun List<RepoRvItem>.filterObsolete() = filter {
|
||||
val module = installedByID(it.item.id) ?: return@filter false
|
||||
module.item.versionCode != it.item.versionCode
|
||||
}
|
||||
|
||||
val resultObsolete = installedModules.filterObsolete()
|
||||
val resultInstalled = installedModules - resultObsolete
|
||||
val resultRemote = toList() - installedModules
|
||||
|
||||
fun buildList(@StringRes text: Int, list: List<RepoRvItem>): List<ComparableRvItem<*>> {
|
||||
return if (list.isEmpty()) list
|
||||
else listOf(SectionRvItem(resources.getString(text))) + list
|
||||
}
|
||||
|
||||
return buildList(R.string.update_available, resultObsolete) +
|
||||
buildList(R.string.installed, resultInstalled) +
|
||||
buildList(R.string.not_installed, resultRemote)
|
||||
}
|
||||
|
||||
private fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
|
||||
val out = mutableListOf<Result>()
|
||||
while (moveToNext()) out.add(transformer(this))
|
||||
|
24
app/src/main/res/layout/item_section.xml
Normal file
24
app/src/main/res/layout/item_section.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.topjohnwu.magisk.model.entity.recycler.SectionRvItem" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="Object" />
|
||||
|
||||
</data>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/Widget.Text.SectionTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{item.text}"
|
||||
tools:text="@string/update_available" />
|
||||
|
||||
</layout>
|
Loading…
x
Reference in New Issue
Block a user