1+ package io.deepone.app
2+
3+ import android.os.Bundle
4+ import android.widget.Toast
5+ import androidx.activity.ComponentActivity
6+ import androidx.activity.compose.setContent
7+ import androidx.activity.enableEdgeToEdge
8+ import androidx.compose.foundation.layout.fillMaxSize
9+ import androidx.compose.foundation.layout.padding
10+ import androidx.compose.material3.Scaffold
11+ import androidx.compose.material3.Text
12+ import androidx.compose.runtime.Composable
13+ import androidx.compose.ui.Modifier
14+ import androidx.compose.ui.tooling.preview.Preview
15+ import io.deepone.app.ui.theme.ExampleTheme
16+ import io.deepone.sdk.DeepOne
17+ import io.deepone.sdk.DeepOneCreateLinkBuilder
18+
19+ class MainActivity : ComponentActivity () {
20+ override fun onCreate (savedInstanceState : Bundle ? ) {
21+ super .onCreate(savedInstanceState)
22+ setupDeepOne()
23+ enableEdgeToEdge()
24+ setContent {
25+ ExampleTheme {
26+ Scaffold (modifier = Modifier .fillMaxSize()) { innerPadding ->
27+ Greeting (
28+ name = " Android" ,
29+ modifier = Modifier .padding(innerPadding)
30+ )
31+ }
32+ }
33+ }
34+ }
35+
36+ fun setupDeepOne () {
37+ // Initialize DeepOne SDK with attribution handler
38+ DeepOne .shared.configure(
39+ context = this , // Use Activity context for UI operations
40+ developmentMode = true // Set to false in production
41+ ) { attributionData, error ->
42+ if (error != null ) {
43+ updateStatus(" Attribution failed: ${error.message} " )
44+ } else if (attributionData != null ) {
45+ updateStatus(" Attribution received!" )
46+ updateStatus(" Origin URL: ${attributionData.originURL ? : " N/A" } " )
47+ updateStatus(" Route host: ${attributionData.routeHost ? : " N/A" } " )
48+ updateStatus(" Route Path: ${attributionData.routePath ? : " N/A" } " )
49+ updateStatus(" Query Params: ${attributionData.queryParameters} " )
50+ updateStatus(" Is First Session: ${attributionData.isFirstSession} " )
51+ if (attributionData.marketingSource != null ) {
52+ updateStatus(" Marketing: ${attributionData.marketingSource} /${attributionData.marketingMedium} " )
53+ }
54+ // Handle attribution data here
55+ } else {
56+ updateStatus(" No attribution data" )
57+ }
58+ }
59+ }
60+
61+ private fun testCreateLinkFunction () {
62+ updateStatus(" Testing createLink function..." )
63+
64+ // Create link configuration using builder pattern
65+ val linkBuilder = DeepOneCreateLinkBuilder (
66+ destinationPath = " /product/123" ,
67+ linkIdentifier = " example_link"
68+ ).setMarketingAttribution(
69+ source = " android_app" ,
70+ medium = " mobile" ,
71+ campaign = " example_campaign" ,
72+ content = " test_link"
73+ ).setSocialPreview(
74+ title = " Check out this product!" ,
75+ description = " Amazing product you'll love"
76+ )
77+
78+ DeepOne .shared.createAttributedLink(linkBuilder) { url, error ->
79+ runOnUiThread {
80+ if (error != null ) {
81+ updateStatus(" Link creation failed: ${error.message} " )
82+ Toast .makeText(this , " Link creation failed" , Toast .LENGTH_SHORT ).show()
83+ } else if (url != null ) {
84+ updateStatus(" Link created successfully: $url " )
85+ Toast .makeText(this , " Link created!" , Toast .LENGTH_SHORT ).show()
86+ } else {
87+ updateStatus(" Link creation returned null" )
88+ }
89+ }
90+ }
91+ }
92+
93+ private fun updateStatus (message : String ) {
94+ // log to console for debugging
95+ println (" MainActivity: $message " )
96+ }
97+ }
98+
99+ @Composable
100+ fun Greeting (name : String , modifier : Modifier = Modifier ) {
101+ Text (
102+ text = " Hello $name !" ,
103+ modifier = modifier
104+ )
105+ }
106+
107+ @Preview(showBackground = true )
108+ @Composable
109+ fun GreetingPreview () {
110+ ExampleTheme {
111+ Greeting (" Android" )
112+ }
113+ }
0 commit comments