Merge pull request #3406 from purinsan/dev

Fix #2767
This commit is contained in:
arkon 2020-07-04 13:48:43 -04:00 committed by GitHub
commit 5733429682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 51 deletions

View File

@ -13,7 +13,6 @@ import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.support.RouterPagerAdapter import com.bluelinelabs.conductor.support.RouterPagerAdapter
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import com.jakewharton.rxrelay.PublishRelay
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
@ -63,8 +62,6 @@ class MangaController : RxController<PagerControllerBinding>, TabbedController {
val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false) val fromSource = args.getBoolean(FROM_SOURCE_EXTRA, false)
val mangaFavoriteRelay: PublishRelay<Boolean> = PublishRelay.create()
private val trackingIconRelay: BehaviorRelay<Boolean> = BehaviorRelay.create() private val trackingIconRelay: BehaviorRelay<Boolean> = BehaviorRelay.create()
private var trackingIconSubscription: Subscription? = null private var trackingIconSubscription: Subscription? = null

View File

@ -97,7 +97,7 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
override fun createPresenter(): MangaInfoChaptersPresenter { override fun createPresenter(): MangaInfoChaptersPresenter {
val ctrl = parentController as MangaController val ctrl = parentController as MangaController
return MangaInfoChaptersPresenter( return MangaInfoChaptersPresenter(
ctrl.manga!!, ctrl.source!!, ctrl.mangaFavoriteRelay ctrl.manga!!, ctrl.source!!
) )
} }
@ -381,35 +381,39 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
toggleFavorite() toggleFavorite()
activity?.toast(activity?.getString(R.string.manga_removed_library)) activity?.toast(activity?.getString(R.string.manga_removed_library))
} else { } else {
val categories = presenter.getCategories() addToLibrary(manga)
val defaultCategoryId = preferences.defaultCategory() }
val defaultCategory = categories.find { it.id == defaultCategoryId } }
when { private fun addToLibrary(manga: Manga) {
// Default category set val categories = presenter.getCategories()
defaultCategory != null -> { val defaultCategoryId = preferences.defaultCategory()
toggleFavorite() val defaultCategory = categories.find { it.id == defaultCategoryId }
presenter.moveMangaToCategory(manga, defaultCategory)
activity?.toast(activity?.getString(R.string.manga_added_library))
}
// Automatic 'Default' or no categories when {
defaultCategoryId == 0 || categories.isEmpty() -> { // Default category set
toggleFavorite() defaultCategory != null -> {
presenter.moveMangaToCategory(manga, null) toggleFavorite()
activity?.toast(activity?.getString(R.string.manga_added_library)) presenter.moveMangaToCategory(manga, defaultCategory)
} activity?.toast(activity?.getString(R.string.manga_added_library))
}
// Choose a category // Automatic 'Default' or no categories
else -> { defaultCategoryId == 0 || categories.isEmpty() -> {
val ids = presenter.getMangaCategoryIds(manga) toggleFavorite()
val preselected = ids.mapNotNull { id -> presenter.moveMangaToCategory(manga, null)
categories.indexOfFirst { it.id == id }.takeIf { it != -1 } activity?.toast(activity?.getString(R.string.manga_added_library))
}.toTypedArray() }
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) // Choose a category
.showDialog(router) 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)
} }
} }
} }
@ -755,11 +759,12 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
private fun downloadChapters(chapters: List<ChapterItem>) { private fun downloadChapters(chapters: List<ChapterItem>) {
val view = view val view = view
val manga = presenter.manga
presenter.downloadChapters(chapters) presenter.downloadChapters(chapters)
if (view != null && !presenter.manga.favorite) { if (view != null && !manga.favorite) {
binding.recycler.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) { binding.recycler.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) {
setAction(R.string.action_add) { setAction(R.string.action_add) {
presenter.addToLibrary() addToLibrary(manga)
} }
} }
} }

View File

@ -31,7 +31,6 @@ import uy.kohesive.injekt.api.get
class MangaInfoChaptersPresenter( class MangaInfoChaptersPresenter(
val manga: Manga, val manga: Manga,
val source: Source, val source: Source,
private val mangaFavoriteRelay: PublishRelay<Boolean>,
val preferences: PreferencesHelper = Injekt.get(), val preferences: PreferencesHelper = Injekt.get(),
private val db: DatabaseHelper = Injekt.get(), private val db: DatabaseHelper = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(),
@ -80,11 +79,6 @@ class MangaInfoChaptersPresenter(
getMangaObservable() getMangaObservable()
.subscribeLatestCache({ view, manga -> view.onNextMangaInfo(manga, source) }) .subscribeLatestCache({ view, manga -> view.onNextMangaInfo(manga, source) })
// Update favorite status
mangaFavoriteRelay.observeOn(AndroidSchedulers.mainThread())
.subscribe { setFavorite(it) }
.apply { add(this) }
// Prepare the relay. // Prepare the relay.
chaptersRelay.flatMap { applyChapterFilters(it) } chaptersRelay.flatMap { applyChapterFilters(it) }
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -162,13 +156,6 @@ class MangaInfoChaptersPresenter(
return manga.favorite return manga.favorite
} }
private fun setFavorite(favorite: Boolean) {
if (manga.favorite == favorite) {
return
}
toggleFavorite()
}
/** /**
* Returns true if the manga has any downloads. * Returns true if the manga has any downloads.
*/ */
@ -503,13 +490,6 @@ class MangaInfoChaptersPresenter(
refreshChapters() refreshChapters()
} }
/**
* Adds manga to library
*/
fun addToLibrary() {
mangaFavoriteRelay.call(true)
}
/** /**
* Sets the active display mode. * Sets the active display mode.
* @param mode the mode to set. * @param mode the mode to set.