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

Feat/customizing in app notification #70

Merged
merged 23 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6bf568c
feat: Added buttons on alert dialog and initialization fragment manager
DanielGreenEngineer Oct 4, 2024
e208287
feat: Added applying color from app
DanielGreenEngineer Oct 4, 2024
8a13f26
feat: Separate views and include it on screen, also added loading ima…
DanielGreenEngineer Oct 4, 2024
6172da2
chore: Optimized imports
DanielGreenEngineer Oct 4, 2024
0cc47e2
feat: Added accept button color
DanielGreenEngineer Oct 4, 2024
6b17ba7
feat: Added closing alert button
DanielGreenEngineer Oct 7, 2024
9ccf1c6
feat: Added pressing animation & separating func for handling views
DanielGreenEngineer Oct 7, 2024
3bfb4b1
feat: Change binding for bottom sheet
DanielGreenEngineer Oct 7, 2024
98549d0
feat: Added customizing colors for bottom sheet
DanielGreenEngineer Oct 7, 2024
84fd3e6
chore: Separating handling views for bottom sheet
DanielGreenEngineer Oct 7, 2024
b076920
feat: Added bottom sheet actual view
DanielGreenEngineer Oct 7, 2024
452de71
chore: Customized pressing animation and container radius
DanielGreenEngineer Oct 7, 2024
a4ece46
feat: Customized crouping images and resizing container
DanielGreenEngineer Oct 7, 2024
17fe725
feat: Added actual full screen dialog view
DanielGreenEngineer Oct 7, 2024
836dab3
feat: Added full screen dialog handling views
DanielGreenEngineer Oct 7, 2024
bee854b
chore: Remove debug options
DanielGreenEngineer Oct 7, 2024
038d1b9
feat: apply suggestions from code review
DanielGreenEngineer Oct 11, 2024
8339ba1
chore: reorganize file structure by FSD
DanielGreenEngineer Oct 11, 2024
51334bc
feat: Added NotificationClickListener for dialogs
DanielGreenEngineer Oct 11, 2024
74e1c00
style: Rename interface
DanielGreenEngineer Oct 11, 2024
1edcaa3
feat: Added localization strings
DanielGreenEngineer Oct 11, 2024
521a265
style: Reformat code and optimized imports
DanielGreenEngineer Oct 11, 2024
d99f738
feat: Added localization to sample
DanielGreenEngineer Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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