Replacing sublist with take where applicable

There's so many helper methods I just cant remember them all
This commit is contained in:
Jays2Kings 2021-04-09 01:23:46 -04:00
parent 248f729768
commit 0cfce71266
4 changed files with 13 additions and 24 deletions

View File

@ -788,7 +788,7 @@ class ReaderActivity :
pViewer.config.shiftDoublePage = ( pViewer.config.shiftDoublePage = (
binding.readerNav.pageSeekbar.progress + 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 ?.count { it.fullPage || it.isolatedPage } ?: 0
) )
) % 2 != 0 ) % 2 != 0
@ -816,7 +816,7 @@ class ReaderActivity :
(viewer as? PagerViewer)?.config?.shiftDoublePage = ( (viewer as? PagerViewer)?.config?.shiftDoublePage = (
currentChapter.requestedPage + currentChapter.requestedPage +
( (
currentChapter.pages?.subList(0, currentChapter.requestedPage) currentChapter.pages?.take(currentChapter.requestedPage)
?.count { it.fullPage || it.isolatedPage } ?: 0 ?.count { it.fullPage || it.isolatedPage } ?: 0
) )
) % 2 != 0 ) % 2 != 0

View File

@ -208,8 +208,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
0, 0,
( (
if (index > -1) ( if (index > -1) (
items.subList(0, index) items.take(index).indexOfLast { it?.fullPage == true }
.indexOfLast { it?.fullPage == true }
) else -1 ) else -1
) )
) )

View File

@ -448,7 +448,7 @@ class BrowseController :
val sortedList = list.filter { it.split(":").size == 2 } val sortedList = list.filter { it.split(":").size == 2 }
.sortedByDescending { it.split(":").last().toLong() } .sortedByDescending { it.split(":").last().toLong() }
preferences.lastUsedSources() preferences.lastUsedSources()
.set(sortedList.subList(0, min(sortedList.size, 2)).toSet()) .set(sortedList.take(2).toSet())
} }
router.pushController(controller.withFadeTransaction()) router.pushController(controller.withFadeTransaction())
} }

View File

@ -49,30 +49,20 @@ class MangaShortcutManager(
sourceManager.getOrStub(id) to splitS[1].toLong() sourceManager.getOrStub(id) to splitS[1].toLong()
} }
} }
var recents = ( val recents =
recentManga.subList( (recentManga.take(shortcutManager.maxShortcutCountPerActivity) + recentSources)
0, .sortedByDescending { it.second }
min( .map { it.first }
recentManga.size, .take(shortcutManager.maxShortcutCountPerActivity)
shortcutManager.maxShortcutCountPerActivity
)
) + recentSources
)
.sortedByDescending { it.second }.map { it.first }
recents = recents.subList(
0,
min(
recentManga.size,
shortcutManager.maxShortcutCountPerActivity
)
)
val shortcuts = recents.mapNotNull { item -> val shortcuts = recents.mapNotNull { item ->
when (item) { when (item) {
is Manga -> { is Manga -> {
val request = GetRequest.Builder(context).data(item).build() 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( ShortcutInfo.Builder(
context, context,