Skip to content

Commit 20f226a

Browse files
committed
Update model
1 parent 785e946 commit 20f226a

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package org.wikipedia.yearinreview
22

33
data class YearInReviewModel(
4-
val enReadingTimeInHours: Long,
4+
val enReadingTimeSpent: Long,
55
val enPopularArticles: List<String>,
6+
val enEditsCount: Long,
7+
val enBytesAddedCount: Long,
68
val availableLanguages: Int,
79
val globalTotalArticles: Long,
10+
val globalEditsCount: Long,
811
val articlesViewedTimes: Long,
912
val articlesSavedTimes: Long,
10-
val localReadingTimeInMinutes: Long,
13+
val localReadingTimeSpent: Long,
1114
val localReadingArticles: Int,
1215
val localReadingRank: String, // TODO: TBD: top 50% or pure numbers,
1316
val localSavedArticles: List<String>,
14-
val topArticles: List<String>,
17+
val localTopVisitedArticles: List<String>,
1518
val favoriteTimeToRead: String,
1619
val favoriteDayToRead: String,
1720
val favoriteMonthDidMostReading: String,
1821
val topCategories: List<String>,
1922
val closestLocation: Pair<Double, Double>,
2023
val closestArticles: List<String>,
2124
val userEditsCount: Long,
22-
val globalEditsCount: Long,
23-
val enEditsCount: Long,
2425
val userEditsViewedTimes: Long,
2526
val appsEditsCount: Long,
2627
val editsPerMinute: Long,
27-
val enBytesAddedCount: Long
2828
)

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.wikipedia.util.log.L
2323
import java.time.Instant
2424
import java.time.LocalDate
2525
import java.time.LocalDateTime
26+
import java.time.ZoneId
2627
import java.time.ZoneOffset
2728
import java.util.concurrent.TimeUnit
2829
import kotlin.math.abs
@@ -48,6 +49,9 @@ class YearInReviewViewModel() : ViewModel() {
4849
viewModelScope.launch(handler) {
4950

5051
_uiScreenListState.value = UiState.Loading
52+
val now = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
53+
val yearInMillis = TimeUnit.DAYS.toMillis(365)
54+
val yearAgo = now - yearInMillis
5155

5256
// TODO: handle remote config to show numbers, maybe grab generic content from the config.
5357
val remoteConfig = RemoteConfig.config
@@ -66,11 +70,16 @@ class YearInReviewViewModel() : ViewModel() {
6670
AppDatabase.instance.historyEntryDao().getDistinctEntriesCountBetween(startTimeInMillis, endTimeInMillis)
6771
}
6872

69-
val latestArticleTitlesFromHistory = async {
73+
val topVisitedArticlesForTheYear = async {
74+
// TODO: update the query
7075
AppDatabase.instance.historyEntryDao().getLatestArticleTitles(MINIMUM_READ_COUNT)
7176
.map { StringUtil.fromHtml(it).toString() }
7277
}
7378

79+
val totalTimeSpent = async {
80+
AppDatabase.instance.historyEntryWithImageDao().getTimeSpentSinceTimeStamp(yearAgo)
81+
}
82+
7483
// TODO: think about the actual data to show.
7584

7685
val impactDataJob = async {
@@ -162,30 +171,30 @@ class YearInReviewViewModel() : ViewModel() {
162171
isIconUnlocked = Prefs.donationResults.isNotEmpty(),
163172
isEnglishWiki = WikipediaApp.instance.wikiSite.languageCode == "en",
164173
yearInReviewModel = YearInReviewModel(
165-
enReadingTimeInHours = 0L,
174+
enReadingTimeSpent = 0L, // TODO: remote config
166175
enPopularArticles = emptyList(),
167-
availableLanguages = 0,
176+
enEditsCount = 0L,
177+
enBytesAddedCount = 0L,
178+
availableLanguages = 0, // TODO: remote config
168179
globalTotalArticles = 0L,
180+
globalEditsCount = 0L,
169181
articlesViewedTimes = 0L,
170182
articlesSavedTimes = 0L,
171-
localReadingTimeInMinutes = 0L,
172-
localReadingArticles = 0,
183+
localReadingTimeSpent = totalTimeSpent.await(),
184+
localReadingArticles = readCountForTheYear.await(),
173185
localReadingRank = "50%",
174-
localSavedArticles = emptyList(),
175-
topArticles = emptyList(),
186+
localSavedArticles = latestArticleTitlesFromSaved.await(),
187+
localTopVisitedArticles = topVisitedArticlesForTheYear.await(),
176188
favoriteTimeToRead = "Evening",
177189
favoriteDayToRead = "Saturday",
178190
favoriteMonthDidMostReading = "March",
179191
topCategories = emptyList(),
180192
closestLocation = Pair(0.0, 0.0),
181193
closestArticles = emptyList(),
182194
userEditsCount = 0L,
183-
globalEditsCount = 0L,
184-
enEditsCount = 0L,
185195
userEditsViewedTimes = 0L,
186196
appsEditsCount = 0L,
187-
editsPerMinute = 0L,
188-
enBytesAddedCount = 0L
197+
editsPerMinute = 0L
189198
)
190199
).finalSlides()
191200

0 commit comments

Comments
 (0)