Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ interface ReadingListPageDao {
@Query("SELECT * FROM ReadingListPage WHERE lang = :lang ORDER BY RANDOM() LIMIT 1")
suspend fun getRandomPage(lang: String): ReadingListPage?

@Query("SELECT displayTitle FROM ReadingListPage WHERE atime > 0 AND atime > :timestamp ORDER BY RANDOM() LIMIT :limit")
suspend fun getRandomPageTitlesSince(limit: Int, timestamp: Long): List<String?>

@Query("SELECT * FROM ReadingListPage WHERE UPPER(displayTitle) LIKE UPPER(:term) ESCAPE '\\'")
suspend fun findPageBySearchTerm(term: String): List<ReadingListPage>

Expand All @@ -98,9 +101,6 @@ interface ReadingListPageDao {
@Query("SELECT * FROM ReadingListPage WHERE atime > 0 ORDER BY atime DESC LIMIT :limit OFFSET :offset")
suspend fun getPagesByLocallySavedTime(limit: Int, offset: Int): List<ReadingListPage>

@Query("SELECT DISTINCT displayTitle FROM ReadingListPage ORDER BY atime DESC LIMIT :limit")
suspend fun getLatestArticleTitles(limit: Int): List<String>

suspend fun getAllPagesToBeSaved() = getPagesByStatus(ReadingListPage.STATUS_QUEUE_FOR_SAVE, true)

suspend fun getAllPagesToBeForcedSave() = getPagesByStatus(ReadingListPage.STATUS_QUEUE_FOR_FORCED_SAVE, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data class YearInReviewModel(
val localReadingTimePerMinute: Long,
val localReadingArticlesCount: Int,
val localReadingRank: String, // TODO: TBD: top 50% or pure numbers,
val localSavedArticlesCount: Int,
val localSavedArticles: List<String>,
val localTopVisitedArticles: List<String>,
val localTopCategories: List<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ class YearInReviewSlides(
)
}

private fun globalSavedArticlesScreen(vararg params: Int): YearInReviewScreenData.StandardScreen {
// TODO: yir126
private fun appSavedArticlesScreen(): YearInReviewScreenData.StandardScreen {
val quantity = yearInReviewModel.appArticlesSavedTimes.toInt()
val formattedNumber = formatter.format(yearInReviewModel.appArticlesSavedTimes)
return YearInReviewScreenData.StandardScreen(
animatedImageResource = R.drawable.year_in_review_puzzle_pieces,
staticImageResource = R.drawable.year_in_review_puzzle_pieces,
headlineText = "We had over 37 million saved articles",
bodyText = "TBD"
animatedImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
staticImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
headlineText = context.resources.getQuantityString(R.plurals.year_in_review_slide_global_saved_articles_headline, quantity, formattedNumber),
bodyText = context.getString(R.string.year_in_review_slide_global_saved_articles_body)
)
}

Expand Down Expand Up @@ -130,13 +131,21 @@ class YearInReviewSlides(
)
}

private fun localSavedArticlesScreen(vararg params: Int): YearInReviewScreenData.StandardScreen {
// TODO: yir113
private fun localSavedArticlesScreen(): YearInReviewScreenData.StandardScreen {
val localSavedArticlesSize = yearInReviewModel.localSavedArticlesCount
if (localSavedArticlesSize < YearInReviewViewModel.MIN_SAVED_ARTICLES) {
return appSavedArticlesScreen()
}
val localSavedFormattedNumber = formatter.format(localSavedArticlesSize)
val appSavedArticlesSize = yearInReviewModel.appArticlesSavedTimes.toInt()
val appSavedFormattedNumber = formatter.format(yearInReviewModel.appArticlesSavedTimes)
return YearInReviewScreenData.StandardScreen(
animatedImageResource = R.drawable.year_in_review_puzzle_pieces,
staticImageResource = R.drawable.year_in_review_puzzle_pieces,
headlineText = "You saved 25 articles",
bodyText = "TBD"
animatedImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
staticImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
headlineText = context.resources.getQuantityString(R.plurals.year_in_review_slide_saved_articles_headline, localSavedArticlesSize, localSavedFormattedNumber),
bodyText = context.resources.getQuantityString(R.plurals.year_in_review_slide_saved_articles_body,
appSavedArticlesSize, yearInReviewModel.localSavedArticles[0], yearInReviewModel.localSavedArticles[1],
yearInReviewModel.localSavedArticles[2], appSavedFormattedNumber)
)
}

Expand Down Expand Up @@ -281,7 +290,7 @@ class YearInReviewSlides(
return (listOf(
spentReadingHoursScreen(1),
popularEnglishArticlesScreen(),
globalSavedArticlesScreen()
appSavedArticlesScreen()
) + editorRoutes() + unlockedIconRoute() + highlightScreen()).filterNotNull()
}

Expand All @@ -290,7 +299,7 @@ class YearInReviewSlides(
return (listOf(
availableLanguagesScreen(),
viewedArticlesTimesScreen(),
globalSavedArticlesScreen()
appSavedArticlesScreen()
) + editorRoutes() + unlockedIconRoute() + highlightScreen()).filterNotNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ class YearInReviewViewModel() : ViewModel() {
// TODO: handle remote config to show numbers, maybe grab generic content from the config.
val remoteConfig = RemoteConfig.config

val latestArticleTitlesFromSaved = async {
val totalSavedArticlesCount = async {
AppDatabase.instance.readingListPageDao()
.getLatestArticleTitles(MINIMUM_SAVED_ARTICLE_COUNT)
.getTotalLocallySavedPagesSince(yearAgo) ?: 0
}
val randomSavedArticleTitles = async {
AppDatabase.instance.readingListPageDao()
.getRandomPageTitlesSince(MIN_SAVED_ARTICLES, yearAgo)
.map { StringUtil.fromHtml(it).toString() }
}

Expand Down Expand Up @@ -184,9 +188,10 @@ class YearInReviewViewModel() : ViewModel() {
appArticlesSavedTimes = 0L, // TODO: remote config
appsEditsCount = 0L, // TODO: remote config
localReadingTimePerMinute = totalTimeSpent.await(),
localSavedArticlesCount = totalSavedArticlesCount.await(),
localReadingArticlesCount = readCountForTheYear.await(),
localReadingRank = "50%", // TODO: compare with the total reading hours
localSavedArticles = latestArticleTitlesFromSaved.await(),
localSavedArticles = randomSavedArticleTitles.await(),
localTopVisitedArticles = topVisitedArticlesForTheYear.await(),
localTopCategories = topVisitedCategoryForTheYear.await(),
favoriteTimeToRead = "Evening",
Expand Down Expand Up @@ -221,8 +226,8 @@ class YearInReviewViewModel() : ViewModel() {
}

companion object {
private const val MINIMUM_SAVED_ARTICLE_COUNT = 3
private const val MINIMUM_EDIT_COUNT = 1
const val MIN_SAVED_ARTICLES = 3
const val MAX_TOP_ARTICLES = 5
const val MIN_TOP_CATEGORY = 3
const val MAX_TOP_CATEGORY = 5
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values-qq/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,19 @@
<item quantity="one">Title of thea added byte slide for the Year in Review. %1$d will be replaced by the current year, %2$s will be replaced by the formatted number, and %3$s will be replaced by the wiki page URL.</item>
<item quantity="other">Title of thea added bytes slide for the Year in Review. %1$d will be replaced by the current year, %2$s will be replaced by the formatted number, and %3$s will be replaced by the wiki page URL.</item>
</plurals>
<plurals name="year_in_review_slide_saved_articles_headline">
<item quantity="one">Title of the user saved articles slide for the Year in Review. %s will be replaced by the number of saved article.</item>
<item quantity="other">Title of the user saved articles slide for the Year in Review. %s will be replaced by the number of saved articles.</item>
</plurals>
<plurals name="year_in_review_slide_saved_articles_body">
<item quantity="one">Body text of the user saved articles slide for the Year in Review. The %1$s, %2$s, and %3$s will be replaced by the article titles, and %4$s will be replaced by the total number of saved article from the app.</item>
<item quantity="other">Body text of the user saved articles slide for the Year in Review. The %1$s, %2$s, and %3$s will be replaced by the article titles, and %4$s will be replaced by the total number of saved articles from the app.</item>
</plurals>
<plurals name="year_in_review_slide_global_saved_articles_headline">
<item quantity="one">Title of the app saved article slide for the Year in Review. %s will be replaced by the total number of saved article from the app.</item>
<item quantity="other">Title of the app saved articles slide for the Year in Review. %s will be replaced by the total number of saved articles from the app.</item>
</plurals>
<string name="year_in_review_slide_global_saved_articles_body">Body text of the app saved articles slide for the Year in Review.</string>
<string name="recommended_reading_list_title">Title for the recommended reading list feature.</string>
<string name="recommended_reading_list_onboarding_card_title">Title of the onboarding card for the recommended reading list.</string>
<string name="recommended_reading_list_onboarding_card_message">Message on the onboarding card for the recommended reading list.</string>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,19 @@
<item quantity="one"><![CDATA[In %1$d, volunteers added %2$s byte to English Wikipedia. The sum of all their work together leads to a steadily improving, fact-based, and reliable knowledge resource that they give to the world. All of us have knowledge to share, <a href="%3$s">learn how to participate.]]></item>
<item quantity="other"><![CDATA[In %1$d, volunteers added %2$s bytes to English Wikipedia. The sum of all their work together leads to a steadily improving, fact-based, and reliable knowledge resource that they give to the world. All of us have knowledge to share, <a href="%3$s">learn how to participate.]]></item>
</plurals>
<plurals name="year_in_review_slide_saved_articles_headline">
<item quantity="one">You saved %s article</item>
<item quantity="other">You saved %s articles</item>
</plurals>
<plurals name="year_in_review_slide_saved_articles_body">
<item quantity="one"><![CDATA[These articles included <b>%1$s</b>, <b>%2$s</b>, and <b>%3$s</b>,. Each saved article reflects your interests and helps build a personalized knowledge base on Wikipedia.<br /><br />Active app users had %4$s saved article this year.]]></item>
<item quantity="other"><![CDATA[These articles included <b>%1$s</b>, <b>%2$s</b>, and <b>%3$s</b>,. Each saved article reflects your interests and helps build a personalized knowledge base on Wikipedia.<br /><br />Active app users had %4$s saved articles this year.]]></item>
</plurals>
<plurals name="year_in_review_slide_global_saved_articles_headline">
<item quantity="one">App users had %s saved article</item>
<item quantity="other">App users had %s saved articles</item>
</plurals>
<string name="year_in_review_slide_global_saved_articles_body">Adding articles to reading lists allows you to access articles even while offline. You can also log in to sync reading lists across devices.</string>

<!--Recommended Reading list -->
<string name="recommended_reading_list_title">Discover</string>
Expand Down
Loading