From 0b0f985e242567ed5054ca2bcde2430cade970b4 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 11 Apr 2020 14:54:11 -0400 Subject: [PATCH] Keeping a private static list of recents for recreation of recents controller --- .../tachiyomi/ui/recents/RecentsController.kt | 4 +--- .../kanade/tachiyomi/ui/recents/RecentsPresenter.kt | 13 ++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index c3c563f486..fc5a4f0215 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -69,7 +69,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), private var adapter = RecentMangaAdapter(this) private var presenter = RecentsPresenter(this) - private var recentItems: List? = null private var snack: Snackbar? = null private var lastChapterId: Long? = null private var showingDownloads = false @@ -112,8 +111,8 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), headerHeight = it.systemWindowInsetTop + appBarHeight } - if (recentItems != null) adapter.updateDataSet(recentItems!!.toList()) presenter.onCreate() + if (presenter.recentItems.isNotEmpty()) adapter.updateDataSet(presenter.recentItems) dl_bottom_sheet.onCreate(this) @@ -217,7 +216,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), fun showLists(recents: List) { swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() - recentItems = recents adapter.updateDataSet(recents) if (lastChapterId != null) { refreshItem(lastChapterId ?: 0L) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index 377d844bd0..a530633779 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -36,7 +36,8 @@ class RecentsPresenter( private var scope = CoroutineScope(Job() + Dispatchers.Default) - private var recentItems = listOf() + var recentItems = listOf() + private set var query = "" private val newAdditionsHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEWLY_ADDED) private val newChaptersHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEW_CHAPTERS) @@ -48,6 +49,11 @@ class RecentsPresenter( fun onCreate() { downloadManager.addListener(this) LibraryUpdateService.setListener(this) + if (lastRecents != null) { + if (recentItems.isEmpty()) + recentItems = lastRecents ?: emptyList() + lastRecents = null + } getRecents() } @@ -170,6 +176,7 @@ class RecentsPresenter( fun onDestroy() { downloadManager.removeListener(this) LibraryUpdateService.removeListener(this) + lastRecents = recentItems } fun cancelScope() { @@ -264,4 +271,8 @@ class RecentsPresenter( getRecents() } } + + private companion object { + var lastRecents: List? = null + } }