11package com.ticketmaster.sampleintegration.demo
22
33import android.os.Bundle
4+ import android.util.Log
45import android.view.LayoutInflater
56import android.view.Menu
67import android.view.MenuItem
@@ -14,6 +15,7 @@ import androidx.compose.ui.graphics.Color
1415import androidx.constraintlayout.widget.ConstraintLayout
1516import androidx.lifecycle.LiveData
1617import androidx.lifecycle.MutableLiveData
18+ import androidx.lifecycle.Observer
1719import androidx.lifecycle.lifecycleScope
1820import com.ticketmaster.authenticationsdk.AuthSource
1921import com.ticketmaster.authenticationsdk.TMAuthentication
@@ -26,9 +28,11 @@ import com.ticketmaster.tickets.event_tickets.ModuleBase
2628import com.ticketmaster.tickets.event_tickets.NAMWebPageSettings
2729import com.ticketmaster.tickets.event_tickets.TicketsSDKModule
2830import com.ticketmaster.tickets.event_tickets.SeatUpgradesModule
31+ import com.ticketmaster.tickets.eventanalytic.UserAnalyticsDelegate
2932import com.ticketmaster.tickets.ticketssdk.TicketsColors
3033import com.ticketmaster.tickets.ticketssdk.TicketsSDKClient
3134import com.ticketmaster.tickets.ticketssdk.TicketsSDKSingleton
35+ import com.ticketmaster.tickets.util.TMTicketsBrandingColor
3236import com.ticketmaster.tickets.venuenext.VenueNextModule
3337import kotlinx.coroutines.launch
3438import kotlinx.coroutines.runBlocking
@@ -63,12 +67,19 @@ class TicketsSdkHostActivity : AppCompatActivity() {
6367 }
6468 }
6569
70+ private val ticketColor: Int by lazy { android.graphics.Color .parseColor(" #ef3e42" ) }
71+
72+ private val brandingColor: Int by lazy { android.graphics.Color .parseColor(BuildConfig .BRANDING_COLOR ) }
73+
74+ private val headerColor: Int by lazy { android.graphics.Color .parseColor(BuildConfig .BRANDING_COLOR ) }
75+
6676 override fun onCreate (savedInstanceState : Bundle ? ) {
6777 super .onCreate(savedInstanceState)
6878 setContentView(R .layout.activity_tickets_sdk_host)
6979 mGettingStartedContainer.visibility = View .VISIBLE
7080 mProgressDialog.show()
7181 setupAuthenticationSDK()
82+ setupAnalytics()
7283 }
7384
7485 private fun setupAuthenticationSDK () {
@@ -86,7 +97,7 @@ class TicketsSdkHostActivity : AppCompatActivity() {
8697 .apiKey(BuildConfig .CONSUMER_KEY ) // Your consumer key
8798 .clientName(BuildConfig .TEAM_NAME ) // Team name to be displayed
8899 // Optional value to define the colors for the Authentication page
89- .colors(createTMAuthenticationColors(android.graphics. Color .parseColor( BuildConfig . BRANDING_COLOR ) ))
100+ .colors(createTMAuthenticationColors(brandingColor ))
90101 .region(TMXDeploymentRegion .US ) // Region that the SDK will use. Default is US
91102 .environment(TMXDeploymentEnvironment .Production ) // Environment that the SDK will use. Default is Production
92103
@@ -114,6 +125,8 @@ class TicketsSdkHostActivity : AppCompatActivity() {
114125 // After creating the TicketsSDKClient object, add it into the TicketsSDKSingleton
115126 TicketsSDKSingleton .setTicketsSdkClient(this )
116127
128+ setupTicketsColors()
129+
117130 // Validate if there is an active token.
118131 if (tokenMap.isNotEmpty()) {
119132 // If there is an active token, it launches the event fragment
@@ -125,6 +138,10 @@ class TicketsSdkHostActivity : AppCompatActivity() {
125138 }
126139 }
127140 }
141+ if (authentication.configuration == null ) {
142+ mProgressDialog.dismiss()
143+ mCancelledDialog.show()
144+ }
128145 }
129146
130147 private suspend fun validateAuthToken (authentication : TMAuthentication ): Map <AuthSource , String > {
@@ -144,6 +161,17 @@ class TicketsSdkHostActivity : AppCompatActivity() {
144161 darkColors(primary = Color (color), primaryVariant = Color (color), secondary = Color (color))
145162 )
146163
164+ private fun setupTicketsColors () {
165+ // Affects the color of the container of ticket.
166+ TMTicketsBrandingColor .setTicketColor(this @TicketsSdkHostActivity, ticketColor)
167+
168+ // Affects the branding color, like the color of the buttons
169+ TMTicketsBrandingColor .setBrandingColor(this @TicketsSdkHostActivity, brandingColor)
170+
171+ // Affects the header color
172+ TMTicketsBrandingColor .setHeaderColor(this @TicketsSdkHostActivity, headerColor)
173+ }
174+
147175 private fun launchTicketsView () {
148176 mGettingStartedContainer.visibility = View .GONE
149177 mProgressDialog.dismiss()
@@ -158,14 +186,35 @@ class TicketsSdkHostActivity : AppCompatActivity() {
158186 ActivityResultContracts .StartActivityForResult ()
159187 ) { result ->
160188 when (result.resultCode) {
161- RESULT_OK -> launchTicketsView()
189+ RESULT_OK -> {
190+ launchTicketsView()
191+ }
162192 RESULT_CANCELED -> {
163193 mProgressDialog.dismiss()
164- mCancelledDialog.show()
165194 }
166195 }
167196 }
168197
198+ private fun setupAnalytics () {
199+ // Initialize observer that will handle the analytics events
200+ // Must be called the observeForever as this will kept alive the observer until
201+ // the Activity is destroyed
202+ UserAnalyticsDelegate .handler.getLiveData().observeForever(userAnalyticsObserver)
203+ }
204+
205+ override fun onDestroy () {
206+ super .onDestroy()
207+ // Remove the observer in the onDestroy, as it won't be needed to keep traking
208+ // the analytics events.
209+ UserAnalyticsDelegate .handler.getLiveData().removeObserver(userAnalyticsObserver)
210+ }
211+
212+ private val userAnalyticsObserver = Observer <UserAnalyticsDelegate .AnalyticsData ?> {
213+ it?.let {
214+ Log .d(" Analytics" , " Action name: ${it.actionName} , data: ${it.data} " )
215+ }
216+ }
217+
169218 /* *
170219 * This is only an example of how to integrate Venue Next SDK with the Presence SDK.
171220 * You don't need to do it, if it's not necessary for your project.
@@ -188,7 +237,8 @@ class TicketsSdkHostActivity : AppCompatActivity() {
188237 TicketsSDKSingleton .moduleDelegate = object : TicketsModuleDelegate {
189238
190239 override fun getCustomModulesLiveData (order : TicketsModuleDelegate .Order ): LiveData <List <TicketsSDKModule >> {
191- val liveData: MutableLiveData <List <TicketsSDKModule >> = MutableLiveData <List <TicketsSDKModule >>()
240+ val liveData: MutableLiveData <List <TicketsSDKModule >> =
241+ MutableLiveData <List <TicketsSDKModule >>()
192242 val modules: ArrayList <TicketsSDKModule > = ArrayList ()
193243 modules.add(getModuleBaseVenueNextView())
194244 modules.add(getDirectionsModule(order.orderInfo.latLng))
@@ -276,7 +326,15 @@ class TicketsSdkHostActivity : AppCompatActivity() {
276326
277327 private fun logout () {
278328 // Logout from TicketsSDKClient and TMAuthentication
279- TicketsSDKSingleton .logout(this @TicketsSdkHostActivity)
329+ TicketsSDKSingleton .logout(this @TicketsSdkHostActivity) {
330+ // listener call after the logout process is completed.
331+ resultLauncher.launch(TicketsSDKSingleton .getLoginIntent(this ))
332+
333+ // remove the fragment from the container
334+ supportFragmentManager.findFragmentById(R .id.tickets_sdk_view)?.let {
335+ supportFragmentManager.beginTransaction().remove(it).commit()
336+ }
337+ }
280338 }
281339
282340 // By calling the runBlocking function, it runs the suspend function in the Main Thread.
0 commit comments