Refactor areContentsTheSame to compare entire objects

This commit is contained in:
FooIbar committed 2023-10-11 01:08:46 +08:00
1 parent 6c00d66334
commit 4d09b895d4
3 files changed
+5 -4

No files matched your search

@@ -25,7 +25,7 @@ import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(tableName = "GALLERIES")
open class BaseGalleryInfo(
data class BaseGalleryInfo(
@PrimaryKey
@ColumnInfo(name = "GID")
override var gid: Long = 0,
@@ -40,7 +40,7 @@ import splitties.init.appCtx
private val diffCallback = object : DiffUtil.ItemCallback<BaseGalleryInfo>() {
override fun areItemsTheSame(oldItem: BaseGalleryInfo, newItem: BaseGalleryInfo) = oldItem.gid == newItem.gid
override fun areContentsTheSame(oldItem: BaseGalleryInfo, newItem: BaseGalleryInfo) = oldItem.gid == newItem.gid
override fun areContentsTheSame(oldItem: BaseGalleryInfo, newItem: BaseGalleryInfo) = oldItem == newItem
}
class GalleryAdapter(
@@ -33,6 +33,7 @@ import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhEngine.fillGalleryListByApi
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.data.BaseGalleryInfo
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.download.downloadLocation
import com.hippo.ehviewer.spider.SpiderQueen
@@ -197,7 +198,7 @@ fun DownloadScreen() {
} else {
val count = result.filterNot { it.title.isNullOrBlank() }.map {
EhDB.putDownloadDirname(it.gid, it.dirname)
DownloadManager.restoreDownload(it, it.dirname)
DownloadManager.restoreDownload(it.galleryInfo, it.dirname)
}.size
launchSnackBar(RESTORE_COUNT_MSG(count + restoreDirCount))
}
@@ -234,7 +235,7 @@ fun DownloadScreen() {
}
}
private class RestoreItem(val dirname: String) : BaseGalleryInfo()
private class RestoreItem(val dirname: String, val galleryInfo: BaseGalleryInfo = BaseGalleryInfo()) : GalleryInfo by galleryInfo
private val RESTORE_NOT_FOUND = appCtx.getString(R.string.settings_download_restore_not_found)
private val RESTORE_COUNT_MSG = { cnt: Int -> if (cnt == 0) RESTORE_NOT_FOUND else appCtx.getString(R.string.settings_download_restore_successfully, cnt) }
private val NO_REDUNDANCY = appCtx.getString(R.string.settings_download_clean_redundancy_no_redundancy)