diff --git a/app/src/main/java/org/wikipedia/readinglist/db/ReadingListPageDao.kt b/app/src/main/java/org/wikipedia/readinglist/db/ReadingListPageDao.kt index 655c6785a46..365c7da6003 100644 --- a/app/src/main/java/org/wikipedia/readinglist/db/ReadingListPageDao.kt +++ b/app/src/main/java/org/wikipedia/readinglist/db/ReadingListPageDao.kt @@ -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 + @Query("SELECT * FROM ReadingListPage WHERE UPPER(displayTitle) LIKE UPPER(:term) ESCAPE '\\'") suspend fun findPageBySearchTerm(term: String): List @@ -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 - @Query("SELECT DISTINCT displayTitle FROM ReadingListPage ORDER BY atime DESC LIMIT :limit") - suspend fun getLatestArticleTitles(limit: Int): List - suspend fun getAllPagesToBeSaved() = getPagesByStatus(ReadingListPage.STATUS_QUEUE_FOR_SAVE, true) suspend fun getAllPagesToBeForcedSave() = getPagesByStatus(ReadingListPage.STATUS_QUEUE_FOR_FORCED_SAVE, true) diff --git a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewModel.kt b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewModel.kt index c9718c0ec98..1816befb56d 100644 --- a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewModel.kt +++ b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewModel.kt @@ -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, val localTopVisitedArticles: List, val localTopCategories: List, diff --git a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt index 9bb603fdb45..0fdb2af3091 100644 --- a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt +++ b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt @@ -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) ) } @@ -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) ) } @@ -281,7 +290,7 @@ class YearInReviewSlides( return (listOf( spentReadingHoursScreen(1), popularEnglishArticlesScreen(), - globalSavedArticlesScreen() + appSavedArticlesScreen() ) + editorRoutes() + unlockedIconRoute() + highlightScreen()).filterNotNull() } @@ -290,7 +299,7 @@ class YearInReviewSlides( return (listOf( availableLanguagesScreen(), viewedArticlesTimesScreen(), - globalSavedArticlesScreen() + appSavedArticlesScreen() ) + editorRoutes() + unlockedIconRoute() + highlightScreen()).filterNotNull() } diff --git a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewViewModel.kt b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewViewModel.kt index 7cc8d6f52df..f3f12ad1f2c 100644 --- a/app/src/main/java/org/wikipedia/yearinreview/YearInReviewViewModel.kt +++ b/app/src/main/java/org/wikipedia/yearinreview/YearInReviewViewModel.kt @@ -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() } } @@ -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", @@ -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 diff --git a/app/src/main/res/values-qq/strings.xml b/app/src/main/res/values-qq/strings.xml index 21c836bba8c..a8961210d34 100644 --- a/app/src/main/res/values-qq/strings.xml +++ b/app/src/main/res/values-qq/strings.xml @@ -1920,6 +1920,19 @@ 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. 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. + + Title of the user saved articles slide for the Year in Review. %s will be replaced by the number of saved article. + Title of the user saved articles slide for the Year in Review. %s will be replaced by the number of saved articles. + + + 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. + 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. + + + 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. + 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. + + Body text of the app saved articles slide for the Year in Review. Title for the recommended reading list feature. Title of the onboarding card for the recommended reading list. Message on the onboarding card for the recommended reading list. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8e0795c9be..87f855f5832 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2027,6 +2027,19 @@ learn how to participate.]]> learn how to participate.]]> + + You saved %s article + You saved %s articles + + + %1$s, %2$s, and %3$s,. Each saved article reflects your interests and helps build a personalized knowledge base on Wikipedia.

Active app users had %4$s saved article this year.]]>
+ %1$s, %2$s, and %3$s,. Each saved article reflects your interests and helps build a personalized knowledge base on Wikipedia.

Active app users had %4$s saved articles this year.]]>
+
+ + App users had %s saved article + App users had %s saved articles + + Adding articles to reading lists allows you to access articles even while offline. You can also log in to sync reading lists across devices. Discover