Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
report status of call to developer
  • Loading branch information
A.Badakhshan committed Apr 18, 2020
1 parent 0289e8d commit 642f13b
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 86 deletions.
2 changes: 1 addition & 1 deletion pushsdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "0.1.1"
versionName "0.1.2"
consumerProguardFiles 'consumer-rules.pro'
}

Expand Down
50 changes: 29 additions & 21 deletions pushsdk/src/main/java/ir/ayantech/pushsdk/core/AyanNotification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ir.ayantech.pushsdk.helper.NotificationUtils
import ir.ayantech.pushsdk.model.Message
import ir.ayantech.pushsdk.model.MessageDeserializer
import ir.ayantech.pushsdk.model.api.NotificationObject
import ir.ayantech.pushsdk.networking.BooleanCallBack
import ir.ayantech.pushsdk.networking.NotificationObjectsCallBack
import ir.ayantech.pushsdk.networking.PushNotificationNetworking
import ir.ayantech.pushsdk.networking.SimpleCallBack
Expand Down Expand Up @@ -92,7 +93,7 @@ object AyanNotification {
getNotificationList(itemCount, 0, notificationObjectsCallBack)
}

fun removeAllNotifications(success: SimpleCallBack) {
fun removeAllNotifications(success: BooleanCallBack) {
PushNotificationNetworking.removeAllNotifications(success)
}

Expand All @@ -101,29 +102,36 @@ object AyanNotification {
offset: Long,
notificationObjectsCallBack: NotificationObjectsCallBack
) {
PushNotificationNetworking.getNotificationsList(itemCount, offset) {
PushNotificationNetworking.getNotificationsList(itemCount, offset) { success, output ->
var nextPageClosure: SimpleCallBack? = null
if (it.HasMore) {
nextPageClosure = {
getNotificationList(itemCount, it.NextOffset, notificationObjectsCallBack)
output?.let {
if (!success) {
notificationObjectsCallBack(success, 0L, 0L, listOf(), null)
return@let
}
if (it.HasMore) {
nextPageClosure = {
getNotificationList(itemCount, it.NextOffset, notificationObjectsCallBack)
}
}
notificationObjectsCallBack(
success,
it.TotalCount,
it.UnSeenCount,
it.Notifications.map {
NotificationObject(
it.NotificationID,
MessageDeserializer.stringToMessage(
it.Notification.Data.message,
it.NotificationID.toString()
),
it.Seen,
it.SendDateTime
)
},
nextPageClosure
)
}
notificationObjectsCallBack(
it.TotalCount,
it.UnSeenCount,
it.Notifications.map {
NotificationObject(
it.NotificationID,
MessageDeserializer.stringToMessage(
it.Notification.Data.message,
it.NotificationID.toString()
),
it.Seen,
it.SendDateTime
)
},
nextPageClosure
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ir.ayantech.pushsdk.helper.ImageHelper
import ir.ayantech.pushsdk.model.Message
import ir.ayantech.pushsdk.model.MessageDeserializer
import ir.ayantech.pushsdk.model.action.PushNotificationAction
import ir.ayantech.pushsdk.networking.BooleanCallBack
import ir.ayantech.pushsdk.networking.PushNotificationNetworking
import ir.ayantech.pushsdk.networking.SimpleCallBack

class NotificationObject<T : PushNotificationAction>(
private val notificationId: Long?,
Expand All @@ -33,24 +33,31 @@ class NotificationObject<T : PushNotificationAction>(
message?.action?.doAction()
}

fun getNotificationDetail(callback: (NotificationObject<*>) -> Unit) {
fun getNotificationDetail(callback: (success: Boolean, notificationObject: NotificationObject<*>?) -> Unit) {
if (notificationId == null) return
PushNotificationNetworking.getNotificationDetail(notificationId) {
callback(
NotificationObject(
it.NotificationID,
MessageDeserializer.stringToMessage(
it.Notification.Data.message,
""
),
it.Seen,
it.SendDateTime
PushNotificationNetworking.getNotificationDetail(notificationId) { success, output ->
if (!success) {
callback(success, null)
return@getNotificationDetail
}
output?.let {
callback(
success,
NotificationObject(
it.NotificationID,
MessageDeserializer.stringToMessage(
it.Notification.Data.message,
""
),
it.Seen,
it.SendDateTime
)
)
)
}
}
}

fun remove(success: SimpleCallBack) {
fun remove(success: BooleanCallBack) {
if (notificationId == null) return
PushNotificationNetworking.removeNotification(notificationId, success)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import ir.ayantech.pushsdk.storage.PushNotificationUser

typealias SimpleCallBack = () -> Unit

typealias BooleanCallBack = (Boolean) -> Unit

typealias NotificationObjectsCallBack = (
success: Boolean,
totalCount: Long,
unSeenCount: Long,
notifications: List<NotificationObject<*>>,
Expand Down Expand Up @@ -70,95 +73,114 @@ object PushNotificationNetworking {
}

fun reportDeviceMobileNumber(mobileNumber: String) {
simpleCall<Void>(
ayanApi.ayanCall<Void>(
AyanCallStatus {
success {
PreferencesManager.saveToSharedPreferences(Constants.SERVER_NOTIFIED_MOBILE, true)
Log.d(
"AyanPush",
"User mobile number successfully reported to the server."
)
}
},
EndPoint.ReportDeviceMobileNumber,
ReportDeviceMobileNumberInput(
mobileNumber,
PushNotificationUser.getPushNotificationToken()
)
) {
PreferencesManager.saveToSharedPreferences(Constants.SERVER_NOTIFIED_MOBILE, true)
Log.d(
"AyanPush",
"User mobile number successfully reported to the server."
)
}
)
}

fun reportDeviceReceivedNotificationStatus(
messageId: String,
status: String,
extraInfo: Any? = null
) {
simpleCall<Void>(
ayanApi.ayanCall<Void>(
AyanCallStatus {
success {
Log.d(
"AyanPush",
"Message status with $status status successfully reported to the server."
)
}
},
EndPoint.ReportDeviceReceivedNotificationStatus,
ReportDeviceReceivedNotificationStatusInput(extraInfo, messageId, status)
) {
Log.d(
"AyanPush",
"Message status with $status status successfully reported to the server."
)
}
)
}

fun getNotificationsList(
itemCount: Long,
offset: Long = 0L,
callback: (GetNotificationsListOutput) -> Unit
callback: (success: Boolean, output: GetNotificationsListOutput?) -> Unit
) {
simpleCall<GetNotificationsListOutput>(
ayanApi.ayanCall<GetNotificationsListOutput>(
AyanCallStatus {
success {
it.response?.Parameters?.let { callback(true, it) }
}
failure {
callback(false, null)
}
},
EndPoint.GetNotificationsList,
GetNotificationsListInput(
itemCount,
offset,
PushNotificationUser.getPushNotificationToken()
)
) {
it?.let { callback(it) }
}
)
}

fun getNotificationDetail(notificationId: Long, callback: (GetNotificationDetailOutput) -> Unit) {
simpleCall<GetNotificationDetailOutput>(
fun getNotificationDetail(
notificationId: Long,
callback: (success: Boolean, output: GetNotificationDetailOutput?) -> Unit
) {
ayanApi.ayanCall<GetNotificationDetailOutput>(
AyanCallStatus {
success {
it.response?.Parameters?.let { callback(true, it) }
}
failure {
callback(false, null)
}
},
EndPoint.GetNotificationDetail,
GetNotificationDetailInput(notificationId, PushNotificationUser.getPushNotificationToken())
) {
it?.let { callback(it) }
}
GetNotificationDetailInput(
notificationId,
PushNotificationUser.getPushNotificationToken()
)
)
}

fun removeNotification(notificationId: Long, success: SimpleCallBack) {
simpleCall<Void>(
fun removeNotification(notificationId: Long, callback: BooleanCallBack) {
ayanApi.ayanCall<Void>(
AyanCallStatus {
success {
callback(true)
}
failure {
callback(false)
}
},
EndPoint.RemoveNotification,
RemoveNotificationInput(notificationId, PushNotificationUser.getPushNotificationToken())
) {
success()
}
}

fun removeAllNotifications(success: SimpleCallBack) {
simpleCall<Void>(
EndPoint.RemoveAllNotifications,
RemoveAllNotificationsInput(PushNotificationUser.getPushNotificationToken())
) {
success()
}
)
}

private inline fun <reified GenericOutput> simpleCall(
endPoint: String,
input: Any? = null,
crossinline onSuccess: (GenericOutput?) -> Unit
) {
ayanApi.ayanCall<GenericOutput>(
fun removeAllNotifications(callback: BooleanCallBack) {
ayanApi.ayanCall<Void>(
AyanCallStatus {
success {
onSuccess(it.response?.Parameters)
callback(true)
}
failure {
callback(false)
}
},
endPoint,
input,
hasIdentity = false
EndPoint.RemoveAllNotifications,
RemoveAllNotificationsInput(PushNotificationUser.getPushNotificationToken())
)
}
}

0 comments on commit 642f13b

Please sign in to comment.