Skip to content

Commit e98d011

Browse files
committed
Release 1.7
1 parent 0b49614 commit e98d011

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId = "io.branch.branchlinksimulator"
1212
minSdk = 26
1313
targetSdk = 34
14-
versionCode = 16
15-
versionName = "1.6"
14+
versionCode = 17
15+
versionName = "1.7"
1616

1717
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1818
vectorDrawables {

app/src/main/java/io/branch/branchlinksimulator/BranchLinkSimulatorApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BranchLinkSimulatorApplication: Application() {
1111

1212
// Branch logging for debugging
1313
Branch.enableLogging()
14-
Branch.setAPIUrl("https://protected-api-test.branch.io/")
14+
Branch.setAPIUrl("https://protected-api.branch.io/")
1515

1616
// Branch object initialization
1717
Branch.getAutoInstance(this)

app/src/main/java/io/branch/branchlinksimulator/MainActivity.kt

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ import androidx.compose.ui.unit.sp
6565
import io.branch.referral.PrefHelper
6666
import java.util.UUID
6767

68-
var customerEventAlias = "alias"
68+
var customerEventAlias = ""
69+
var sessionID = ""
6970

7071
class MainActivity : ComponentActivity() {
7172
private var navController: NavHostController? = null
@@ -155,14 +156,20 @@ fun MainContent(navController: NavController) {
155156
var showSessionIdDialog by remember { mutableStateOf(false) }
156157

157158
var textFieldValue by remember { mutableStateOf(PrefHelper.getInstance(context).apiBaseUrl) }
158-
var aliasValue by remember { mutableStateOf("") }
159159

160160
val sharedPreferences = context.getSharedPreferences("branch_session_prefs", Context.MODE_PRIVATE)
161161
val blsSessionId = sharedPreferences.getString("bls_session_id", null) ?: UUID.randomUUID().toString().also {
162162
sharedPreferences.edit().putString("bls_session_id", it).apply()
163163
}
164+
sessionID = blsSessionId
164165
var sessionIdValue by remember { mutableStateOf(blsSessionId) }
165166

167+
val savedAlias = sharedPreferences.getString("customer_event_alias", null) ?: "".also {
168+
sharedPreferences.edit().putString("customer_event_alias", it).apply()
169+
}
170+
customerEventAlias = savedAlias
171+
var aliasValue by remember { mutableStateOf(savedAlias) }
172+
166173
Column(modifier = Modifier.padding(16.dp)) {
167174
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
168175
Image(
@@ -232,6 +239,7 @@ fun MainContent(navController: NavController) {
232239
},
233240
confirmButton = {
234241
TextButton(onClick = {
242+
sharedPreferences.edit().putString("customer_event_alias", aliasValue).apply()
235243
customerEventAlias = aliasValue
236244
Toast.makeText(context, "Set Customer Event Alias to $aliasValue", Toast.LENGTH_SHORT).show()
237245
showAliasDialog = false
@@ -301,12 +309,46 @@ fun ButtonRow(navController: NavController, modifier: Modifier = Modifier) {
301309

302310
@Composable
303311
fun FunctionButtonRow(modifier: Modifier = Modifier, context: android.content.Context) {
312+
val showDialog = remember { mutableStateOf(false) }
313+
314+
fun sendEvent(eventType: String) {
315+
when (eventType) {
316+
"Purchase" -> sendStandardEvent(context, BRANCH_STANDARD_EVENT.PURCHASE)
317+
"Add to Cart" -> sendStandardEvent(context, BRANCH_STANDARD_EVENT.ADD_TO_CART)
318+
"Login" -> sendStandardEvent(context, BRANCH_STANDARD_EVENT.LOGIN)
319+
"Search" -> sendStandardEvent(context, BRANCH_STANDARD_EVENT.SEARCH)
320+
"Share" -> sendStandardEvent(context, BRANCH_STANDARD_EVENT.SHARE)
321+
}
322+
showDialog.value = false
323+
}
324+
304325
Column(modifier = modifier) {
305326
RoundedButton(
306327
title = "Send Standard Event",
307328
icon = R.drawable.send
308329
)
309-
{ sendStandardEvent(context) }
330+
{ showDialog.value = true }
331+
if (showDialog.value) {
332+
// Dialog with event options
333+
AlertDialog(
334+
onDismissRequest = { showDialog.value = false },
335+
title = { Text("Choose Event Type") },
336+
text = {
337+
Column {
338+
Button(onClick = { sendEvent("Purchase") }) { Text("Purchase") }
339+
Button(onClick = { sendEvent("Add to Cart") }) { Text("Add to Cart") }
340+
Button(onClick = { sendEvent("Login") }) { Text("Login") }
341+
Button(onClick = { sendEvent("Search") }) { Text("Search") }
342+
Button(onClick = { sendEvent("Share") }) { Text("Share") }
343+
}
344+
},
345+
confirmButton = {
346+
Button(onClick = { showDialog.value = false }) {
347+
Text("Cancel")
348+
}
349+
}
350+
)
351+
}
310352

311353
RoundedButton(
312354
title = "Send Custom Event",
@@ -316,10 +358,13 @@ fun FunctionButtonRow(modifier: Modifier = Modifier, context: android.content.Co
316358
}
317359
}
318360

319-
fun sendStandardEvent(context: android.content.Context) {
320-
BranchEvent(BRANCH_STANDARD_EVENT.SEARCH).setCustomerEventAlias(customerEventAlias).logEvent(context, object : BranchLogEventCallback {
361+
fun sendStandardEvent(context: Context, event: BRANCH_STANDARD_EVENT) {
362+
BranchEvent(event)
363+
.setCustomerEventAlias(customerEventAlias)
364+
.addCustomDataProperty("bls_session_id", sessionID)
365+
.logEvent(context, object : BranchLogEventCallback {
321366
override fun onSuccess(responseCode: Int) {
322-
Toast.makeText(context, "Sent Standard Event!", Toast.LENGTH_SHORT).show()
367+
Toast.makeText(context, "Sent ${event.getName()} Event!", Toast.LENGTH_SHORT).show()
323368
}
324369

325370
override fun onFailure(e: Exception) {
@@ -328,7 +373,10 @@ fun sendStandardEvent(context: android.content.Context) {
328373
})
329374
}
330375
fun sendCustomEvent(context: android.content.Context) {
331-
BranchEvent("My Custom Event").setCustomerEventAlias(customerEventAlias).logEvent(context, object : BranchLogEventCallback {
376+
BranchEvent("My Custom Event")
377+
.setCustomerEventAlias(customerEventAlias)
378+
.addCustomDataProperty("bls_session_id", sessionID)
379+
.logEvent(context, object : BranchLogEventCallback {
332380
override fun onSuccess(responseCode: Int) {
333381
Toast.makeText(context, "Sent Custom Event!", Toast.LENGTH_SHORT).show()
334382
}

0 commit comments

Comments
 (0)