From ff71b9670390ed5d1a3823e16393953e29bfb99c Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 2 Feb 2020 02:15:30 -0800 Subject: [PATCH] Fixed Download intent + help button in settings --- .../data/notification/NotificationHandler.kt | 9 ++-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 52 +++++++++++++++++-- .../ui/setting/SettingsMainController.kt | 32 +++++++++--- .../main/res/drawable/ic_help_black_24dp.xml | 3 +- app/src/main/res/menu/download_queue.xml | 11 ++-- app/src/main/res/menu/settings_main.xml | 9 ++++ 6 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/menu/settings_main.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt index 2f474f3f5a..e43f3b1e1b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationHandler.kt @@ -18,11 +18,10 @@ object NotificationHandler { * @param context context of application */ internal fun openDownloadManagerPendingActivity(context: Context): PendingIntent { - val intent = Intent(context, MainActivity::class.java).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - action = MainActivity.SHORTCUT_DOWNLOADS - } - return PendingIntent.getActivity(context, 0, intent, 0) + val intent = Intent(context, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.action = MainActivity.SHORTCUT_DOWNLOADS + return PendingIntent.getActivity(context, -201, intent, PendingIntent.FLAG_UPDATE_CURRENT) } /** 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 75b257ac43..9bce1d74f1 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 @@ -23,6 +23,8 @@ import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler +import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler import com.google.android.material.snackbar.Snackbar import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -169,7 +171,10 @@ open class MainActivity : BaseActivity() { R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id) R.id.nav_drawer_extensions -> setRoot(ExtensionController(), id) R.id.nav_drawer_downloads -> { - setRoot(DownloadController(), id) + if (router.backstack.isEmpty()) { + setRoot(LibraryController(), R.id.nav_drawer_library) + } + router.pushController(DownloadController().withFadeTransaction()) } R.id.nav_drawer_settings -> { setRoot(SettingsMainController(), id) @@ -453,8 +458,49 @@ open class MainActivity : BaseActivity() { if (!isFinishing) { nav_view.setCheckedItem(itemId) navigationView.selectedItemId = itemId - nav_view.menu.performIdentifierAction(itemId, 0) - //navigationView.menu.performIdentifierAction(itemId, 0) + jumpToController(itemId) + } + } + + fun jumpToController(id: Int) { + + 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 -> { + if (router.backstack.isEmpty()) { + navigationView.selectedItemId = R.id.nav_drawer_settings + setRoot(SettingsMainController(), 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.backstack.isEmpty()) { + setRoot(LibraryController(), R.id.nav_drawer_library) + router.pushController(RouterTransaction.with(DownloadController()) + .pushChangeHandler(SimpleSwapChangeHandler()) + .popChangeHandler(FadeChangeHandler())) + } + else { + router.pushController(DownloadController().withFadeTransaction()) + } + } + R.id.nav_drawer_settings -> { + setRoot(SettingsMainController(), id) + } + R.id.nav_drawer_help -> { + openInBrowser(URL_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 32bdc4f5d6..dc2a0c019d 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,19 +1,22 @@ package eu.kanade.tachiyomi.ui.setting +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import androidx.preference.PreferenceScreen import com.bluelinelabs.conductor.Controller import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceKeys -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault -import eu.kanade.tachiyomi.data.track.TrackManager -import eu.kanade.tachiyomi.data.updater.UpdaterJob import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.ui.extension.ExtensionController -import uy.kohesive.injekt.injectLazy +import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.openInBrowser class SettingsMainController : SettingsController() { + + init { + setHasOptionsMenu(true) + } + override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.label_settings @@ -75,8 +78,23 @@ class SettingsMainController : SettingsController() { onClick { navigateTo(SettingsAboutController()) } } } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.settings_main, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_help -> activity?.openInBrowser(URL_HELP) + else -> return super.onOptionsItemSelected(item) + } + return true + } private fun navigateTo(controller: Controller) { router.pushController(controller.withFadeTransaction()) } + + private companion object { + private const val URL_HELP = "https://tachiyomi.org/help/" + } } diff --git a/app/src/main/res/drawable/ic_help_black_24dp.xml b/app/src/main/res/drawable/ic_help_black_24dp.xml index 1517747d07..4e613fd6ee 100644 --- a/app/src/main/res/drawable/ic_help_black_24dp.xml +++ b/app/src/main/res/drawable/ic_help_black_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportHeight="24.0" + android:tint="?attr/actionBarTintColor"> diff --git a/app/src/main/res/menu/download_queue.xml b/app/src/main/res/menu/download_queue.xml index cceaff411e..fbcb11648c 100644 --- a/app/src/main/res/menu/download_queue.xml +++ b/app/src/main/res/menu/download_queue.xml @@ -14,11 +14,6 @@ android:visible="false" app:showAsAction="ifRoom"/> - - + + + \ No newline at end of file diff --git a/app/src/main/res/menu/settings_main.xml b/app/src/main/res/menu/settings_main.xml new file mode 100644 index 0000000000..10bcb4d6f3 --- /dev/null +++ b/app/src/main/res/menu/settings_main.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file