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
This commit is contained in:
Jays2Kings 2021-07-02 20:09:12 -04:00
parent f2ad4725d8
commit 56bfa65a54
7 changed files with 82 additions and 17 deletions

View File

@ -121,6 +121,17 @@ object Migrations {
UpdaterJob.setupTask() 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 true
} }
return false return false

View File

@ -204,7 +204,9 @@ object PreferenceKeys {
const val showSideNavOnBottom = "show_side_nav_on_bottom" 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" const val createLegacyBackup = "create_legacy_backup"

View File

@ -402,7 +402,10 @@ class PreferencesHelper(val context: Context) {
fun createLegacyBackup() = flowPrefs.getBoolean(Keys.createLegacyBackup, true) fun createLegacyBackup() = flowPrefs.getBoolean(Keys.createLegacyBackup, true)
fun dohProvider() = prefs.getInt(Keys.dohProvider, -1) 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) fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false)
} }

View File

@ -9,16 +9,20 @@ import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.BaseController
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController 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.security.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsController
import eu.kanade.tachiyomi.ui.setting.SettingsReaderController import eu.kanade.tachiyomi.ui.setting.SettingsReaderController
import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class SearchActivity : MainActivity() { class SearchActivity : MainActivity() {
@ -109,6 +113,21 @@ class SearchActivity : MainActivity() {
} }
SHORTCUT_MANGA, SHORTCUT_MANGA_BACK -> { SHORTCUT_MANGA, SHORTCUT_MANGA_BACK -> {
val extras = intent.extras ?: return false 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<DatabaseHelper>()
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( router.replaceTopController(
RouterTransaction.with(MangaDetailsController(extras)) RouterTransaction.with(MangaDetailsController(extras))
.pushChangeHandler(SimpleSwapChangeHandler()) .pushChangeHandler(SimpleSwapChangeHandler())

View File

@ -84,13 +84,6 @@ class SettingsGeneralController : SettingsController() {
isVisible = activity?.isTablet() == true isVisible = activity?.isTablet() == true
} }
switchPreference {
key = Keys.showMangaAppShortcuts
titleRes = R.string.app_shortcuts
summaryRes = R.string.show_recent_in_shortcuts
defaultValue = true
}
preferenceCategory { preferenceCategory {
titleRes = R.string.display 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 { preferenceCategory {
titleRes = R.string.locale titleRes = R.string.locale

View File

@ -38,7 +38,7 @@ class MangaShortcutManager(
val context: Context = preferences.context val context: Context = preferences.context
fun updateShortcuts() { fun updateShortcuts() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { 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) val shortcutManager = context.getSystemService(ShortcutManager::class.java)
shortcutManager.removeAllDynamicShortcuts() shortcutManager.removeAllDynamicShortcuts()
return return
@ -46,12 +46,20 @@ class MangaShortcutManager(
GlobalScope.launchIO { GlobalScope.launchIO {
val shortcutManager = context.getSystemService(ShortcutManager::class.java) val shortcutManager = context.getSystemService(ShortcutManager::class.java)
val recentManga = RecentsPresenter.getRecentManga() val recentManga = if (preferences.showSeriesInShortcuts()) {
val recentSources = preferences.lastUsedSources().get().mapNotNull { RecentsPresenter.getRecentManga()
val splitS = it.split(":") } else {
splitS.first().toLongOrNull()?.let { id -> emptyList()
sourceManager.getOrStub(id) to splitS[1].toLong() }
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 = val recents =
(recentManga.take(shortcutManager.maxShortcutCountPerActivity) + recentSources) (recentManga.take(shortcutManager.maxShortcutCountPerActivity) + recentSources)

View File

@ -619,8 +619,6 @@
<string name="secure_screen">Secure screen</string> <string name="secure_screen">Secure screen</string>
<string name="hide_bottom_nav">Auto-hide bottom navigation</string> <string name="hide_bottom_nav">Auto-hide bottom navigation</string>
<string name="move_side_nav_to_bottom">Move side navigation buttons to bottom</string> <string name="move_side_nav_to_bottom">Move side navigation buttons to bottom</string>
<string name="app_shortcuts">App shortcuts</string>
<string name="show_recent_in_shortcuts">Show recent sources and series in app shortcuts</string>
<string name="follow_system_theme">Follow system theme</string> <string name="follow_system_theme">Follow system theme</string>
<string name="hides_on_scroll">Hides when scrolling</string> <string name="hides_on_scroll">Hides when scrolling</string>
<string name="hide_app_block_screenshots">Hide app contents when switching apps and block screenshots</string> <string name="hide_app_block_screenshots">Hide app contents when switching apps and block screenshots</string>
@ -629,6 +627,13 @@
<string name="back_to_start">Back to start</string> <string name="back_to_start">Back to start</string>
<string name="pressing_back_to_start">Pressing back to starting screen</string> <string name="pressing_back_to_start">Pressing back to starting screen</string>
<string name="app_shortcuts">App shortcuts</string>
<string name="show_recent_sources">Show recently used sources</string>
<string name="show_recent_series">Show recent series</string>
<string name="includes_recently_read_updated_added">Includes recently read, updated, and added series</string>
<string name="series_opens_new_chapters">Series shortcuts opens new chapters</string>
<string name="no_new_chapters_open_details">When there\'s no new chapters, the series\' details will open instead</string>
<!-- Backup --> <!-- Backup -->
<string name="backup">Backup</string> <string name="backup">Backup</string>
<string name="backup_and_restore">Backup and restore</string> <string name="backup_and_restore">Backup and restore</string>