From 11544fe8eff59636c83565d48a82215215584293 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 25 Feb 2020 19:40:14 -0500 Subject: [PATCH] Migrate to bottom navigation --- .../tachiyomi/ui/library/LibraryController.kt | 5 -- .../kanade/tachiyomi/ui/main/MainActivity.kt | 73 ++++++----------- .../AboutController.kt} | 5 +- .../tachiyomi/ui/more/MoreController.kt | 81 +++++++++++++++++++ .../ui/setting/SettingsMainController.kt | 30 ------- .../res/drawable/bottom_nav_item_selector.xml | 8 ++ .../drawable/ic_compare_arrows_black_24dp.xml | 9 +++ ..._white_24dp.xml => ic_help_black_24dp.xml} | 2 +- app/src/main/res/layout/main_activity.xml | 24 +++--- app/src/main/res/layout/navigation_header.xml | 21 ----- app/src/main/res/menu/bottom_nav.xml | 23 ++++++ app/src/main/res/menu/library.xml | 5 -- app/src/main/res/menu/menu_navigation.xml | 42 ---------- app/src/main/res/menu/settings.xml | 11 --- app/src/main/res/values/attrs.xml | 3 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 9 --- app/src/main/res/values/themes.xml | 6 +- 18 files changed, 169 insertions(+), 189 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/ui/{setting/SettingsAboutController.kt => more/AboutController.kt} (97%) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt create mode 100644 app/src/main/res/drawable/bottom_nav_item_selector.xml create mode 100644 app/src/main/res/drawable/ic_compare_arrows_black_24dp.xml rename app/src/main/res/drawable/{ic_help_white_24dp.xml => ic_help_black_24dp.xml} (93%) delete mode 100644 app/src/main/res/layout/navigation_header.xml create mode 100644 app/src/main/res/menu/bottom_nav.xml delete mode 100644 app/src/main/res/menu/menu_navigation.xml delete mode 100644 app/src/main/res/menu/settings.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 1e3f64a1bf..2e62040434 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController -import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.inflate import kotlinx.android.synthetic.main.library_controller.empty_view @@ -396,10 +395,6 @@ class LibraryController( preferences.downloadBadge().set(item.isChecked) onDownloadBadgeChanged() } - - R.id.action_source_migration -> { - router.pushController(MigrationController().withFadeTransaction()) - } } return super.onOptionsItemSelected(item) 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 bd90d0689c..986f641966 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 @@ -1,14 +1,10 @@ package eu.kanade.tachiyomi.ui.main -import android.animation.ObjectAnimator import android.app.SearchManager import android.content.Intent -import android.graphics.Color import android.os.Bundle import android.view.ViewGroup -import androidx.appcompat.graphics.drawable.DrawerArrowDrawable import androidx.core.view.GravityCompat -import androidx.drawerlayout.widget.DrawerLayout import com.bluelinelabs.conductor.* import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -18,12 +14,11 @@ import eu.kanade.tachiyomi.ui.base.controller.* import eu.kanade.tachiyomi.ui.catalogue.CatalogueController 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.manga.MangaController +import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController -import eu.kanade.tachiyomi.ui.setting.SettingsMainController import kotlinx.android.synthetic.main.main_activity.* @@ -31,15 +26,13 @@ class MainActivity : BaseActivity() { private lateinit var router: Router - private var drawerArrow: DrawerArrowDrawable? = null - private var secondaryDrawer: ViewGroup? = null private val startScreenId by lazy { when (preferences.startScreen()) { - 2 -> R.id.nav_drawer_recently_read - 3 -> R.id.nav_drawer_recent_updates - else -> R.id.nav_drawer_library + 2 -> R.id.nav_history + 3 -> R.id.nav_updates + else -> R.id.nav_library } } @@ -58,33 +51,25 @@ class MainActivity : BaseActivity() { setSupportActionBar(toolbar) - drawerArrow = DrawerArrowDrawable(this) - drawerArrow?.color = Color.WHITE - toolbar.navigationIcon = drawerArrow - tabAnimator = TabsAnimator(tabs) - // Set behavior of Navigation drawer - nav_view.setNavigationItemSelectedListener { item -> + // Set behavior of bottom nav + bottom_nav.setOnNavigationItemSelectedListener { item -> val id = item.itemId val currentRoot = router.backstack.firstOrNull() if (currentRoot?.tag()?.toIntOrNull() != id) { when (id) { - R.id.nav_drawer_library -> setRoot(LibraryController(), id) - R.id.nav_drawer_recent_updates -> setRoot(RecentChaptersController(), id) - R.id.nav_drawer_recently_read -> setRoot(RecentlyReadController(), id) - R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) - R.id.nav_drawer_extensions -> setRoot(ExtensionController(), id) - R.id.nav_drawer_downloads -> { - router.pushController(DownloadController().withFadeTransaction()) - } - R.id.nav_drawer_settings -> { - router.pushController(SettingsMainController().withFadeTransaction()) - } + R.id.nav_library -> setRoot(LibraryController(), id) + R.id.nav_updates -> setRoot(RecentChaptersController(), id) + R.id.nav_history -> setRoot(RecentlyReadController(), id) + R.id.nav_catalogues -> setRoot(CatalogueController(), id) + R.id.nav_more -> setRoot(MoreController(), id) } + } else { + router.popToRoot() } - drawer.closeDrawer(GravityCompat.START) + true } @@ -143,18 +128,18 @@ class MainActivity : BaseActivity() { } 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_LIBRARY -> setSelectedDrawerItem(R.id.nav_library) + SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_updates) + SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_history) + SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_catalogues) SHORTCUT_MANGA -> { val extras = intent.extras ?: return false - router.setRoot(RouterTransaction.with(MangaController(extras))) + setSelectedDrawerItem(R.id.nav_library) + router.pushController(RouterTransaction.with(MangaController(extras))) } SHORTCUT_DOWNLOADS -> { - if (router.backstack.none { it.controller() is DownloadController }) { - setSelectedDrawerItem(R.id.nav_drawer_downloads) - } + setSelectedDrawerItem(R.id.nav_more) + router.pushController(RouterTransaction.with(DownloadController())) } Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> { //If the intent match the "standard" Android search intent @@ -186,7 +171,7 @@ class MainActivity : BaseActivity() { override fun onDestroy() { super.onDestroy() - nav_view?.setNavigationItemSelectedListener(null) + bottom_nav?.setOnNavigationItemSelectedListener(null) toolbar?.setNavigationOnClickListener(null) } @@ -203,8 +188,7 @@ class MainActivity : BaseActivity() { private fun setSelectedDrawerItem(itemId: Int) { if (!isFinishing) { - nav_view.setCheckedItem(itemId) - nav_view.menu.performIdentifierAction(itemId, 0) + bottom_nav.selectedItemId = itemId } } @@ -217,14 +201,7 @@ class MainActivity : BaseActivity() { return } - val showHamburger = router.backstackSize == 1 - if (showHamburger) { - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) - } else { - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) - } - - ObjectAnimator.ofFloat(drawerArrow, "progress", if (showHamburger) 0f else 1f).start() + supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1) if (from is TabbedController) { from.cleanupTabs(tabs) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt similarity index 97% rename from app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 13c0e35d13..c7ca1ed007 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.setting +package eu.kanade.tachiyomi.ui.more import android.app.Dialog import android.content.Intent @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.data.updater.UpdaterJob import eu.kanade.tachiyomi.data.updater.UpdaterService import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.main.ChangelogDialogController +import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.util.lang.launchNow import eu.kanade.tachiyomi.util.lang.toTimestampString import eu.kanade.tachiyomi.util.preference.* @@ -29,7 +30,7 @@ import java.util.Locale import java.util.TimeZone import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys -class SettingsAboutController : SettingsController() { +class AboutController : SettingsController() { /** * Checks for new releases diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt new file mode 100644 index 0000000000..f6cd6d422c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -0,0 +1,81 @@ +package eu.kanade.tachiyomi.ui.more + +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.download.DownloadController +import eu.kanade.tachiyomi.ui.extension.ExtensionController +import eu.kanade.tachiyomi.ui.migration.MigrationController +import eu.kanade.tachiyomi.ui.setting.SettingsController +import eu.kanade.tachiyomi.ui.setting.SettingsMainController +import eu.kanade.tachiyomi.util.preference.* +import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.openInBrowser + +class MoreController : SettingsController() { + + override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + titleRes = R.string.label_more + + val tintColor = context.getResourceColor(R.attr.colorAccent) + + preferenceCategory { + preference { + titleRes = R.string.label_extensions + iconRes = R.drawable.ic_extension_black_24dp + iconTint = tintColor + onClick { + router.pushController(ExtensionController().withFadeTransaction()) + } + } + preference { + titleRes = R.string.label_download_queue + iconRes = R.drawable.ic_file_download_black_24dp + iconTint = tintColor + onClick { + router.pushController(DownloadController().withFadeTransaction()) + } + } + preference { + titleRes = R.string.label_migration + iconRes = R.drawable.ic_compare_arrows_black_24dp + iconTint = tintColor + onClick { + router.pushController(MigrationController().withFadeTransaction()) + } + } + } + + preferenceCategory { + preference { + titleRes = R.string.label_settings + iconRes = R.drawable.ic_settings_black_24dp + iconTint = tintColor + onClick { + router.pushController(SettingsMainController().withFadeTransaction()) + } + } + preference { + iconRes = R.drawable.ic_info_black_24dp + iconTint = tintColor + titleRes = R.string.pref_category_about + onClick { + router.pushController(AboutController().withFadeTransaction()) + } + } + preference { + titleRes = R.string.label_help + iconRes = R.drawable.ic_help_black_24dp + iconTint = tintColor + onClick { + activity?.openInBrowser(URL_HELP) + } + } + } + } + + companion object { + private const val URL_HELP = "https://tachiyomi.org/help/" + } + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index e4910528ea..cd7056a62c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -1,33 +1,13 @@ package eu.kanade.tachiyomi.ui.setting -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.util.preference.* import eu.kanade.tachiyomi.util.system.getResourceColor -import eu.kanade.tachiyomi.util.system.openInBrowser class SettingsMainController : SettingsController() { - init { - setHasOptionsMenu(true) - } - - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - inflater.inflate(R.menu.settings, menu) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.action_help -> activity?.openInBrowser(URL_HELP) - } - - return super.onOptionsItemSelected(item) - } - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.label_settings @@ -75,19 +55,9 @@ class SettingsMainController : SettingsController() { titleRes = R.string.pref_category_advanced onClick { navigateTo(SettingsAdvancedController()) } } - preference { - iconRes = R.drawable.ic_info_black_24dp - iconTint = tintColor - titleRes = R.string.pref_category_about - onClick { navigateTo(SettingsAboutController()) } - } } private fun navigateTo(controller: SettingsController) { router.pushController(controller.withFadeTransaction()) } - - companion object { - private const val URL_HELP = "https://tachiyomi.org/help/" - } } diff --git a/app/src/main/res/drawable/bottom_nav_item_selector.xml b/app/src/main/res/drawable/bottom_nav_item_selector.xml new file mode 100644 index 0000000000..a4b1bce02b --- /dev/null +++ b/app/src/main/res/drawable/bottom_nav_item_selector.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_compare_arrows_black_24dp.xml b/app/src/main/res/drawable/ic_compare_arrows_black_24dp.xml new file mode 100644 index 0000000000..261c56592d --- /dev/null +++ b/app/src/main/res/drawable/ic_compare_arrows_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_help_white_24dp.xml b/app/src/main/res/drawable/ic_help_black_24dp.xml similarity index 93% rename from app/src/main/res/drawable/ic_help_white_24dp.xml rename to app/src/main/res/drawable/ic_help_black_24dp.xml index 04c1c00fc2..b1d7a2cf55 100644 --- a/app/src/main/res/drawable/ic_help_white_24dp.xml +++ b/app/src/main/res/drawable/ic_help_black_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 5cb599510a..9b52435c33 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -7,7 +7,6 @@ android:fitsSystemWindows="true"> @@ -40,18 +39,19 @@ + android:layout_height="0dp" + android:layout_weight="1" /> + + - - diff --git a/app/src/main/res/layout/navigation_header.xml b/app/src/main/res/layout/navigation_header.xml deleted file mode 100644 index 7bf03685e2..0000000000 --- a/app/src/main/res/layout/navigation_header.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/menu/bottom_nav.xml b/app/src/main/res/menu/bottom_nav.xml new file mode 100644 index 0000000000..838b04efac --- /dev/null +++ b/app/src/main/res/menu/bottom_nav.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/app/src/main/res/menu/library.xml b/app/src/main/res/menu/library.xml index c30edde98f..60980efdf0 100644 --- a/app/src/main/res/menu/library.xml +++ b/app/src/main/res/menu/library.xml @@ -42,9 +42,4 @@ - - 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 0773fce1ee..0000000000 --- a/app/src/main/res/menu/menu_navigation.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/settings.xml b/app/src/main/res/menu/settings.xml deleted file mode 100644 index 3f8a0773ab..0000000000 --- a/app/src/main/res/menu/settings.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 24c6b15dea..978a248515 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -20,12 +20,13 @@ - + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b052c11a4f..998c604496 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,7 @@ History + More Settings Download queue Library diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0adfb1b256..f268632c10 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -36,15 +36,6 @@ @color/colorAmoledPrimary - - - - diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index deecd0573a..bb5efe3653 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -40,6 +40,8 @@ @color/textColorPrimaryLight @color/dialogLight @color/iconColorLight + @android:color/white + @color/textColorHintDark @@ -81,14 +83,14 @@ @color/dialogDark @style/Theme.AlertDialog.Dark - - @style/Theme.Widget.NavigationView.Dark @drawable/list_item_selector_dark @drawable/library_item_selector_dark @color/textColorPrimaryDark @color/dialogDark @color/iconColorDark + @android:color/white + @color/textColorHintDark