diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt index 562cddba5..000191baf 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/ExploreFragment.kt @@ -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) { 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 ee1c14d73..b79693a55 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 @@ -130,7 +130,7 @@ class ExploreViewModel @Inject constructor( val result = ArrayList(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" } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/data/SuggestionDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/data/SuggestionDao.kt index a71ca9e9b..53088f007 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/data/SuggestionDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/data/SuggestionDao.kt @@ -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 + @Query("SELECT COUNT(*) FROM suggestions") abstract suspend fun count(): Int diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/domain/SuggestionRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/domain/SuggestionRepository.kt index f62a3b7de..2f159ea5c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/domain/SuggestionRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/domain/SuggestionRepository.kt @@ -35,7 +35,9 @@ class SuggestionRepository @Inject constructor( } suspend fun getRandomList(limit: Int): List { - return List(limit) { getRandom() }.filterNotNull().distinct() //TODO improve + return db.getSuggestionDao().getRandom(limit).map { + it.manga.toManga(it.tags.toMangaTags()) + } } suspend fun clear() { diff --git a/app/src/main/res/layout/item_recommendation.xml b/app/src/main/res/layout/item_recommendation.xml index e87508187..350a311d1 100644 --- a/app/src/main/res/layout/item_recommendation.xml +++ b/app/src/main/res/layout/item_recommendation.xml @@ -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" /> diff --git a/app/src/main/res/layout/item_recommendation_manga.xml b/app/src/main/res/layout/item_recommendation_manga.xml index 432375ef7..dd667974e 100644 --- a/app/src/main/res/layout/item_recommendation_manga.xml +++ b/app/src/main/res/layout/item_recommendation_manga.xml @@ -37,9 +37,10 @@