diff --git a/app/src/main/kotlin/org/cru/godtools/ui/account/AccountLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/account/AccountLayout.kt index d852cd9270..83c0413cf7 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/account/AccountLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/account/AccountLayout.kt @@ -63,7 +63,7 @@ internal val ACCOUNT_PAGE_MARGIN_HORIZONTAL = 16.dp internal fun AccountLayout(onEvent: (AccountLayoutEvent) -> Unit = {}) { val viewModel = viewModel() 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 } diff --git a/app/src/main/kotlin/org/cru/godtools/ui/account/AccountViewModel.kt b/app/src/main/kotlin/org/cru/godtools/ui/account/AccountViewModel.kt index 1ea1ea1b19..896e74bb47 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/account/AccountViewModel.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/account/AccountViewModel.kt @@ -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) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 519dff6837..63dae742fe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" diff --git a/library/base/build.gradle.kts b/library/base/build.gradle.kts index b027ab9448..d7554c5bab 100644 --- a/library/base/build.gradle.kts +++ b/library/base/build.gradle.kts @@ -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) diff --git a/library/base/src/main/kotlin/org/cru/godtools/base/BaseModule.kt b/library/base/src/main/kotlin/org/cru/godtools/base/BaseModule.kt index 531fe69625..427b9a0eb4 100644 --- a/library/base/src/main/kotlin/org/cru/godtools/base/BaseModule.kt +++ b/library/base/src/main/kotlin/org/cru/godtools/base/BaseModule.kt @@ -1,6 +1,8 @@ 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 @@ -8,6 +10,7 @@ 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 @@ -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() + } } diff --git a/library/base/src/main/kotlin/org/cru/godtools/base/Config.kt b/library/base/src/main/kotlin/org/cru/godtools/base/Config.kt new file mode 100644 index 0000000000..81e43bbdfe --- /dev/null +++ b/library/base/src/main/kotlin/org/cru/godtools/base/Config.kt @@ -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 +)