Keeping a private static list of recents for recreation of recents controller

This commit is contained in:
Jay 2020-04-11 14:54:11 -04:00
parent ed3e819829
commit 0b0f985e24
2 changed files with 13 additions and 4 deletions

View File

@ -69,7 +69,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
private var adapter = RecentMangaAdapter(this) private var adapter = RecentMangaAdapter(this)
private var presenter = RecentsPresenter(this) private var presenter = RecentsPresenter(this)
private var recentItems: List<RecentMangaItem>? = null
private var snack: Snackbar? = null private var snack: Snackbar? = null
private var lastChapterId: Long? = null private var lastChapterId: Long? = null
private var showingDownloads = false private var showingDownloads = false
@ -112,8 +111,8 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
headerHeight = it.systemWindowInsetTop + appBarHeight headerHeight = it.systemWindowInsetTop + appBarHeight
} }
if (recentItems != null) adapter.updateDataSet(recentItems!!.toList())
presenter.onCreate() presenter.onCreate()
if (presenter.recentItems.isNotEmpty()) adapter.updateDataSet(presenter.recentItems)
dl_bottom_sheet.onCreate(this) dl_bottom_sheet.onCreate(this)
@ -217,7 +216,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
fun showLists(recents: List<RecentMangaItem>) { fun showLists(recents: List<RecentMangaItem>) {
swipe_refresh.isRefreshing = LibraryUpdateService.isRunning() swipe_refresh.isRefreshing = LibraryUpdateService.isRunning()
recentItems = recents
adapter.updateDataSet(recents) adapter.updateDataSet(recents)
if (lastChapterId != null) { if (lastChapterId != null) {
refreshItem(lastChapterId ?: 0L) refreshItem(lastChapterId ?: 0L)

View File

@ -36,7 +36,8 @@ class RecentsPresenter(
private var scope = CoroutineScope(Job() + Dispatchers.Default) private var scope = CoroutineScope(Job() + Dispatchers.Default)
private var recentItems = listOf<RecentMangaItem>() var recentItems = listOf<RecentMangaItem>()
private set
var query = "" var query = ""
private val newAdditionsHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEWLY_ADDED) private val newAdditionsHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEWLY_ADDED)
private val newChaptersHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEW_CHAPTERS) private val newChaptersHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEW_CHAPTERS)
@ -48,6 +49,11 @@ class RecentsPresenter(
fun onCreate() { fun onCreate() {
downloadManager.addListener(this) downloadManager.addListener(this)
LibraryUpdateService.setListener(this) LibraryUpdateService.setListener(this)
if (lastRecents != null) {
if (recentItems.isEmpty())
recentItems = lastRecents ?: emptyList()
lastRecents = null
}
getRecents() getRecents()
} }
@ -170,6 +176,7 @@ class RecentsPresenter(
fun onDestroy() { fun onDestroy() {
downloadManager.removeListener(this) downloadManager.removeListener(this)
LibraryUpdateService.removeListener(this) LibraryUpdateService.removeListener(this)
lastRecents = recentItems
} }
fun cancelScope() { fun cancelScope() {
@ -264,4 +271,8 @@ class RecentsPresenter(
getRecents() getRecents()
} }
} }
private companion object {
var lastRecents: List<RecentMangaItem>? = null
}
} }