|
@@ -15,7 +15,9 @@ import com.f2prateek.rx.preferences.Preference
|
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
|
import eu.davidea.flexibleadapter.items.IFlexible
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
+import eu.kanade.tachiyomi.data.database.models.Category
|
|
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
|
+import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
import eu.kanade.tachiyomi.source.model.FilterList
|
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
|
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
|
@@ -33,11 +35,8 @@ import nucleus.factory.RequiresPresenter
|
|
|
import rx.Subscription
|
|
|
import rx.android.schedulers.AndroidSchedulers
|
|
|
import rx.subjects.PublishSubject
|
|
|
-import java.util.concurrent.TimeUnit.MILLISECONDS
|
|
|
-import android.widget.Toast
|
|
|
-import eu.kanade.tachiyomi.data.database.models.Category
|
|
|
-import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
+import java.util.concurrent.TimeUnit.MILLISECONDS
|
|
|
|
|
|
/**
|
|
|
* Fragment that shows the manga from the catalogue.
|
|
@@ -546,54 +545,64 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(),
|
|
|
* @param position the position of the element clicked.
|
|
|
*/
|
|
|
override fun onItemLongClick(position: Int) {
|
|
|
+ // Get manga
|
|
|
val manga = (adapter.getItem(position) as? CatalogueItem?)?.manga ?: return
|
|
|
+ // Fetch categories
|
|
|
val categories = presenter.getCategories()
|
|
|
|
|
|
- val defaultCategory = categories.find { it.id == preferences.defaultCategory()}
|
|
|
- if(defaultCategory != null) {
|
|
|
- if(!manga.favorite) {
|
|
|
- presenter.changeMangaFavorite(manga)
|
|
|
- }
|
|
|
- presenter.moveMangaToCategory(defaultCategory, manga)
|
|
|
- } else {
|
|
|
+ if (manga.favorite){
|
|
|
MaterialDialog.Builder(activity)
|
|
|
- .title(R.string.action_move_category)
|
|
|
- .items(categories.map { it.name })
|
|
|
- .itemsCallbackMultiChoice(presenter.getMangaCategoryIds(manga)) { dialog, position, _ ->
|
|
|
- if (defaultSelectedWithOtherCategory(position)) {
|
|
|
- // Deselect default category
|
|
|
- dialog.setSelectedIndices(position.filter {it > 0}.toTypedArray())
|
|
|
- Toast.makeText(dialog.context, R.string.invalid_combination, Toast.LENGTH_SHORT).show()
|
|
|
+ .items(getString(R.string.remove_from_library ))
|
|
|
+ .itemsCallback { _, _, which, _ ->
|
|
|
+ when (which) {
|
|
|
+ 0 -> {
|
|
|
+ presenter.changeMangaFavorite(manga)
|
|
|
+ adapter.notifyItemChanged(position)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- true
|
|
|
- }
|
|
|
- .alwaysCallMultiChoiceCallback()
|
|
|
- .positiveText(android.R.string.ok)
|
|
|
- .negativeText(android.R.string.cancel)
|
|
|
- .onPositive { dialog, _ ->
|
|
|
- updateMangaCategories(manga, dialog, categories, position)
|
|
|
- }
|
|
|
- .build()
|
|
|
- .show()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private fun defaultSelectedWithOtherCategory(position: Array<Int>): Boolean {
|
|
|
- return position.contains(0) && position.count() > 1
|
|
|
- }
|
|
|
-
|
|
|
- private fun updateMangaCategories(manga: Manga, dialog: MaterialDialog, categories: List<Category>, position: Int) {
|
|
|
- val selectedCategories = dialog.selectedIndices?.map { categories[it] } ?: emptyList()
|
|
|
-
|
|
|
- if(!selectedCategories.isEmpty()) {
|
|
|
- if(!manga.favorite) {
|
|
|
+ }.show()
|
|
|
+ }else{
|
|
|
+ val defaultCategory = categories.find { it.id == preferences.defaultCategory()}
|
|
|
+ if(defaultCategory != null) {
|
|
|
presenter.changeMangaFavorite(manga)
|
|
|
+ presenter.moveMangaToCategory(defaultCategory, manga)
|
|
|
+ // Show manga has been added
|
|
|
+ context.toast(R.string.added_to_library)
|
|
|
+ adapter.notifyItemChanged(position)
|
|
|
+ } else {
|
|
|
+ MaterialDialog.Builder(activity)
|
|
|
+ .title(R.string.action_move_category)
|
|
|
+ .items(categories.map { it.name })
|
|
|
+ .itemsCallbackMultiChoice(presenter.getMangaCategoryIds(manga)) { dialog, position, _ ->
|
|
|
+ if (position.contains(0) && position.count() > 1) {
|
|
|
+ // Deselect default category
|
|
|
+ dialog.setSelectedIndices(position.filter {it > 0}.toTypedArray())
|
|
|
+ dialog.context.toast(R.string.invalid_combination)
|
|
|
+ }
|
|
|
+ true
|
|
|
+ }
|
|
|
+ .alwaysCallMultiChoiceCallback()
|
|
|
+ .positiveText(android.R.string.ok)
|
|
|
+ .negativeText(android.R.string.cancel)
|
|
|
+ .onPositive { dialog, _ ->
|
|
|
+ val selectedCategories = dialog.selectedIndices?.map { categories[it] } ?: emptyList()
|
|
|
+ updateMangaCategories(manga, selectedCategories, position)
|
|
|
+ }
|
|
|
+ .build()
|
|
|
+ .show()
|
|
|
}
|
|
|
- presenter.moveMangaToCategories(selectedCategories.filter { it.id != 0}, manga)
|
|
|
- } else {
|
|
|
- presenter.changeMangaFavorite(manga)
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update manga to use selected categories.
|
|
|
+ *
|
|
|
+ * @param manga needed to change
|
|
|
+ * @param selectedCategories selected categories
|
|
|
+ * @param position position of adapter
|
|
|
+ */
|
|
|
+ private fun updateMangaCategories(manga: Manga, selectedCategories: List<Category>, position: Int) {
|
|
|
+ presenter.updateMangaCategories(manga,selectedCategories)
|
|
|
adapter.notifyItemChanged(position)
|
|
|
}
|
|
|
|