Skip to content

Commit

Permalink
update global activity to use firebase remote config to check if it's…
Browse files Browse the repository at this point in the history
… enabled
  • Loading branch information
frett committed Jan 13, 2025
1 parent 6bf011f commit 9135651
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal val ACCOUNT_PAGE_MARGIN_HORIZONTAL = 16.dp
internal fun AccountLayout(onEvent: (AccountLayoutEvent) -> Unit = {}) {
val viewModel = viewModel<AccountViewModel>()
val user by viewModel.user.collectAsState()
val pages by viewModel.pages.collectAsState()
val pages by viewModel.pages.collectAsState(emptyList())
val refreshing by viewModel.isSyncRunning.collectAsState()

val pagerState = rememberPagerState { pages.size }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,36 @@ package org.cru.godtools.ui.account

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.cru.godtools.base.CONFIG_UI_GLOBAL_ACTIVITY_ENABLED
import org.cru.godtools.sync.GodToolsSyncService
import org.cru.godtools.user.data.UserManager

@HiltViewModel
class AccountViewModel @Inject internal constructor(
remoteConfig: FirebaseRemoteConfig,
private val syncService: GodToolsSyncService,
userManager: UserManager
) : ViewModel() {
val user = userManager.userFlow.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)

val pages = MutableStateFlow(listOf(AccountPage.ACTIVITY, AccountPage.GLOBAL_ACTIVITY))
val pages = flow {
emit(
buildList {
add(AccountPage.ACTIVITY)
if (remoteConfig.getBoolean(CONFIG_UI_GLOBAL_ACTIVITY_ENABLED)) add(AccountPage.GLOBAL_ACTIVITY)
}
)
}

// region Sync logic
private val syncsRunning = MutableStateFlow(0)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ facebook-flipper = { module = "com.facebook.flipper:flipper", version.ref = "fac
facebook-flipper-plugins-leakcanary2 = { module = "com.facebook.flipper:flipper-leakcanary2-plugin", version.ref = "facebook-flipper" }
facebook-flipper-plugins-network = { module = "com.facebook.flipper:flipper-network-plugin", version.ref = "facebook-flipper" }
facebook-soloader = "com.facebook.soloader:soloader:0.12.1"
firebase-config = "com.google.firebase:firebase-config:22.0.1"
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics", version.ref = "firebase-crashlytics" }
firebase-crashlytics-ndk = { module = "com.google.firebase:firebase-crashlytics-ndk", version.ref = "firebase-crashlytics" }
firebase-dynamic-links = "com.google.firebase:firebase-dynamic-links-ktx:22.1.0"
Expand Down
2 changes: 2 additions & 0 deletions library/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.datastore.preferences)

implementation(libs.firebase.config)

implementation(libs.gtoSupport.androidx.core)
implementation(libs.gtoSupport.androidx.lifecycle)
implementation(libs.gtoSupport.kotlin.coroutines)
Expand Down
10 changes: 10 additions & 0 deletions library/base/src/main/kotlin/org/cru/godtools/base/BaseModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.cru.godtools.base

import android.content.Context
import com.google.firebase.Firebase
import com.google.firebase.remoteconfig.remoteConfig
import dagger.Module
import dagger.Provides
import dagger.Reusable
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Named
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
import kotlinx.coroutines.flow.stateIn
Expand All @@ -23,4 +26,11 @@ object BaseModule {
@Named(IS_CONNECTED_STATE_FLOW)
fun isConnectedStateFlow(@ApplicationContext context: Context, scope: CoroutineScope) = context.isConnectedFlow()
.stateIn(scope, WhileSubscribed(5_000), false)

@Provides
@Singleton
fun firebaseRemoteConfig() = Firebase.remoteConfig.apply {
setDefaultsAsync(CONFIG_DEFAULTS)
fetchAndActivate()
}
}
7 changes: 7 additions & 0 deletions library/base/src/main/kotlin/org/cru/godtools/base/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.cru.godtools.base

const val CONFIG_UI_GLOBAL_ACTIVITY_ENABLED = "ui_account_globalactivity_enabled"

internal val CONFIG_DEFAULTS = mapOf(
CONFIG_UI_GLOBAL_ACTIVITY_ENABLED to true
)

0 comments on commit 9135651

Please sign in to comment.