Added assigning repo to installed modules to show readme

Close #1089
This commit is contained in:
Viktor De Pasquale 2019-12-13 15:18:47 +01:00
parent 3bda7cb26b
commit 89b1fa341b
4 changed files with 35 additions and 0 deletions

View File

@ -14,6 +14,9 @@ interface RepoBase {
@Query("SELECT * FROM repos WHERE id = :id AND versionCode > :versionCode LIMIT 1")
fun getUpdatableRepoById(id: String, versionCode: Int): Repo?
@Query("SELECT * FROM repos WHERE id = :id LIMIT 1")
fun getRepoById(id: String): Repo?
companion object {
const val LIMIT = 10
}

View File

@ -170,6 +170,13 @@ 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
notifyChange(BR.repo)
}
@get:Bindable
var isEnabled = item.enable
set(value) {

View File

@ -129,6 +129,7 @@ class ModuleViewModel(
override fun refresh() = Single.fromCallable { Module.loadModules() }
.map { it.map { ModuleItem(it) } }
.map { it.order() }
.map { it.loadDetail() }
.map { build(active = it, updatable = loadUpdates(it)) }
.map { it to items.calculateDiff(it) }
.applyViewModel(this)
@ -222,6 +223,13 @@ class ModuleViewModel(
.sortedBy { it.item.name.toLowerCase(currentLocale) }
.toList()
@WorkerThread
private fun List<ModuleItem>.loadDetail() = onEach { module ->
Single.fromCallable { dao.getRepoById(module.item.id)!! }
.subscribeK { module.repo = it }
.add()
}
private fun update(repo: Repo, progress: Int) =
Single.fromCallable { itemsRemote + itemsSearch }
.map { it.first { it.item.id == repo.id } }
@ -263,6 +271,9 @@ class ModuleViewModel(
fun downloadPressed(item: RepoItem) = ModuleInstallDialog(item.item).publish()
fun installPressed() = InstallExternalModuleEvent().publish()
fun infoPressed(item: RepoItem) = OpenChangelogEvent(item.item).publish()
fun infoPressed(item: ModuleItem) {
OpenChangelogEvent(item.repo ?: return).publish()
}
// ---

View File

@ -97,7 +97,21 @@
android:background="?colorSurfaceVariant"
app:layout_constraintTop_toBottomOf="@+id/module_description" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/module_info"
style="@style/WidgetFoundation.Icon"
gone="@{item.repo == null}"
android:layout_width="wrap_content"
android:alpha=".5"
android:onClick="@{() -> viewModel.infoPressed(item)}"
android:paddingEnd="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="@+id/module_remove"
app:layout_constraintEnd_toStartOf="@+id/module_remove"
app:layout_constraintTop_toTopOf="@+id/module_remove"
app:srcCompat="@drawable/ic_info" />
<com.google.android.material.button.MaterialButton
android:id="@+id/module_remove"
style="@style/WidgetFoundation.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"