From 7b090c4ccd3f24d268004294f1e1a183a83554b1 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 2 Aug 2023 05:29:36 +0530 Subject: [PATCH] Add default constructor values --- .../ui/sheet/BookmarksSheetViewModel.kt | 2 +- .../download/ui/list/DownloadsViewModel.kt | 2 +- .../kotatsu/explore/ui/ExploreViewModel.kt | 4 +-- .../kotatsu/filter/ui/FilterCoordinator.kt | 4 +-- .../history/ui/HistoryListViewModel.kt | 2 +- .../kotatsu/list/ui/model/ListHeader.kt | 25 ++++++++----------- .../ui/thumbnails/PagesThumbnailsViewModel.kt | 2 +- .../kotatsu/tracker/ui/feed/FeedViewModel.kt | 2 +- 8 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/sheet/BookmarksSheetViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/sheet/BookmarksSheetViewModel.kt index cc72e0cea..937a50917 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/sheet/BookmarksSheetViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/ui/sheet/BookmarksSheetViewModel.kt @@ -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 diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsViewModel.kt index 27a20f686..f4add9ac5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadsViewModel.kt @@ -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 diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreViewModel.kt index 03cf4c38e..14836b6d4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreViewModel.kt @@ -133,11 +133,11 @@ class ExploreViewModel @Inject constructor( val result = ArrayList(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, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt index 643b078b2..30516882b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/filter/ui/FilterCoordinator.kt @@ -207,13 +207,13 @@ class FilterCoordinator @Inject constructor( val list = ArrayList(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) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt index 3b041f9d5..ff4acb3c4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/ui/HistoryListViewModel.kt @@ -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 } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/ListHeader.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/ListHeader.kt index 805eba6b1..e4182c5cf 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/ListHeader.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/ListHeader.kt @@ -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 diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/PagesThumbnailsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/PagesThumbnailsViewModel.kt index 7fee3bf49..18d41b1ef 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/PagesThumbnailsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/thumbnails/PagesThumbnailsViewModel.kt @@ -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 } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedViewModel.kt index 49c033704..51e8dfe26 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/FeedViewModel.kt @@ -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()