mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
			v0.17.1
			...
			ab0893b2d4
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | ab0893b2d4 | ||
|  | 078758391e | ||
|  | 2eb1580788 | ||
|  | d328ded17f | ||
|  | 80f9dfb699 | ||
|  | 3d087f4428 | ||
|  | 0ab795bfa3 | 
| @@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.ColumnScope | ||||
| import androidx.compose.foundation.layout.padding | ||||
| import androidx.compose.foundation.rememberScrollState | ||||
| import androidx.compose.foundation.verticalScroll | ||||
| import androidx.compose.material.icons.Icons | ||||
| import androidx.compose.material.icons.filled.Refresh | ||||
| import androidx.compose.material3.FilterChip | ||||
| import androidx.compose.material3.Text | ||||
| import androidx.compose.runtime.Composable | ||||
| @@ -27,6 +29,7 @@ import tachiyomi.domain.library.model.LibrarySort | ||||
| import tachiyomi.domain.library.model.sort | ||||
| import tachiyomi.domain.library.service.LibraryPreferences | ||||
| import tachiyomi.i18n.MR | ||||
| import tachiyomi.presentation.core.components.BaseSortItem | ||||
| import tachiyomi.presentation.core.components.CheckboxItem | ||||
| import tachiyomi.presentation.core.components.HeadingItem | ||||
| import tachiyomi.presentation.core.components.SettingsChipRow | ||||
| @@ -178,7 +181,23 @@ private fun ColumnScope.SortPage( | ||||
|         MR.strings.action_sort_latest_chapter to LibrarySort.Type.LatestChapter, | ||||
|         MR.strings.action_sort_chapter_fetch_date to LibrarySort.Type.ChapterFetchDate, | ||||
|         MR.strings.action_sort_date_added to LibrarySort.Type.DateAdded, | ||||
|         MR.strings.action_sort_random to LibrarySort.Type.Random, | ||||
|     ).plus(trackerSortOption).map { (titleRes, mode) -> | ||||
|         if (mode == LibrarySort.Type.Random) { | ||||
|             val enabledIcon = if (sortingMode == LibrarySort.Type.Random) { | ||||
|                 Icons.Default.Refresh | ||||
|             } else { | ||||
|                 null | ||||
|             } | ||||
|             BaseSortItem( | ||||
|                 label = stringResource(titleRes), | ||||
|                 icon = enabledIcon, | ||||
|                 onClick = { | ||||
|                     screenModel.setSort(category, mode, LibrarySort.Direction.Ascending) | ||||
|                 }, | ||||
|             ) | ||||
|             return@map | ||||
|         } | ||||
|         SortItem( | ||||
|             label = stringResource(titleRes), | ||||
|             sortDescending = sortDescending.takeIf { sortingMode == mode }, | ||||
|   | ||||
| @@ -72,6 +72,7 @@ import tachiyomi.domain.track.model.Track | ||||
| import tachiyomi.source.local.isLocal | ||||
| import uy.kohesive.injekt.Injekt | ||||
| import uy.kohesive.injekt.api.get | ||||
| import kotlin.random.Random | ||||
|  | ||||
| /** | ||||
|  * Typealias for the library manga, using the category as keys, and list of manga as values. | ||||
| @@ -300,10 +301,18 @@ class LibraryScreenModel( | ||||
|                     val item2Score = trackerScores[i2.libraryManga.id] ?: defaultTrackerScoreSortValue | ||||
|                     item1Score.compareTo(item2Score) | ||||
|                 } | ||||
|                 LibrarySort.Type.Random -> { | ||||
|                     error("A comparator should not be requested for the random sort style. Instead, intercept this " + | ||||
|                         "case and call .shuffle()") | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return mapValues { (key, value) -> | ||||
|            if (key.sort.type == LibrarySort.Type.Random) { | ||||
|                return@mapValues value.shuffled(Random(libraryPreferences.currentRandomSortSeed().get())) | ||||
|            } | ||||
|  | ||||
|             val comparator = key.sort.comparator() | ||||
|                 .let { if (key.sort.isAscending) it else it.reversed() } | ||||
|                 .thenComparator(sortAlphabetically) | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import tachiyomi.domain.category.repository.CategoryRepository | ||||
| import tachiyomi.domain.library.model.LibrarySort | ||||
| import tachiyomi.domain.library.model.plus | ||||
| import tachiyomi.domain.library.service.LibraryPreferences | ||||
| import kotlin.random.Random | ||||
|  | ||||
| class SetSortModeForCategory( | ||||
|     private val preferences: LibraryPreferences, | ||||
| @@ -15,6 +16,9 @@ class SetSortModeForCategory( | ||||
|     suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) { | ||||
|         val category = categoryId?.let { categoryRepository.get(it) } | ||||
|         val flags = (category?.flags ?: 0) + type + direction | ||||
|         if (type == LibrarySort.Type.Random) { | ||||
|             preferences.currentRandomSortSeed().set(Random.nextInt()) | ||||
|         } | ||||
|         if (category != null && preferences.categorizedDisplaySettings().get()) { | ||||
|             categoryRepository.updatePartial( | ||||
|                 CategoryUpdate( | ||||
|   | ||||
| @@ -30,7 +30,8 @@ data class LibrarySort( | ||||
|         data object LatestChapter : Type(0b00010100) | ||||
|         data object ChapterFetchDate : Type(0b00011000) | ||||
|         data object DateAdded : Type(0b00011100) | ||||
|         data object TrackerMean : Type(0b000100000) | ||||
|         data object TrackerMean : Type(0b00100000) | ||||
|         data object Random : Type(0b00100100) | ||||
|  | ||||
|         companion object { | ||||
|             fun valueOf(flag: Long): Type { | ||||
| @@ -77,6 +78,7 @@ data class LibrarySort( | ||||
|                 Type.ChapterFetchDate, | ||||
|                 Type.DateAdded, | ||||
|                 Type.TrackerMean, | ||||
|                 Type.Random, | ||||
|             ) | ||||
|         } | ||||
|         val directions by lazy { setOf(Direction.Ascending, Direction.Descending) } | ||||
| @@ -104,6 +106,7 @@ data class LibrarySort( | ||||
|                     "CHAPTER_FETCH_DATE" -> Type.ChapterFetchDate | ||||
|                     "DATE_ADDED" -> Type.DateAdded | ||||
|                     "TRACKER_MEAN" -> Type.TrackerMean | ||||
|                     "RANDOM" -> Type.Random | ||||
|                     else -> Type.Alphabetical | ||||
|                 } | ||||
|                 val ascending = if (values[1] == "ASCENDING") Direction.Ascending else Direction.Descending | ||||
| @@ -125,6 +128,7 @@ data class LibrarySort( | ||||
|             Type.ChapterFetchDate -> "CHAPTER_FETCH_DATE" | ||||
|             Type.DateAdded -> "DATE_ADDED" | ||||
|             Type.TrackerMean -> "TRACKER_MEAN" | ||||
|             Type.Random -> "RANDOM" | ||||
|         } | ||||
|         val direction = if (direction == Direction.Ascending) "ASCENDING" else "DESCENDING" | ||||
|         return "$type,$direction" | ||||
|   | ||||
| @@ -26,6 +26,8 @@ class LibraryPreferences( | ||||
|         LibrarySort.Serializer::deserialize, | ||||
|     ) | ||||
|  | ||||
|     fun currentRandomSortSeed() = preferenceStore.getInt("library_random_sort_seed", 0) | ||||
|  | ||||
|     fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0) | ||||
|  | ||||
|     fun landscapeColumns() = preferenceStore.getInt("pref_library_columns_landscape_key", 0) | ||||
|   | ||||
| @@ -69,6 +69,7 @@ | ||||
|     <string name="action_sort_chapter_fetch_date">Chapter fetch date</string> | ||||
|     <string name="action_sort_date_added">Date added</string> | ||||
|     <string name="action_sort_tracker_score">Tracker score</string> | ||||
|     <string name="action_sort_random">Random</string> | ||||
|     <string name="action_search">Search</string> | ||||
|     <string name="action_search_hint">Search…</string> | ||||
|     <string name="action_search_settings">Search settings</string> | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||||
| import androidx.compose.material.icons.Icons | ||||
| import androidx.compose.material.icons.filled.ArrowDownward | ||||
| import androidx.compose.material.icons.filled.ArrowUpward | ||||
| import androidx.compose.material.icons.filled.Refresh | ||||
| import androidx.compose.material.icons.rounded.CheckBox | ||||
| import androidx.compose.material.icons.rounded.CheckBoxOutlineBlank | ||||
| import androidx.compose.material.icons.rounded.DisabledByDefault | ||||
| @@ -98,12 +99,21 @@ fun SortItem(label: String, sortDescending: Boolean?, onClick: () -> Unit) { | ||||
|         null -> null | ||||
|     } | ||||
|  | ||||
|     BaseSortItem( | ||||
|         label = label, | ||||
|         icon = arrowIcon, | ||||
|         onClick = onClick, | ||||
|     ) | ||||
| } | ||||
|  | ||||
| @Composable | ||||
| fun BaseSortItem(label: String, icon: ImageVector?, onClick: () -> Unit) { | ||||
|     BaseSettingsItem( | ||||
|         label = label, | ||||
|         widget = { | ||||
|             if (arrowIcon != null) { | ||||
|             if (icon != null) { | ||||
|                 Icon( | ||||
|                     imageVector = arrowIcon, | ||||
|                     imageVector = icon, | ||||
|                     contentDescription = null, | ||||
|                     tint = MaterialTheme.colorScheme.primary, | ||||
|                 ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user