Skip to content

Commit

Permalink
Merge pull request #70 from rees46/feat/customizing-in-app-notification
Browse files Browse the repository at this point in the history
Feat/customizing in app notification
  • Loading branch information
TorinAsakura authored Oct 11, 2024
2 parents b66b2a8 + d99f738 commit 530bbe6
Show file tree
Hide file tree
Showing 37 changed files with 1,266 additions and 556 deletions.
3 changes: 3 additions & 0 deletions personalization-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ android {
viewBinding {
enabled = true
}
dataBinding {
enabled = true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 34
Expand Down
153 changes: 108 additions & 45 deletions personalization-sdk/src/main/kotlin/com/personalization/SDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.core.util.Consumer
import androidx.fragment.app.FragmentManager
import com.google.firebase.messaging.RemoteMessage
import com.personalization.Params.InternalParameter
import com.personalization.Params.TrackEvent
Expand Down Expand Up @@ -35,6 +36,7 @@ open class SDK {

internal lateinit var context: Context
private lateinit var segment: String
lateinit var fragmentManager: FragmentManager

private var onMessageListener: OnMessageListener? = null
private var search: Search = Search(JSONObject())
Expand Down Expand Up @@ -107,8 +109,7 @@ open class SDK {
sdkComponent.inject(this)

initPreferencesUseCase.invoke(
context = context,
preferencesKey = preferencesKey
context = context, preferencesKey = preferencesKey
)

this.context = context
Expand All @@ -122,10 +123,7 @@ open class SDK {
notificationHandler.initialize(context)

initUserSettingsUseCase.invoke(
shopId = shopId,
shopSecretKey = shopSecretKey,
segment = segment,
stream = stream
shopId = shopId, shopSecretKey = shopSecretKey, segment = segment, stream = stream
)
initNetworkUseCase.invoke(
baseUrl = apiUrl
Expand Down Expand Up @@ -153,6 +151,79 @@ open class SDK {
storiesManager.showStories(context.mainLooper, code)
}

fun initializeFragmentManager(fragmentManager: FragmentManager) {
this.fragmentManager = fragmentManager
}

fun showAlertDialog(
title: String,
message: String,
imageUrl: String,
buttonNegativeText: String,
buttonPositiveText: String,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
onPositiveClick: () -> Unit,
onNegativeClick: () -> Unit
) = inAppNotificationManager.showAlertDialog(
fragmentManager = fragmentManager,
title = title,
message = message,
imageUrl = imageUrl,
buttonPositiveColor = buttonPositiveColor,
buttonNegativeColor = buttonNegativeColor,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
onNegativeClick = onNegativeClick,
onPositiveClick = onPositiveClick,
)

fun showFullScreenDialog(
title: String,
message: String,
imageUrl: String,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
buttonNegativeText: String,
buttonPositiveText: String,
onPositiveClick: () -> Unit,
onNegativeClick: () -> Unit
) = inAppNotificationManager.showFullScreenDialog(
fragmentManager = fragmentManager,
title = title,
message = message,
imageUrl = imageUrl,
buttonPositiveColor = buttonPositiveColor,
buttonNegativeColor = buttonNegativeColor,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
onNegativeClick = onNegativeClick,
onPositiveClick = onPositiveClick,
)

fun showBottomSheetDialog(
title: String,
message: String,
imageUrl: String?,
buttonPositiveText: String,
buttonNegativeText: String?,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
onPositiveClick: () -> Unit,
onNegativeClick: () -> Unit
) = inAppNotificationManager.showBottomSheetDialog(
fragmentManager = fragmentManager,
title = title,
message = message,
imageUrl = imageUrl,
buttonNegativeText = buttonNegativeText,
buttonPositiveText = buttonPositiveText,
buttonPositiveColor = buttonPositiveColor,
buttonNegativeColor = buttonNegativeColor,
onNegativeClick = onNegativeClick,
onPositiveClick = onPositiveClick,
)

/**
* Triggers a story event
*
Expand All @@ -164,10 +235,7 @@ open class SDK {
fun trackStory(event: String, code: String, storyId: Int, slideId: String) {
if (::storiesManager.isInitialized) {
storiesManager.trackStory(
event = event,
code = code,
storyId = storyId,
slideId = slideId
event = event, code = code, storyId = storyId, slideId = slideId
)
} else {
Log.i(TAG, "storiesManager is not initialized")
Expand All @@ -186,8 +254,7 @@ open class SDK {
/**
* Return the session ID
*/
fun getSid(): String =
getUserSettingsValueUseCase.getSid()
fun getSid(): String = getUserSettingsValueUseCase.getSid()

/**
* Returns the session ID
Expand All @@ -212,10 +279,8 @@ open class SDK {
* @param extras from data notification
*/
fun notificationClicked(extras: Bundle?) {
notificationHandler.notificationClicked(
extras = extras,
sendAsync = { method, params -> sendNetworkMethodUseCase.postAsync(method, params) }
)
notificationHandler.notificationClicked(extras = extras,
sendAsync = { method, params -> sendNetworkMethodUseCase.postAsync(method, params) })
}

/**
Expand Down Expand Up @@ -262,8 +327,7 @@ open class SDK {
)
fun setPushTokenNotification(token: String, listener: OnApiCallbackListener?) {
registerManager.setPushTokenNotification(
token = token,
listener = listener
token = token, listener = listener
)
}

Expand All @@ -276,7 +340,8 @@ open class SDK {
*/
@Deprecated(
"This class will be removed in future versions. Use searchManager.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"searchManager.searchInstant(...) or searchManager.searchFull(...)"
)
)
Expand All @@ -294,7 +359,8 @@ open class SDK {
*/
@Deprecated(
"This class will be removed in future versions. Use searchManager.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"searchManager.searchInstant(...) or searchManager.searchFull(...)"
)
)
Expand All @@ -315,25 +381,24 @@ open class SDK {

@Deprecated(
"This class will be removed in future versions. Use searchManager.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"searchManager.searchBlank(...)"
)
)
fun searchBlank(listener: OnApiCallbackListener) {
if (search != null) {
if (search?.blank == null) {
getAsync(
BLANK_SEARCH_FIELD,
Params().build(), object : OnApiCallbackListener() {
override fun onSuccess(response: JSONObject?) {
search?.blank = response
listener.onSuccess(response)
}

override fun onError(code: Int, msg: String?) {
listener.onError(code, msg)
}
})
getAsync(BLANK_SEARCH_FIELD, Params().build(), object : OnApiCallbackListener() {
override fun onSuccess(response: JSONObject?) {
search?.blank = response
listener.onSuccess(response)
}

override fun onError(code: Int, msg: String?) {
listener.onError(code, msg)
}
})
} else {
listener.onSuccess(search?.blank)
}
Expand All @@ -350,7 +415,8 @@ open class SDK {
*/
@Deprecated(
"This method will be removed in future versions. Use recommendationManager.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"recommendationManager.getRecommendation(recommender_code, ...)"
)
)
Expand All @@ -367,7 +433,8 @@ open class SDK {
*/
@Deprecated(
"This method will be removed in future versions. Use recommendationManager.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"recommendationManager.getRecommendation(code, ...)"
)
)
Expand All @@ -383,7 +450,8 @@ open class SDK {
*/
@Deprecated(
"This method will be removed in future versions.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"trackEventManager.track(event, itemId)"
)
)
Expand All @@ -400,7 +468,8 @@ open class SDK {
*/
@Deprecated(
"This method will be removed in future versions.",
level = DeprecationLevel.WARNING, replaceWith = ReplaceWith(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
"trackEventManager.track(event, params, listener)"
)
)
Expand Down Expand Up @@ -655,10 +724,7 @@ open class SDK {
* @param phone
*/
fun addToSegment(
segmentId: String,
email: String?,
phone: String?,
listener: OnApiCallbackListener? = null
segmentId: String, email: String?, phone: String?, listener: OnApiCallbackListener? = null
) {
segmentMethod(ADD_FIELD, segmentId, email, phone, listener)
}
Expand All @@ -671,10 +737,7 @@ open class SDK {
* @param phone
*/
fun removeFromSegment(
segment_id: String,
email: String?,
phone: String?,
listener: OnApiCallbackListener? = null
segment_id: String, email: String?, phone: String?, listener: OnApiCallbackListener? = null
) {
segmentMethod(REMOVE_FIELD, segment_id, email, phone, listener)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ interface InAppNotificationManager {
fragmentManager: FragmentManager,
title: String,
message: String,
buttonText: String
imageUrl: String,
buttonPositiveText: String,
buttonNegativeText: String,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
onPositiveClick: () -> Unit,
onNegativeClick: () -> Unit
)

fun showFullScreenDialog(
fragmentManager: FragmentManager,
title: String,
message: String,
imageUrl: String?,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
buttonPositiveText: String,
buttonNegativeText: String,
onPositiveClick: () -> Unit,
Expand All @@ -29,7 +37,9 @@ interface InAppNotificationManager {
message: String,
imageUrl: String?,
buttonPositiveText: String,
buttonNegativeText: String,
buttonNegativeText: String?,
buttonPositiveColor: Int,
buttonNegativeColor: Int,
onPositiveClick: () -> Unit,
onNegativeClick: () -> Unit
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.personalization.di

import androidx.fragment.app.FragmentManager
import com.personalization.RegisterManager
import com.personalization.api.managers.InAppNotificationManager
import com.personalization.api.managers.RecommendationManager
import com.personalization.api.managers.SearchManager
import com.personalization.api.managers.TrackEventManager
import com.personalization.sdk.domain.usecases.preferences.GetPreferencesValueUseCase
import com.personalization.sdk.domain.usecases.preferences.SavePreferencesValueUseCase
import com.personalization.sdk.domain.usecases.recommendation.GetRecommendedByUseCase
import com.personalization.sdk.domain.usecases.recommendation.SetRecommendedByUseCase
import com.personalization.features.inAppNotification.impl.InAppNotificationManagerImpl
import com.personalization.features.recommendation.impl.RecommendationManagerImpl
import com.personalization.features.search.impl.SearchManagerImpl
import com.personalization.features.trackEvent.impl.TrackEventManagerImpl
import com.personalization.features.inAppNotification.impl.InAppNotificationManagerImpl
import com.personalization.sdk.domain.usecases.network.ExecuteQueueTasksUseCase
import com.personalization.sdk.domain.usecases.network.SendNetworkMethodUseCase
import com.personalization.sdk.domain.usecases.preferences.GetPreferencesValueUseCase
import com.personalization.sdk.domain.usecases.preferences.SavePreferencesValueUseCase
import com.personalization.sdk.domain.usecases.recommendation.GetRecommendedByUseCase
import com.personalization.sdk.domain.usecases.recommendation.SetRecommendedByUseCase
import com.personalization.sdk.domain.usecases.userSettings.GetUserSettingsValueUseCase
import com.personalization.sdk.domain.usecases.userSettings.UpdateUserSettingsValueUseCase
import com.personalization.stories.StoriesManager
Expand Down Expand Up @@ -84,7 +83,5 @@ class SdkModule {

@Singleton
@Provides
fun provideInAppNotificationManager(

): InAppNotificationManager = InAppNotificationManagerImpl()
fun provideInAppNotificationManager(): InAppNotificationManager = InAppNotificationManagerImpl()
}
Loading

0 comments on commit 530bbe6

Please sign in to comment.