Skip to content

Commit

Permalink
Show a loading label during sync
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed Jan 27, 2024
1 parent 2763eec commit 8b28065
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/src/gestalt/java/io/bimmergestalt/reader/carapp/CarApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.bimmergestalt.reader.carapp

import android.util.Log
import androidx.work.WorkManager
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import de.bmw.idrive.BMWRemoting
Expand All @@ -25,13 +26,14 @@ import me.ash.reader.domain.service.RssService

const val TAG = "ReaderGestalt"
class CarApp(val iDriveConnectionStatus: IDriveConnectionStatus, securityAccess: SecurityAccess,
val carAppResources: CarAppSharedAssetResources, val rssService: RssService
val carAppResources: CarAppSharedAssetResources,
val rssService: RssService, workManager: WorkManager
) {

val carConnection: BMWRemotingServer
val carApp: RHMIApplication
val readoutController: ReadoutController
val model: Model = Model()
val model: Model = Model(workManager)
val homeView: HomeView
val feedView: FeedView
val readView: ReadView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import androidx.work.WorkManager
import dagger.hilt.android.AndroidEntryPoint
import io.bimmergestalt.idriveconnectkit.android.CarAppAssetResources
import io.bimmergestalt.idriveconnectkit.android.IDriveConnectionReceiver
Expand All @@ -19,6 +20,8 @@ class CarAppService: Service() {
var app: CarApp? = null
@Inject
lateinit var rssService: RssService
@Inject
lateinit var workManager: WorkManager

override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -75,7 +78,7 @@ class CarAppService: Service() {
iDriveConnectionStatus,
securityAccess,
CarAppSharedAssetResources(applicationContext, "news"),
rssService
rssService, workManager
)
}
thread?.start()
Expand Down
11 changes: 10 additions & 1 deletion app/src/gestalt/java/io/bimmergestalt/reader/carapp/Model.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.bimmergestalt.reader.carapp

import androidx.lifecycle.asFlow
import androidx.work.WorkInfo
import androidx.work.WorkManager
import io.bimmergestalt.reader.L
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import me.ash.reader.domain.model.article.ArticleWithFeed
import me.ash.reader.domain.service.SyncWorker

data class FeedConfig(val groupId: String?, val feedId: String?,
val isStarred: Boolean, val isUnread: Boolean) {
Expand All @@ -19,7 +24,11 @@ data class FeedConfig(val groupId: String?, val feedId: String?,
}
class FeedSelection(val name: String, val feedConfig: FeedConfig)

class Model {
class Model(workManager: WorkManager) {
val isSyncing = workManager.getWorkInfosByTagLiveData(SyncWorker.WORK_NAME)
.asFlow().map { it.any { workInfo ->
workInfo.state == WorkInfo.State.RUNNING
} }
var feed = MutableStateFlow(FeedSelection(L.UNREAD, FeedConfig.UNREAD))
var articles = MutableStateFlow(emptyList<ArticleWithFeed>())
var articleIndex = MutableStateFlow(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,18 @@ class HomeView(state: RHMIState, val rssService: RssService, val model: Model):
fun getEntryListDest() = entriesList.getAction()?.asHMIAction()?.target!!

override suspend fun onFocus() {
val account = rssService.get()
entriesList.setProperty(RHMIProperty.PropertyId.LABEL_WAITINGANIMATION, true)
model.isSyncing.collectLatest { active ->
loadingLabel.setVisible(active)

if (!active) {
showFeed()
}
}
}

suspend fun showFeed() {
val account = rssService.get()
model.feed.collectLatest { feedSelection ->
feedButton.getModel()?.asRaDataModel()?.value = feedSelection.name

Expand All @@ -68,8 +78,8 @@ class HomeView(state: RHMIState, val rssService: RssService, val model: Model):
entriesList.getModel()?.value = object: RHMIModel.RaListModel.RHMIListAdapter<ArticleWithFeed>(2, data) {
override fun convertRow(index: Int, item: ArticleWithFeed): Array<Any> {
val icon = if (item.article.isUnread) ""
else if (item.article.isStarred) ""
else ""
else if (item.article.isStarred) ""
else ""
return arrayOf(icon, item.article.title)
}
}
Expand Down

0 comments on commit 8b28065

Please sign in to comment.