Skip to content

Commit

Permalink
new - remote config incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
violeroares committed Nov 9, 2024
1 parent d7ccd18 commit f9cf6a3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions JetNews/app/src/main/java/com/example/jetnews/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
package com.example.jetnews.ui

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import com.example.jetnews.JetnewsApplication
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings

class MainActivity : ComponentActivity() {

Expand All @@ -36,5 +40,31 @@ class MainActivity : ComponentActivity() {
val widthSizeClass = calculateWindowSizeClass(this).widthSizeClass
JetnewsApp(appContainer, widthSizeClass)
}

// Inicializa Firebase Remote Config
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 3600 // Intervalo de fetch mínimo en segundos
}
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.setDefaultsAsync(mapOf(
"property_1" to "default_value_1",
"property_2" to "default_value_2"
))

// Realiza el fetch de los valores remotos
remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
if (task.isSuccessful) {
val updated = task.result
Log.d("RemoteConfig", "Config params updated: $updated")
// Usa los valores de remoteConfig
val property1 = remoteConfig.getString("property_1")
val property2 = remoteConfig.getString("property_2")
// Actualiza la UI o lógica de negocio con estos valores
} else {
Log.w("RemoteConfig", "Fetch failed")
}
}

}
}

0 comments on commit f9cf6a3

Please sign in to comment.