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