Skip to content

Commit 40d135a

Browse files
committed
chore(flipcash): create activity feed updater @ 60s
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 8c61a00 commit 40d135a

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.flipcash.app.activityfeed
2+
3+
import com.flipcash.app.core.updater.NetworkUpdater
4+
import kotlinx.coroutines.CoroutineScope
5+
import kotlinx.coroutines.launch
6+
import javax.inject.Inject
7+
import kotlin.concurrent.fixedRateTimer
8+
import kotlin.time.Duration
9+
10+
class ActivityFeedUpdater @Inject constructor(
11+
private val coordinator: ActivityFeedCoordinator,
12+
): NetworkUpdater() {
13+
override fun poll(
14+
scope: CoroutineScope,
15+
frequency: Duration,
16+
startIn: Duration,
17+
) {
18+
updater = fixedRateTimer(
19+
name = "update activity feed",
20+
initialDelay = startIn.inWholeMilliseconds,
21+
period = frequency.inWholeMilliseconds
22+
) {
23+
scope.launch {
24+
coordinator.fetchSinceLatest(count = 50)
25+
}
26+
}
27+
}
28+
}

apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/internal/RealSessionController.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flipcash.app.session.internal
22

33
import com.flipcash.app.activityfeed.ActivityFeedCoordinator
4+
import com.flipcash.app.activityfeed.ActivityFeedUpdater
45
import com.flipcash.app.core.bill.Bill
56
import com.flipcash.app.core.bill.BillState
67
import com.flipcash.app.core.bill.PaymentValuation
@@ -67,6 +68,7 @@ class RealSessionController @Inject constructor(
6768
private val vibrator: Vibrator,
6869
private val balanceUpdater: BalanceUpdater,
6970
private val exchangeUpdater: ExchangeUpdater,
71+
private val activityFeedUpdater: ActivityFeedUpdater,
7072
private val shareSheetController: ShareSheetController,
7173
private val toastController: ToastController,
7274
private val billingClient: BillingClient,
@@ -124,12 +126,14 @@ class RealSessionController @Inject constructor(
124126
if (userManager.authState.canAccessAuthenticatedApis) {
125127
exchangeUpdater.poll(scope = scope, frequency = 10.seconds, startIn = 10.seconds)
126128
balanceUpdater.poll(scope = scope, frequency = 60.seconds, startIn = 60.seconds)
129+
activityFeedUpdater.poll(scope = scope, frequency = 60.seconds, startIn = 60.seconds)
127130
}
128131
}
129132

130133
private fun stopPolling() {
131134
exchangeUpdater.stop()
132135
balanceUpdater.stop()
136+
activityFeedUpdater.stop()
133137
}
134138

135139
private fun updateUserFlags() {

0 commit comments

Comments
 (0)