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

View File

@ -206,6 +206,17 @@
android:text="@string/add_to_library" android:text="@string/add_to_library"
app:icon="@drawable/ic_add_to_library_24dp" /> 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 <com.google.android.material.button.MaterialButton
android:id="@+id/btn_share" android:id="@+id/btn_share"
style="@style/Theme.Widget.Button.Icon.Textless" style="@style/Theme.Widget.Button.Icon.Textless"

View File

@ -61,7 +61,7 @@
<string name="action_add_category">Add category</string> <string name="action_add_category">Add category</string>
<string name="action_edit_categories">Edit categories</string> <string name="action_edit_categories">Edit categories</string>
<string name="action_rename_category">Rename category</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_edit_cover">Edit the cover picture</string>
<string name="action_sort_up">Sort up</string> <string name="action_sort_up">Sort up</string>
<string name="action_sort_down">Sort down</string> <string name="action_sort_down">Sort down</string>