Update stats details library if something is removed/migrated

This commit is contained in:
Jays2Kings 2022-12-17 04:10:40 -05:00
parent 4b56d84428
commit 35d81dfd97
4 changed files with 27 additions and 2 deletions

View file

@ -5,8 +5,12 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.View
import androidx.core.view.isVisible
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet
import eu.kanade.tachiyomi.ui.more.stats.details.StatsDetailsController
import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.previousController
class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bundle) {
@ -87,6 +91,22 @@ class FilteredLibraryController(bundle: Bundle? = null) : LibraryController(bund
return false
}
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
super.onChangeStarted(handler, type)
if (type == ControllerChangeType.POP_ENTER) {
updateStatsPage()
}
}
override fun deleteMangasFromLibrary() {
super.deleteMangasFromLibrary()
updateStatsPage()
}
fun updateStatsPage() {
(previousController as? StatsDetailsController)?.updateLibrary()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {}
override fun toggleCategoryVisibility(position: Int) {}
override fun hasActiveFiltersFromPref(): Boolean = false

View file

@ -2109,7 +2109,7 @@ open class LibraryController(
startActivity(Intent.createChooser(intent, context.getString(R.string.share)))
}
private fun deleteMangasFromLibrary() {
open fun deleteMangasFromLibrary() {
val mangas = selectedMangas.toList()
presenter.removeMangaFromLibrary(mangas)
destroyActionModeIfNeeded()

View file

@ -1078,11 +1078,12 @@ class LibraryPresenter(
}
/** Undo the removal of the manga once in library */
fun reAddMangas(mangas: List<Manga>) {
fun reAddMangas(mangas: List<Manga) {
presenterScope.launch {
val mangaToAdd = mangas.distinctBy { it.id }
mangaToAdd.forEach { it.favorite = true }
db.insertMangas(mangaToAdd).executeOnIO()
(controller as? FilteredLibraryController)?.updateStatsPage()
getLibrary()
mangaToAdd.forEach { db.insertManga(it).executeAsBlocking() }
}

View file

@ -231,6 +231,10 @@ class StatsDetailsController :
}
}
fun updateLibrary() {
presenter.libraryMangas = presenter.getLibrary()
}
/** Set the toolbar to fully transparent or colored and translucent */
private fun colorToolbar(isColor: Boolean) {
if (isColor == toolbarIsColored) return