Cleaned out old nav drawer menu

This commit is contained in:
Jay 2020-02-10 19:46:32 -08:00
parent d2dae05ab2
commit ecbb55f058
6 changed files with 81 additions and 150 deletions

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.library package eu.kanade.tachiyomi.ui.library
import android.os.Bundle
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
@ -35,7 +34,6 @@ import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.Serializable
import java.util.ArrayList import java.util.ArrayList
import java.util.Collections import java.util.Collections
import java.util.Comparator import java.util.Comparator
@ -43,12 +41,12 @@ import java.util.Comparator
/** /**
* Class containing library information. * Class containing library information.
*/ */
private data class Library(val categories: List<Category>, val mangaMap: LibraryMap): Serializable private data class Library(val categories: List<Category>, val mangaMap: LibraryMap)
/** /**
* Typealias for the library manga, using the category as keys, and list of manga as values. * Typealias for the library manga, using the category as keys, and list of manga as values.
*/ */
private typealias LibraryMap = HashMap<Int, List<LibraryItem>> private typealias LibraryMap = Map<Int, List<LibraryItem>>
/** /**
* Presenter of [LibraryController]. * Presenter of [LibraryController].
@ -80,10 +78,6 @@ class LibraryPresenter(
private var currentMangaMap:LibraryMap? = null private var currentMangaMap:LibraryMap? = null
private companion object {
var currentLibrary:Library? = null
}
fun isDownloading() = downloadManager.hasQueue() fun isDownloading() = downloadManager.hasQueue()
fun onDestroy() { fun onDestroy() {
@ -197,13 +191,7 @@ class LibraryPresenter(
true true
} }
val filterMap = map.mapValues { entry -> entry.value.filter(filterFn) } return map.mapValues { entry -> entry.value.filter(filterFn) }
val hashMap = hashMapOf<Int, List<LibraryItem>>()
filterMap.map {
hashMap.put(it.key, it.value)
}
return hashMap
} }
/** /**
@ -241,9 +229,10 @@ class LibraryPresenter(
private fun applyCatSort(map: LibraryMap, catId: Int?): LibraryMap { private fun applyCatSort(map: LibraryMap, catId: Int?): LibraryMap {
if (catId == null) return map if (catId == null) return map
val categoryManga = map[catId] ?: return map val categoryManga = map[catId] ?: return map
val catSorted = applySort(hashMapOf(catId to categoryManga), catId) val catSorted = applySort(mapOf(catId to categoryManga), catId)
map[catId] = catSorted.values.first() val mutableMap = map.toMutableMap()
return map mutableMap[catId] = catSorted.values.first()
return mutableMap
} }
private fun applySort(map: LibraryMap, catId: Int?): LibraryMap { private fun applySort(map: LibraryMap, catId: Int?): LibraryMap {
@ -298,13 +287,7 @@ class LibraryPresenter(
} }
val comparator = Comparator(sortFn) val comparator = Comparator(sortFn)
val sortedMap = map.mapValues { entry -> entry.value.sortedWith(comparator) } return map.mapValues { entry -> entry.value.sortedWith(comparator) }
val hashMap = hashMapOf<Int, List<LibraryItem>>()
sortedMap.map {
hashMap.put(it.key, it.value)
}
return hashMap
} }
/** /**
@ -412,13 +395,7 @@ class LibraryPresenter(
else else
Collections.reverseOrder(sortFn) Collections.reverseOrder(sortFn)
val sortedMap = map.mapValues { entry -> entry.value.sortedWith(comparator) } return map.mapValues { entry -> entry.value.sortedWith(comparator) }
val hashMap = hashMapOf<Int, List<LibraryItem>>()
sortedMap.map {
hashMap.put(it.key, it.value)
}
return hashMap
} }
private fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int { private fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int {
@ -452,11 +429,8 @@ class LibraryPresenter(
this.categories = if (preferences.hideCategories().getOrDefault()) this.categories = if (preferences.hideCategories().getOrDefault())
arrayListOf(createDefaultCategory()) arrayListOf(createDefaultCategory())
else categories else categories
val hashMap = hashMapOf<Int, List<LibraryItem>>()
libraryMap.map { return Library(this.categories, libraryMap)
hashMap.put(it.key, it.value)
}
return Library(this.categories, hashMap)
} }
private fun createDefaultCategory(): Category { private fun createDefaultCategory(): Category {
@ -709,4 +683,8 @@ class LibraryPresenter(
db.updateMangaTitle(manga).executeAsBlocking() db.updateMangaTitle(manga).executeAsBlocking()
} }
} }
private companion object {
var currentLibrary:Library? = null
}
} }

View File

@ -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.download.DownloadController
import eu.kanade.tachiyomi.ui.extension.ExtensionController import eu.kanade.tachiyomi.ui.extension.ExtensionController
import eu.kanade.tachiyomi.ui.library.LibraryController 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.manga.MangaController
import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController
import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController
@ -128,20 +129,20 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
val currentRoot = router.backstack.firstOrNull() val currentRoot = router.backstack.firstOrNull()
if (currentRoot?.tag()?.toIntOrNull() != id) { if (currentRoot?.tag()?.toIntOrNull() != id) {
when (id) { when (id) {
R.id.nav_drawer_library -> setRoot(LibraryController(), id) R.id.nav_library -> setRoot(LibraryController(), id)
R.id.nav_drawer_recents -> { R.id.nav_recents -> {
if (preferences.showRecentUpdates().getOrDefault()) if (preferences.showRecentUpdates().getOrDefault())
setRoot(RecentChaptersController(), id) setRoot(RecentChaptersController(), id)
else else
setRoot(RecentlyReadController(), id) setRoot(RecentlyReadController(), id)
} }
R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) R.id.nav_catalogues -> setRoot(CatalogueController(), id)
R.id.nav_drawer_settings -> setRoot(SettingsMainController(), id) R.id.nav_settings -> setRoot(SettingsMainController(), id)
} }
} }
else if (currentRoot.tag()?.toIntOrNull() == id) { else if (currentRoot.tag()?.toIntOrNull() == id) {
when (id) { when (id) {
R.id.nav_drawer_recents -> { R.id.nav_recents -> {
if (router.backstack.size > 1) router.popToRoot() if (router.backstack.size > 1) router.popToRoot()
else { else {
val showRecents = preferences.showRecentUpdates().getOrDefault() val showRecents = preferences.showRecentUpdates().getOrDefault()
@ -151,8 +152,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
updateRecentsIcon() updateRecentsIcon()
} }
} }
R.id.nav_drawer_library, R.id.nav_drawer_catalogues, R.id.nav_library, R.id.nav_catalogues,
R.id.nav_drawer_settings -> router.popToRoot() R.id.nav_settings -> router.popToRoot()
} }
} }
true true
@ -232,7 +233,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
if (!router.hasRootController()) { if (!router.hasRootController()) {
// Set start screen // Set start screen
if (!handleIntentAction(intent)) { 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() { fun updateRecentsIcon() {
navigationView.menu.findItem(R.id.nav_drawer_recents).icon = navigationView.menu.findItem(R.id.nav_recents).icon =
AppCompatResources.getDrawable(this, AppCompatResources.getDrawable(this,
if (preferences.showRecentUpdates().getOrDefault()) R.drawable.ic_update_black_24dp if (preferences.showRecentUpdates().getOrDefault()) R.drawable.ic_update_black_24dp
else R.drawable.ic_history_black_24dp) else R.drawable.ic_history_black_24dp)
@ -301,13 +302,13 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
private fun setExtensionsBadge() { private fun setExtensionsBadge() {
val updates = preferences.extensionUpdatesCount().getOrDefault() val updates = preferences.extensionUpdatesCount().getOrDefault()
if (updates > 0) { if (updates > 0) {
val badge = navigationView.getOrCreateBadge(R.id.nav_drawer_settings) val badge = navigationView.getOrCreateBadge(R.id.nav_settings)
badge.number = updates badge.number = updates
badge.backgroundColor = getResourceColor(R.attr.badgeColor) badge.backgroundColor = getResourceColor(R.attr.badgeColor)
badge.badgeTextColor = Color.WHITE badge.badgeTextColor = Color.WHITE
} }
else { 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) applicationContext, notificationId, intent.getIntExtra("groupId", 0)
) )
when (intent.action) { when (intent.action) {
SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library) SHORTCUT_LIBRARY -> navigationView.selectedItemId = R.id.nav_library
SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_drawer_recent_updates) SHORTCUT_RECENTLY_UPDATED, SHORTCUT_RECENTLY_READ -> {
SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_drawer_recently_read) preferences.showRecentUpdates().set(intent.action == SHORTCUT_RECENTLY_UPDATED)
SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_drawer_catalogues) navigationView.selectedItemId = R.id.nav_recents
SHORTCUT_EXTENSIONS -> setSelectedDrawerItem(R.id.nav_drawer_extensions) 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 -> { SHORTCUT_MANGA -> {
val extras = intent.extras ?: return false val extras = intent.extras ?: return false
router.setRoot(RouterTransaction.with(MangaController(extras))) router.setRoot(RouterTransaction.with(MangaController(extras)))
} }
SHORTCUT_DOWNLOADS -> { SHORTCUT_DOWNLOADS -> {
if (router.backstack.none { it.controller() is DownloadController }) { 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" -> { 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) { private fun setRoot(controller: Controller, id: Int) {
router.setRoot(controller.withFadeTransaction().tag(id.toString())) router.setRoot(controller.withFadeTransaction().tag(id.toString()))
} }
@ -552,11 +529,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
val hasQueue = downloading || downloadManager.hasQueue() val hasQueue = downloading || downloadManager.hasQueue()
launchUI { launchUI {
if (hasQueue) { 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.clearNumber()
badge.backgroundColor = getResourceColor(R.attr.badgeColor) badge.backgroundColor = getResourceColor(R.attr.badgeColor)
} else { } else {
navigationView?.removeBadge(R.id.nav_drawer_library) navigationView?.removeBadge(R.id.nav_library)
} }
} }
} }

View File

@ -344,8 +344,7 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
when (item.itemId) { when (item.itemId) {
R.id.action_recents -> { R.id.action_recents -> {
router.setRoot( router.setRoot(
RecentlyReadController().withFadeTransaction() RecentlyReadController().withFadeTransaction().tag(R.id.nav_recents.toString()))
.tag(R.id.nav_drawer_recents.toString()))
Injekt.get<PreferencesHelper>().showRecentUpdates().set(false) Injekt.get<PreferencesHelper>().showRecentUpdates().set(false)
(activity as? MainActivity)?.updateRecentsIcon() (activity as? MainActivity)?.updateRecentsIcon()
} }

View File

@ -15,16 +15,21 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.backup.BackupRestoreService import eu.kanade.tachiyomi.data.backup.BackupRestoreService
import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.History
import eu.kanade.tachiyomi.data.database.models.Manga 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.BaseController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.catalogue.browse.ProgressItem 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.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity 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.launchUI
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener
import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener
import kotlinx.android.synthetic.main.recently_read_controller.* 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. * 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<PreferencesHelper>().showRecentUpdates().set(true)
(activity as? MainActivity)?.updateRecentsIcon()
}
}
return super.onOptionsItemSelected(item)
}
} }

View File

@ -4,19 +4,19 @@
<group android:id="@+id/group_feature"> <group android:id="@+id/group_feature">
<item <item
android:checked="true" android:checked="true"
android:id="@+id/nav_drawer_library" android:id="@+id/nav_library"
android:icon="@drawable/ic_book_black_24dp" android:icon="@drawable/ic_book_black_24dp"
android:title="@string/pref_category_library" /> android:title="@string/pref_category_library" />
<item <item
android:id="@+id/nav_drawer_recents" android:id="@+id/nav_recents"
android:icon="@drawable/ic_update_black_24dp" android:icon="@drawable/ic_update_black_24dp"
android:title="@string/short_recents" /> android:title="@string/short_recents" />
<item <item
android:id="@+id/nav_drawer_catalogues" android:id="@+id/nav_catalogues"
android:icon="@drawable/ic_explore_black_24dp" android:icon="@drawable/ic_explore_black_24dp"
android:title="@string/short_catalogues" /> android:title="@string/short_catalogues" />
<item <item
android:id="@+id/nav_drawer_settings" android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings_black_24dp" android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/label_settings" android:title="@string/label_settings"
android:checkable="false" /> android:checkable="false" />

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single"
android:id="@+id/menu_top">
<item
android:checked="true"
android:id="@+id/nav_drawer_library"
android:icon="@drawable/ic_book_black_24dp"
android:title="@string/label_library" />
<item
android:id="@+id/nav_drawer_recent_updates"
android:icon="@drawable/ic_update_black_24dp"
android:title="@string/label_recent_updates" />
<item
android:id="@+id/nav_drawer_recently_read"
android:icon="@drawable/ic_glasses_black_24dp"
android:title="@string/label_recent_manga"/>
<item
android:id="@+id/nav_drawer_catalogues"
android:icon="@drawable/ic_explore_black_24dp"
android:title="@string/label_catalogues" />
<item
android:id="@+id/nav_drawer_extensions"
android:icon="@drawable/ic_extension_black_24dp"
app:actionLayout="@layout/menu_counter"
android:title="@string/label_extensions"/>
</group>
<group android:checkableBehavior="single"
android:id="@+id/menu_bottom">
<item
android:id="@+id/nav_drawer_downloads"
android:icon="@drawable/ic_file_download_black_24dp"
android:title="@string/label_download_queue" />
<item
android:id="@+id/nav_drawer_settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/label_settings" />
</group>
</menu>