Skip to content

Commit 13f2a75

Browse files
Williamraicooltey
andauthored
Yir Highlights screen logic update (#6141)
* - updates highlights slide logic when user is logged in * - conditional logic fix * - logic fix --------- Co-authored-by: Cooltey Feng <[email protected]>
1 parent 795ab08 commit 13f2a75

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -318,57 +318,79 @@ class YearInReviewSlides(
318318
)
319319
}
320320

321-
private fun loggedInHighlightScreen(): HighlightsScreen {
322-
return HighlightsScreen(
323-
highlights = buildList {
324-
if (yearInReviewModel.localTopVisitedArticles.isNotEmpty()) {
325-
val topVisitedArticles = yearInReviewModel.localTopVisitedArticles.take(3)
326-
add(
327-
HighlightItem(
328-
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_most_read_article_title, topVisitedArticles.size),
329-
items = topVisitedArticles,
330-
highlightColor = ComposeColors.Blue600
331-
)
321+
private fun loggedInHighlightScreen(): HighlightsScreen? {
322+
val highlights = buildList {
323+
// Top visited articles
324+
if (yearInReviewModel.localTopVisitedArticles.isNotEmpty()) {
325+
val topVisitedArticles = yearInReviewModel.localTopVisitedArticles.take(3)
326+
add(
327+
HighlightItem(
328+
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_most_read_article_title, topVisitedArticles.size),
329+
items = topVisitedArticles,
330+
highlightColor = ComposeColors.Blue600
332331
)
333-
}
332+
)
333+
}
334+
335+
// Reading time
336+
if (yearInReviewModel.totalReadingTimeMinutes >= YearInReviewViewModel.MIN_READING_MINUTES) {
334337
add(
335338
HighlightItem(
336339
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_minutes_read_title, yearInReviewModel.totalReadingTimeMinutes.toInt()),
337340
singleValue = numberFormatter.format(yearInReviewModel.totalReadingTimeMinutes)
338341
)
339342
)
343+
}
344+
345+
if (yearInReviewModel.localReadingArticlesCount >= YearInReviewViewModel.MIN_READING_ARTICLES) {
346+
// Favorite day
340347
add(
341348
HighlightItem(
342349
title = context.resources.getString(R.string.year_in_review_highlights_logged_in_favorite_day_title),
343350
singleValue = DayOfWeek.of(yearInReviewModel.favoriteDayToRead)
344351
.getDisplayName(TextStyle.FULL, Locale.getDefault())
345352
)
346353
)
354+
// Articles read count
347355
add(
348356
HighlightItem(
349357
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_articles_read_title, yearInReviewModel.localReadingArticlesCount),
350358
singleValue = numberFormatter.format(yearInReviewModel.localReadingArticlesCount)
351359
)
352360
)
353-
val topCategories = yearInReviewModel.localTopCategories.take(3)
361+
}
362+
363+
// Top categories
364+
if (yearInReviewModel.localTopCategories.size > YearInReviewViewModel.MIN_TOP_CATEGORY) {
365+
val topCategories = yearInReviewModel.localTopCategories.take(YearInReviewViewModel.MIN_TOP_CATEGORY)
354366
add(
355367
HighlightItem(
356368
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_articles_interested_categories_title, topCategories.size),
357369
items = topCategories
358370
)
359371
)
360-
if (isEditor) {
361-
add(
362-
HighlightItem(
363-
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_total_edits_title, yearInReviewModel.userEditsCount),
364-
singleValue = numberFormatter.format(yearInReviewModel.userEditsCount)
365-
)
372+
}
373+
374+
// Editor stats
375+
if (isEditor) {
376+
add(
377+
HighlightItem(
378+
title = context.resources.getQuantityString(R.plurals.year_in_review_highlights_logged_in_total_edits_title, yearInReviewModel.userEditsCount),
379+
singleValue = numberFormatter.format(yearInReviewModel.userEditsCount)
366380
)
367-
}
368-
},
369-
slideName = if (isEnglishWiki) "li_en_summary" else "li_non_summary",
370-
screenshotUrl = context.getString(R.string.year_in_highlights_screenshot_url)
371-
)
381+
)
382+
}
383+
}
384+
385+
return if (highlights.size < 2) {
386+
null
387+
} else {
388+
HighlightsScreen(
389+
highlights = highlights,
390+
slideName = if (isEnglishWiki) "li_en_summary" else "li_non_summary",
391+
screenshotUrl = context.getString(R.string.year_in_highlights_screenshot_url)
392+
)
393+
}
372394
}
373395

374396
private fun enWikiLoggedOutHighlightsScreen(): HighlightsScreen {

0 commit comments

Comments
 (0)