diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt index 590b66436..066b031ce 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouritesDao.kt @@ -6,6 +6,7 @@ import androidx.sqlite.db.SupportSQLiteQuery import kotlinx.coroutines.flow.Flow import org.intellij.lang.annotations.Language import org.koitharu.kotatsu.core.db.entity.MangaEntity +import org.koitharu.kotatsu.favourites.domain.model.Cover import org.koitharu.kotatsu.parsers.model.SortOrder @Dao @@ -71,12 +72,12 @@ abstract class FavouritesDao { ) abstract suspend fun findAllManga(categoryId: Int): List - suspend fun findCovers(categoryId: Long, order: SortOrder): List { + suspend fun findCovers(categoryId: Long, order: SortOrder): List { val orderBy = getOrderBy(order) @Language("RoomSql") val query = SimpleSQLiteQuery( - "SELECT m.cover_url FROM favourites AS f LEFT JOIN manga AS m ON f.manga_id = m.manga_id " + + "SELECT m.cover_url AS url, m.source AS source FROM favourites AS f LEFT JOIN manga AS m ON f.manga_id = m.manga_id " + "WHERE f.category_id = ? AND deleted_at = 0 ORDER BY $orderBy", arrayOf(categoryId), ) @@ -145,7 +146,7 @@ abstract class FavouritesDao { protected abstract fun observeAllImpl(query: SupportSQLiteQuery): Flow> @RawQuery - protected abstract suspend fun findCoversImpl(query: SupportSQLiteQuery): List + protected abstract suspend fun findCoversImpl(query: SupportSQLiteQuery): List @Query("UPDATE favourites SET deleted_at = :deletedAt WHERE manga_id = :mangaId") protected abstract suspend fun setDeletedAt(mangaId: Long, deletedAt: Long) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt index e99653964..a21923ed5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt @@ -19,6 +19,7 @@ import org.koitharu.kotatsu.favourites.data.FavouriteEntity import org.koitharu.kotatsu.favourites.data.toFavouriteCategory import org.koitharu.kotatsu.favourites.data.toManga import org.koitharu.kotatsu.favourites.data.toMangaList +import org.koitharu.kotatsu.favourites.domain.model.Cover import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.SortOrder import org.koitharu.kotatsu.tracker.work.TrackerNotificationChannels @@ -66,11 +67,11 @@ class FavouritesRepository @Inject constructor( }.distinctUntilChanged() } - fun observeCategoriesWithCovers(): Flow>> { + fun observeCategoriesWithCovers(): Flow>> { return db.favouriteCategoriesDao.observeAll() .map { db.withTransaction { - val res = LinkedHashMap>() + val res = LinkedHashMap>() for (entity in it) { val cat = entity.toFavouriteCategory() res[cat] = db.favouritesDao.findCovers( diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt new file mode 100644 index 000000000..293a318a9 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt @@ -0,0 +1,32 @@ +package org.koitharu.kotatsu.favourites.domain.model + +import org.koitharu.kotatsu.parsers.model.MangaSource + +class Cover( + val url: String, + val source: String, +) { + + val mangaSource: MangaSource? + get() = if (source.isEmpty()) null else MangaSource.values().find { it.name == source } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Cover + + if (url != other.url) return false + return source == other.source + } + + override fun hashCode(): Int { + var result = url.hashCode() + result = 31 * result + source.hashCode() + return result + } + + override fun toString(): String { + return "Cover(url='$url', source=$source)" + } +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt index 57d73ad5e..9ab263483 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt @@ -15,11 +15,12 @@ import androidx.lifecycle.LifecycleOwner import coil.ImageLoader import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R -import org.koitharu.kotatsu.core.util.ext.animatorDurationScale import org.koitharu.kotatsu.core.util.ext.disposeImageRequest import org.koitharu.kotatsu.core.util.ext.enqueueWith +import org.koitharu.kotatsu.core.util.ext.getAnimationDuration import org.koitharu.kotatsu.core.util.ext.getThemeColor import org.koitharu.kotatsu.core.util.ext.newImageRequest +import org.koitharu.kotatsu.core.util.ext.source import org.koitharu.kotatsu.databinding.ItemCategoryBinding import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesListListener import org.koitharu.kotatsu.list.ui.model.ListModel @@ -53,10 +54,7 @@ fun categoryAD( ColorStateList.valueOf(ColorUtils.setAlphaComponent(backgroundColor, 153)) val fallback = ColorDrawable(Color.TRANSPARENT) val coverViews = arrayOf(binding.imageViewCover1, binding.imageViewCover2, binding.imageViewCover3) - val crossFadeDuration = ( - context.resources.getInteger(R.integer.config_defaultAnimTime) * - context.animatorDurationScale - ).toInt() + val crossFadeDuration = context.getAnimationDuration(R.integer.config_defaultAnimTime).toInt() itemView.setOnClickListener(eventListener) itemView.setOnLongClickListener(eventListener) itemView.setOnTouchListener(eventListener) @@ -77,9 +75,11 @@ fun categoryAD( ) } repeat(coverViews.size) { i -> - coverViews[i].newImageRequest(lifecycleOwner, item.covers.getOrNull(i))?.run { + val cover = item.covers.getOrNull(i) + coverViews[i].newImageRequest(lifecycleOwner, cover?.url)?.run { placeholder(R.drawable.ic_placeholder) fallback(fallback) + source(cover?.mangaSource) crossfade(crossFadeDuration * (i + 1)) error(R.drawable.ic_error_placeholder) allowRgb565(true) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryListModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryListModel.kt index abc5e6314..f09c775d1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryListModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryListModel.kt @@ -1,11 +1,12 @@ package org.koitharu.kotatsu.favourites.ui.categories.adapter import org.koitharu.kotatsu.core.model.FavouriteCategory +import org.koitharu.kotatsu.favourites.domain.model.Cover import org.koitharu.kotatsu.list.ui.model.ListModel class CategoryListModel( val mangaCount: Int, - val covers: List, + val covers: List, val category: FavouriteCategory, val isReorderMode: Boolean, ) : ListModel { @@ -21,9 +22,7 @@ class CategoryListModel( if (covers != other.covers) return false if (category.id != other.category.id) return false if (category.title != other.category.title) return false - if (category.order != other.category.order) return false - - return true + return category.order == other.category.order } override fun hashCode(): Int { @@ -35,4 +34,4 @@ class CategoryListModel( result = 31 * result + category.order.hashCode() return result } -} \ No newline at end of file +}