Add default constructor values

This commit is contained in:
Isira Seneviratne
2023-08-02 05:29:36 +05:30
committed by Koitharu
parent bf1b8e8b75
commit 7b090c4ccd
8 changed files with 19 additions and 24 deletions

View File

@@ -46,7 +46,7 @@ class BookmarksSheetViewModel @Inject constructor(
if (b.isNullOrEmpty()) {
continue
}
result += ListHeader(chapter.name, 0, null)
result += ListHeader(chapter.name)
result.addAll(b)
}
return result

View File

@@ -186,7 +186,7 @@ class DownloadsViewModel @Inject constructor(
for (item in this) {
val date = timeAgo(item.timestamp)
if (prevDate != date) {
destination += ListHeader(date, 0, null)
destination += ListHeader(date)
}
prevDate = date
destination += item

View File

@@ -133,11 +133,11 @@ class ExploreViewModel @Inject constructor(
val result = ArrayList<ListModel>(sources.size + 4)
result += ExploreButtons(randomLoading)
if (recommendation != null) {
result += ListHeader(R.string.suggestions, 0, null)
result += ListHeader(R.string.suggestions)
result += RecommendationsItem(recommendation)
}
if (sources.isNotEmpty()) {
result += ListHeader(R.string.remote_sources, R.string.manage, null)
result += ListHeader(R.string.remote_sources, R.string.manage)
if (newSources.isNotEmpty()) {
result += TipModel(
key = TIP_NEW_SOURCES,

View File

@@ -207,13 +207,13 @@ class FilterCoordinator @Inject constructor(
val list = ArrayList<ListModel>(tags.size + sortOrders.size + 3)
if (query.isEmpty()) {
if (sortOrders.isNotEmpty()) {
list.add(ListHeader(R.string.sort_order, 0, null))
list.add(ListHeader(R.string.sort_order))
sortOrders.mapTo(list) {
FilterItem.Sort(it, isSelected = it == state.sortOrder)
}
}
if (allTags.isLoading || allTags.isError || tags.isNotEmpty()) {
list.add(ListHeader(R.string.genres, if (state.tags.isEmpty()) 0 else R.string.reset, null))
list.add(ListHeader(R.string.genres, if (state.tags.isEmpty()) 0 else R.string.reset))
tags.mapTo(list) {
FilterItem.Tag(it, isChecked = it in state.tags)
}

View File

@@ -135,7 +135,7 @@ class HistoryListViewModel @Inject constructor(
if (grouped) {
val date = timeAgo(history.updatedAt)
if (prevDate != date) {
result += ListHeader(date, 0, null)
result += ListHeader(date)
}
prevDate = date
}

View File

@@ -5,30 +5,25 @@ import androidx.annotation.StringRes
import org.koitharu.kotatsu.core.ui.model.DateTimeAgo
data class ListHeader private constructor(
private val text: CharSequence?,
@StringRes private val textRes: Int,
private val dateTimeAgo: DateTimeAgo?,
@StringRes val buttonTextRes: Int,
val payload: Any?,
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,
) : ListModel {
constructor(
text: CharSequence,
@StringRes buttonTextRes: Int,
payload: Any?,
@StringRes buttonTextRes: Int = 0,
payload: Any? = null,
) : this(text, 0, null, buttonTextRes, payload)
constructor(
@StringRes textRes: Int,
@StringRes buttonTextRes: Int,
payload: Any?,
) : this(null, textRes, null, buttonTextRes, payload)
@StringRes buttonTextRes: Int = 0
) : this(null, textRes, null, buttonTextRes)
constructor(
dateTimeAgo: DateTimeAgo,
@StringRes buttonTextRes: Int,
payload: Any?,
) : this(null, 0, dateTimeAgo, buttonTextRes, payload)
constructor(dateTimeAgo: DateTimeAgo) : this(null, dateTimeAgo = dateTimeAgo)
fun getText(context: Context): CharSequence? = when {
text != null -> text

View File

@@ -95,7 +95,7 @@ class PagesThumbnailsViewModel @Inject constructor(
for (page in snapshot) {
if (page.chapterId != previousChapterId) {
chaptersLoader.peekChapter(page.chapterId)?.let {
add(ListHeader(it.name, 0, null))
add(ListHeader(it.name))
}
previousChapterId = page.chapterId
}

View File

@@ -85,7 +85,7 @@ class FeedViewModel @Inject constructor(
for (item in this) {
val date = timeAgo(item.createdAt)
if (prevDate != date) {
destination += ListHeader(date, 0, null)
destination += ListHeader(date)
}
prevDate = date
destination += item.toFeedItem()