From 75324a3614b41c628ee51d525021e0b8bc26b87c Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 17 Nov 2019 16:04:42 -0800 Subject: [PATCH] Fixed notch support in landscape also fallback alphabetical sorting on library now also ignores articles --- .../tachiyomi/ui/library/LibraryController.kt | 1 + .../tachiyomi/ui/library/LibraryPresenter.kt | 15 ++++++--- .../kanade/tachiyomi/ui/main/MainActivity.kt | 32 +++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 2db2e1fadd..04bfa7354c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -403,6 +403,7 @@ class LibraryController( } R.id.action_update_library -> { activity?.let { LibraryUpdateService.start(it) } + snack = view?.snack(R.string.updating_library) } R.id.action_edit_categories -> { router.pushController(CategoryController().withFadeTransaction()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index c68c9d9430..a2f84f4345 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -190,24 +190,27 @@ class LibraryPresenter( val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 -> when (sortingMode) { - LibrarySort.ALPHA -> i1.manga.title.removeArticles().compareTo(i2.manga.title.removeArticles(), true) + LibrarySort.ALPHA -> sortAlphabetical(i1, i2) LibrarySort.LAST_READ -> { // Get index of manga, set equal to list if size unknown. val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size val manga2LastRead = lastReadManga[i2.manga.id!!] ?: lastReadManga.size - manga1LastRead.compareTo(manga2LastRead) + val mangaCompare = manga1LastRead.compareTo(manga2LastRead) + if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare } LibrarySort.LAST_UPDATED -> i2.manga.last_update.compareTo(i1.manga.last_update) LibrarySort.UNREAD -> i1.manga.unread.compareTo(i2.manga.unread) LibrarySort.TOTAL -> { val manga1TotalChapter = totalChapterManga[i1.manga.id!!] ?: 0 val mange2TotalChapter = totalChapterManga[i2.manga.id!!] ?: 0 - manga1TotalChapter.compareTo(mange2TotalChapter) + val mangaCompare = manga1TotalChapter.compareTo(mange2TotalChapter) + if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare } LibrarySort.SOURCE -> { val source1Name = sourceManager.getOrStub(i1.manga.source).name val source2Name = sourceManager.getOrStub(i2.manga.source).name - source1Name.compareTo(source2Name) + val mangaCompare = source1Name.compareTo(source2Name) + if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare } else -> throw Exception("Unknown sorting mode") } @@ -221,6 +224,10 @@ class LibraryPresenter( return map.mapValues { entry -> entry.value.sortedWith(comparator) } } + fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int { + return i1.manga.title.removeArticles().compareTo(i2.manga.title.removeArticles(), true) + } + fun String.removeArticles(): String { return this.replace(Regex("^(an|a|the) ", RegexOption.IGNORE_CASE), "") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 59b5e7c3c6..255aeb0a15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -158,21 +158,33 @@ class MainActivity : BaseActivity() { ) } content.setOnApplyWindowInsetsListener { v, insets -> + window.navigationBarColor = + // if the os does not support light nav bar and is portrait, draw a dark translucent + // nav bar if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0)) - window.navigationBarColor = Color.BLACK - else window.navigationBarColor = Color.argb(179, 0, 0, 0) - } else if (v.rootWindowInsets.systemWindowInsetLeft > 0 + // For lollipop, draw opaque nav bar + Color.BLACK + else Color.argb(179, 0, 0, 0) + } + // if the android q+ device has gesture nav, transparent nav bar + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q + && (v.rootWindowInsets.systemWindowInsetBottom != v.rootWindowInsets + .tappableElementInsets.bottom)) { + getColor(android.R.color.transparent) + } + // if in landscape with 2/3 button mode, fully opaque nav bar + else if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0) { - window.navigationBarColor = - v.context.getResourceColor(android.R.attr.colorBackground) - } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q - || insets.tappableElementInsets.bottom > 0) { - window.navigationBarColor = ColorUtils.setAlphaComponent( + v.context.getResourceColor(android.R.attr.colorBackground) + } + // if in portrait with 2/3 button mode, translucent nav bar + else { + ColorUtils.setAlphaComponent( v.context.getResourceColor(android.R.attr.colorBackground), 179) - } else window.navigationBarColor = getColor(android.R.color.transparent) + } v.setPadding(insets.systemWindowInsetLeft, insets.systemWindowInsetTop, insets.systemWindowInsetRight, 0) insets