Commit f5aa6a3c authored by topjohnwu's avatar topjohnwu

Update module fragment

Update UI and logic for loading modules
parent c944277e
......@@ -92,7 +92,7 @@ class RepoUpdater(
}
}
suspend operator fun invoke(forced: Boolean) = withContext(Dispatchers.IO) {
suspend fun run(forced: Boolean) = withContext(Dispatchers.IO) {
val cached = HashSet(repoDB.repoIDList).synchronized()
when (loadPage(cached, etag = repoDB.etagKey)) {
PageResult.CACHED -> if (forced) forcedReload(cached)
......
package com.topjohnwu.magisk.model.entity.recycler
import androidx.databinding.Bindable
import androidx.databinding.Observable
import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.model.module.Module
......@@ -62,7 +61,7 @@ sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() {
}
}
class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {
class ModuleItem(val item: Module) : ObservableItem<ModuleItem>() {
override val layoutRes = R.layout.item_module_md2
......@@ -71,19 +70,15 @@ class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {
set(value) = set(value, field, { field = it }, BR.repo)
@get:Bindable
var isEnabled
get() = item.enable
set(value) {
var isEnabled = item.enable
set(value) = set(value, field, { field = it }, BR.enabled) {
item.enable = value
notifyPropertyChanged(BR.enabled)
}
@get:Bindable
var isRemoved
get() = item.remove
set(value) {
var isRemoved = item.remove
set(value) = set(value, field, { field = it }, BR.removed) {
item.remove = value
notifyPropertyChanged(BR.removed)
}
val isUpdated get() = item.updated
......
......@@ -27,7 +27,7 @@ inline fun <T : ComparableRvItem<*>> filterableListOf(
override fun areContentsTheSame(oldItem: T, newItem: T) = oldItem.genericContentSameAs(newItem)
}).also { it.update(newItems.toList()) }
fun <T : ComparableRvItem<*>> adapterOf() = object : BindingRecyclerViewAdapter<T>() {
fun <T : RvItem> adapterOf() = object : BindingRecyclerViewAdapter<T>() {
override fun onBindBinding(
binding: ViewDataBinding,
variableId: Int,
......
......@@ -32,7 +32,7 @@
android:id="@+id/module_list"
adapter="@{viewModel.adapter}"
dividerHorizontal="@{@drawable/divider_l1}"
dividerVertical="@{@drawable/divider_l1}"
dividerVertical="@{@drawable/divider_l_50}"
gone="@{viewModel.loading &amp;&amp; viewModel.items.empty}"
itemBinding="@{viewModel.itemBinding}"
items="@{viewModel.items}"
......
......@@ -15,42 +15,36 @@
</data>
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:layout_height="wrap_content">
android:gravity="center_vertical">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_title"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{item.title}"
android:textAppearance="@style/AppearanceFoundation.Body"
android:textAppearance="@style/AppearanceFoundation.Large"
android:textColor="@color/color_primary_transient"
android:textStyle="bold"
tools:text="@tools:sample/lorem/random"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/module_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
tools:text="Installed" />
<com.google.android.material.button.MaterialButton
android:id="@+id/module_button"
style="@style/WidgetFoundation.Button.Text.Secondary"
gone="@{!item.hasButton}"
invisible="@{!item.hasButton}"
android:onClick="@{() -> viewModel.sectionPressed(item)}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
android:text="@{item.button}"
tools:text="@tools:sample/lorem"
android:textAllCaps="false"
app:icon="@{item.icon}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/module_title"
app:layout_constraintTop_toTopOf="parent" />
tools:text="Reboot" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</layout>
......@@ -22,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{item.title}"
android:textAppearance="@style/AppearanceFoundation.Display.Secondary"
android:textAppearance="@style/AppearanceFoundation.Large.Secondary"
android:textStyle="bold"
tools:text="@tools:sample/lorem" />
......@@ -36,4 +36,4 @@
</LinearLayout>
</layout>
\ No newline at end of file
</layout>
......@@ -2,19 +2,19 @@
<resources>
<!--region Display-->
<style name="AppearanceFoundation.Display" parent="TextAppearance.AppCompat.Display1">
<style name="AppearanceFoundation.Large" parent="TextAppearance.AppCompat.Large">
<item name="android:textColor">?attr/colorOnSurface</item>
</style>
<style name="AppearanceFoundation.Display.Secondary">
<style name="AppearanceFoundation.Large.Secondary">
<item name="android:textColor">?colorSecondary</item>
</style>
<style name="AppearanceFoundation.Display.Variant">
<style name="AppearanceFoundation.Large.Variant">
<item name="android:textColor">?attr/colorOnSurfaceVariant</item>
</style>
<style name="AppearanceFoundation.Display.OnPrimary">
<style name="AppearanceFoundation.Display.OnPrimary" parent="TextAppearance.AppCompat.Display1">
<item name="android:textColor">?attr/colorOnPrimary</item>
</style>
......@@ -119,4 +119,4 @@
</style>
<!--endregion-->
</resources>
\ No newline at end of file
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment