diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 16446563fb..c97f246df4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.library -import android.os.Bundle import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -35,7 +34,6 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.io.Serializable import java.util.ArrayList import java.util.Collections import java.util.Comparator @@ -43,12 +41,12 @@ import java.util.Comparator /** * Class containing library information. */ -private data class Library(val categories: List, val mangaMap: LibraryMap): Serializable +private data class Library(val categories: List, val mangaMap: LibraryMap) /** * Typealias for the library manga, using the category as keys, and list of manga as values. */ -private typealias LibraryMap = HashMap> +private typealias LibraryMap = Map> /** * Presenter of [LibraryController]. @@ -80,10 +78,6 @@ class LibraryPresenter( private var currentMangaMap:LibraryMap? = null - private companion object { - var currentLibrary:Library? = null - } - fun isDownloading() = downloadManager.hasQueue() fun onDestroy() { @@ -197,13 +191,7 @@ class LibraryPresenter( true } - val filterMap = map.mapValues { entry -> entry.value.filter(filterFn) } - val hashMap = hashMapOf>() - filterMap.map { - hashMap.put(it.key, it.value) - } - - return hashMap + return map.mapValues { entry -> entry.value.filter(filterFn) } } /** @@ -241,9 +229,10 @@ class LibraryPresenter( private fun applyCatSort(map: LibraryMap, catId: Int?): LibraryMap { if (catId == null) return map val categoryManga = map[catId] ?: return map - val catSorted = applySort(hashMapOf(catId to categoryManga), catId) - map[catId] = catSorted.values.first() - return map + val catSorted = applySort(mapOf(catId to categoryManga), catId) + val mutableMap = map.toMutableMap() + mutableMap[catId] = catSorted.values.first() + return mutableMap } private fun applySort(map: LibraryMap, catId: Int?): LibraryMap { @@ -298,13 +287,7 @@ class LibraryPresenter( } val comparator = Comparator(sortFn) - val sortedMap = map.mapValues { entry -> entry.value.sortedWith(comparator) } - val hashMap = hashMapOf>() - sortedMap.map { - hashMap.put(it.key, it.value) - } - - return hashMap + return map.mapValues { entry -> entry.value.sortedWith(comparator) } } /** @@ -412,13 +395,7 @@ class LibraryPresenter( else Collections.reverseOrder(sortFn) - val sortedMap = map.mapValues { entry -> entry.value.sortedWith(comparator) } - val hashMap = hashMapOf>() - sortedMap.map { - hashMap.put(it.key, it.value) - } - - return hashMap + return map.mapValues { entry -> entry.value.sortedWith(comparator) } } private fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int { @@ -452,11 +429,8 @@ class LibraryPresenter( this.categories = if (preferences.hideCategories().getOrDefault()) arrayListOf(createDefaultCategory()) else categories - val hashMap = hashMapOf>() - libraryMap.map { - hashMap.put(it.key, it.value) - } - return Library(this.categories, hashMap) + + return Library(this.categories, libraryMap) } private fun createDefaultCategory(): Category { @@ -709,4 +683,8 @@ class LibraryPresenter( db.updateMangaTitle(manga).executeAsBlocking() } } + + private companion object { + var currentLibrary:Library? = null + } } 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 157298412a..a322b459c4 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 @@ -46,6 +46,7 @@ import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.extension.ExtensionController import eu.kanade.tachiyomi.ui.library.LibraryController +import eu.kanade.tachiyomi.ui.library.LibraryPresenter import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController @@ -128,20 +129,20 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { val currentRoot = router.backstack.firstOrNull() if (currentRoot?.tag()?.toIntOrNull() != id) { when (id) { - R.id.nav_drawer_library -> setRoot(LibraryController(), id) - R.id.nav_drawer_recents -> { + R.id.nav_library -> setRoot(LibraryController(), id) + R.id.nav_recents -> { if (preferences.showRecentUpdates().getOrDefault()) setRoot(RecentChaptersController(), id) else setRoot(RecentlyReadController(), id) } - R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) - R.id.nav_drawer_settings -> setRoot(SettingsMainController(), id) + R.id.nav_catalogues -> setRoot(CatalogueController(), id) + R.id.nav_settings -> setRoot(SettingsMainController(), id) } } else if (currentRoot.tag()?.toIntOrNull() == id) { when (id) { - R.id.nav_drawer_recents -> { + R.id.nav_recents -> { if (router.backstack.size > 1) router.popToRoot() else { val showRecents = preferences.showRecentUpdates().getOrDefault() @@ -151,8 +152,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { updateRecentsIcon() } } - R.id.nav_drawer_library, R.id.nav_drawer_catalogues, - R.id.nav_drawer_settings -> router.popToRoot() + R.id.nav_library, R.id.nav_catalogues, + R.id.nav_settings -> router.popToRoot() } } true @@ -232,7 +233,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { if (!router.hasRootController()) { // Set start screen if (!handleIntentAction(intent)) { - setSelectedDrawerItem(R.id.nav_drawer_library) + navigationView.selectedItemId = R.id.nav_library } } @@ -273,7 +274,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } fun updateRecentsIcon() { - navigationView.menu.findItem(R.id.nav_drawer_recents).icon = + navigationView.menu.findItem(R.id.nav_recents).icon = AppCompatResources.getDrawable(this, if (preferences.showRecentUpdates().getOrDefault()) R.drawable.ic_update_black_24dp else R.drawable.ic_history_black_24dp) @@ -301,13 +302,13 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { private fun setExtensionsBadge() { val updates = preferences.extensionUpdatesCount().getOrDefault() if (updates > 0) { - val badge = navigationView.getOrCreateBadge(R.id.nav_drawer_settings) + val badge = navigationView.getOrCreateBadge(R.id.nav_settings) badge.number = updates badge.backgroundColor = getResourceColor(R.attr.badgeColor) badge.badgeTextColor = Color.WHITE } else { - navigationView.removeBadge(R.id.nav_drawer_settings) + navigationView.removeBadge(R.id.nav_settings) } } @@ -357,18 +358,42 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { applicationContext, notificationId, intent.getIntExtra("groupId", 0) ) when (intent.action) { - SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library) - SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates) - SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_drawer_recently_read) - SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_drawer_catalogues) - SHORTCUT_EXTENSIONS -> setSelectedDrawerItem(R.id.nav_drawer_extensions) + SHORTCUT_LIBRARY -> navigationView.selectedItemId = R.id.nav_library + SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> { + preferences.showRecentUpdates().set(intent.action == SHORTCUT_RECENTLY_UPDATED) + navigationView.selectedItemId = R.id.nav_recents + updateRecentsIcon() + } + SHORTCUT_CATALOGUES -> navigationView.selectedItemId = R.id.nav_catalogues + SHORTCUT_EXTENSIONS -> { + if (router.backstack.none { it.controller() is ExtensionController }) { + if (router.backstack.isEmpty()) { + navigationView.selectedItemId = R.id.nav_library + router.pushController( + RouterTransaction.with(ExtensionController()).pushChangeHandler( + SimpleSwapChangeHandler() + ).popChangeHandler(FadeChangeHandler()) + ) + } else { + router.pushController(ExtensionController().withFadeTransaction()) + } + } + } SHORTCUT_MANGA -> { val extras = intent.extras ?: return false router.setRoot(RouterTransaction.with(MangaController(extras))) } SHORTCUT_DOWNLOADS -> { if (router.backstack.none { it.controller() is DownloadController }) { - setSelectedDrawerItem(R.id.nav_drawer_downloads) + if (router.backstack.isEmpty()) { + navigationView.selectedItemId = R.id.nav_library + router.pushController(RouterTransaction.with(DownloadController()) + .pushChangeHandler(SimpleSwapChangeHandler()) + .popChangeHandler(FadeChangeHandler())) + } + else { + router.pushController(DownloadController().withFadeTransaction()) + } } } Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> { @@ -422,54 +447,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { } } - private fun setSelectedDrawerItem(itemId: Int) { - if (!isFinishing) { - if (itemId == R.id.nav_drawer_library || - itemId == R.id.nav_drawer_settings || - itemId == R.id.nav_drawer_catalogues) - navigationView.selectedItemId = itemId - jumpToController(itemId) - } - } - - private fun jumpToController(id: Int) { - val currentRoot = router.backstack.firstOrNull() - if (currentRoot?.tag()?.toIntOrNull() != id) { - when (id) { - R.id.nav_drawer_recent_updates, R.id.nav_drawer_recently_read -> { - preferences.showRecentUpdates().set(id == R.id.nav_drawer_recent_updates) - navigationView.selectedItemId = R.id.nav_drawer_recents - updateRecentsIcon() - } - R.id.nav_drawer_extensions -> { - if (router.backstack.isEmpty()) { - navigationView.selectedItemId = R.id.nav_drawer_settings - router.pushController(RouterTransaction.with(ExtensionController()) - .pushChangeHandler(SimpleSwapChangeHandler()) - .popChangeHandler(FadeChangeHandler())) - } - else { - router.pushController(ExtensionController().withFadeTransaction()) - } - } - R.id.nav_drawer_downloads -> { - if (router.backstackSize > 1) { - router.popToRoot() - } - if (router.backstack.isEmpty()) { - navigationView.selectedItemId = R.id.nav_drawer_library - router.pushController(RouterTransaction.with(DownloadController()) - .pushChangeHandler(SimpleSwapChangeHandler()) - .popChangeHandler(FadeChangeHandler())) - } - else { - router.pushController(DownloadController().withFadeTransaction()) - } - } - } - } - } - private fun setRoot(controller: Controller, id: Int) { router.setRoot(controller.withFadeTransaction().tag(id.toString())) } @@ -552,11 +529,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { val hasQueue = downloading || downloadManager.hasQueue() launchUI { if (hasQueue) { - val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library) ?: return@launchUI + val badge = navigationView?.getOrCreateBadge(R.id.nav_library) ?: return@launchUI badge.clearNumber() badge.backgroundColor = getResourceColor(R.attr.badgeColor) } else { - navigationView?.removeBadge(R.id.nav_drawer_library) + navigationView?.removeBadge(R.id.nav_library) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 4762c5b79e..298ed09f64 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -344,8 +344,7 @@ class RecentChaptersController : NucleusController(), when (item.itemId) { R.id.action_recents -> { router.setRoot( - RecentlyReadController().withFadeTransaction() - .tag(R.id.nav_drawer_recents.toString())) + RecentlyReadController().withFadeTransaction().tag(R.id.nav_recents.toString())) Injekt.get().showRecentUpdates().set(false) (activity as? MainActivity)?.updateRecentsIcon() } 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 4810b06471..de39c8a6e2 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 @@ -15,16 +15,21 @@ import eu.kanade.tachiyomi.R 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.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController 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.ui.recent_updates.RecentChaptersController 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.* +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get /** * Fragment that shows recently read manga. @@ -216,4 +221,16 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle), } }) } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_recents -> { + router.setRoot( + RecentChaptersController().withFadeTransaction().tag(R.id.nav_recents.toString())) + Injekt.get().showRecentUpdates().set(true) + (activity as? MainActivity)?.updateRecentsIcon() + } + } + return super.onOptionsItemSelected(item) + } } diff --git a/app/src/main/res/menu/bottom_navigation.xml b/app/src/main/res/menu/bottom_navigation.xml index 333b91de63..4782c30000 100644 --- a/app/src/main/res/menu/bottom_navigation.xml +++ b/app/src/main/res/menu/bottom_navigation.xml @@ -4,19 +4,19 @@ diff --git a/app/src/main/res/menu/menu_navigation.xml b/app/src/main/res/menu/menu_navigation.xml deleted file mode 100644 index ca5c267838..0000000000 --- a/app/src/main/res/menu/menu_navigation.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - -