From 56bfa65a54fd2593a05d79c5c9ce2db176f65c50 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 2 Jul 2021 20:09:12 -0400 Subject: [PATCH] Manga app shortcuts now open the newest chapter With the option to turn it off Also refactoring app shortcut settings to turn off only series or sources or both, as well as disable the shortcut jumping straight to the reader --- .../java/eu/kanade/tachiyomi/Migrations.kt | 11 +++++++ .../data/preference/PreferenceKeys.kt | 4 ++- .../data/preference/PreferencesHelper.kt | 5 ++- .../tachiyomi/ui/main/SearchActivity.kt | 19 ++++++++++++ .../ui/setting/SettingsGeneralController.kt | 31 ++++++++++++++----- .../util/manga/MangaShortcutManager.kt | 20 ++++++++---- app/src/main/res/values/strings.xml | 9 ++++-- 7 files changed, 82 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 0c1f19e2ab..2d73d04578 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -121,6 +121,17 @@ object Migrations { UpdaterJob.setupTask() } } + if (oldVersion < 75) { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + val wasShortcutsDisabled = !prefs.getBoolean("show_manga_app_shortcuts", true) + if (wasShortcutsDisabled) { + prefs.edit { + putBoolean(PreferenceKeys.showSourcesInShortcuts, false) + putBoolean(PreferenceKeys.showSeriesInShortcuts, false) + remove("show_manga_app_shortcuts") + } + } + } return true } return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index df748e177f..0f65b4b339 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -204,7 +204,9 @@ object PreferenceKeys { const val showSideNavOnBottom = "show_side_nav_on_bottom" - const val showMangaAppShortcuts = "show_manga_app_shortcuts" + const val showSeriesInShortcuts = "show_series_shortcuts" + const val showSourcesInShortcuts = "show_sources_shortcuts" + const val openChapterInShortcuts = "open_chapter_shortcuts" const val createLegacyBackup = "create_legacy_backup" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index afdfa90e16..f47c93f092 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -402,7 +402,10 @@ class PreferencesHelper(val context: Context) { fun createLegacyBackup() = flowPrefs.getBoolean(Keys.createLegacyBackup, true) fun dohProvider() = prefs.getInt(Keys.dohProvider, -1) - fun appShortcuts() = prefs.getBoolean(Keys.showMangaAppShortcuts, true) + + fun showSeriesInShortcuts() = prefs.getBoolean(Keys.showSeriesInShortcuts, true) + fun showSourcesInShortcuts() = prefs.getBoolean(Keys.showSourcesInShortcuts, true) + fun openChapterInShortcuts() = prefs.getBoolean(Keys.openChapterInShortcuts, true) fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt index 8b8a236845..8c8bacec73 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/SearchActivity.kt @@ -9,16 +9,20 @@ import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler +import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.manga.MangaDetailsController +import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsReaderController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.util.view.withFadeTransaction +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get class SearchActivity : MainActivity() { @@ -109,6 +113,21 @@ class SearchActivity : MainActivity() { } SHORTCUT_MANGA, SHORTCUT_MANGA_BACK -> { val extras = intent.extras ?: return false + if (intent.action == SHORTCUT_MANGA_BACK && preferences.openChapterInShortcuts()) { + val mangaId = extras.getLong(MangaDetailsController.MANGA_EXTRA) + if (mangaId != 0L) { + val db = Injekt.get() + val chapters = db.getChapters(mangaId).executeAsBlocking() + val nextUnreadChapter = chapters.sortedByDescending { it.source_order }.find { !it.read } + val manga = db.getManga(mangaId).executeAsBlocking() + if (nextUnreadChapter != null && manga != null) { + val activity = ReaderActivity.newIntent(this, manga, nextUnreadChapter) + startActivity(activity) + finish() + return true + } + } + } router.replaceTopController( RouterTransaction.with(MangaDetailsController(extras)) .pushChangeHandler(SimpleSwapChangeHandler()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index fa93d23885..29337d717b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -84,13 +84,6 @@ class SettingsGeneralController : SettingsController() { isVisible = activity?.isTablet() == true } - switchPreference { - key = Keys.showMangaAppShortcuts - titleRes = R.string.app_shortcuts - summaryRes = R.string.show_recent_in_shortcuts - defaultValue = true - } - preferenceCategory { titleRes = R.string.display @@ -136,6 +129,30 @@ class SettingsGeneralController : SettingsController() { } } + preferenceCategory { + titleRes = R.string.app_shortcuts + + switchPreference { + key = Keys.showSeriesInShortcuts + titleRes = R.string.show_recent_series + summaryRes = R.string.includes_recently_read_updated_added + defaultValue = true + } + + switchPreference { + key = Keys.showSourcesInShortcuts + titleRes = R.string.show_recent_sources + defaultValue = true + } + + switchPreference { + key = Keys.openChapterInShortcuts + titleRes = R.string.series_opens_new_chapters + summaryRes = R.string.no_new_chapters_open_details + defaultValue = true + } + } + preferenceCategory { titleRes = R.string.locale diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt b/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt index ba8f246e15..b8c5cead51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/manga/MangaShortcutManager.kt @@ -38,7 +38,7 @@ class MangaShortcutManager( val context: Context = preferences.context fun updateShortcuts() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { - if (!preferences.appShortcuts()) { + if (!preferences.showSeriesInShortcuts() && !preferences.showSourcesInShortcuts()) { val shortcutManager = context.getSystemService(ShortcutManager::class.java) shortcutManager.removeAllDynamicShortcuts() return @@ -46,12 +46,20 @@ class MangaShortcutManager( GlobalScope.launchIO { val shortcutManager = context.getSystemService(ShortcutManager::class.java) - val recentManga = RecentsPresenter.getRecentManga() - val recentSources = preferences.lastUsedSources().get().mapNotNull { - val splitS = it.split(":") - splitS.first().toLongOrNull()?.let { id -> - sourceManager.getOrStub(id) to splitS[1].toLong() + val recentManga = if (preferences.showSeriesInShortcuts()) { + RecentsPresenter.getRecentManga() + } else { + emptyList() + } + val recentSources = if (preferences.showSourcesInShortcuts()) { + preferences.lastUsedSources().get().mapNotNull { + val splitS = it.split(":") + splitS.first().toLongOrNull()?.let { id -> + sourceManager.getOrStub(id) to splitS[1].toLong() + } } + } else { + emptyList() } val recents = (recentManga.take(shortcutManager.maxShortcutCountPerActivity) + recentSources) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5fb544506f..f91ce47da2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -619,8 +619,6 @@ Secure screen Auto-hide bottom navigation Move side navigation buttons to bottom - App shortcuts - Show recent sources and series in app shortcuts Follow system theme Hides when scrolling Hide app contents when switching apps and block screenshots @@ -629,6 +627,13 @@ Back to start Pressing back to starting screen + App shortcuts + Show recently used sources + Show recent series + Includes recently read, updated, and added series + Series shortcuts opens new chapters + When there\'s no new chapters, the series\' details will open instead + Backup Backup and restore