@@ -23,6 +23,7 @@ import org.wikipedia.util.log.L
2323import java.time.Instant
2424import java.time.LocalDate
2525import java.time.LocalDateTime
26+ import java.time.ZoneId
2627import java.time.ZoneOffset
2728import java.util.concurrent.TimeUnit
2829import 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