From ab7fcd37bae833f668d19a06fd6e946a163071c4 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 10 Feb 2020 01:08:52 -0800 Subject: [PATCH] Fixed pressing back on settings + reverting recent read changes --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 4 +- .../recently_read/RecentlyReadController.kt | 37 +++++++------------ .../ui/recently_read/RecentlyReadPresenter.kt | 5 ++- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 428c604f13..157298412a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -413,8 +413,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { if (drawer.isDrawerOpen(GravityCompat.START) || drawer.isDrawerOpen(GravityCompat.END)) { drawer.closeDrawers() } else { - val baseController = router.backstack.last().controller() as BaseController - if (if (router.backstackSize == 1) !baseController.handleRootBack() + val baseController = router.backstack.last().controller() as? BaseController + if (if (router.backstackSize == 1) !(baseController?.handleRootBack() ?: false) else !router.handleBack()) { unlocked = false super.onBackPressed() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index d4bbe7f6bd..4810b06471 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -16,21 +16,15 @@ import eu.kanade.tachiyomi.data.backup.BackupRestoreService import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.ui.base.controller.BaseController -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.catalogue.browse.ProgressItem -import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener -import kotlinx.android.synthetic.main.recently_read_controller.empty_view -import kotlinx.android.synthetic.main.recently_read_controller.recycler -import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get +import kotlinx.android.synthetic.main.recently_read_controller.* /** * Fragment that shows recently read manga. @@ -111,18 +105,16 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), * * @param mangaHistory list of manga history */ - fun onNextManga(mangaHistory: List, freshList:Boolean = false) { + fun onNextManga(mangaHistory: List) { val adapter = adapter ?: return adapter.updateDataSet(mangaHistory) adapter.onLoadMoreComplete(null) - if (recentItems == null || adapter.endlessTargetCount == 1) + if (recentItems == null) resetProgressItem() - else if (freshList && mangaHistory.size == recentItems!!.size) - onAddPageError() recentItems = mangaHistory.toMutableList() } - private fun onAddPageError() { + fun onAddPageError() { adapter?.onLoadMoreComplete(null) adapter?.endlessTargetCount = 1 } @@ -213,18 +205,15 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), } // Fixes problem with the overflow icon showing up in lieu of search - searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.action_recents -> { - router.setRoot(RecentChaptersController().withFadeTransaction() - .tag(R.id.nav_drawer_recents.toString())) - Injekt.get().showRecentUpdates().set(true) - (activity as? MainActivity)?.updateRecentsIcon() + searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { + return true } - } - return super.onOptionsItemSelected(item) + + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { + activity?.invalidateOptionsMenu() + return true + } + }) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt index 30c0fbbb99..bcf73ba09b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadPresenter.kt @@ -55,13 +55,14 @@ class RecentlyReadPresenter(private val view: RecentlyReadController) { } fun observe() { + readerSubscription?.unsubscribe() val cal = Calendar.getInstance() cal.time = Date() cal.add(Calendar.YEAR, -50) - db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { + readerSubscription = db.getRecentMangaLimit(cal.time, lastCount, "").asRxObservable().map { val items = it.map(::RecentlyReadItem) launchUI { - view.onNextManga(items, false) + view.onNextManga(items) } }.observeOn(Schedulers.io()).skip(1).take(1).subscribe() }