From 0cfce7126685170e22c4c4c71a79b85eb265bb42 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 9 Apr 2021 01:23:46 -0400 Subject: [PATCH] Replacing sublist with take where applicable There's so many helper methods I just cant remember them all --- .../tachiyomi/ui/reader/ReaderActivity.kt | 4 +-- .../reader/viewer/pager/PagerViewerAdapter.kt | 3 +- .../tachiyomi/ui/source/BrowseController.kt | 2 +- .../util/manga/MangaShortcutManager.kt | 28 ++++++------------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 99da73d4fb..fad2ec16cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -788,7 +788,7 @@ class ReaderActivity : pViewer.config.shiftDoublePage = ( binding.readerNav.pageSeekbar.progress + ( - currentChapter?.pages?.subList(0, binding.readerNav.pageSeekbar.progress) + currentChapter?.pages?.take(binding.readerNav.pageSeekbar.progress) ?.count { it.fullPage || it.isolatedPage } ?: 0 ) ) % 2 != 0 @@ -816,7 +816,7 @@ class ReaderActivity : (viewer as? PagerViewer)?.config?.shiftDoublePage = ( currentChapter.requestedPage + ( - currentChapter.pages?.subList(0, currentChapter.requestedPage) + currentChapter.pages?.take(currentChapter.requestedPage) ?.count { it.fullPage || it.isolatedPage } ?: 0 ) ) % 2 != 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 82e744c0dc..743227e762 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -208,8 +208,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { 0, ( if (index > -1) ( - items.subList(0, index) - .indexOfLast { it?.fullPage == true } + items.take(index).indexOfLast { it?.fullPage == true } ) else -1 ) ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt index 9f4b8d4f0a..cadcf3fb9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/BrowseController.kt @@ -448,7 +448,7 @@ class BrowseController : val sortedList = list.filter { it.split(":").size == 2 } .sortedByDescending { it.split(":").last().toLong() } preferences.lastUsedSources() - .set(sortedList.subList(0, min(sortedList.size, 2)).toSet()) + .set(sortedList.take(2).toSet()) } router.pushController(controller.withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt b/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt index f7cf8fab47..1c12518a22 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt @@ -49,30 +49,20 @@ class MangaShortcutManager( sourceManager.getOrStub(id) to splitS[1].toLong() } } - var recents = ( - recentManga.subList( - 0, - min( - recentManga.size, - shortcutManager.maxShortcutCountPerActivity - ) - ) + recentSources - ) - .sortedByDescending { it.second }.map { it.first } - - recents = recents.subList( - 0, - min( - recentManga.size, - shortcutManager.maxShortcutCountPerActivity - ) - ) + val recents = + (recentManga.take(shortcutManager.maxShortcutCountPerActivity) + recentSources) + .sortedByDescending { it.second } + .map { it.first } + .take(shortcutManager.maxShortcutCountPerActivity) val shortcuts = recents.mapNotNull { item -> when (item) { is Manga -> { val request = GetRequest.Builder(context).data(item).build() - val bitmap = (Coil.imageLoader(context).execute(request).drawable as? BitmapDrawable)?.bitmap + val bitmap = ( + Coil.imageLoader(context) + .execute(request).drawable as? BitmapDrawable + )?.bitmap ShortcutInfo.Builder( context,