Add ability to ask for category on long press

This commit is contained in:
NerdNumber9
2018-08-04 10:49:29 -04:00
parent 450fcccaa6
commit ec0fe2210d
5 changed files with 35 additions and 11 deletions

View File

@ -169,6 +169,8 @@ object PreferenceKeys {
const val eh_expandFilters = "eh_expand_filters"
const val eh_askCategoryOnLongPress = "eh_ask_category_on_long_press"
const val eh_readerThreads = "eh_reader_threads"
const val eh_readerInstantRetry = "eh_reader_instant_retry"

View File

@ -251,4 +251,6 @@ class PreferencesHelper(val context: Context) {
fun eh_preserveReadingPosition() = rxPrefs.getBoolean(Keys.eh_preserveReadingPosition, false)
fun eh_incogWebview() = rxPrefs.getBoolean(Keys.eh_incogWebview, false)
fun eh_askCategoryOnLongPress() = rxPrefs.getBoolean(Keys.eh_askCategoryOnLongPress, false)
}

View File

@ -93,6 +93,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
// Set onclickListener to toggle favorite when FAB clicked.
fab_favorite.clicks().subscribeUntilDestroy { onFabClick() }
fab_favorite.longClicks().subscribeUntilDestroy { onFabLongClick() }
// Set SwipeRefresh to refresh manga data.
swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() }
@ -408,15 +409,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
categories.size <= 1 -> // default or the one from the user
presenter.moveMangaToCategory(manga, categories.firstOrNull())
else -> {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
.showDialog(router)
}
else -> askCategories(manga, categories)
}
activity?.toast(activity?.getString(R.string.manga_added_library))
} else {
@ -424,6 +417,27 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
}
}
private fun onFabLongClick() {
if(preferences.eh_askCategoryOnLongPress().getOrDefault()) {
val manga = presenter.manga
if(!manga.favorite) toggleFavorite()
val categories = presenter.getCategories()
if(categories.size > 1) {
askCategories(manga, categories)
}
}
}
private fun askCategories(manga: Manga, categories: List<Category>) {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
.showDialog(router)
}
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
val manga = mangas.firstOrNull() ?: return
presenter.moveMangaToCategories(manga, categories)

View File

@ -180,6 +180,12 @@ class SettingsGeneralController : SettingsController() {
}
// --> EH
switchPreference {
key = Keys.eh_askCategoryOnLongPress
title = "Long-press favorite button to specify category"
defaultValue = false
}
switchPreference {
key = Keys.eh_expandFilters
title = "Expand all search filters by default"
@ -189,7 +195,7 @@ class SettingsGeneralController : SettingsController() {
switchPreference {
key = Keys.eh_incogWebview
title = "Incognito 'Open in browser'"
summary = "Prevent pages viewed from the 'Open in browser' menu option from being placed into Chrome's browsing history. Some browser features will be unavailable."
summary = "Prevent pages viewed from the 'Open in browser' menu option from being placed into Chrome's browsing history. May be buggy, some browser features will be unavailable."
defaultValue = false
}

View File

@ -18,7 +18,7 @@ buildscript {
// in the individual module build.gradle files
// Realm (EH)
classpath "io.realm:realm-gradle-plugin:5.3.1"
classpath "io.realm:realm-gradle-plugin:5.4.1"
// Firebase (EH)
classpath 'com.google.firebase:firebase-plugins:1.1.5'