Skip to content

Commit

Permalink
fix: added alternative route to fetch screen name for automatic track…
Browse files Browse the repository at this point in the history
…ing (customerio#92)
  • Loading branch information
Shahroz16 committed Apr 30, 2022
1 parent 1789ebf commit 37a20b5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 15 deletions.
1 change: 0 additions & 1 deletion base/src/main/java/io/customer/base/comunication/Action.kt
Expand Up @@ -40,4 +40,3 @@ interface Action<T : Any> {
fun onResult(result: Result<T>)
}
}

1 change: 0 additions & 1 deletion base/src/main/java/io/customer/base/comunication/Call.kt
Expand Up @@ -39,4 +39,3 @@ public interface Call<T : Any> {
public fun onResult(result: Result<T>)
}
}

2 changes: 0 additions & 2 deletions base/src/main/java/io/customer/base/utils/ActionUtils.kt
Expand Up @@ -46,7 +46,5 @@ abstract class ActionUtils {
override fun cancel() {}
}
}

}

}
Expand Up @@ -41,5 +41,4 @@ object Dependencies {
const val okhttpMockWebserver = "com.squareup.okhttp3:mockwebserver:${Versions.OKHTTP}"
const val okhttpLoggingInterceptor =
"com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}"

}
Expand Up @@ -64,7 +64,6 @@ class CustomerIOFirebaseMessagingService : FirebaseMessagingService() {
}
}


private fun handleMessageReceived(
context: Context,
remoteMessage: RemoteMessage,
Expand All @@ -73,7 +72,6 @@ class CustomerIOFirebaseMessagingService : FirebaseMessagingService() {
val handler = CustomerIOPushNotificationHandler(remoteMessage = remoteMessage)
return handler.handleMessage(context, handleNotificationTrigger)
}

}

override fun onNewToken(token: String) {
Expand Down
Expand Up @@ -36,7 +36,6 @@ class CustomerIOPushNotificationHandler(private val remoteMessage: RemoteMessage
const val BODY_KEY = "body"

const val NOTIFICATION_REQUEST_CODE = "requestCode"

}

private val bundle: Bundle by lazy {
Expand Down Expand Up @@ -87,7 +86,6 @@ class CustomerIOPushNotificationHandler(private val remoteMessage: RemoteMessage
return true
}


@SuppressLint("LaunchActivityFromNotification")
private fun handleNotification(
context: Context
Expand Down Expand Up @@ -135,7 +133,6 @@ class CustomerIOPushNotificationHandler(private val remoteMessage: RemoteMessage
val notificationManager =
context.getSystemService(FirebaseMessagingService.NOTIFICATION_SERVICE) as NotificationManager


val channelName = "$applicationName Notifications"

// Since android Oreo notification channel is needed.
Expand Down Expand Up @@ -165,7 +162,6 @@ class CustomerIOPushNotificationHandler(private val remoteMessage: RemoteMessage
notificationManager.notify(requestCode, notification)
}


private fun addImage(
imageUrl: String,
builder: NotificationCompat.Builder,
Expand All @@ -188,6 +184,4 @@ class CustomerIOPushNotificationHandler(private val remoteMessage: RemoteMessage
builder.setStyle(style)
}
}


}
Expand Up @@ -78,4 +78,3 @@ class CustomerIOPushReceiver : BroadcastReceiver() {
}
}
}

7 changes: 6 additions & 1 deletion sdk/src/main/java/io/customer/sdk/CustomerIO.kt
Expand Up @@ -13,6 +13,7 @@ import io.customer.sdk.data.model.Region
import io.customer.sdk.data.request.MetricEvent
import io.customer.sdk.data.store.CustomerIOStore
import io.customer.sdk.di.CustomerIOComponent
import io.customer.sdk.extensions.getScreenNameFromActivity

/**
Welcome to the Customer.io Android SDK!
Expand Down Expand Up @@ -205,7 +206,11 @@ class CustomerIO internal constructor(
activity.componentName, PackageManager.GET_META_DATA
)
val activityLabel = info.loadLabel(packageManager)
screen(activityLabel.toString(), attributes)

val screenName = activityLabel.toString().ifEmpty {
activity::class.java.simpleName.getScreenNameFromActivity()
}
screen(screenName, attributes)
} catch (e: PackageManager.NameNotFoundException) {
ActionUtils.getErrorAction(ErrorResult(error = ErrorDetail(message = "Activity Not Found: $e")))
} catch (e: Exception) {
Expand Down
@@ -0,0 +1,9 @@
package io.customer.sdk.extensions

fun String.getScreenNameFromActivity(): String {
val regex = Regex(
pattern = "Activity|ListActivity|FragmentActivity|DialogActivity",
option = RegexOption.IGNORE_CASE
)
return this.replace(regex, "")
}
@@ -0,0 +1,18 @@
package io.customer.sdk.extensions

import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test

internal class StringExtensionsTest {

@Test
fun verify_activityScreenFormatting_expectFormattedScreenName() {

"HomeActivity".getScreenNameFromActivity() shouldBeEqualTo "Home"
"ActivityHome".getScreenNameFromActivity() shouldBeEqualTo "Home"
"ActivityHomeActivity".getScreenNameFromActivity() shouldBeEqualTo "Home"
"ItemsListActivity".getScreenNameFromActivity() shouldBeEqualTo "Items"
"ItemsDialogActivity".getScreenNameFromActivity() shouldBeEqualTo "Items"
"MapFragmentActivity".getScreenNameFromActivity() shouldBeEqualTo "Map"
}
}

0 comments on commit 37a20b5

Please sign in to comment.