Update suggestions section on explore screen

master
Koitharu 2 years ago
parent 5c8157b81f
commit c98d7561b8
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -111,8 +111,12 @@ class ExploreFragment :
} }
override fun onListHeaderClick(item: ListHeader, view: View) { override fun onListHeaderClick(item: ListHeader, view: View) {
if (item.payload == R.id.nav_suggestions) {
startActivity(SuggestionsActivity.newIntent(view.context))
} else {
startActivity(Intent(view.context, SourcesCatalogActivity::class.java)) startActivity(Intent(view.context, SourcesCatalogActivity::class.java))
} }
}
override fun onPrimaryButtonClick(tipView: TipView) { override fun onPrimaryButtonClick(tipView: TipView) {
when ((tipView.tag as? TipModel)?.key) { when ((tipView.tag as? TipModel)?.key) {

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

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

@ -35,7 +35,9 @@ class SuggestionRepository @Inject constructor(
} }
suspend fun getRandomList(limit: Int): List<Manga> { 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() { suspend fun clear() {

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

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

Loading…
Cancel
Save