Separate categories picker from long pressing manga favorite button

This commit is contained in:
arkon 2020-04-23 23:03:20 -04:00
parent 8e6b7aaec0
commit c0bbbdb7ee
4 changed files with 31 additions and 23 deletions

View File

@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.util.view.toggle
import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import reactivecircus.flowbinding.android.view.clicks
@ -77,15 +78,16 @@ class MangaInfoController(private val fromSource: Boolean = false) :
override fun onViewCreated(view: View) {
super.onViewCreated(view)
// Set onclickListener to toggle favorite when favorite button clicked.
binding.btnFavorite.clicks()
.onEach { onFavoriteClick() }
.launchIn(scope)
// Set onLongClickListener to manage categories when favorite button is clicked.
binding.btnFavorite.longClicks()
.onEach { onFavoriteLongClick() }
.launchIn(scope)
if (presenter.manga.favorite && presenter.getCategories().isNotEmpty()) {
binding.btnCategories.visible()
binding.btnCategories.clicks()
.onEach { onCategoriesClick() }
.launchIn(scope)
}
if (presenter.source is HttpSource) {
binding.btnWebview.visible()
@ -332,6 +334,8 @@ class MangaInfoController(private val fromSource: Boolean = false) :
}
}
}
binding.btnCategories.visibleIf { isNowFavorite && presenter.getCategories().isNotEmpty() }
}
private fun openInWebView() {
@ -455,22 +459,17 @@ class MangaInfoController(private val fromSource: Boolean = false) :
}
}
private fun onFavoriteLongClick() {
private fun onCategoriesClick() {
val manga = presenter.manga
val categories = presenter.getCategories()
if (manga.favorite && presenter.getCategories().isNotEmpty()) {
val categories = presenter.getCategories()
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
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 {
onFavoriteClick()
}
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
.showDialog(router)
}
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
@ -478,10 +477,10 @@ class MangaInfoController(private val fromSource: Boolean = false) :
if (!manga.favorite) {
toggleFavorite()
activity?.toast(activity?.getString(R.string.manga_added_library))
}
presenter.moveMangaToCategories(manga, categories)
activity?.toast(activity?.getString(R.string.manga_added_library))
}
/**

View File

@ -197,9 +197,7 @@ class SettingsBackupController : SettingsController() {
CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) {
val uri = data.data
if (uri != null) {
val ctrl = RestoreBackupDialog(uri)
ctrl.targetController = this@SettingsBackupController
ctrl.showDialog(router)
RestoreBackupDialog(uri).showDialog(router)
}
}
}

View File

@ -206,6 +206,17 @@
android:text="@string/add_to_library"
app:icon="@drawable/ic_add_to_library_24dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_categories"
style="@style/Theme.Widget.Button.Icon.Textless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:contentDescription="@string/action_edit_categories"
android:visibility="gone"
app:icon="@drawable/ic_label_24dp"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_share"
style="@style/Theme.Widget.Button.Icon.Textless"

View File

@ -61,7 +61,7 @@
<string name="action_add_category">Add category</string>
<string name="action_edit_categories">Edit categories</string>
<string name="action_rename_category">Rename category</string>
<string name="action_move_category">Move to categories</string>
<string name="action_move_category">Set categories</string>
<string name="action_edit_cover">Edit the cover picture</string>
<string name="action_sort_up">Sort up</string>
<string name="action_sort_down">Sort down</string>