Migrate some classes to data classes
This commit is contained in:
@@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import java.util.Date
|
||||
|
||||
class Bookmark(
|
||||
data class Bookmark(
|
||||
val manga: Manga,
|
||||
val pageId: Long,
|
||||
val chapterId: Long,
|
||||
@@ -41,32 +41,4 @@ class Bookmark(
|
||||
val extension = imageUrl.substringAfterLast('.')
|
||||
return extension.isNotEmpty() && ImageFileFilter().isExtensionValid(extension)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Bookmark
|
||||
|
||||
if (manga != other.manga) return false
|
||||
if (pageId != other.pageId) return false
|
||||
if (chapterId != other.chapterId) return false
|
||||
if (page != other.page) return false
|
||||
if (scroll != other.scroll) return false
|
||||
if (imageUrl != other.imageUrl) return false
|
||||
if (createdAt != other.createdAt) return false
|
||||
return percent == other.percent
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = manga.hashCode()
|
||||
result = 31 * result + pageId.hashCode()
|
||||
result = 31 * result + chapterId.hashCode()
|
||||
result = 31 * result + page
|
||||
result = 31 * result + scroll
|
||||
result = 31 * result + imageUrl.hashCode()
|
||||
result = 31 * result + createdAt.hashCode()
|
||||
result = 31 * result + percent.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
class EmptyHint(
|
||||
data class EmptyHint(
|
||||
@DrawableRes val icon: Int,
|
||||
@StringRes val textPrimary: Int,
|
||||
@StringRes val textSecondary: Int,
|
||||
@@ -15,24 +15,4 @@ class EmptyHint(
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is EmptyHint && textPrimary == other.textPrimary
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as EmptyHint
|
||||
|
||||
if (icon != other.icon) return false
|
||||
if (textPrimary != other.textPrimary) return false
|
||||
if (textSecondary != other.textSecondary) return false
|
||||
return actionStringRes == other.actionStringRes
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = icon
|
||||
result = 31 * result + textPrimary
|
||||
result = 31 * result + textSecondary
|
||||
result = 31 * result + actionStringRes
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,33 +3,13 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
class EmptyState(
|
||||
data class EmptyState(
|
||||
@DrawableRes val icon: Int,
|
||||
@StringRes val textPrimary: Int,
|
||||
@StringRes val textSecondary: Int,
|
||||
@StringRes val actionStringRes: Int,
|
||||
) : ListModel {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as EmptyState
|
||||
|
||||
if (icon != other.icon) return false
|
||||
if (textPrimary != other.textPrimary) return false
|
||||
if (textSecondary != other.textSecondary) return false
|
||||
return actionStringRes == other.actionStringRes
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = icon
|
||||
result = 31 * result + textPrimary
|
||||
result = 31 * result + textSecondary
|
||||
result = 31 * result + actionStringRes
|
||||
return result
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is EmptyState
|
||||
}
|
||||
|
||||
@@ -2,27 +2,11 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
|
||||
class ErrorFooter(
|
||||
data class ErrorFooter(
|
||||
val exception: Throwable,
|
||||
@DrawableRes val icon: Int
|
||||
) : ListModel {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as ErrorFooter
|
||||
|
||||
if (exception != other.exception) return false
|
||||
return icon == other.icon
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = exception.hashCode()
|
||||
result = 31 * result + icon
|
||||
return result
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is ErrorFooter && exception == other.exception
|
||||
}
|
||||
|
||||
@@ -3,32 +3,12 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
class ErrorState(
|
||||
data class ErrorState(
|
||||
val exception: Throwable,
|
||||
@DrawableRes val icon: Int,
|
||||
val canRetry: Boolean,
|
||||
@StringRes val buttonText: Int
|
||||
) : ListModel {
|
||||
|
||||
|
||||
override fun areItemsTheSame(other: ListModel) = other is ErrorState
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as ErrorState
|
||||
|
||||
if (exception != other.exception) return false
|
||||
if (icon != other.icon) return false
|
||||
if (canRetry != other.canRetry) return false
|
||||
return buttonText == other.buttonText
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = exception.hashCode()
|
||||
result = 31 * result + icon
|
||||
result = 31 * result + canRetry.hashCode()
|
||||
result = 31 * result + buttonText
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.content.Context
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.core.ui.model.DateTimeAgo
|
||||
|
||||
@Suppress("DataClassPrivateConstructor")
|
||||
data class ListHeader private constructor(
|
||||
private val text: CharSequence? = null,
|
||||
@StringRes private val textRes: Int = 0,
|
||||
private val dateTimeAgo: DateTimeAgo? = null,
|
||||
@StringRes val buttonTextRes: Int = 0,
|
||||
val payload: Any? = null,
|
||||
private val text: CharSequence?,
|
||||
@StringRes private val textRes: Int,
|
||||
private val dateTimeAgo: DateTimeAgo?,
|
||||
@StringRes val buttonTextRes: Int,
|
||||
val payload: Any?,
|
||||
) : ListModel {
|
||||
|
||||
constructor(
|
||||
@@ -20,10 +21,15 @@ data class ListHeader private constructor(
|
||||
|
||||
constructor(
|
||||
@StringRes textRes: Int,
|
||||
@StringRes buttonTextRes: Int = 0
|
||||
) : this(null, textRes, null, buttonTextRes)
|
||||
@StringRes buttonTextRes: Int = 0,
|
||||
payload: Any? = null,
|
||||
) : this(null, textRes, null, buttonTextRes, payload)
|
||||
|
||||
constructor(dateTimeAgo: DateTimeAgo) : this(null, dateTimeAgo = dateTimeAgo)
|
||||
constructor(
|
||||
dateTimeAgo: DateTimeAgo,
|
||||
@StringRes buttonTextRes: Int = 0,
|
||||
payload: Any? = null,
|
||||
) : this(null, 0, dateTimeAgo, buttonTextRes, payload)
|
||||
|
||||
fun getText(context: Context): CharSequence? = when {
|
||||
text != null -> text
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
package org.koitharu.kotatsu.list.ui.model
|
||||
|
||||
class LoadingFooter @JvmOverloads constructor(
|
||||
data class LoadingFooter @JvmOverloads constructor(
|
||||
val key: Int = 0,
|
||||
) : ListModel {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as LoadingFooter
|
||||
|
||||
return key == other.key
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return key
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is LoadingFooter && key == other.key
|
||||
}
|
||||
|
||||
@@ -1,38 +1,12 @@
|
||||
package org.koitharu.kotatsu.list.ui.model
|
||||
|
||||
import org.koitharu.kotatsu.list.ui.adapter.MangaListAdapter
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
|
||||
class MangaGridModel(
|
||||
data class MangaGridModel(
|
||||
override val id: Long,
|
||||
override val title: String,
|
||||
override val coverUrl: String,
|
||||
override val manga: Manga,
|
||||
override val counter: Int,
|
||||
override val progress: Float,
|
||||
) : MangaItemModel() {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaGridModel
|
||||
|
||||
if (id != other.id) return false
|
||||
if (title != other.title) return false
|
||||
if (coverUrl != other.coverUrl) return false
|
||||
if (manga != other.manga) return false
|
||||
if (counter != other.counter) return false
|
||||
return progress == other.progress
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + coverUrl.hashCode()
|
||||
result = 31 * result + manga.hashCode()
|
||||
result = 31 * result + counter
|
||||
result = 31 * result + progress.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
) : MangaItemModel()
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ChipsView
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
|
||||
class MangaListDetailedModel(
|
||||
data class MangaListDetailedModel(
|
||||
override val id: Long,
|
||||
override val title: String,
|
||||
val subtitle: String?,
|
||||
@@ -12,33 +12,4 @@ class MangaListDetailedModel(
|
||||
override val counter: Int,
|
||||
override val progress: Float,
|
||||
val tags: List<ChipsView.ChipModel>,
|
||||
) : MangaItemModel() {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaListDetailedModel
|
||||
|
||||
if (id != other.id) return false
|
||||
if (title != other.title) return false
|
||||
if (subtitle != other.subtitle) return false
|
||||
if (coverUrl != other.coverUrl) return false
|
||||
if (manga != other.manga) return false
|
||||
if (counter != other.counter) return false
|
||||
if (progress != other.progress) return false
|
||||
return tags == other.tags
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + (subtitle?.hashCode() ?: 0)
|
||||
result = 31 * result + coverUrl.hashCode()
|
||||
result = 31 * result + manga.hashCode()
|
||||
result = 31 * result + counter
|
||||
result = 31 * result + progress.hashCode()
|
||||
result = 31 * result + tags.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
) : MangaItemModel()
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
|
||||
class MangaListModel(
|
||||
data class MangaListModel(
|
||||
override val id: Long,
|
||||
override val title: String,
|
||||
val subtitle: String,
|
||||
@@ -10,31 +10,4 @@ class MangaListModel(
|
||||
override val manga: Manga,
|
||||
override val counter: Int,
|
||||
override val progress: Float,
|
||||
) : MangaItemModel() {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaListModel
|
||||
|
||||
if (id != other.id) return false
|
||||
if (title != other.title) return false
|
||||
if (subtitle != other.subtitle) return false
|
||||
if (coverUrl != other.coverUrl) return false
|
||||
if (manga != other.manga) return false
|
||||
if (counter != other.counter) return false
|
||||
return progress == other.progress
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + subtitle.hashCode()
|
||||
result = 31 * result + coverUrl.hashCode()
|
||||
result = 31 * result + manga.hashCode()
|
||||
result = 31 * result + counter
|
||||
result = 31 * result + progress.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
) : MangaItemModel()
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.koitharu.kotatsu.list.ui.model
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
|
||||
class TipModel(
|
||||
data class TipModel(
|
||||
val key: String,
|
||||
@StringRes val title: Int,
|
||||
@StringRes val text: Int,
|
||||
@@ -15,28 +15,4 @@ class TipModel(
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is TipModel && other.key == key
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as TipModel
|
||||
|
||||
if (key != other.key) return false
|
||||
if (title != other.title) return false
|
||||
if (text != other.text) return false
|
||||
if (icon != other.icon) return false
|
||||
if (primaryButtonText != other.primaryButtonText) return false
|
||||
return secondaryButtonText == other.secondaryButtonText
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = key.hashCode()
|
||||
result = 31 * result + title
|
||||
result = 31 * result + text
|
||||
result = 31 * result + icon
|
||||
result = 31 * result + primaryButtonText
|
||||
result = 31 * result + secondaryButtonText
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,61 +6,28 @@ import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.areItemsEquals
|
||||
|
||||
sealed interface SearchSuggestionItem : ListModel {
|
||||
|
||||
class MangaList(
|
||||
data class MangaList(
|
||||
val items: List<Manga>,
|
||||
) : SearchSuggestionItem {
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is MangaList
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaList
|
||||
|
||||
return items.areItemsEquals(other.items) { a, b ->
|
||||
a.title == b.title && a.coverUrl == b.coverUrl
|
||||
}
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return items.fold(0) { acc, t ->
|
||||
var r = 31 * acc + t.title.hashCode()
|
||||
r = 31 * r + t.coverUrl.hashCode()
|
||||
r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RecentQuery(
|
||||
data class RecentQuery(
|
||||
val query: String,
|
||||
) : SearchSuggestionItem {
|
||||
|
||||
override fun areItemsTheSame(other: ListModel): Boolean {
|
||||
return other is RecentQuery && query == other.query
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as RecentQuery
|
||||
|
||||
return query == other.query
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return query.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
class Source(
|
||||
data class Source(
|
||||
val source: MangaSource,
|
||||
val isEnabled: Boolean,
|
||||
) : SearchSuggestionItem {
|
||||
@@ -82,25 +49,9 @@ sealed interface SearchSuggestionItem : ListModel {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Source
|
||||
|
||||
if (source != other.source) return false
|
||||
return isEnabled == other.isEnabled
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = source.hashCode()
|
||||
result = 31 * result + isEnabled.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class Tags(
|
||||
data class Tags(
|
||||
val tags: List<ChipsView.ChipModel>,
|
||||
) : SearchSuggestionItem {
|
||||
|
||||
@@ -111,18 +62,5 @@ sealed interface SearchSuggestionItem : ListModel {
|
||||
override fun getChangePayload(previousState: ListModel): Any {
|
||||
return ListModelDiffCallback.PAYLOAD_NESTED_LIST_CHANGED
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Tags
|
||||
|
||||
return tags == other.tags
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return tags.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user