mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Kissmanga loading through Cloudflare. A lot of refactoring was needed
This commit is contained in:
@@ -98,10 +98,9 @@ class LibraryCategoryAdapter(val fragment: LibraryCategoryFragment) :
|
||||
* @param position the position to bind.
|
||||
*/
|
||||
override fun onBindViewHolder(holder: LibraryHolder, position: Int) {
|
||||
val presenter = (fragment.parentFragment as LibraryFragment).presenter
|
||||
val manga = getItem(position)
|
||||
|
||||
holder.onSetValues(manga, presenter)
|
||||
holder.onSetValues(manga)
|
||||
//When user scrolls this bind the correct selection status
|
||||
holder.itemView.isActivated = isSelected(position)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.library.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
||||
|
||||
@@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
|
||||
import eu.kanade.tachiyomi.ui.category.CategoryActivity
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
@@ -388,7 +387,10 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
* @param mangas the manga list to move.
|
||||
*/
|
||||
private fun moveMangasToCategories(mangas: List<Manga>) {
|
||||
val categories = presenter.categories
|
||||
// Hide the default category because it has a different behavior than the ones from db.
|
||||
val categories = presenter.categories.filter { it.id != 0 }
|
||||
|
||||
// Get indexes of the common categories to preselect.
|
||||
val commonCategoriesIndexes = presenter.getCommonCategories(mangas)
|
||||
.map { categories.indexOf(it) }
|
||||
.toTypedArray()
|
||||
@@ -397,7 +399,8 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||
.title(R.string.action_move_category)
|
||||
.items(categories.map { it.name })
|
||||
.itemsCallbackMultiChoice(commonCategoriesIndexes) { dialog, positions, text ->
|
||||
presenter.moveMangasToCategories(positions, mangas)
|
||||
val selectedCategories = positions.map { categories[it] }
|
||||
presenter.moveMangasToCategories(selectedCategories, mangas)
|
||||
destroyActionModeIfNeeded()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@ package eu.kanade.tachiyomi.ui.library
|
||||
import android.view.View
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.signature.StringSignature
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.source.base.Source
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.item_catalogue_grid.view.*
|
||||
|
||||
@@ -19,8 +16,10 @@ import kotlinx.android.synthetic.main.item_catalogue_grid.view.*
|
||||
* @param listener a listener to react to single tap and long tap events.
|
||||
* @constructor creates a new library holder.
|
||||
*/
|
||||
class LibraryHolder(private val view: View, private val adapter: LibraryCategoryAdapter, listener: FlexibleViewHolder.OnListItemClickListener) :
|
||||
FlexibleViewHolder(view, adapter, listener) {
|
||||
class LibraryHolder(private val view: View,
|
||||
private val adapter: LibraryCategoryAdapter,
|
||||
listener: FlexibleViewHolder.OnListItemClickListener)
|
||||
: FlexibleViewHolder(view, adapter, listener) {
|
||||
|
||||
private var manga: Manga? = null
|
||||
|
||||
@@ -29,9 +28,8 @@ class LibraryHolder(private val view: View, private val adapter: LibraryCategory
|
||||
* holder with the given manga.
|
||||
*
|
||||
* @param manga the manga to bind.
|
||||
* @param presenter the library presenter.
|
||||
*/
|
||||
fun onSetValues(manga: Manga, presenter: LibraryPresenter) {
|
||||
fun onSetValues(manga: Manga) {
|
||||
this.manga = manga
|
||||
|
||||
// Update the title of the manga.
|
||||
@@ -44,31 +42,13 @@ class LibraryHolder(private val view: View, private val adapter: LibraryCategory
|
||||
}
|
||||
|
||||
// Update the cover.
|
||||
loadCover(manga, presenter.sourceManager.get(manga.source)!!, presenter.coverCache)
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the cover of a manga in a image view.
|
||||
*
|
||||
* @param manga the manga to bind.
|
||||
* @param source the source of the manga.
|
||||
* @param coverCache the cache that stores the cover in the filesystem.
|
||||
*/
|
||||
private fun loadCover(manga: Manga, source: Source, coverCache: CoverCache) {
|
||||
Glide.clear(view.thumbnail)
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
coverCache.saveOrLoadFromCache(manga.thumbnail_url, source.glideHeaders) {
|
||||
if (adapter.fragment.isResumed && this.manga == manga) {
|
||||
Glide.with(view.context)
|
||||
.load(it)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.signature(StringSignature(it.lastModified().toString()))
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(itemView.thumbnail)
|
||||
}
|
||||
}
|
||||
}
|
||||
Glide.with(view.context)
|
||||
.load(manga)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(view.thumbnail)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
||||
class LibraryMangaEvent(val mangas: Map<Int, List<Manga>>) {
|
||||
|
||||
fun getMangaForCategory(category: Category): List<Manga>? {
|
||||
return mangas[category.id]
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@ import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import rx.subjects.BehaviorSubject
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -236,26 +236,18 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||
* Remove the selected manga from the library.
|
||||
*/
|
||||
fun deleteMangas() {
|
||||
for (manga in selectedMangas) {
|
||||
manga.favorite = false
|
||||
}
|
||||
// Create a set of the list
|
||||
val mangaToDelete = selectedMangas.toSet()
|
||||
|
||||
db.insertMangas(selectedMangas).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the given list of manga to categories.
|
||||
*
|
||||
* @param positions the indexes of the selected categories.
|
||||
* @param mangas the list of manga to move.
|
||||
*/
|
||||
fun moveMangasToCategories(positions: Array<Int>, mangas: List<Manga>) {
|
||||
val categoriesToAdd = ArrayList<Category>()
|
||||
for (index in positions) {
|
||||
categoriesToAdd.add(categories[index])
|
||||
}
|
||||
|
||||
moveMangasToCategories(categoriesToAdd, mangas)
|
||||
Observable.from(mangaToDelete)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.doOnNext {
|
||||
it.favorite = false
|
||||
coverCache.deleteFromCache(it.thumbnail_url)
|
||||
}
|
||||
.toList()
|
||||
.flatMap { db.insertMangas(it).asRxObservable() }
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user