Update suggestions section on explore screen

This commit is contained in:
Koitharu
2024-04-10 14:14:21 +03:00
parent 5c8157b81f
commit c98d7561b8
6 changed files with 19 additions and 6 deletions

View File

@@ -111,7 +111,11 @@ class ExploreFragment :
}
override fun onListHeaderClick(item: ListHeader, view: View) {
startActivity(Intent(view.context, SourcesCatalogActivity::class.java))
if (item.payload == R.id.nav_suggestions) {
startActivity(SuggestionsActivity.newIntent(view.context))
} else {
startActivity(Intent(view.context, SourcesCatalogActivity::class.java))
}
}
override fun onPrimaryButtonClick(tipView: TipView) {

View File

@@ -130,7 +130,7 @@ class ExploreViewModel @Inject constructor(
val result = ArrayList<ListModel>(sources.size + 3)
result += ExploreButtons(randomLoading)
if (recommendation.isNotEmpty()) {
result += ListHeader(R.string.suggestions, R.string.more)
result += ListHeader(R.string.suggestions, R.string.more, R.id.nav_suggestions)
result += RecommendationsItem(recommendation.toRecommendationList())
}
if (sources.isNotEmpty()) {
@@ -159,7 +159,7 @@ class ExploreViewModel @Inject constructor(
private fun getSuggestionFlow() = isSuggestionsEnabled.mapLatest { isEnabled ->
if (isEnabled) {
runCatchingCancellable {
suggestionRepository.getRandomList(8)
suggestionRepository.getRandomList(SUGGESTIONS_COUNT)
}.getOrDefault(emptyList())
} else {
emptyList()
@@ -181,6 +181,7 @@ class ExploreViewModel @Inject constructor(
companion object {
private const val TIP_SUGGESTIONS = "suggestions"
private const val SUGGESTIONS_COUNT = 8
const val TIP_NEW_SOURCES = "new_sources"
}
}

View File

@@ -23,6 +23,10 @@ abstract class SuggestionDao {
@Query("SELECT * FROM suggestions ORDER BY RANDOM() LIMIT 1")
abstract suspend fun getRandom(): SuggestionWithManga?
@Transaction
@Query("SELECT * FROM suggestions ORDER BY RANDOM() LIMIT :limit")
abstract suspend fun getRandom(limit: Int): List<SuggestionWithManga>
@Query("SELECT COUNT(*) FROM suggestions")
abstract suspend fun count(): Int

View File

@@ -35,7 +35,9 @@ class SuggestionRepository @Inject constructor(
}
suspend fun getRandomList(limit: Int): List<Manga> {
return List(limit) { getRandom() }.filterNotNull().distinct() //TODO improve
return db.getSuggestionDao().getRandom(limit).map {
it.manga.toManga(it.tags.toMangaTags())
}
}
suspend fun clear() {

View File

@@ -19,7 +19,8 @@
android:layout_gravity="center_horizontal"
android:layout_marginVertical="@dimen/margin_small"
app:dotAlpha="0.6"
app:dotSize="8dp"
app:dotScale="0.4"
app:dotSize="10dp"
app:dotSpacing="4dp"
tools:max="6"
tools:progress="2" />

View File

@@ -37,9 +37,10 @@
<TextView
android:id="@+id/textView_subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:ellipsize="end"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintBottom_toBottomOf="parent"