mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Switch to different ktlint plugin
Should be better at incremental builds. To format, run `./gradlew ktlintFormat`.
This commit is contained in:
		| @@ -16,11 +16,9 @@ class ReorderCategory( | ||||
|  | ||||
|     private val mutex = Mutex() | ||||
|  | ||||
|     suspend fun moveUp(category: Category): Result = | ||||
|         await(category, MoveTo.UP) | ||||
|     suspend fun moveUp(category: Category): Result = await(category, MoveTo.UP) | ||||
|  | ||||
|     suspend fun moveDown(category: Category): Result = | ||||
|         await(category, MoveTo.DOWN) | ||||
|     suspend fun moveDown(category: Category): Result = await(category, MoveTo.DOWN) | ||||
|  | ||||
|     private suspend fun await(category: Category, moveTo: MoveTo) = withNonCancellableContext { | ||||
|         mutex.withLock { | ||||
|   | ||||
| @@ -28,7 +28,11 @@ class SetSortModeForCategory( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     suspend fun await(category: Category?, type: LibrarySort.Type, direction: LibrarySort.Direction) { | ||||
|     suspend fun await( | ||||
|         category: Category?, | ||||
|         type: LibrarySort.Type, | ||||
|         direction: LibrarySort.Direction, | ||||
|     ) { | ||||
|         await(category?.id, type, direction) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -30,7 +30,11 @@ object ChapterRecognition { | ||||
|      */ | ||||
|     private val unwantedWhiteSpace = Regex("""\s(?=extra|special|omake)""") | ||||
|  | ||||
|     fun parseChapterNumber(mangaTitle: String, chapterName: String, chapterNumber: Double? = null): Double { | ||||
|     fun parseChapterNumber( | ||||
|         mangaTitle: String, | ||||
|         chapterName: String, | ||||
|         chapterNumber: Double? = null, | ||||
|     ): Double { | ||||
|         // If chapter number is known return. | ||||
|         if (chapterNumber != null && (chapterNumber == -2.0 || chapterNumber > -1.0)) { | ||||
|             return chapterNumber | ||||
|   | ||||
| @@ -3,7 +3,13 @@ package tachiyomi.domain.chapter.service | ||||
| import tachiyomi.domain.chapter.model.Chapter | ||||
| import tachiyomi.domain.manga.model.Manga | ||||
|  | ||||
| fun getChapterSort(manga: Manga, sortDescending: Boolean = manga.sortDescending()): (Chapter, Chapter) -> Int { | ||||
| fun getChapterSort( | ||||
|     manga: Manga, | ||||
|     sortDescending: Boolean = manga.sortDescending(), | ||||
| ): ( | ||||
|     Chapter, | ||||
|     Chapter, | ||||
| ) -> Int { | ||||
|     return when (manga.sorting) { | ||||
|         Manga.CHAPTER_SORTING_SOURCE -> when (sortDescending) { | ||||
|             true -> { c1, c2 -> c1.sourceOrder.compareTo(c2.sourceOrder) } | ||||
|   | ||||
| @@ -8,9 +8,15 @@ class DownloadPreferences( | ||||
|     private val preferenceStore: PreferenceStore, | ||||
| ) { | ||||
|  | ||||
|     fun downloadsDirectory() = preferenceStore.getString("download_directory", folderProvider.path()) | ||||
|     fun downloadsDirectory() = preferenceStore.getString( | ||||
|         "download_directory", | ||||
|         folderProvider.path(), | ||||
|     ) | ||||
|  | ||||
|     fun downloadOnlyOverWifi() = preferenceStore.getBoolean("pref_download_only_over_wifi_key", true) | ||||
|     fun downloadOnlyOverWifi() = preferenceStore.getBoolean( | ||||
|         "pref_download_only_over_wifi_key", | ||||
|         true, | ||||
|     ) | ||||
|  | ||||
|     fun saveChaptersAsCBZ() = preferenceStore.getBoolean("save_chapter_as_cbz", true) | ||||
|  | ||||
| @@ -20,15 +26,27 @@ class DownloadPreferences( | ||||
|  | ||||
|     fun removeAfterReadSlots() = preferenceStore.getInt("remove_after_read_slots", -1) | ||||
|  | ||||
|     fun removeAfterMarkedAsRead() = preferenceStore.getBoolean("pref_remove_after_marked_as_read_key", false) | ||||
|     fun removeAfterMarkedAsRead() = preferenceStore.getBoolean( | ||||
|         "pref_remove_after_marked_as_read_key", | ||||
|         false, | ||||
|     ) | ||||
|  | ||||
|     fun removeBookmarkedChapters() = preferenceStore.getBoolean("pref_remove_bookmarked", false) | ||||
|  | ||||
|     fun removeExcludeCategories() = preferenceStore.getStringSet("remove_exclude_categories", emptySet()) | ||||
|     fun removeExcludeCategories() = preferenceStore.getStringSet( | ||||
|         "remove_exclude_categories", | ||||
|         emptySet(), | ||||
|     ) | ||||
|  | ||||
|     fun downloadNewChapters() = preferenceStore.getBoolean("download_new", false) | ||||
|  | ||||
|     fun downloadNewChapterCategories() = preferenceStore.getStringSet("download_new_categories", emptySet()) | ||||
|     fun downloadNewChapterCategories() = preferenceStore.getStringSet( | ||||
|         "download_new_categories", | ||||
|         emptySet(), | ||||
|     ) | ||||
|  | ||||
|     fun downloadNewChapterCategoriesExclude() = preferenceStore.getStringSet("download_new_categories_exclude", emptySet()) | ||||
|     fun downloadNewChapterCategoriesExclude() = preferenceStore.getStringSet( | ||||
|         "download_new_categories_exclude", | ||||
|         emptySet(), | ||||
|     ) | ||||
| } | ||||
|   | ||||
| @@ -30,7 +30,11 @@ class GetNextChapters( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     suspend fun await(mangaId: Long, fromChapterId: Long, onlyUnread: Boolean = true): List<Chapter> { | ||||
|     suspend fun await( | ||||
|         mangaId: Long, | ||||
|         fromChapterId: Long, | ||||
|         onlyUnread: Boolean = true, | ||||
|     ): List<Chapter> { | ||||
|         val chapters = await(mangaId, onlyUnread) | ||||
|         val currChapterIndex = chapters.indexOfFirst { it.id == fromChapterId } | ||||
|         val nextChapters = chapters.subList(max(0, currChapterIndex), chapters.size) | ||||
|   | ||||
| @@ -65,7 +65,18 @@ data class LibrarySort( | ||||
|     } | ||||
|  | ||||
|     companion object { | ||||
|         val types by lazy { setOf(Type.Alphabetical, Type.LastRead, Type.LastUpdate, Type.UnreadCount, Type.TotalChapters, Type.LatestChapter, Type.ChapterFetchDate, Type.DateAdded) } | ||||
|         val types by lazy { | ||||
|             setOf( | ||||
|                 Type.Alphabetical, | ||||
|                 Type.LastRead, | ||||
|                 Type.LastUpdate, | ||||
|                 Type.UnreadCount, | ||||
|                 Type.TotalChapters, | ||||
|                 Type.LatestChapter, | ||||
|                 Type.ChapterFetchDate, | ||||
|                 Type.DateAdded, | ||||
|             ) | ||||
|         } | ||||
|         val directions by lazy { setOf(Direction.Ascending, Direction.Descending) } | ||||
|         val default = LibrarySort(Type.Alphabetical, Direction.Ascending) | ||||
|  | ||||
|   | ||||
| @@ -11,9 +11,19 @@ class LibraryPreferences( | ||||
|     private val preferenceStore: PreferenceStore, | ||||
| ) { | ||||
|  | ||||
|     fun displayMode() = preferenceStore.getObject("pref_display_mode_library", LibraryDisplayMode.default, LibraryDisplayMode.Serializer::serialize, LibraryDisplayMode.Serializer::deserialize) | ||||
|     fun displayMode() = preferenceStore.getObject( | ||||
|         "pref_display_mode_library", | ||||
|         LibraryDisplayMode.default, | ||||
|         LibraryDisplayMode.Serializer::serialize, | ||||
|         LibraryDisplayMode.Serializer::deserialize, | ||||
|     ) | ||||
|  | ||||
|     fun sortingMode() = preferenceStore.getObject("library_sorting_mode", LibrarySort.default, LibrarySort.Serializer::serialize, LibrarySort.Serializer::deserialize) | ||||
|     fun sortingMode() = preferenceStore.getObject( | ||||
|         "library_sorting_mode", | ||||
|         LibrarySort.default, | ||||
|         LibrarySort.Serializer::serialize, | ||||
|         LibrarySort.Serializer::deserialize, | ||||
|     ) | ||||
|  | ||||
|     fun portraitColumns() = preferenceStore.getInt("pref_library_columns_portrait_key", 0) | ||||
|  | ||||
| @@ -42,31 +52,64 @@ class LibraryPreferences( | ||||
|  | ||||
|     fun autoUpdateTrackers() = preferenceStore.getBoolean("auto_update_trackers", false) | ||||
|  | ||||
|     fun showContinueReadingButton() = preferenceStore.getBoolean("display_continue_reading_button", false) | ||||
|     fun showContinueReadingButton() = preferenceStore.getBoolean( | ||||
|         "display_continue_reading_button", | ||||
|         false, | ||||
|     ) | ||||
|  | ||||
|     // region Filter | ||||
|  | ||||
|     fun filterDownloaded() = preferenceStore.getEnum("pref_filter_library_downloaded_v2", TriState.DISABLED) | ||||
|     fun filterDownloaded() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_downloaded_v2", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterUnread() = preferenceStore.getEnum("pref_filter_library_unread_v2", TriState.DISABLED) | ||||
|  | ||||
|     fun filterStarted() = preferenceStore.getEnum("pref_filter_library_started_v2", TriState.DISABLED) | ||||
|     fun filterStarted() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_started_v2", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterBookmarked() = preferenceStore.getEnum("pref_filter_library_bookmarked_v2", TriState.DISABLED) | ||||
|     fun filterBookmarked() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_bookmarked_v2", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterCompleted() = preferenceStore.getEnum("pref_filter_library_completed_v2", TriState.DISABLED) | ||||
|     fun filterCompleted() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_completed_v2", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterIntervalCustom() = preferenceStore.getEnum("pref_filter_library_interval_custom", TriState.DISABLED) | ||||
|     fun filterIntervalCustom() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_interval_custom", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterIntervalLong() = preferenceStore.getEnum("pref_filter_library_interval_long", TriState.DISABLED) | ||||
|     fun filterIntervalLong() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_interval_long", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterIntervalLate() = preferenceStore.getEnum("pref_filter_library_interval_late", TriState.DISABLED) | ||||
|     fun filterIntervalLate() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_interval_late", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterIntervalDropped() = preferenceStore.getEnum("pref_filter_library_interval_dropped", TriState.DISABLED) | ||||
|     fun filterIntervalDropped() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_interval_dropped", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterIntervalPassed() = preferenceStore.getEnum("pref_filter_library_interval_passed", TriState.DISABLED) | ||||
|     fun filterIntervalPassed() = preferenceStore.getEnum( | ||||
|         "pref_filter_library_interval_passed", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     fun filterTracking(id: Int) = preferenceStore.getEnum("pref_filter_library_tracked_${id}_v2", TriState.DISABLED) | ||||
|     fun filterTracking(id: Int) = preferenceStore.getEnum( | ||||
|         "pref_filter_library_tracked_${id}_v2", | ||||
|         TriState.DISABLED, | ||||
|     ) | ||||
|  | ||||
|     // endregion | ||||
|  | ||||
| @@ -97,24 +140,45 @@ class LibraryPreferences( | ||||
|  | ||||
|     fun updateCategories() = preferenceStore.getStringSet("library_update_categories", emptySet()) | ||||
|  | ||||
|     fun updateCategoriesExclude() = preferenceStore.getStringSet("library_update_categories_exclude", emptySet()) | ||||
|     fun updateCategoriesExclude() = preferenceStore.getStringSet( | ||||
|         "library_update_categories_exclude", | ||||
|         emptySet(), | ||||
|     ) | ||||
|  | ||||
|     // endregion | ||||
|  | ||||
|     // region Chapter | ||||
|  | ||||
|     fun filterChapterByRead() = preferenceStore.getLong("default_chapter_filter_by_read", Manga.SHOW_ALL) | ||||
|     fun filterChapterByRead() = preferenceStore.getLong( | ||||
|         "default_chapter_filter_by_read", | ||||
|         Manga.SHOW_ALL, | ||||
|     ) | ||||
|  | ||||
|     fun filterChapterByDownloaded() = preferenceStore.getLong("default_chapter_filter_by_downloaded", Manga.SHOW_ALL) | ||||
|     fun filterChapterByDownloaded() = preferenceStore.getLong( | ||||
|         "default_chapter_filter_by_downloaded", | ||||
|         Manga.SHOW_ALL, | ||||
|     ) | ||||
|  | ||||
|     fun filterChapterByBookmarked() = preferenceStore.getLong("default_chapter_filter_by_bookmarked", Manga.SHOW_ALL) | ||||
|     fun filterChapterByBookmarked() = preferenceStore.getLong( | ||||
|         "default_chapter_filter_by_bookmarked", | ||||
|         Manga.SHOW_ALL, | ||||
|     ) | ||||
|  | ||||
|     // and upload date | ||||
|     fun sortChapterBySourceOrNumber() = preferenceStore.getLong("default_chapter_sort_by_source_or_number", Manga.CHAPTER_SORTING_SOURCE) | ||||
|     fun sortChapterBySourceOrNumber() = preferenceStore.getLong( | ||||
|         "default_chapter_sort_by_source_or_number", | ||||
|         Manga.CHAPTER_SORTING_SOURCE, | ||||
|     ) | ||||
|  | ||||
|     fun displayChapterByNameOrNumber() = preferenceStore.getLong("default_chapter_display_by_name_or_number", Manga.CHAPTER_DISPLAY_NAME) | ||||
|     fun displayChapterByNameOrNumber() = preferenceStore.getLong( | ||||
|         "default_chapter_display_by_name_or_number", | ||||
|         Manga.CHAPTER_DISPLAY_NAME, | ||||
|     ) | ||||
|  | ||||
|     fun sortChapterByAscendingOrDescending() = preferenceStore.getLong("default_chapter_sort_by_ascending_or_descending", Manga.CHAPTER_SORT_DESC) | ||||
|     fun sortChapterByAscendingOrDescending() = preferenceStore.getLong( | ||||
|         "default_chapter_sort_by_ascending_or_descending", | ||||
|         Manga.CHAPTER_SORT_DESC, | ||||
|     ) | ||||
|  | ||||
|     fun setChapterSettingsDefault(manga: Manga) { | ||||
|         filterChapterByRead().set(manga.unreadFilterRaw) | ||||
| @@ -122,7 +186,9 @@ class LibraryPreferences( | ||||
|         filterChapterByBookmarked().set(manga.bookmarkedFilterRaw) | ||||
|         sortChapterBySourceOrNumber().set(manga.sorting) | ||||
|         displayChapterByNameOrNumber().set(manga.displayMode) | ||||
|         sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC) | ||||
|         sortChapterByAscendingOrDescending().set( | ||||
|             if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC, | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false) | ||||
| @@ -131,9 +197,15 @@ class LibraryPreferences( | ||||
|  | ||||
|     // region Swipe Actions | ||||
|  | ||||
|     fun swipeToStartAction() = preferenceStore.getEnum("pref_chapter_swipe_end_action", ChapterSwipeAction.ToggleBookmark) | ||||
|     fun swipeToStartAction() = preferenceStore.getEnum( | ||||
|         "pref_chapter_swipe_end_action", | ||||
|         ChapterSwipeAction.ToggleBookmark, | ||||
|     ) | ||||
|  | ||||
|     fun swipeToEndAction() = preferenceStore.getEnum("pref_chapter_swipe_start_action", ChapterSwipeAction.ToggleRead) | ||||
|     fun swipeToEndAction() = preferenceStore.getEnum( | ||||
|         "pref_chapter_swipe_start_action", | ||||
|         ChapterSwipeAction.ToggleRead, | ||||
|     ) | ||||
|  | ||||
|     // endregion | ||||
|  | ||||
|   | ||||
| @@ -27,7 +27,10 @@ class SetFetchInterval( | ||||
|             window | ||||
|         } | ||||
|         val chapters = getChapterByMangaId.await(manga.id) | ||||
|         val interval = manga.fetchInterval.takeIf { it < 0 } ?: calculateInterval(chapters, dateTime) | ||||
|         val interval = manga.fetchInterval.takeIf { it < 0 } ?: calculateInterval( | ||||
|             chapters, | ||||
|             dateTime, | ||||
|         ) | ||||
|         val nextUpdate = calculateNextUpdate(manga, interval, dateTime, currentWindow) | ||||
|  | ||||
|         return if (manga.nextUpdate == nextUpdate && manga.fetchInterval == interval) { | ||||
| @@ -46,7 +49,9 @@ class SetFetchInterval( | ||||
|  | ||||
|     internal fun calculateInterval(chapters: List<Chapter>, zonedDateTime: ZonedDateTime): Int { | ||||
|         val sortedChapters = chapters | ||||
|             .sortedWith(compareByDescending<Chapter> { it.dateUpload }.thenByDescending { it.dateFetch }) | ||||
|             .sortedWith( | ||||
|                 compareByDescending<Chapter> { it.dateUpload }.thenByDescending { it.dateFetch }, | ||||
|             ) | ||||
|             .take(50) | ||||
|  | ||||
|         val uploadDates = sortedChapters | ||||
| @@ -95,7 +100,10 @@ class SetFetchInterval( | ||||
|             manga.nextUpdate !in window.first.rangeTo(window.second + 1) || | ||||
|             manga.fetchInterval == 0 | ||||
|         ) { | ||||
|             val latestDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(manga.lastUpdate), dateTime.zone) | ||||
|             val latestDate = ZonedDateTime.ofInstant( | ||||
|                 Instant.ofEpochMilli(manga.lastUpdate), | ||||
|                 dateTime.zone, | ||||
|             ) | ||||
|                 .toLocalDate() | ||||
|                 .atStartOfDay() | ||||
|             val timeSinceLatest = ChronoUnit.DAYS.between(latestDate, dateTime).toInt() | ||||
|   | ||||
| @@ -20,7 +20,10 @@ class GetApplicationRelease( | ||||
|         val now = Instant.now() | ||||
|  | ||||
|         // Limit checks to once every 3 days at most | ||||
|         if (arguments.forceCheck.not() && now.isBefore(Instant.ofEpochMilli(lastChecked.get()).plus(3, ChronoUnit.DAYS))) { | ||||
|         if (arguments.forceCheck.not() && now.isBefore( | ||||
|                 Instant.ofEpochMilli(lastChecked.get()).plus(3, ChronoUnit.DAYS), | ||||
|             ) | ||||
|         ) { | ||||
|             return Result.NoNewUpdate | ||||
|         } | ||||
|  | ||||
| @@ -29,7 +32,12 @@ class GetApplicationRelease( | ||||
|         lastChecked.set(now.toEpochMilli()) | ||||
|  | ||||
|         // Check if latest version is different from current version | ||||
|         val isNewVersion = isNewVersion(arguments.isPreview, arguments.commitCount, arguments.versionName, release.version) | ||||
|         val isNewVersion = isNewVersion( | ||||
|             arguments.isPreview, | ||||
|             arguments.commitCount, | ||||
|             arguments.versionName, | ||||
|             release.version, | ||||
|         ) | ||||
|         return when { | ||||
|             isNewVersion && arguments.isThirdParty -> Result.ThirdPartyInstallation | ||||
|             isNewVersion -> Result.NewUpdate(release) | ||||
| @@ -37,7 +45,12 @@ class GetApplicationRelease( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun isNewVersion(isPreview: Boolean, commitCount: Int, versionName: String, versionTag: String): Boolean { | ||||
|     private fun isNewVersion( | ||||
|         isPreview: Boolean, | ||||
|         commitCount: Int, | ||||
|         versionName: String, | ||||
|         versionTag: String, | ||||
|     ): Boolean { | ||||
|         // Removes prefixes like "r" or "v" | ||||
|         val newVersion = versionTag.replace("[^\\d.]".toRegex(), "") | ||||
|         return if (isPreview) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user