Skip to content

Commit

Permalink
Merge pull request #44 from spotify/generalise-demo-app
Browse files Browse the repository at this point in the history
Cleanup: move clientSecret declaration to AndroidManifest.xml
  • Loading branch information
nickybondarenko authored Jul 21, 2023
2 parents 15d91e8 + 08040b9 commit 394c662
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
21 changes: 12 additions & 9 deletions ConfidenceDemoApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Provider">
<activity
android:name=".MainActivity"
android:exported="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Provider">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Provider">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.example.confidencedemoapp.clientSecret"
android:value="@string/client_secret" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.confidencedemoapp

import android.app.Application
import android.content.pm.PackageManager
import android.util.Log
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.AndroidViewModel
Expand All @@ -9,7 +10,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import dev.openfeature.contrib.providers.ConfidenceFeatureProvider
import dev.openfeature.sdk.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*

Expand All @@ -28,14 +28,21 @@ class MainVm(app: Application) : AndroidViewModel(app) {

init {
val start = System.currentTimeMillis()
val applicationContext = app.applicationContext
val metadataBundle = applicationContext.packageManager.getApplicationInfo(
applicationContext.packageName,
PackageManager.GET_META_DATA
).metaData
val clientSecret = metadataBundle.getString("com.example.confidencedemoapp.clientSecret")!!
viewModelScope.launch {
OpenFeatureAPI.setProvider(
ConfidenceFeatureProvider.create(
app.applicationContext,
"xa0fQ4WKSvuxdjPtesupleiSbZeik6Gf"
clientSecret
),
initialContext = ctx
)
Log.d(TAG, "client secret is $clientSecret")
Log.d(TAG, "init took ${System.currentTimeMillis() - start} ms")
refreshUi()
}
Expand All @@ -45,8 +52,12 @@ class MainVm(app: Application) : AndroidViewModel(app) {

fun refreshUi() {
Log.d(TAG, "refreshing UI")
val messageValue = client.getStringValue("hawkflag.message", "default")
val colorFlag = client.getStringDetails("hawkflag.color", "Gray").apply {
val flagMessageKey = "myFlag.message"
val flagMessageDefault = "default"
val messageValue = client.getStringValue(flagMessageKey, flagMessageDefault)
val flagColorKey = "myFlag.color"
val flagColorDefault = "Gray"
val colorFlag = client.getStringDetails(flagColorKey, flagColorDefault).apply {
Log.d(TAG, "reason=$reason")
Log.d(TAG, "variant=$variant")
}.toComposeColor()
Expand Down
1 change: 1 addition & 0 deletions ConfidenceDemoApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">ConfidenceDemoApp</string>
<string name="client_secret">Some client secret</string>
</resources>

0 comments on commit 394c662

Please sign in to comment.