Fixed notch support in landscape

also fallback alphabetical sorting on library now also ignores articles
pull/2497/head
Jay 5 years ago
parent ef54c61876
commit 75324a3614

@ -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())

@ -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), "")
}

@ -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

Loading…
Cancel
Save