Added sorting order to modules

This commit is contained in:
Viktor De Pasquale 2019-11-16 20:07:59 +01:00
parent 59c5363933
commit 1c77e26c05
6 changed files with 70 additions and 7 deletions

View File

@ -90,11 +90,24 @@ object InstallModule : ComparableRvItem<InstallModule>() {
class SectionTitle( class SectionTitle(
val title: Int, val title: Int,
val button: Int = 0, _button: Int = 0,
val icon: Int = 0 _icon: Int = 0
) : ComparableRvItem<SectionTitle>() { ) : ObservableItem<SectionTitle>() {
override val layoutRes = R.layout.item_section_md2 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) val hasButton = KObservableField(button != 0 || icon != 0)
override fun onBindingBound(binding: ViewDataBinding) { override fun onBindingBound(binding: ViewDataBinding) {

View File

@ -68,12 +68,25 @@ class ModuleViewModel(
} }
companion object { 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( private val sectionActive = SectionTitle(
R.string.module_section_installed, R.string.module_section_installed,
R.string.reboot, R.string.reboot,
R.drawable.ic_restart R.drawable.ic_restart
).also { it.hasButton.value = false } ).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) { fun sectionPressed(item: SectionTitle) = when (item) {
sectionActive -> reboot() //TODO add reboot picker, regular reboot is not always preferred 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 else -> Unit
} }

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="M7.78,7C9.08,7.04 10,7.53 10.57,8.46C11.13,9.4 11.41,10.56 11.39,11.95C11.4,13.5 11.09,14.73 10.5,15.62C9.88,16.5 8.95,16.97 7.71,17C6.45,16.96 5.54,16.5 4.96,15.56C4.38,14.63 4.09,13.45 4.09,12C4.09,10.55 4.39,9.36 5,8.44C5.59,7.5 6.5,7.04 7.78,7M7.75,8.63C7.31,8.63 6.96,8.9 6.7,9.46C6.44,10 6.32,10.87 6.32,12C6.31,13.15 6.44,14 6.69,14.54C6.95,15.1 7.31,15.37 7.77,15.37C8.69,15.37 9.16,14.24 9.17,12C9.17,9.77 8.7,8.65 7.75,8.63M13.33,17V15.22L13.76,15.24L14.3,15.22L15.34,15.03C15.68,14.92 16,14.78 16.26,14.58C16.59,14.35 16.86,14.08 17.07,13.76C17.29,13.45 17.44,13.12 17.53,12.78L17.5,12.77C17.05,13.19 16.38,13.4 15.47,13.41C14.62,13.4 13.91,13.15 13.34,12.65C12.77,12.15 12.5,11.43 12.46,10.5C12.47,9.5 12.81,8.69 13.47,8.03C14.14,7.37 15,7.03 16.12,7C17.37,7.04 18.29,7.45 18.88,8.24C19.47,9 19.76,10 19.76,11.19C19.75,12.15 19.61,13 19.32,13.76C19.03,14.5 18.64,15.13 18.12,15.64C17.66,16.06 17.11,16.38 16.47,16.61C15.83,16.83 15.12,16.96 14.34,17H13.33M16.06,8.63C15.65,8.64 15.32,8.8 15.06,9.11C14.81,9.42 14.68,9.84 14.68,10.36C14.68,10.8 14.8,11.16 15.03,11.46C15.27,11.77 15.63,11.92 16.11,11.93C16.43,11.93 16.7,11.86 16.92,11.74C17.14,11.61 17.3,11.46 17.41,11.28C17.5,11.17 17.53,10.97 17.53,10.71C17.54,10.16 17.43,9.69 17.2,9.28C16.97,8.87 16.59,8.65 16.06,8.63M9.25,5L12.5,1.75L15.75,5H9.25M15.75,19L12.5,22.25L9.25,19H15.75Z" />
</vector>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?colorOnSurface"
android:pathData="M9.25,5L12.5,1.75L15.75,5H9.25M15.75,19L12.5,22.25L9.25,19H15.75M8.89,14.3H6L5.28,17H2.91L6,7H9L12.13,17H9.67L8.89,14.3M6.33,12.68H8.56L7.93,10.56L7.67,9.59L7.42,8.63H7.39L7.17,9.6L6.93,10.58L6.33,12.68M13.05,17V15.74L17.8,8.97V8.91H13.5V7H20.73V8.34L16.09,15V15.08H20.8V17H13.05Z" />
</vector>

View File

@ -16,7 +16,7 @@
</data> </data>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="?styleButtonText" style="?styleButtonTextSecondary"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.installPressed()}" android:onClick="@{() -> viewModel.installPressed()}"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data> <data>
@ -27,6 +28,7 @@
android:textAppearance="?appearanceTextBodyNormal" android:textAppearance="?appearanceTextBodyNormal"
android:textColor="?colorPrimaryTransient" android:textColor="?colorPrimaryTransient"
android:textStyle="bold" android:textStyle="bold"
tools:text="@tools:sample/lorem/random"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/module_button" app:layout_constraintEnd_toStartOf="@+id/module_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -34,13 +36,14 @@
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/module_button" android:id="@+id/module_button"
style="?styleButtonText" style="?styleButtonTextSecondary"
gone="@{!item.hasButton}" gone="@{!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:iconPadding="@dimen/l_50" app:iconPadding="@dimen/l_50"