-
Notifications
You must be signed in to change notification settings - Fork 1
AB#280444 - Add Gamify Widget SDK module and QA app integration #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rustam-k-optimove
merged 7 commits into
master
from
feature/280444-gamify-widget-sdk-integration
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dec128d
Add Gamify Widget SDK module and QA app integration
dmytro-b-optimove 0253f93
AB#280444 - fix AndroidBridgeTest missing onReady parameter
dmytro-b-optimove 148b39f
AB#280444 - remove Log.d from AndroidBridge to fix unit tests
dmytro-b-optimove 26c1708
AB#280444 - gamify-widget-sdk use JSON parsing for READY detection in…
dmytro-b-optimove 7a70278
AB#280444 - gamify-widget-sdk redact token in INIT log
dmytro-b-optimove 38ab215
AB#280444 - bump version to 7.13.0 and update CHANGELOG
dmytro-b-optimove e4b9403
AB#280444 - merge master, resolve version conflict (7.13.0)
dmytro-b-optimove File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
OptimoveSDK/app/src/main/java/com/optimove/android/optimovemobilesdk/GamifyWidgetActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.optimove.android.optimovemobilesdk | ||
|
|
||
| import android.content.Context | ||
| import android.content.SharedPreferences | ||
| import android.os.Bundle | ||
| import androidx.activity.compose.setContent | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.setValue | ||
| import com.optimove.android.gamifywidgetsdk.GamifyWidgetSDK | ||
| import com.optimove.android.optimovemobilesdk.ui.GamifyWidgetScreen | ||
| import com.optimove.android.optimovemobilesdk.ui.theme.AppTheme | ||
|
|
||
| enum class GamifyEnv(val label: String, val baseUrl: String) { | ||
| DEV("Dev", "https://opti-ls-widget-dev.optimove.net"), | ||
| PROD_US("Prod US", "https://opti-ls-widget-us.optimove.net"), | ||
| PROD_EU("Prod EU", "https://opti-ls-widget-eu.optimove.net") | ||
| } | ||
|
|
||
| class GamifyWidgetActivity : AppCompatActivity() { | ||
|
|
||
| private lateinit var prefs: SharedPreferences | ||
|
|
||
| private var tenant by mutableStateOf("") | ||
| private var userId by mutableStateOf("") | ||
| private var env by mutableStateOf(GamifyEnv.DEV) | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) | ||
| tenant = prefs.getString(KEY_TENANT, "") ?: "" | ||
| userId = prefs.getString(KEY_USER_ID, "") ?: "" | ||
| env = enumValues<GamifyEnv>().find { it.name == prefs.getString(KEY_ENV, null) } ?: GamifyEnv.DEV | ||
|
|
||
| setContent { | ||
| AppTheme { | ||
| GamifyWidgetScreen( | ||
| tenant = tenant, | ||
| userId = userId, | ||
| env = env, | ||
| onTenantChange = { tenant = it; save() }, | ||
| onWidgetIdChange = { userId = it; save() }, | ||
| onEnvChange = { env = it; save() }, | ||
| onOpenWidget = ::openWidget | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun save() { | ||
| prefs.edit() | ||
| .putString(KEY_TENANT, tenant) | ||
| .putString(KEY_USER_ID, userId) | ||
| .putString(KEY_ENV, env.name) | ||
| .apply() | ||
| } | ||
|
|
||
| private fun openWidget() { | ||
| val widgetUrl = "${env.baseUrl}/$tenant/$userId" | ||
| GamifyWidgetSDK.init(widgetUrl = widgetUrl) | ||
| GamifyWidgetSDK.open(supportFragmentManager) | ||
| } | ||
|
|
||
| companion object { | ||
| private const val PREFS_NAME = "gamify_widget_config" | ||
| private const val KEY_TENANT = "tenant" | ||
| private const val KEY_USER_ID = "user_id" | ||
| private const val KEY_ENV = "env" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...moveSDK/app/src/main/java/com/optimove/android/optimovemobilesdk/ui/GamifyWidgetScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package com.optimove.android.optimovemobilesdk.ui | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.OutlinedButton | ||
| import androidx.compose.material3.OutlinedTextField | ||
| import androidx.compose.material3.OutlinedTextFieldDefaults | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import com.optimove.android.optimovemobilesdk.GamifyEnv | ||
| import androidx.compose.foundation.layout.Row | ||
|
|
||
| private val CardShape = RoundedCornerShape(12.dp) | ||
| private val SectionPadding = 16.dp | ||
|
|
||
| @Composable | ||
| fun GamifyWidgetScreen( | ||
| tenant: String, | ||
| userId: String, | ||
| env: GamifyEnv, | ||
| onTenantChange: (String) -> Unit, | ||
| onWidgetIdChange: (String) -> Unit, | ||
| onEnvChange: (GamifyEnv) -> Unit, | ||
| onOpenWidget: () -> Unit | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .background(MaterialTheme.colorScheme.surface) | ||
| .padding(SectionPadding) | ||
| ) { | ||
| Text( | ||
| "Gamify Widget", | ||
| style = MaterialTheme.typography.titleLarge, | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(vertical = 8.dp) | ||
| ) | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
| Surface( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| shape = CardShape, | ||
| color = MaterialTheme.colorScheme.surfaceVariant | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.padding(SectionPadding), | ||
| verticalArrangement = Arrangement.spacedBy(8.dp) | ||
| ) { | ||
| OutlinedTextField( | ||
| value = tenant, | ||
| onValueChange = onTenantChange, | ||
| label = { Text("Tenant") }, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| singleLine = true, | ||
| colors = OutlinedTextFieldDefaults.colors( | ||
| focusedBorderColor = MaterialTheme.colorScheme.primary, | ||
| focusedLabelColor = MaterialTheme.colorScheme.primary, | ||
| cursorColor = MaterialTheme.colorScheme.primary | ||
| ) | ||
| ) | ||
| OutlinedTextField( | ||
| value = userId, | ||
| onValueChange = onWidgetIdChange, | ||
| label = { Text("User ID") }, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| singleLine = true, | ||
| colors = OutlinedTextFieldDefaults.colors( | ||
| focusedBorderColor = MaterialTheme.colorScheme.primary, | ||
| focusedLabelColor = MaterialTheme.colorScheme.primary, | ||
| cursorColor = MaterialTheme.colorScheme.primary | ||
| ) | ||
| ) | ||
| Text( | ||
| "Environment", | ||
| style = MaterialTheme.typography.labelMedium, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant | ||
| ) | ||
| Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { | ||
| enumValues<GamifyEnv>().forEach { option -> | ||
| if (env == option) { | ||
| Button( | ||
| onClick = { onEnvChange(option) }, | ||
| shape = RoundedCornerShape(10.dp) | ||
| ) { | ||
| Text(option.label) | ||
| } | ||
| } else { | ||
| OutlinedButton( | ||
| onClick = { onEnvChange(option) }, | ||
| shape = RoundedCornerShape(10.dp), | ||
| colors = ButtonDefaults.outlinedButtonColors( | ||
| contentColor = MaterialTheme.colorScheme.onSurfaceVariant | ||
| ) | ||
| ) { | ||
| Text(option.label) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| Button( | ||
| onClick = onOpenWidget, | ||
| enabled = tenant.isNotBlank() && userId.isNotBlank(), | ||
| modifier = Modifier.fillMaxWidth(), | ||
| shape = RoundedCornerShape(10.dp) | ||
| ) { | ||
| Text("Open Widget") | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| apply plugin: 'com.android.library' | ||
| apply plugin: 'kotlin-android' | ||
|
|
||
| android { | ||
| namespace 'com.optimove.android.gamifywidgetsdk' | ||
| compileSdk 34 | ||
|
|
||
| defaultConfig { | ||
| minSdk 21 | ||
| targetSdk 34 | ||
| consumerProguardFiles 'proguard-rules.pro' | ||
| testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
|
|
||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_17 | ||
| targetCompatibility JavaVersion.VERSION_17 | ||
| } | ||
| kotlinOptions { | ||
| jvmTarget = "17" | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22' | ||
| implementation 'androidx.appcompat:appcompat:1.3.1' | ||
| implementation 'androidx.fragment:fragment-ktx:1.6.2' | ||
| implementation 'com.google.android.material:material:1.9.0' | ||
| testImplementation 'junit:junit:4.13.2' | ||
| testImplementation 'org.json:json:20230227' | ||
| testImplementation 'org.mockito:mockito-core:5.11.0' | ||
| testImplementation 'org.mockito.kotlin:mockito-kotlin:5.3.1' | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -keep class com.optimove.android.gamifywidgetsdk.** { *; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| </manifest> |
40 changes: 40 additions & 0 deletions
40
...SDK/gamify-widget-sdk/src/main/java/com/optimove/android/gamifywidgetsdk/AndroidBridge.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.optimove.android.gamifywidgetsdk | ||
|
|
||
| import android.util.Log | ||
| import android.webkit.JavascriptInterface | ||
| import org.json.JSONException | ||
| import org.json.JSONObject | ||
|
|
||
| /** | ||
| * Native bridge exposed to the widget's JavaScript as `window.AndroidBridge`. | ||
| * | ||
| * The widget calls: | ||
| * window.AndroidBridge.closeWidget() — to dismiss the bottom sheet | ||
| * window.AndroidBridge.receiveMessage(json) — generic widget → SDK messages, | ||
| * including the READY handshake (type = "READY") | ||
| */ | ||
| internal class AndroidBridge( | ||
| private val onClose: () -> Unit, | ||
| private val onReady: () -> Unit | ||
| ) { | ||
|
|
||
| @JavascriptInterface | ||
| fun closeWidget() { | ||
| onClose() | ||
| } | ||
|
|
||
| @JavascriptInterface | ||
| fun receiveMessage(json: String) { | ||
| try { | ||
| if (JSONObject(json).getString("type") == "READY") { | ||
| onReady() | ||
| } | ||
| } catch (e: JSONException) { | ||
| Log.d(TAG, "Incorrect message format: $json") | ||
| } | ||
| } | ||
|
dmytro-b-optimove marked this conversation as resolved.
|
||
|
|
||
| companion object { | ||
| private const val TAG = "GamifyWidget" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.