Skip to content
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

fix: added alternative route to fetch screen name for automatic tracking #92

Merged
merged 2 commits into from Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Shahroz16 marked this conversation as resolved.
Show resolved Hide resolved
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"
}
}