mirror of
https://github.com/null2264/yokai.git
synced 2025-07-16 22:06:54 +00:00
fix: Selected icon for Random should be a reload icon
This commit is contained in:
parent
568859891a
commit
0565fc2665
3 changed files with 36 additions and 28 deletions
|
@ -37,8 +37,7 @@ interface Category : Serializable {
|
||||||
return ((mangaSort?.minus('a') ?: 0) % 2) != 1
|
return ((mangaSort?.minus('a') ?: 0) % 2) != 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sortingMode(nullAsDND: Boolean = false): LibrarySort? = LibrarySort.valueOf(mangaSort)
|
fun sortingMode(): LibrarySort? = LibrarySort.valueOf(mangaSort)
|
||||||
?: if (nullAsDND && !isDynamic) LibrarySort.DragAndDrop else null
|
|
||||||
|
|
||||||
val isDragAndDrop
|
val isDragAndDrop
|
||||||
get() = (
|
get() = (
|
||||||
|
|
|
@ -201,7 +201,7 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
|
|
||||||
val isAscending = category.isAscending()
|
val isAscending = category.isAscending()
|
||||||
val sortingMode = category.sortingMode()
|
val sortingMode = category.sortingMode()
|
||||||
val sortDrawable = getSortRes(sortingMode, isAscending, R.drawable.ic_sort_24dp)
|
val sortDrawable = getSortRes(sortingMode, isAscending, category.isDynamic, false)
|
||||||
|
|
||||||
binding.categorySort.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, sortDrawable, 0)
|
binding.categorySort.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, sortDrawable, 0)
|
||||||
binding.categorySort.setText(category.sortRes())
|
binding.categorySort.setText(category.sortRes())
|
||||||
|
@ -266,7 +266,7 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
val cat = category ?: return
|
val cat = category ?: return
|
||||||
adapter.controller?.activity?.let { activity ->
|
adapter.controller?.activity?.let { activity ->
|
||||||
val items = LibrarySort.entries.map { it.menuSheetItem(cat.isDynamic) }
|
val items = LibrarySort.entries.map { it.menuSheetItem(cat.isDynamic) }
|
||||||
val sortingMode = cat.sortingMode(true)
|
val sortingMode = cat.sortingMode() ?: if (!cat.isDynamic) LibrarySort.DragAndDrop else null
|
||||||
val sheet = MaterialMenuSheet(
|
val sheet = MaterialMenuSheet(
|
||||||
activity,
|
activity,
|
||||||
items,
|
items,
|
||||||
|
@ -275,42 +275,48 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
) { sheet, item ->
|
) { sheet, item ->
|
||||||
onCatSortClicked(cat, item)
|
onCatSortClicked(cat, item)
|
||||||
val nCategory = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
val nCategory = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||||
val isAscending = nCategory?.isAscending() ?: false
|
sheet.updateSortIcon(nCategory, LibrarySort.valueOf(item))
|
||||||
val drawableRes = getSortRes(item, isAscending)
|
|
||||||
sheet.setDrawable(item, drawableRes)
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
val isAscending = cat.isAscending()
|
sheet.updateSortIcon(cat, sortingMode)
|
||||||
val drawableRes = getSortRes(sortingMode, isAscending)
|
|
||||||
sheet.setDrawable(sortingMode?.mainValue ?: -1, drawableRes)
|
|
||||||
sheet.show()
|
sheet.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun MaterialMenuSheet.updateSortIcon(category: Category?, sortingMode: LibrarySort?) {
|
||||||
|
val isAscending = category?.isAscending() ?: false
|
||||||
|
val drawableRes = getSortRes(sortingMode, isAscending, category?.isDynamic ?: false, true)
|
||||||
|
this.setDrawable(sortingMode?.mainValue ?: -1, drawableRes)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getSortRes(
|
private fun getSortRes(
|
||||||
sortMode: LibrarySort?,
|
sortMode: LibrarySort?,
|
||||||
isAscending: Boolean,
|
isAscending: Boolean,
|
||||||
@DrawableRes defaultDrawableRes: Int = R.drawable.ic_check_24dp,
|
isDynamic: Boolean,
|
||||||
|
onSelection: Boolean,
|
||||||
|
@DrawableRes defaultDrawableRes: Int = R.drawable.ic_sort_24dp,
|
||||||
|
@DrawableRes defaultSelectedDrawableRes: Int = R.drawable.ic_check_24dp,
|
||||||
): Int {
|
): Int {
|
||||||
sortMode ?: return defaultDrawableRes
|
sortMode ?: return if (onSelection) defaultSelectedDrawableRes else defaultDrawableRes
|
||||||
return when (sortMode) {
|
|
||||||
LibrarySort.DragAndDrop -> defaultDrawableRes
|
if (sortMode.isDirectional) {
|
||||||
LibrarySort.Random -> R.drawable.ic_shuffle_24dp
|
return if (if (sortMode.hasInvertedSort) !isAscending else isAscending) {
|
||||||
else -> {
|
R.drawable.ic_arrow_downward_24dp
|
||||||
if (if (sortMode.hasInvertedSort) !isAscending else isAscending) {
|
} else {
|
||||||
R.drawable.ic_arrow_downward_24dp
|
R.drawable.ic_arrow_upward_24dp
|
||||||
} else {
|
|
||||||
R.drawable.ic_arrow_upward_24dp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSortRes(
|
if (onSelection) {
|
||||||
sortingMode: Int?,
|
return when(sortMode) {
|
||||||
isAscending: Boolean,
|
LibrarySort.DragAndDrop -> R.drawable.ic_check_24dp
|
||||||
@DrawableRes defaultDrawableRes: Int = R.drawable.ic_check_24dp,
|
LibrarySort.Random -> R.drawable.ic_refresh_24dp
|
||||||
): Int = getSortRes(sortingMode?.let { LibrarySort.valueOf(it) }, isAscending, defaultDrawableRes)
|
else -> defaultSelectedDrawableRes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortMode.iconRes(isDynamic)
|
||||||
|
}
|
||||||
|
|
||||||
private fun onCatSortClicked(category: Category, menuId: Int?) {
|
private fun onCatSortClicked(category: Category, menuId: Int?) {
|
||||||
val (mode, modType) = if (menuId == null) {
|
val (mode, modType) = if (menuId == null) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ enum class LibrarySort(
|
||||||
8,
|
8,
|
||||||
MR.strings.random,
|
MR.strings.random,
|
||||||
R.drawable.ic_shuffle_24dp,
|
R.drawable.ic_shuffle_24dp,
|
||||||
)
|
),
|
||||||
;
|
;
|
||||||
|
|
||||||
val categoryValue: Char
|
val categoryValue: Char
|
||||||
|
@ -65,6 +65,9 @@ enum class LibrarySort(
|
||||||
val hasInvertedSort: Boolean
|
val hasInvertedSort: Boolean
|
||||||
get() = this in listOf(LastRead, DateAdded, LatestChapter, DateFetched)
|
get() = this in listOf(LastRead, DateAdded, LatestChapter, DateFetched)
|
||||||
|
|
||||||
|
val isDirectional: Boolean
|
||||||
|
get() = this !in listOf(DragAndDrop, Random)
|
||||||
|
|
||||||
fun menuSheetItem(isDynamic: Boolean): MaterialMenuSheet.MenuSheetItem {
|
fun menuSheetItem(isDynamic: Boolean): MaterialMenuSheet.MenuSheetItem {
|
||||||
return MaterialMenuSheet.MenuSheetItem(
|
return MaterialMenuSheet.MenuSheetItem(
|
||||||
mainValue,
|
mainValue,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue