Skip to content

Commit

Permalink
chore: merge current v7.7.0 changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
maureenorea-clores committed Sep 19, 2024
1 parent e6d822e commit ab97a3e
Show file tree
Hide file tree
Showing 31 changed files with 294 additions and 98 deletions.
6 changes: 6 additions & 0 deletions inappmessaging/USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ All the events "launch the app event, login event, purchase successful event, cu
<details>
<summary style="cursor: pointer;";>(click to expand)</summary>

#### 7.7.0 (In-Progress)
* Improvements:
- RMCCX-6876: Improved console logging.
* RMC SDK updates:
- RMCCX-7186: Supported Clickable Image through CustomJson.

#### 7.6.0 (2024-09-17)
* Improvements:
- SDKCF-6327: Updated compile and target SDK to API 34 (Android 14).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ internal object EventTrackerHelper {
com.rakuten.tech.mobile.analytics.RatTracker.event(eventName, serializableData).track()
return true
} catch (e: Exception) {
InAppLogger(TAG).warn("Could not send event: $e")
InAppLogger(TAG).warn("sendEvent - analytics.track() failed")
InAppLogger(TAG).debug("exception: $e")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ internal class InApp(
override var onPushPrimer: (() -> Unit)? = null

override fun registerPreference(userInfoProvider: UserInfoProvider) {
InAppLogger(TAG).info("registerPreference - userInfoProvider: $userInfoProvider")
InAppLogger(TAG).info("registerPreference: $userInfoProvider")
accountRepo.userInfoProvider = userInfoProvider
}

@SuppressWarnings("TooGenericExceptionCaught")
override fun registerMessageDisplayActivity(activity: Activity) {
InAppLogger(TAG).info("registerMessageDisplayActivity - Activity: $activity")
InAppLogger(TAG).info("registerActivity: $activity")
try {
hostAppInfoRepo.registerActivity(activity)
// Making worker thread to display message.
if (configRepo.isConfigEnabled()) {
displayManager.displayMessage()
}
} catch (ex: Exception) {
InAppLogger(TAG).error("registerActivity - error: ${ex.message}")
errorCallback?.let {
it(InAppMessagingException("In-App Messaging register activity failed", ex))
}
Expand All @@ -79,13 +80,14 @@ internal class InApp(

@SuppressWarnings("FunctionMaxLength", "TooGenericExceptionCaught")
override fun unregisterMessageDisplayActivity() {
InAppLogger(TAG).info("unregisterMessageDisplayActivity")
InAppLogger(TAG).info("unregisterActivity")
try {
if (configRepo.isConfigEnabled()) {
displayManager.removeMessage(hostAppInfoRepo.getRegisteredActivity(), removeAll = true)
}
hostAppInfoRepo.registerActivity(null)
} catch (ex: Exception) {
InAppLogger(TAG).warn("unregisterActivity - error: ${ex.message}")
errorCallback?.let {
it(InAppMessagingException("In-App Messaging unregister activity failed", ex))
}
Expand All @@ -102,48 +104,50 @@ internal class InApp(
val isSameUser = !accountRepo.updateUserInfo()
val areCampaignsSynced = campaignRepo.lastSyncMillis != null && eventMatchingUtil.eventBuffer.isEmpty()

InAppLogger(TAG).debug(
"name: ${event.getEventName()}, attributes: ${event.getAttributeMap()}, " +
"isConfigEnabled: $isConfigEnabled, isSameUser: $isSameUser, synced: $areCampaignsSynced",
InAppLogger(TAG).info(
"logEvent: ${event.getEventName()} - isConfigEnabled: $isConfigEnabled," +
" isSameUser: $isSameUser, synced: $areCampaignsSynced",
)
InAppLogger(TAG).debug("attributes: ${event.getAttributeMap()}")

if (!isConfigEnabled || !isSameUser || !areCampaignsSynced) {
// To be processed later (flushed after sync)
InAppLogger(TAG).debug("Event added to buffer")
InAppLogger(TAG).debug("event added to buffer")
eventMatchingUtil.addToEventBuffer(event)
}

if (!isSameUser) {
// Sync campaigns, flush event buffer, then match events
InAppLogger(TAG).debug("There is a change in user, will perform onSessionUpdate")
InAppLogger(TAG).debug("there is a change in user, will perform onSessionUpdate")
sessionManager.onSessionUpdate()
return
}

if (areCampaignsSynced) {
// Match event right away
InAppLogger(TAG).debug("Event ${event.getEventName()} will be processed")
InAppLogger(TAG).debug("event ${event.getEventName()} will be processed")
eventsManager.onEventReceived(event)
}
} catch (ex: Exception) {
InAppLogger(TAG).error("logEvent - error: ${ex.message}")
errorCallback?.let {
it(InAppMessagingException("In-App Messaging log event failed", ex))
}
}
}

override fun closeMessage(clearQueuedCampaigns: Boolean) {
InAppLogger(TAG).info("closeMessage - clearQueuedCampaigns: $clearQueuedCampaigns")
InAppLogger(TAG).info("closeMessage: $clearQueuedCampaigns")
closeCampaign(clearQueuedCampaigns = clearQueuedCampaigns)
}

override fun closeTooltip(viewId: String) {
InAppLogger(TAG).info("closeTooltip - viewId: $viewId")
InAppLogger(TAG).info("closeTooltip: $viewId")
closeCampaign(viewId = viewId)
}

override fun trackPushPrimer(permissions: Array<String>, grantResults: IntArray) {
InAppLogger(TAG).info("trackPushPrimer - permissions: $permissions, grantResults: $grantResults")
InAppLogger(TAG).info("trackPushPrimer - perm: $permissions, res: $grantResults")
if (!BuildVersionChecker.isAndroidTAndAbove()) {
return
}
Expand Down Expand Up @@ -178,6 +182,7 @@ internal class InApp(
removeMessage(viewId)
}
} catch (ex: Exception) {
InAppLogger(TAG).warn("closeCampaign - error: ${ex.message}")
errorCallback?.let {
it(InAppMessagingException("In-App Messaging close message failed", ex))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ abstract class InAppMessaging internal constructor() {
configUrl: String? = null,
enableTooltipFeature: Boolean? = false,
): Boolean {
InAppLogger(TAG).info("configure")
return try {
if (!shouldProcess(subscriptionKey)) {
InAppLogger(TAG).debug("Not processed since RMC is integrated")
InAppLogger(TAG).info("configure called but using RMC, skipping")
return false
}

Expand All @@ -158,6 +157,7 @@ abstract class InAppMessaging internal constructor() {
errorCallback?.let {
it(InAppMessagingException("In-App Messaging configuration failed", ex))
}
InAppLogger(TAG).error("configure - error: ${ex.message}")
false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ internal class MessageActionsCoroutine(
R.id.message_close_button, BACK_BUTTON -> ImpressionType.EXIT
R.id.message_single_button, R.id.message_button_left -> ImpressionType.ACTION_ONE
R.id.message_button_right -> ImpressionType.ACTION_TWO
R.id.slide_up, R.id.message_tooltip_image_view, R.id.message_tip -> ImpressionType.CLICK_CONTENT
R.id.slide_up, R.id.message_tooltip_image_view, R.id.message_tip, R.id.message_image_view ->
ImpressionType.CLICK_CONTENT
else -> ImpressionType.INVALID
}
}
Expand Down Expand Up @@ -165,7 +166,7 @@ internal class MessageActionsCoroutine(
try {
activityContext.startActivity(intent)
} catch (e: ActivityNotFoundException) {
InAppLogger(TAG).debug(e.message)
InAppLogger(TAG).info("handleDeeplinkRedirection - error: ${e.message}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.rakuten.tech.mobile.inappmessaging.runtime.data.customjson

import com.rakuten.tech.mobile.inappmessaging.runtime.data.enums.ButtonActionType
import com.rakuten.tech.mobile.inappmessaging.runtime.data.enums.InAppMessageType
import com.rakuten.tech.mobile.inappmessaging.runtime.data.responses.ping.Content
import com.rakuten.tech.mobile.inappmessaging.runtime.data.responses.ping.OnClickBehavior
import com.rakuten.tech.mobile.inappmessaging.runtime.data.ui.UiMessage

internal fun UiMessage.applyCustomClickableImage(clickableImage: ClickableImage?, isPushPrimer: Boolean): UiMessage {
fun Int.campaignTypeCanBeClickable(): Boolean {
return this in listOf(
InAppMessageType.FULL.typeId,
InAppMessageType.MODAL.typeId,
)
}

@SuppressWarnings("ComplexCondition")
if (clickableImage == null ||
clickableImage.url.isNullOrEmpty() ||
imageUrl.isNullOrEmpty() ||
!type.campaignTypeCanBeClickable() ||
isPushPrimer
) {
return this
}

val newOnclick = OnClickBehavior(action = ButtonActionType.REDIRECT.typeId, uri = clickableImage.url)
return this.copy(
content = if (this.content == null) {
Content(onClick = newOnclick)
} else {
this.content.copy(onClick = newOnclick)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.rakuten.tech.mobile.inappmessaging.runtime.data.customjson

internal data class CustomJson(
val pushPrimer: PushPrimer? = null,
val clickableImage: ClickableImage? = null,
)

internal data class PushPrimer(
Expand All @@ -10,3 +11,10 @@ internal data class PushPrimer(
*/
val button: Int? = null,
)

internal data class ClickableImage(
/**
* Redirect URL or deeplink.
*/
val url: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ internal object MessageMapper : Mapper<Message, UiMessage> {
uiModel
} else {
uiModel
.applyCustomPushPrimer(customJsonData.pushPrimer) // PushPrimer
.applyCustomPushPrimer(customJsonData.pushPrimer)
.applyCustomClickableImage(customJsonData.clickableImage, from.isPushPrimer)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal abstract class CampaignRepository {
}

override fun syncWith(messageList: List<Message>, timestampMillis: Long, ignoreTooltips: Boolean) {
InAppLogger(TAG).debug("START - message size: ${messageList.size}")
InAppLogger(TAG).info("syncWith start")
lastSyncMillis = timestampMillis
loadCachedData() // ensure we're using latest cache data for syncing below
val oldList = LinkedHashMap(messages) // copy
Expand All @@ -68,7 +68,7 @@ internal abstract class CampaignRepository {
messages[updatedCampaign.campaignId] = updatedCampaign
}
saveDataToCache()
InAppLogger(TAG).debug("END")
InAppLogger(TAG).info("syncWith end")
}

private fun List<Message>.filterMessages(ignoreTooltips: Boolean): List<Message> {
Expand Down Expand Up @@ -99,13 +99,10 @@ internal abstract class CampaignRepository {
}

override fun optOutCampaign(id: String): Message? {
InAppLogger(TAG).debug("Campaign: $id}")
InAppLogger(TAG).debug("campaign: $id}")
val localCampaign = messages[id]
if (localCampaign == null) {
InAppLogger(TAG).debug(
"Campaign ($id) could not be updated -" +
"not found in the repository",
)
InAppLogger(TAG).debug("campaign not found in repository")
return null
}
val updatedCampaign = localCampaign.apply { isOptedOut = true }
Expand All @@ -116,7 +113,7 @@ internal abstract class CampaignRepository {
}

override fun decrementImpressions(id: String): Message? {
InAppLogger(TAG).debug("Campaign: $id")
InAppLogger(TAG).debug("campaign: $id")
val campaign = messages[id] ?: return null
return updateImpressions(
campaign,
Expand All @@ -136,7 +133,7 @@ internal abstract class CampaignRepository {
@SuppressWarnings("TooGenericExceptionCaught")
private fun loadCachedData() {
if (InAppMessaging.instance().isLocalCachingEnabled()) {
InAppLogger(TAG).debug("START")
InAppLogger(TAG).debug("start")
messages.clear()
try {
val jsonObject = JSONObject(retrieveData())
Expand All @@ -146,9 +143,9 @@ internal abstract class CampaignRepository {
)
}
} catch (ex: Exception) {
InAppLogger(TAG).debug(ex.cause, "Invalid JSON format for $IAM_USER_CACHE data")
InAppLogger(TAG).debug(ex.cause, "invalid JSON format for $IAM_USER_CACHE data")
}
InAppLogger(TAG).debug("END")
InAppLogger(TAG).debug("end")
}
}

Expand All @@ -161,7 +158,8 @@ internal abstract class CampaignRepository {
key = IAM_USER_CACHE,
defValue = "",
)
InAppLogger(TAG).debug("Cache Read - file: $preferenceFile, data: $preferenceData")
InAppLogger(TAG).info("retrieveData - file: $preferenceFile")
InAppLogger(TAG).debug("retrieveData - data: $preferenceData")
preferenceData
}.orEmpty()
}
Expand All @@ -171,7 +169,8 @@ internal abstract class CampaignRepository {
HostAppInfoRepository.instance().getContext()?.let { ctx ->
val preferenceFile = InAppMessaging.getPreferencesFile()
val preferenceData = Gson().toJson(messages)
InAppLogger(TAG).debug("Cache Write - file: $preferenceFile, data: $preferenceData")
InAppLogger(TAG).info("saveData - file: $preferenceFile")
InAppLogger(TAG).debug("saveData - data: $preferenceData")
PreferencesUtil.putString(
context = ctx,
name = preferenceFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ internal data class Message(
tooltip = null
}
} catch (je: JsonParseException) {
InAppLogger(TAG).warn("Invalid format for tooltip config.", je)
InAppLogger(TAG).warn("getTooltipConfig - invalid tooltip format")
InAppLogger(TAG).debug("parse exception: $je")
}
}
return tooltip
Expand All @@ -86,7 +87,8 @@ internal data class Message(
try {
customJsonData = Gson().fromJson(customJson, CustomJson::class.java)
} catch (je: JsonParseException) {
InAppLogger(TAG).warn("Invalid format/representation for CustomJson", je)
InAppLogger(TAG).warn("getCustomJsonData - invalid customJson format")
InAppLogger(TAG).debug("parse exception: $je")
}
}
return customJsonData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.rakuten.tech.mobile.inappmessaging.runtime.extensions

import android.Manifest
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import com.rakuten.tech.mobile.inappmessaging.runtime.InAppMessaging
import com.rakuten.tech.mobile.inappmessaging.runtime.utils.InAppLogger

private const val TAG = "IAM_ActivityExt"

/**
* Prompts the push notification permission dialog if applicable.
Expand All @@ -24,5 +28,9 @@ internal fun Activity.openAppNotifPermissionSettings() {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra("android.provider.extra.APP_PACKAGE", this.packageName)

this.startActivity(intent)
try {
this.startActivity(intent)
} catch (e: ActivityNotFoundException) {
InAppLogger(TAG).info("openAppNotifPermissionSettings - error: ${e.message}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ internal interface DisplayManager {
parent.removeView(inAppMessageBaseView)
}

InAppLogger(TAG).debug("View removed")
InAppLogger(TAG).debug("view removed")
}

private fun removeTooltip(parent: ViewGroup, id: String?, activity: Activity) {
Expand Down
Loading

0 comments on commit ab97a3e

Please sign in to comment.