diff --git a/README.md b/README.md index df79514..d06f574 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ cardProps | Props for customizing the notification cards | CardProps | null | inboxHeaderProps | Props for customizing the header | InboxHeaderProps | null | listEmptyComponent | Custom composable function for empty notification list | (@Composable () -> Unit) | null | customFooter | Custom footer composable function | (@Composable () -> Unit) | null | -customNotificationCard | Custom click handler for notification cards | (@Composable (AllNotificationResponseData) -> Unit) | null | +customCard | Custom notification card composable | (@Composable (AllNotificationResponseData) -> Unit) | null | customLoader | Custom composable function to display the initial loading state | (@Composable () -> Unit) | null | customErrorWindow | Custom error window | (@Composable () -> Unit) | null | itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | Int | 20 @@ -291,11 +291,11 @@ Utility functions for modifying notifications: Functions | Parameters | Type | Description | ----------|------------|-------|------------| -markNotificationsAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date | +markAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date | markAsRead | id | string | Set read status of a notification to true | -deleteNotification | id | string | Delete a notification by id | -deleteNotificationsByDate | startDate | ISO date string | Delete all notifications until given date | -markNotificationsAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date | +deleteById | id | string | Delete a notification by id | +deleteByDate | startDate | ISO date string | Delete all notifications until given date | +markAllAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date | updateToken | userToken, recipientId | string | To change the tokens Sample code: @@ -317,7 +317,7 @@ import com.keyvalue.siren.androidsdk.helper.client.callbacks.MarkAsReadByIdCallb ) fun markAsRead() { sirenSDK.markAsRead( - notificationId = "notificationId", + id = "ID_VALUE", callback = object : MarkAsReadByIdCallback { override fun onSuccess(responseData: MarkAsReadByIdResponseData?) { // onSuccess @@ -411,8 +411,8 @@ import com.keyvalue.siren.androidsdk.helper.customization.SirenInboxProps ) fun deleteNotification() { - sirenSDK.deleteNotification( - notificationId = "notificationId", + sirenSDK.deleteById( + id = "ID_VALUE", callback = object : SirenAllNotificationUpdateCallback { override fun onSuccess(dataStatus: DataStatus?) { // onSuccess diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/AuthorizeUserAction.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/AuthorizeUserAction.kt index 141c79b..ceb5473 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/AuthorizeUserAction.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/AuthorizeUserAction.kt @@ -1,9 +1,11 @@ package com.keyvalue.siren.androidsdk -import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_TOKEN_VERIFICATION_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.AUTHENTICATION_PENDING +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_AUTHENTICATION_PENDING +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_UNAUTHORIZED_OPERATION import com.keyvalue.siren.androidsdk.utils.constants.SirenErrorTypes -import com.keyvalue.siren.androidsdk.utils.constants.TOKEN_VERIFICATION_FAILED import com.keyvalue.siren.androidsdk.utils.constants.TokenVerificationStatus +import com.keyvalue.siren.androidsdk.utils.constants.UNAUTHORIZED_OPERATION import org.json.JSONObject object AuthorizeUserAction { @@ -13,8 +15,15 @@ object AuthorizeUserAction { if (authenticationStatus == TokenVerificationStatus.FAILED) { callback( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", TOKEN_VERIFICATION_FAILED) - .put("message", ERROR_MESSAGE_TOKEN_VERIFICATION_FAILED), + .put("code", UNAUTHORIZED_OPERATION) + .put("message", ERROR_MESSAGE_UNAUTHORIZED_OPERATION), + TokenVerificationStatus.FAILED, + ) + } else if (authenticationStatus == TokenVerificationStatus.PENDING) { + callback( + JSONObject().put("type", SirenErrorTypes.ERROR) + .put("code", AUTHENTICATION_PENDING) + .put("message", ERROR_MESSAGE_AUTHENTICATION_PENDING), TokenVerificationStatus.FAILED, ) } else { diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCore.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCore.kt index 9f77f1c..0e8ddfb 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCore.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCore.kt @@ -30,7 +30,7 @@ abstract class SDKCore(var context: Context, var userToken: String, var recipien } } - protected fun markNotificationsAsViewedInner( + protected fun markAllAsViewedInner( startDate: String?, callback: (MarkAsViewedResponseData?, JSONObject?, Boolean) -> Unit, ) { @@ -83,7 +83,7 @@ abstract class SDKCore(var context: Context, var userToken: String, var recipien } } - protected fun deleteNotificationsByDateInner( + protected fun deleteByDateInner( startDate: String?, callback: (DataStatus?, JSONObject?, Boolean) -> Unit, ) { @@ -109,7 +109,7 @@ abstract class SDKCore(var context: Context, var userToken: String, var recipien } } - protected fun deleteNotificationInner( + protected fun deleteByIdInner( notificationId: String, callback: (DataStatus?, String?, JSONObject?, Boolean) -> Unit, ) { diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCoreUI.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCoreUI.kt index f6709d5..4afc767 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCoreUI.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/core/SDKCoreUI.kt @@ -118,7 +118,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin } var verificationRetryCount = 1 - val verificationRetryTimer: Timer = Timer() + val verificationRetryTimer = Timer() Box( modifier = @@ -261,7 +261,6 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin mutableStateOf(false) } val isLoading = remember { mutableStateOf(false) } - val isRetry = remember { mutableStateOf(false) } val listState = rememberLazyListState() val endTime = remember { mutableStateOf("") } val startTime = remember { mutableStateOf("") } @@ -295,7 +294,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin } fun executeMarkAsViewed(startDate: String) { - markNotificationsAsViewedInner( + markAllAsViewedInner( startDate, ) { _, _, _ -> } @@ -327,7 +326,6 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin } isRefreshing = false isInitialListCall = false - isRetry.value = false if (isError) { error?.let { callback.onError(it) } notificationListState = notificationListState.ifEmpty { emptyList() } @@ -367,12 +365,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin val enableClearAllButton = notificationListState.isNotEmpty() && !showListEmptyState && !showListErrorState && - !isLoading.value && !isRefreshing && !isRetry.value - - fun retryFetch() { - isRetry.value = true - fetchNotifications() - } + !isLoading.value && !isRefreshing authenticationState.collectAsState().apply { if (this.value == TokenVerificationStatus.FAILED) { @@ -555,7 +548,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin backButton = props.inboxHeaderProps?.backButton, clearAllIconSize = styles.windowHeader.clearAllIconSize!!, ) { - deleteNotificationsByDateInner( + deleteByDateInner( startDate = null, ) { dataStatus, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { @@ -570,7 +563,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin } } - if (isInitialListCall || isRetry.value || isRefreshing) { + if (isInitialListCall || isRefreshing) { props.customLoader?.let { it() } ?: SkeletonLoader(isDarkMode = props.darkMode, hideAvatar = props.cardProps?.hideAvatar) } else if (showListEmptyState) { props.listEmptyComponent?.let { it() } ?: InboxEmptyScreen( @@ -601,7 +594,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin ) { items(notificationListState) { notificationData -> Box { - props.customNotificationCard?.let { + props.customCard?.let { if (notificationData != null) { it(notificationData) } @@ -615,7 +608,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin }, deleteNotificationCallback = { notificationData?.id?.let { - deleteNotificationInner( + deleteByIdInner( it, ) { dataStatus, id, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/AuthenticationRepositoryImplementation.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/AuthenticationRepositoryImplementation.kt index d0b8720..6b62cac 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/AuthenticationRepositoryImplementation.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/AuthenticationRepositoryImplementation.kt @@ -5,9 +5,11 @@ import com.keyvalue.siren.androidsdk.data.model.AuthenticationResponse import com.keyvalue.siren.androidsdk.data.networkcallbacks.NetworkCallback import com.keyvalue.siren.androidsdk.data.retrofit.RetrofitClient import com.keyvalue.siren.androidsdk.data.service.AuthenticationApiService -import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_SERVICE_NOT_AVAILABLE +import com.keyvalue.siren.androidsdk.utils.constants.API_ERROR +import com.keyvalue.siren.androidsdk.utils.constants.AUTHENTICATION_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_API_ERROR +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_AUTHENTICATION_FAILED import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_TIMED_OUT -import com.keyvalue.siren.androidsdk.utils.constants.GENERIC_API_ERROR import com.keyvalue.siren.androidsdk.utils.constants.SirenErrorTypes import com.keyvalue.siren.androidsdk.utils.constants.TIMED_OUT import org.json.JSONObject @@ -40,17 +42,17 @@ class AuthenticationRepositoryImplementation(baseURL: String) : AuthenticationRe networkCallback.onError( JSONObject() .put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR) - .put("message", errors.error?.message ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}"), + .put("code", errors.error?.errorCode ?: AUTHENTICATION_FAILED) + .put("message", errors.error?.message ?: ERROR_MESSAGE_AUTHENTICATION_FAILED), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { - networkCallback.onError(JSONObject().put("code", GENERIC_API_ERROR).put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE)) + networkCallback.onError(JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR).put("message", ERROR_MESSAGE_API_ERROR)) } } } diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/NotificationRepositoryImplementation.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/NotificationRepositoryImplementation.kt index dde013e..f85cfc3 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/NotificationRepositoryImplementation.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/data/repository/NotificationRepositoryImplementation.kt @@ -14,12 +14,26 @@ import com.keyvalue.siren.androidsdk.data.model.UnViewedNotificationResponse import com.keyvalue.siren.androidsdk.data.networkcallbacks.NetworkCallback import com.keyvalue.siren.androidsdk.data.retrofit.RetrofitClient import com.keyvalue.siren.androidsdk.data.service.NotificationApiService +import com.keyvalue.siren.androidsdk.utils.constants.API_ERROR +import com.keyvalue.siren.androidsdk.utils.constants.BULK_DELETE_FAILED import com.keyvalue.siren.androidsdk.utils.constants.BulkUpdateType -import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_SERVICE_NOT_AVAILABLE +import com.keyvalue.siren.androidsdk.utils.constants.DELETE_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_API_ERROR +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_BULK_DELETE_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_DELETE_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_MARK_ALL_AS_READ_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_MARK_ALL_AS_VIEWED_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_MARK_AS_READ_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_NOTIFICATION_FETCH_FAILED import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_TIMED_OUT -import com.keyvalue.siren.androidsdk.utils.constants.GENERIC_API_ERROR +import com.keyvalue.siren.androidsdk.utils.constants.ERROR_MESSAGE_UNVIEWED_COUNT_FETCH_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.MARK_ALL_AS_READ_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.MARK_ALL_AS_VIEWED_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.MARK_AS_READ_FAILED +import com.keyvalue.siren.androidsdk.utils.constants.NOTIFICATION_FETCH_FAILED import com.keyvalue.siren.androidsdk.utils.constants.SirenErrorTypes import com.keyvalue.siren.androidsdk.utils.constants.TIMED_OUT +import com.keyvalue.siren.androidsdk.utils.constants.UNVIEWED_COUNT_FETCH_FAILED import org.json.JSONObject import java.net.SocketTimeoutException @@ -56,22 +70,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: UNVIEWED_COUNT_FETCH_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_UNVIEWED_COUNT_FETCH_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -110,22 +124,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: NOTIFICATION_FETCH_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_NOTIFICATION_FETCH_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -157,22 +171,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: MARK_AS_READ_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_MARK_AS_READ_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -206,22 +220,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: MARK_ALL_AS_READ_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_MARK_ALL_AS_READ_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -254,22 +268,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: MARK_ALL_AS_VIEWED_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_MARK_ALL_AS_VIEWED_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -297,22 +311,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi Gson().fromJson(errorBody, DeleteNotificationByIdResponse::class.java) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: DELETE_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_DELETE_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } @@ -346,22 +360,22 @@ class NotificationRepositoryImplementation(baseURL: String) : NotificationReposi ) networkCallback.onError( JSONObject().put("type", SirenErrorTypes.ERROR) - .put("code", errors.error?.errorCode ?: GENERIC_API_ERROR).put( + .put("code", errors.error?.errorCode ?: BULK_DELETE_FAILED).put( "message", errors.error?.message - ?: "HTTP error! status: ${parentResponse.raw().code} ${parentResponse.raw().message}", + ?: ERROR_MESSAGE_BULK_DELETE_FAILED, ), ) } } } catch (e: SocketTimeoutException) { networkCallback.onError( - JSONObject().put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", TIMED_OUT).put("message", ERROR_MESSAGE_TIMED_OUT), ) } catch (e: Exception) { networkCallback.onError( - JSONObject().put("code", GENERIC_API_ERROR) - .put("message", ERROR_MESSAGE_SERVICE_NOT_AVAILABLE), + JSONObject().put("type", SirenErrorTypes.ERROR).put("code", API_ERROR) + .put("message", ERROR_MESSAGE_API_ERROR), ) } } diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/SirenSDKCore.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/SirenSDKCore.kt index 3bdd301..45d5bf0 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/SirenSDKCore.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/SirenSDKCore.kt @@ -93,7 +93,7 @@ class SirenSDKCore( } } - private fun markNotificationsAsReadByDateInner( + private fun markAsReadByDateInner( startDate: String?, callback: (DataStatus?, JSONObject?, Boolean) -> Unit, ) { @@ -120,11 +120,11 @@ class SirenSDKCore( } } - override fun markNotificationsAsReadByDate( + override fun markAsReadByDate( untilDate: String?, callback: SirenAllNotificationUpdateCallback, ) { - markNotificationsAsReadByDateInner(untilDate) { responseData, jsonObject, isError -> + markAsReadByDateInner(untilDate) { responseData, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { if (isError && jsonObject != null) { callback.onError(jsonObject) @@ -140,11 +140,11 @@ class SirenSDKCore( } } - override fun markNotificationsAsViewed( + override fun markAllAsViewed( untilDate: String?, callback: MarkAsViewedCallback, ) { - markNotificationsAsViewedInner(untilDate) { responseData, jsonObject, isError -> + markAllAsViewedInner(untilDate) { responseData, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { if (isError && jsonObject != null) { callback.onError(jsonObject) @@ -156,11 +156,11 @@ class SirenSDKCore( } } - override fun deleteNotificationsByDate( + override fun deleteByDate( untilDate: String?, callback: SirenAllNotificationUpdateCallback, ) { - deleteNotificationsByDateInner(untilDate) { dataStatus, jsonObject, isError -> + deleteByDateInner(untilDate) { dataStatus, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { if (isError && jsonObject != null) { callback.onError(jsonObject) @@ -172,11 +172,11 @@ class SirenSDKCore( } } - override fun deleteNotification( - notificationId: String, + override fun deleteById( + id: String, callback: SirenAllNotificationUpdateCallback, ) { - deleteNotificationInner(notificationId) { dataStatus, id, jsonObject, isError -> + deleteByIdInner(id) { dataStatus, id, jsonObject, isError -> CoroutineScope(Dispatchers.Main).launch { deleteByIdState.emit(id ?: "") if (isError && jsonObject != null) { diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/SirenSDKClient.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/SirenSDKClient.kt index 43a31b0..02d5b21 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/SirenSDKClient.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/SirenSDKClient.kt @@ -29,7 +29,7 @@ interface SirenSDKClient { * @param untilDate The end date until which notifications should be marked as read. * @param callback The callback interface for handling the result of the operation. */ - fun markNotificationsAsReadByDate( + fun markAsReadByDate( untilDate: String?, callback: SirenAllNotificationUpdateCallback, ) @@ -40,7 +40,7 @@ interface SirenSDKClient { * @param untilDate The end date until which notifications should be marked as viewed. * @param callback The callback interface for handling the result of the operation. */ - fun markNotificationsAsViewed( + fun markAllAsViewed( untilDate: String?, callback: MarkAsViewedCallback, ) @@ -51,7 +51,7 @@ interface SirenSDKClient { * @param untilDate The end date until which notifications should be deleted. * @param callback The callback interface for handling the result of the operation. */ - fun deleteNotificationsByDate( + fun deleteByDate( untilDate: String?, callback: SirenAllNotificationUpdateCallback, ) @@ -59,11 +59,11 @@ interface SirenSDKClient { /** * Deletes a notification by its ID. * - * @param notificationId The ID of the notification to delete. + * @param id The ID of the notification to delete. * @param callback The callback interface for handling the result of the operation. */ - fun deleteNotification( - notificationId: String, + fun deleteById( + id: String, callback: SirenAllNotificationUpdateCallback, ) diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/callbacks/SirenInboxCallback.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/callbacks/SirenInboxCallback.kt index 45b3289..365abd6 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/callbacks/SirenInboxCallback.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/client/callbacks/SirenInboxCallback.kt @@ -15,9 +15,9 @@ interface SirenInboxCallback { fun onError(jsonObject: JSONObject) /** - * Called when a notification card in the Siren inbox is clicked. + * Called when a card in the Siren inbox is clicked. * - * @param notificationItem The data associated with the clicked notification. + * @param item The data associated with the clicked notification. */ - fun onCardClick(notificationItem: AllNotificationResponseData) + fun onCardClick(item: AllNotificationResponseData) } diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/customization/ClientTheme.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/customization/ClientTheme.kt index 0d252eb..f5b44ec 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/customization/ClientTheme.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/helper/customization/ClientTheme.kt @@ -74,7 +74,7 @@ data class SirenInboxIconProps( * @property inboxHeaderProps Properties for customizing the header * @property listEmptyComponent Custom composable function to display when the notification list is empty. * @property customFooter Custom composable function to be displayed below the inbox list. - * @property customNotificationCard Custom composable function for rendering individual notification cards. + * @property customCard Custom composable function for rendering individual notification cards. * @property customLoader Custom composable function for loader to be displayed when the notification list is loading. * @property customErrorWindow Custom composable function for error window to be displayed when an error occurs. * @property itemsPerFetch Number of notifications to be fetched each time @@ -88,7 +88,7 @@ data class SirenInboxProps( val listEmptyComponent: (@Composable () -> Unit)? = null, val inboxHeaderProps: InboxHeaderProps? = null, val customFooter: (@Composable () -> Unit)? = null, - val customNotificationCard: (@Composable (AllNotificationResponseData) -> Unit)? = null, + val customCard: (@Composable (AllNotificationResponseData) -> Unit)? = null, val customLoader: (@Composable () -> Unit)? = null, val customErrorWindow: (@Composable () -> Unit)? = null, val itemsPerFetch: Int? = 20, diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorCodes.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorCodes.kt index ac85429..f1c74aa 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorCodes.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorCodes.kt @@ -3,5 +3,14 @@ package com.keyvalue.siren.androidsdk.utils.constants const val TIMED_OUT = "TIMED_OUT" const val INVALID_TOKEN = "INVALID_TOKEN" const val INVALID_RECIPIENT_ID = "INVALID_RECIPIENT_ID" -const val TOKEN_VERIFICATION_FAILED = "TOKEN_VERIFICATION_FAILED" -const val GENERIC_API_ERROR = "GENERIC_API_ERROR" +const val API_ERROR = "API_ERROR" +const val AUTHENTICATION_FAILED = "AUTHENTICATION_FAILED" +const val UNVIEWED_COUNT_FETCH_FAILED = "UNVIEWED_COUNT_FETCH_FAILED" +const val NOTIFICATION_FETCH_FAILED = "NOTIFICATION_FETCH_FAILED" +const val MARK_AS_READ_FAILED = "MARK_AS_READ_FAILED" +const val DELETE_FAILED = "DELETE_FAILED" +const val MARK_ALL_AS_VIEWED_FAILED = "MARK_ALL_AS_VIEWED_FAILED" +const val BULK_DELETE_FAILED = "BULK_DELETE_FAILED" +const val MARK_ALL_AS_READ_FAILED = "MARK_ALL_AS_READ_FAILED" +const val AUTHENTICATION_PENDING = "AUTHENTICATION_PENDING" +const val UNAUTHORIZED_OPERATION = "UNAUTHORIZED_OPERATION" diff --git a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorMessages.kt b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorMessages.kt index b7edc63..2f55158 100644 --- a/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorMessages.kt +++ b/siren-sdk/src/main/java/com/keyvalue/siren/androidsdk/utils/constants/ErrorMessages.kt @@ -3,5 +3,14 @@ package com.keyvalue.siren.androidsdk.utils.constants const val ERROR_MESSAGE_TIMED_OUT = "Request timed out" const val ERROR_MESSAGE_INVALID_TOKEN = "Invalid token" const val ERROR_MESSAGE_INVALID_RECIPIENT_ID = "Invalid recipient id" -const val ERROR_MESSAGE_TOKEN_VERIFICATION_FAILED = "This operation requires a valid token" -const val ERROR_MESSAGE_SERVICE_NOT_AVAILABLE = "Service is not available" +const val ERROR_MESSAGE_API_ERROR = "Something went wrong" +const val ERROR_MESSAGE_AUTHENTICATION_FAILED = "Failed to authenticate given credentials" +const val ERROR_MESSAGE_UNVIEWED_COUNT_FETCH_FAILED = "Failed to fetch unviewed notifications count" +const val ERROR_MESSAGE_NOTIFICATION_FETCH_FAILED = "Failed to fetch notifications" +const val ERROR_MESSAGE_MARK_AS_READ_FAILED = "Failed to mark notification as read" +const val ERROR_MESSAGE_DELETE_FAILED = "Failed to delete notification" +const val ERROR_MESSAGE_MARK_ALL_AS_VIEWED_FAILED = "Failed to mark notification as viewed" +const val ERROR_MESSAGE_BULK_DELETE_FAILED = "Bulk deletion of notifications failed" +const val ERROR_MESSAGE_MARK_ALL_AS_READ_FAILED = "Failed to mark all notifications as read" +const val ERROR_MESSAGE_AUTHENTICATION_PENDING = "Authentication in progress" +const val ERROR_MESSAGE_UNAUTHORIZED_OPERATION = "This operation requires valid credentials"