Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions app/src/main/java/org/wikipedia/history/db/HistoryEntryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ interface HistoryEntryDao {
@Query("SELECT * FROM HistoryEntry ORDER BY timestamp DESC LIMIT 1")
suspend fun getMostRecentEntry(): HistoryEntry?

@Query("SELECT CAST(strftime('%H', timestamp / 1000, 'unixepoch') AS INTEGER) AS hour FROM HistoryEntry WHERE timestamp BETWEEN :startDate AND :endDate GROUP BY hour ORDER BY COUNT(id) DESC LIMIT 1")
suspend fun getFavoriteTimeToReadSince(startDate: Long, endDate: Long): Int?

@Query("SELECT CAST(strftime('%w', timestamp / 1000, 'unixepoch') AS INTEGER) AS dayOfWeek FROM HistoryEntry WHERE timestamp BETWEEN :startDate AND :endDate GROUP BY dayOfWeek ORDER BY COUNT(id) DESC LIMIT 1")
suspend fun getFavoriteDayToReadSince(startDate: Long, endDate: Long): Int?

@Query("SELECT CAST(strftime('%m', timestamp / 1000, 'unixepoch') AS INTEGER) AS month FROM HistoryEntry WHERE timestamp BETWEEN :startDate AND :endDate GROUP BY month ORDER BY COUNT(id) DESC LIMIT 1")
suspend fun getMostReadingMonthSince(startDate: Long, endDate: Long): Int?

@Transaction
suspend fun insert(entries: List<HistoryEntry>) {
entries.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ data class YearInReviewModel(
val localSavedArticles: List<String>,
val localTopVisitedArticles: List<String>,
val localTopCategories: List<String>,
val favoriteTimeToRead: String,
val favoriteDayToRead: String,
val favoriteMonthDidMostReading: String,
val favoriteTimeToRead: Int,
val favoriteDayToRead: Int,
val favoriteMonthDidMostReading: Int,
val closestLocation: Pair<Double, Double>,
val closestArticles: List<String>,
val userEditsCount: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ sealed class YearInReviewScreenData(
val bodyText: String? = null
) : YearInReviewScreenData()

class ReadingPatterns(
animatedImageResource: Int = 0,
staticImageResource: Int = 0,
headlineText: Any? = null,
bodyText: Any? = null,
val favoriteTimeText: String,
val favoriteDayText: String,
val favoriteMonthText: String
) : StandardScreen(
animatedImageResource = animatedImageResource,
staticImageResource = staticImageResource,
headlineText = headlineText,
bodyText = bodyText,
)

class CustomIconScreen(
headlineText: Any? = null,
bodyText: Any? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ fun YearInReviewScreenContent(
) {
when (screenData) {
is YearInReviewScreenData.StandardScreen -> {
StandardLayoutWithVariants(
StandardScreenContent(
innerPadding = innerPadding,
screenData = screenData,
screenCaptureMode = screenCaptureMode,
Expand All @@ -418,7 +418,7 @@ fun YearInReviewScreenContent(
}

@Composable
private fun StandardLayoutWithVariants(
private fun StandardScreenContent(
modifier: Modifier = Modifier,
innerPadding: PaddingValues,
screenData: YearInReviewScreenData.StandardScreen,
Expand Down Expand Up @@ -466,23 +466,63 @@ private fun StandardLayoutWithVariants(
}
}
}
HtmlText(
modifier = Modifier
.padding(top = 10.dp, start = 16.dp, end = 16.dp, bottom = 16.dp)
.height(IntrinsicSize.Min),
text = processString(screenData.bodyText),
linkStyle = TextLinkStyles(
style = SpanStyle(
color = WikipediaTheme.colors.progressiveColor,
fontSize = 16.sp
if (screenData is YearInReviewScreenData.ReadingPatterns) {
val readingPattersMap = mapOf(
screenData.favoriteTimeText to R.string.year_in_review_slide_reading_patterns_body_favorite_time,
screenData.favoriteDayText to R.string.year_in_review_slide_reading_patterns_body_favorite_day,
screenData.favoriteMonthText to R.string.year_in_review_slide_reading_patterns_body_favorite_month,
)
readingPattersMap.forEach { (title, description) ->
ReadingPatternsItem(
title = title,
description = description
)
),
style = MaterialTheme.typography.bodyLarge
)
}
} else {
HtmlText(
modifier = Modifier
.padding(top = 10.dp, start = 16.dp, end = 16.dp, bottom = 16.dp)
.height(IntrinsicSize.Min),
text = processString(screenData.bodyText),
linkStyle = TextLinkStyles(
style = SpanStyle(
color = WikipediaTheme.colors.progressiveColor,
fontSize = 16.sp
)
),
style = MaterialTheme.typography.bodyLarge
)
}
}
}
}

@Composable
fun ReadingPatternsItem(
title: String,
description: Int,
) {
Column(
modifier = Modifier
.padding(horizontal = 16.dp, vertical = 12.dp)
) {
Text(
modifier = Modifier
.height(IntrinsicSize.Min),
text = processString(title),
color = WikipediaTheme.colors.primaryColor,
style = MaterialTheme.typography.bodyLarge
)
Text(
modifier = Modifier
.height(IntrinsicSize.Min),
text = processString(description),
color = WikipediaTheme.colors.primaryColor,
style = MaterialTheme.typography.bodyMedium
)
}
}

@Composable
fun LoadingIndicator() {
Column(
Expand Down Expand Up @@ -534,7 +574,7 @@ fun PreviewScreenShot() {

@Preview
@Composable
fun PreviewContent() {
fun PreviewStandardContent() {
BaseTheme(currentTheme = Theme.LIGHT) {
YearInReviewScreenDeck(
state = UiState.Success(listOf(
Expand All @@ -551,3 +591,26 @@ fun PreviewContent() {
)
}
}

@Preview
@Composable
fun PreviewReadingPatternsContent() {
BaseTheme(currentTheme = Theme.LIGHT) {
YearInReviewScreenDeck(
state = UiState.Success(listOf(
YearInReviewScreenData.ReadingPatterns(
animatedImageResource = R.drawable.year_in_review_puzzle_pieces,
staticImageResource = R.drawable.year_in_review_puzzle_pieces,
headlineText = "You have clear reading patterns",
bodyText = "",
favoriteTimeText = "Afternoon",
favoriteDayText = "Wednesday",
favoriteMonthText = "February"
)
)),
onDonateClick = {},
onBackButtonClick = {},
onNextButtonClick = {}
)
}
}
31 changes: 24 additions & 7 deletions app/src/main/java/org/wikipedia/yearinreview/YearInReviewSlides.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.content.Context
import org.wikipedia.R
import org.wikipedia.settings.Prefs
import java.text.NumberFormat
import java.time.DayOfWeek
import java.time.Month
import java.time.format.TextStyle
import java.util.Locale

class YearInReviewSlides(
Expand Down Expand Up @@ -81,13 +84,27 @@ class YearInReviewSlides(
)
}

private fun readingPatternsScreen(vararg params: Int): YearInReviewScreenData.StandardScreen {
// TODO: yir106 + yir107
return YearInReviewScreenData.StandardScreen(
animatedImageResource = R.drawable.year_in_review_puzzle_pieces,
staticImageResource = R.drawable.year_in_review_puzzle_pieces,
headlineText = "You have clear reading patterns",
bodyText = "TBD"
private fun readingPatternsScreen(): YearInReviewScreenData.StandardScreen {
// TODO: check if the time needs to follow the locale
val favoriteTimeText = when (yearInReviewModel.favoriteTimeToRead) {
Comment on lines +91 to +92
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending. Please share other ideas on how to set up the hour based on the timezone properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do in a followup.

in 0..5 -> context.getString(R.string.year_in_review_slide_reading_pattern_late_night)
in 5..12 -> context.getString(R.string.year_in_review_slide_reading_pattern_morning)
in 12..13 -> context.getString(R.string.year_in_review_slide_reading_pattern_midday)
in 13..17 -> context.getString(R.string.year_in_review_slide_reading_pattern_afternoon)
in 17..21 -> context.getString(R.string.year_in_review_slide_reading_pattern_evening)
else -> context.getString(R.string.year_in_review_slide_reading_pattern_night)
}
val favoriteDayText = DayOfWeek.of(yearInReviewModel.favoriteDayToRead)
.getDisplayName(TextStyle.FULL, Locale.getDefault())
val favoriteMonthText = Month.of(yearInReviewModel.favoriteMonthDidMostReading)
.getDisplayName(TextStyle.FULL, Locale.getDefault())
return YearInReviewScreenData.ReadingPatterns(
animatedImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
staticImageResource = R.drawable.year_in_review_puzzle_pieces, // TODO: tbd
headlineText = context.getString(R.string.year_in_review_slide_reading_patterns_headline),
favoriteTimeText = favoriteTimeText,
favoriteDayText = favoriteDayText,
favoriteMonthText = favoriteMonthText
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ class YearInReviewViewModel() : ViewModel() {
editCount += wikidataResponse.query?.userInfo!!.editCount
editCount += commonsResponse.query?.userInfo!!.editCount

val favoriteTimeToRead = async {
AppDatabase.instance.historyEntryDao()
.getFavoriteTimeToReadSince(startTimeInMillis, endTimeInMillis)
}

val favoriteDayToRead = async {
AppDatabase.instance.historyEntryDao()
.getFavoriteDayToReadSince(startTimeInMillis, endTimeInMillis)
}

val mostReadingMonth = async {
AppDatabase.instance.historyEntryDao()
.getMostReadingMonthSince(startTimeInMillis, endTimeInMillis)
}

val favoriteTimeToReadHour = favoriteTimeToRead.await() ?: 0

val favoriteDayToReadIndex = favoriteDayToRead.await()?.let {
it % 7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious: will this ever be greater than 7? i.e. why do we need % 7 here, but not % 24 for hours or % 12 for month?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return 0 to 6, which indicates Sunday to Monday

I have replaced it with an if statement because DayOfWeek is Monday to Sunday, which counts from 1 to 7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - we're converting between two different conventions (sqlite does it differently from java.time (because why would anything be consistent?)) 👍

} ?: 0

val mostReadingMonthIndex = mostReadingMonth.await() ?: 1

yearInReviewModelMap[YIR_YEAR] = YearInReviewModel(
enReadingTimePerHour = 0L, // TODO: remote config
enPopularArticles = listOf("Dog", "Cat", "Bear", "Bird", "Tiger"), // TODO: remote config
Expand All @@ -192,9 +215,9 @@ class YearInReviewViewModel() : ViewModel() {
localSavedArticles = randomSavedArticleTitles.await(),
localTopVisitedArticles = topVisitedArticlesForTheYear.await(),
localTopCategories = topVisitedCategoryForTheYear.await(),
favoriteTimeToRead = "Evening",
favoriteDayToRead = "Saturday",
favoriteMonthDidMostReading = "March",
favoriteTimeToRead = favoriteTimeToReadHour,
favoriteDayToRead = favoriteDayToReadIndex,
favoriteMonthDidMostReading = mostReadingMonthIndex,
closestLocation = Pair(0.0, 0.0),
closestArticles = emptyList(),
userEditsCount = editCount,
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/res/values-qq/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1908,8 +1908,8 @@
<string name="year_in_review_slide_top_categories_body">Body text of the top categories slide for the Year in Review. The %1$d will be replaced by the current year and %2$s will be replaced by the list of top categories.</string>
<string name="year_in_review_slide_popular_english_articles_headline">Title of the most popular English Wikipedia articles for the Year in Review.</string>
<plurals name="year_in_review_slide_popular_english_articles_body">
<item quantity="one">Title of the most popular English Wikipedia articles for the Year in Review. The %1$d will be replaced by the number of articles and %2$s will be replaced by the list of the most popular English articles.</item>
<item quantity="other">Title of the most popular English Wikipedia articles for the Year in Review. The %1$d will be replaced by the number of articles and %2$s will be replaced by the list of the most popular English articles.</item>
<item quantity="one">Body text of the most popular English Wikipedia articles for the Year in Review. The %1$d will be replaced by the number of articles and %2$s will be replaced by the list of the most popular English articles.</item>
<item quantity="other">Body text of the most popular English Wikipedia articles for the Year in Review. The %1$d will be replaced by the number of articles and %2$s will be replaced by the list of the most popular English articles.</item>
</plurals>
<plurals name="year_in_review_slide_edits_viewed_times_headline">
<item quantity="one">Title of the edit viewed times slide for the Year in Review. %s will be replaced by the formatted number.</item>
Expand All @@ -1923,14 +1923,14 @@
<item quantity="one">Title of the edited time per minute slide for the Year in Review. %s will be replaced by the formatted number.</item>
<item quantity="other">Title of the edited times per minute slide for the Year in Review. %s will be replaced by the formatted number.</item>
</plurals>
<string name="year_in_review_slide_edited_per_minute_body">Title of the edited times per minute slide for the Year in Review. %s will be replaced by the wiki page URL.</string>
<string name="year_in_review_slide_edited_per_minute_body">Body text of the edited times per minute slide for the Year in Review. %s will be replaced by the wiki page URL.</string>
<plurals name="year_in_review_slide_bytes_added_headline">
<item quantity="one">Title of the added byte slide for the Year in Review. %s will be replaced by the formatted number.</item>
<item quantity="other">Title of the added bytes slide for the Year in Review. %s will be replaced by the formatted number.</item>
</plurals>
<plurals name="year_in_review_slide_bytes_added_body">
<item quantity="one">Title of the 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 the 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>
<item quantity="one">Body text 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">Body text 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_edited_times_headline">
<item quantity="one">Title of the user edited times slide for the Year in Review. %s will be replaced by the formatted number.</item>
Expand Down Expand Up @@ -1970,6 +1970,16 @@
<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="year_in_review_slide_reading_patterns_headline">Title of the reading patterns slide for the Year in Review</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_time">Text of the time bucket that indicates the favorite time to read.</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_day">Text of the time bucket that indicates the favorite day to read.</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_month">Text of the time bucket that indicates the month you did the most reading.</string>
<string name="year_in_review_slide_reading_pattern_morning">Text of the time bucket that indicates morning.</string>
<string name="year_in_review_slide_reading_pattern_midday">Text of the time bucket that indicates midday</string>
<string name="year_in_review_slide_reading_pattern_afternoon">Text of the time bucket that indicates afternoon</string>
<string name="year_in_review_slide_reading_pattern_evening">Text of the time bucket that indicates evening</string>
<string name="year_in_review_slide_reading_pattern_night">Text of the time bucket that indicates night</string>
<string name="year_in_review_slide_reading_pattern_late_night">Text of the time bucket that indicates late night</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
10 changes: 10 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,16 @@
<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>
<string name="year_in_review_slide_reading_patterns_headline">You have clear reading patterns</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_time">Favorite time to read</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_day">Favorite day to read</string>
<string name="year_in_review_slide_reading_patterns_body_favorite_month">Month you did the most reading</string>
<string name="year_in_review_slide_reading_pattern_morning">Morning</string>
<string name="year_in_review_slide_reading_pattern_midday">Midday</string>
<string name="year_in_review_slide_reading_pattern_afternoon">Afternoon</string>
<string name="year_in_review_slide_reading_pattern_evening">Evening</string>
<string name="year_in_review_slide_reading_pattern_night">Night</string>
<string name="year_in_review_slide_reading_pattern_late_night">Late night</string>

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