Skip to content

Commit

Permalink
Merge branch 'recommended-content-design' into abctest-rc-design
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltey committed Aug 27, 2024
2 parents 2aa28c2 + 3f71e61 commit a32aa82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface HistoryEntryWithImageDao {
else SearchResults(entries.take(3).map { SearchResult(toHistoryEntry(it).title, SearchResult.SearchResultType.HISTORY) }.toMutableList())
}

fun filterHistoryItemsWithoutTime(searchQuery: String): List<HistoryEntry> {
fun filterHistoryItemsWithoutTime(searchQuery: String = ""): List<HistoryEntry> {
return findEntriesBySearchTerm("%${normalizedQuery(searchQuery)}%").map { toHistoryEntry(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {

val wikiSite = WikipediaApp.instance.wikiSite
val inHistory = bundle.getBoolean(RecommendedContentFragment.ARG_IN_HISTORY)
private val sectionIds: List<Int> = bundle.getIntegerArrayList(RecommendedContentFragment.ARG_SECTION_IDS)!!
private val sectionIds = bundle.getIntegerArrayList(RecommendedContentFragment.ARG_SECTION_IDS)!!
val sections = sectionIds.map { RecommendedContentSection.find(it) }

private var exploreTerm: String? = null
Expand Down Expand Up @@ -98,7 +98,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {

// Get term from last history entry if no article is opened
if (term.isEmpty()) {
term = AppDatabase.instance.historyEntryWithImageDao().findEntriesBySearchTerm("%%").firstOrNull()?.apiTitle ?: ""
term = AppDatabase.instance.historyEntryWithImageDao().filterHistoryItemsWithoutTime().firstOrNull()?.apiTitle ?: ""
}

// Ger term from Because you read if no history entry is found
Expand Down Expand Up @@ -149,9 +149,9 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {

private suspend fun loadHistoryItems(): List<PageTitle> {
return withContext(Dispatchers.IO) {
AppDatabase.instance.historyEntryWithImageDao().filterHistoryItemsWithoutTime("").map {
AppDatabase.instance.historyEntryWithImageDao().filterHistoryItemsWithoutTime().map {
it.title
}.take(3)
}.take(HISTORY_ITEMS)
}
}

Expand All @@ -162,7 +162,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {
// Put timestamp in description for the delete action.
description = it.timestamp.time.toString()
}
}.take(3)
}.take(HISTORY_ITEMS)
}
}

Expand Down Expand Up @@ -220,7 +220,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {

val list = moreLikeResponse.query?.pages?.map {
PageSummary(it.displayTitle(wikiSite.languageCode), it.title, it.description, it.extract, it.thumbUrl(), wikiSite.languageCode)
}?.take(5) ?: emptyList()
}?.take(RECOMMENDED_CONTENT_ITEMS) ?: emptyList()

if (hasParentLanguageCode) {
L10nUtil.getPagesForLanguageVariant(list, wikiSite)
Expand Down Expand Up @@ -248,7 +248,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {
tab.backStackPositionTitle?.let {
PageSummary(it.displayText, it.prefixedText, it.description, null, it.thumbUrl, it.wikiSite.languageCode)
}
}.take(5)
}.take(RECOMMENDED_CONTENT_ITEMS)
}
}

Expand All @@ -270,7 +270,7 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {
}
}
pages
}?.take(5) ?: emptyList()
}?.take(RECOMMENDED_CONTENT_ITEMS) ?: emptyList()
}
}

Expand All @@ -280,4 +280,9 @@ class RecommendedContentViewModel(bundle: Bundle) : ViewModel() {
return RecommendedContentViewModel(bundle) as T
}
}

companion object {
const val RECOMMENDED_CONTENT_ITEMS = 5
const val HISTORY_ITEMS = 5
}
}

0 comments on commit a32aa82

Please sign in to comment.