Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:KeyValueSoftwareSystems/siren-an…
Browse files Browse the repository at this point in the history
…droid-inbox into feat-delete-animation
  • Loading branch information
vinaygregoryjohn183 committed Apr 22, 2024
2 parents ec76243 + b47a701 commit 9b0e4f0
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 97 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down Expand Up @@ -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,
) {
Expand All @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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("") }
Expand Down Expand Up @@ -295,7 +294,7 @@ abstract class SDKCoreUI(context: Context, userToken: String, recipientId: Strin
}

fun executeMarkAsViewed(startDate: String) {
markNotificationsAsViewedInner(
markAllAsViewedInner(
startDate,
) { _, _, _ ->
}
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}
}
Loading

0 comments on commit 9b0e4f0

Please sign in to comment.