From 4d4359c653af4e7a31772b810482cbd9db4238f7 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Mon, 13 Jan 2025 14:21:20 -0700 Subject: [PATCH] add a config parameter for the number of favorites tools available on the home screen --- app/google-services.json | 2 +- .../godtools/ui/dashboard/home/HomePresenter.kt | 14 ++++++++++++-- .../main/kotlin/org/cru/godtools/base/Config.kt | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/google-services.json b/app/google-services.json index d54d791143..5144a6443e 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -3,7 +3,7 @@ "project_number": "71275134527", "firebase_url": "https://godtools-b2f82.firebaseio.com", "project_id": "godtools-b2f82", - "storage_bucket": "godtools-b2f82.appspot.com" + "storage_bucket": "godtools-b2f82.firebasestorage.app" }, "client": [ { diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt index 604e2e5b52..0a8f8565bc 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomePresenter.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.key import androidx.compose.runtime.remember +import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.slack.circuit.codegen.annotations.CircuitInject import com.slack.circuit.runtime.Navigator import com.slack.circuit.runtime.presenter.Presenter @@ -23,6 +24,7 @@ import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.ACTIO import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.ACTION_OPEN_TOOL_DETAILS import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.SOURCE_FAVORITE import org.cru.godtools.analytics.model.OpenAnalyticsActionEvent.Companion.SOURCE_FEATURED +import org.cru.godtools.base.CONFIG_UI_DASHBOARD_HOME_FAVORITE_TOOLS import org.cru.godtools.base.Settings import org.cru.godtools.db.repository.ToolsRepository import org.cru.godtools.tutorial.PageSet @@ -40,6 +42,7 @@ class HomePresenter @AssistedInject constructor( @ApplicationContext private val context: Context, private val eventBus: EventBus, + private val remoteConfig: FirebaseRemoteConfig, private val settings: Settings, private val toolCardPresenter: ToolCardPresenter, private val toolsRepository: ToolsRepository, @@ -107,8 +110,15 @@ class HomePresenter @AssistedInject constructor( } @Composable - private fun rememberFavoriteTools() = remember { toolsRepository.getFavoriteToolsFlow().map { it.take(5) } } - .collectAsState(null).value + private fun rememberFavoriteTools() = remember { + toolsRepository.getFavoriteToolsFlow() + .map { + it.take( + remoteConfig.getLong(CONFIG_UI_DASHBOARD_HOME_FAVORITE_TOOLS) + .coerceIn(0, Int.MAX_VALUE.toLong()).toInt() + ) + } + }.collectAsState(null).value ?.mapNotNull { tool -> val toolCode = tool.code ?: return@mapNotNull null 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 index 81e43bbdfe..a130c0d4ac 100644 --- a/library/base/src/main/kotlin/org/cru/godtools/base/Config.kt +++ b/library/base/src/main/kotlin/org/cru/godtools/base/Config.kt @@ -1,7 +1,9 @@ package org.cru.godtools.base +const val CONFIG_UI_DASHBOARD_HOME_FAVORITE_TOOLS = "ui_dashboard_home_favorite_tool_cards_count" const val CONFIG_UI_GLOBAL_ACTIVITY_ENABLED = "ui_account_globalactivity_enabled" internal val CONFIG_DEFAULTS = mapOf( + CONFIG_UI_DASHBOARD_HOME_FAVORITE_TOOLS to 5, CONFIG_UI_GLOBAL_ACTIVITY_ENABLED to true )