diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt index ac8ec6f12..657c144ab 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt @@ -90,11 +90,24 @@ object InstallModule : ComparableRvItem() { class SectionTitle( val title: Int, - val button: Int = 0, - val icon: Int = 0 -) : ComparableRvItem() { + _button: Int = 0, + _icon: Int = 0 +) : ObservableItem() { override val layoutRes = R.layout.item_section_md2 + @Bindable + var button = _button + set(value) { + field = value + notifyChange(BR.button) + } + @Bindable + var icon = _icon + set(value) { + field = value + notifyChange(BR.icon) + } + val hasButton = KObservableField(button != 0 || icon != 0) override fun onBindingBound(binding: ViewDataBinding) { diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index 22261169e..b19f51c66 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -68,12 +68,25 @@ class ModuleViewModel( } companion object { - private val sectionRemote = SectionTitle(R.string.module_section_remote) + private val sectionRemote = + SectionTitle(R.string.module_section_remote, R.string.sorting_order) private val sectionActive = SectionTitle( R.string.module_section_installed, R.string.reboot, R.drawable.ic_restart ).also { it.hasButton.value = false } + + init { + updateOrderIcon() + } + + private fun updateOrderIcon() { + sectionRemote.icon = when (Config.repoOrder) { + Config.Value.ORDER_NAME -> R.drawable.ic_order_name + Config.Value.ORDER_DATE -> R.drawable.ic_order_date + else -> return + } + } } // --- @@ -221,6 +234,20 @@ class ModuleViewModel( fun sectionPressed(item: SectionTitle) = when (item) { sectionActive -> reboot() //TODO add reboot picker, regular reboot is not always preferred + sectionRemote -> { + Config.repoOrder = when (Config.repoOrder) { + Config.Value.ORDER_NAME -> Config.Value.ORDER_DATE + Config.Value.ORDER_DATE -> Config.Value.ORDER_NAME + else -> Config.Value.ORDER_NAME + } + updateOrderIcon() + Single.fromCallable { itemsRemote } + .subscribeK { + items.removeAll(it) + remoteJob?.dispose() + loadRemote() + }.add() + } else -> Unit } diff --git a/app/src/main/res/drawable/ic_order_date.xml b/app/src/main/res/drawable/ic_order_date.xml new file mode 100644 index 000000000..f98e20ddd --- /dev/null +++ b/app/src/main/res/drawable/ic_order_date.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_order_name.xml b/app/src/main/res/drawable/ic_order_name.xml new file mode 100644 index 000000000..a845aa351 --- /dev/null +++ b/app/src/main/res/drawable/ic_order_name.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_module_download.xml b/app/src/main/res/layout/item_module_download.xml index 6773a1a93..1bfb357f9 100644 --- a/app/src/main/res/layout/item_module_download.xml +++ b/app/src/main/res/layout/item_module_download.xml @@ -16,7 +16,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> @@ -27,6 +28,7 @@ android:textAppearance="?appearanceTextBodyNormal" android:textColor="?colorPrimaryTransient" 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" @@ -34,13 +36,14 @@