Small fixes (#740)
This commit is contained in:
parent
f6a79bde6f
commit
6069659e0f
@ -15,7 +15,9 @@ import com.f2prateek.rx.preferences.Preference
|
|||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.R
|
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.database.models.Manga
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
@ -33,11 +35,8 @@ import nucleus.factory.RequiresPresenter
|
|||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.subjects.PublishSubject
|
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 uy.kohesive.injekt.injectLazy
|
||||||
|
import java.util.concurrent.TimeUnit.MILLISECONDS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that shows the manga from the catalogue.
|
* 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.
|
* @param position the position of the element clicked.
|
||||||
*/
|
*/
|
||||||
override fun onItemLongClick(position: Int) {
|
override fun onItemLongClick(position: Int) {
|
||||||
|
// Get manga
|
||||||
val manga = (adapter.getItem(position) as? CatalogueItem?)?.manga ?: return
|
val manga = (adapter.getItem(position) as? CatalogueItem?)?.manga ?: return
|
||||||
|
// Fetch categories
|
||||||
val categories = presenter.getCategories()
|
val categories = presenter.getCategories()
|
||||||
|
|
||||||
|
if (manga.favorite){
|
||||||
|
MaterialDialog.Builder(activity)
|
||||||
|
.items(getString(R.string.remove_from_library ))
|
||||||
|
.itemsCallback { _, _, which, _ ->
|
||||||
|
when (which) {
|
||||||
|
0 -> {
|
||||||
|
presenter.changeMangaFavorite(manga)
|
||||||
|
adapter.notifyItemChanged(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.show()
|
||||||
|
}else{
|
||||||
val defaultCategory = categories.find { it.id == preferences.defaultCategory()}
|
val defaultCategory = categories.find { it.id == preferences.defaultCategory()}
|
||||||
if(defaultCategory != null) {
|
if(defaultCategory != null) {
|
||||||
if(!manga.favorite) {
|
|
||||||
presenter.changeMangaFavorite(manga)
|
presenter.changeMangaFavorite(manga)
|
||||||
}
|
|
||||||
presenter.moveMangaToCategory(defaultCategory, manga)
|
presenter.moveMangaToCategory(defaultCategory, manga)
|
||||||
|
// Show manga has been added
|
||||||
|
context.toast(R.string.added_to_library)
|
||||||
|
adapter.notifyItemChanged(position)
|
||||||
} else {
|
} else {
|
||||||
MaterialDialog.Builder(activity)
|
MaterialDialog.Builder(activity)
|
||||||
.title(R.string.action_move_category)
|
.title(R.string.action_move_category)
|
||||||
.items(categories.map { it.name })
|
.items(categories.map { it.name })
|
||||||
.itemsCallbackMultiChoice(presenter.getMangaCategoryIds(manga)) { dialog, position, _ ->
|
.itemsCallbackMultiChoice(presenter.getMangaCategoryIds(manga)) { dialog, position, _ ->
|
||||||
if (defaultSelectedWithOtherCategory(position)) {
|
if (position.contains(0) && position.count() > 1) {
|
||||||
// Deselect default category
|
// Deselect default category
|
||||||
dialog.setSelectedIndices(position.filter {it > 0}.toTypedArray())
|
dialog.setSelectedIndices(position.filter {it > 0}.toTypedArray())
|
||||||
Toast.makeText(dialog.context, R.string.invalid_combination, Toast.LENGTH_SHORT).show()
|
dialog.context.toast(R.string.invalid_combination)
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
.alwaysCallMultiChoiceCallback()
|
.alwaysCallMultiChoiceCallback()
|
||||||
.positiveText(android.R.string.ok)
|
.positiveText(android.R.string.ok)
|
||||||
.negativeText(android.R.string.cancel)
|
.negativeText(android.R.string.cancel)
|
||||||
.onPositive { dialog, _ ->
|
.onPositive { dialog, _ ->
|
||||||
updateMangaCategories(manga, dialog, categories, position)
|
val selectedCategories = dialog.selectedIndices?.map { categories[it] } ?: emptyList()
|
||||||
|
updateMangaCategories(manga, selectedCategories, position)
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
.show()
|
.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()
|
* Update manga to use selected categories.
|
||||||
|
*
|
||||||
if(!selectedCategories.isEmpty()) {
|
* @param manga needed to change
|
||||||
if(!manga.favorite) {
|
* @param selectedCategories selected categories
|
||||||
presenter.changeMangaFavorite(manga)
|
* @param position position of adapter
|
||||||
}
|
*/
|
||||||
presenter.moveMangaToCategories(selectedCategories.filter { it.id != 0}, manga)
|
private fun updateMangaCategories(manga: Manga, selectedCategories: List<Category>, position: Int) {
|
||||||
} else {
|
presenter.updateMangaCategories(manga,selectedCategories)
|
||||||
presenter.changeMangaFavorite(manga)
|
|
||||||
}
|
|
||||||
adapter.notifyItemChanged(position)
|
adapter.notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import rx.schedulers.Schedulers
|
|||||||
import rx.subjects.PublishSubject
|
import rx.subjects.PublishSubject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presenter of [CatalogueFragment].
|
* Presenter of [CatalogueFragment].
|
||||||
@ -416,7 +415,7 @@ open class CataloguePresenter : BasePresenter<CatalogueFragment>() {
|
|||||||
*/
|
*/
|
||||||
fun getMangaCategoryIds(manga: Manga): Array<Int?> {
|
fun getMangaCategoryIds(manga: Manga): Array<Int?> {
|
||||||
val categories = db.getCategoriesForManga(manga).executeAsBlocking()
|
val categories = db.getCategoriesForManga(manga).executeAsBlocking()
|
||||||
if(categories.isEmpty()) {
|
if (categories.isEmpty()) {
|
||||||
return arrayListOf(Category.createDefault().id).toTypedArray()
|
return arrayListOf(Category.createDefault().id).toTypedArray()
|
||||||
}
|
}
|
||||||
return categories.map { it.id }.toTypedArray()
|
return categories.map { it.id }.toTypedArray()
|
||||||
@ -444,4 +443,21 @@ open class CataloguePresenter : BasePresenter<CatalogueFragment>() {
|
|||||||
moveMangaToCategories(arrayListOf(category), manga)
|
moveMangaToCategories(arrayListOf(category), manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update manga to use selected categories.
|
||||||
|
*
|
||||||
|
* @param manga needed to change
|
||||||
|
* @param selectedCategories selected categories
|
||||||
|
*/
|
||||||
|
fun updateMangaCategories(manga: Manga, selectedCategories: List<Category>) {
|
||||||
|
if (!selectedCategories.isEmpty()) {
|
||||||
|
if (!manga.favorite)
|
||||||
|
changeMangaFavorite(manga)
|
||||||
|
|
||||||
|
moveMangaToCategories(selectedCategories.filter { it.id != 0 }, manga)
|
||||||
|
} else {
|
||||||
|
changeMangaFavorite(manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -272,6 +272,7 @@
|
|||||||
<string name="no_more_results">No more results</string>
|
<string name="no_more_results">No more results</string>
|
||||||
<string name="local_source">Local manga</string>
|
<string name="local_source">Local manga</string>
|
||||||
<string name="invalid_combination">Default can\'t be selected with other categories</string>
|
<string name="invalid_combination">Default can\'t be selected with other categories</string>
|
||||||
|
<string name="added_to_library">The manga has been added to your library</string>
|
||||||
|
|
||||||
<!-- Manga activity -->
|
<!-- Manga activity -->
|
||||||
<string name="manga_not_in_db">This manga was removed from the database!</string>
|
<string name="manga_not_in_db">This manga was removed from the database!</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user