-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from igorescodro/feature/notification-action
🔔 Implement notification actions to iOS
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...res/alarm/src/iosMain/kotlin/com/escodro/alarm/notification/NotificationActionDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.escodro.alarm.notification | ||
|
||
import com.escodro.coroutines.AppCoroutineScope | ||
import com.escodro.domain.usecase.task.CompleteTask | ||
import platform.Foundation.NSLog | ||
import platform.UserNotifications.UNNotificationResponse | ||
|
||
/** | ||
* Class to handle the notification actions in iOS. | ||
* | ||
* @param appCoroutineScope the app-wide coroutine scope | ||
* @param completeTaskUseCase the use case to complete a task | ||
*/ | ||
class NotificationActionDelegate( | ||
private val appCoroutineScope: AppCoroutineScope, | ||
private val completeTaskUseCase: CompleteTask, | ||
) { | ||
|
||
/** | ||
* Handles the notification response and actions. | ||
* | ||
* @param response the notification response | ||
* @param onCompletion the action to be executed after the task is completed | ||
*/ | ||
fun userNotificationCenter(response: UNNotificationResponse, onCompletion: () -> Unit) { | ||
NSLog("NotificationActionDelegate - userNotificationCenter") | ||
val content = response.notification.request.content | ||
NSLog("NotificationActionDelegate - content: $content") | ||
val taskId: Long = content.userInfo[IosNotificationScheduler.USER_INFO_TASK_ID] as? Long | ||
?: return | ||
|
||
when (response.actionIdentifier) { | ||
IosNotificationScheduler.ACTION_IDENTIFIER_DONE -> completeTask( | ||
taskId = taskId, | ||
onCompletion = onCompletion, | ||
) | ||
|
||
else -> NSLog("NotificationActionDelegate - Action not supported") | ||
} | ||
} | ||
|
||
private fun completeTask(taskId: Long, onCompletion: () -> Unit) { | ||
appCoroutineScope.launch { | ||
NSLog("NotificationActionDelegate - completeTask") | ||
completeTaskUseCase(taskId) | ||
onCompletion() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
shared/src/iosMain/kotlin/com/escodro/shared/di/InjectionHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.escodro.shared.di | ||
|
||
import com.escodro.alarm.notification.NotificationActionDelegate | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
/** | ||
* Helper class to inject dependencies in the iOS platform. | ||
*/ | ||
class InjectionHelper : KoinComponent { | ||
|
||
/** | ||
* Provides the [NotificationActionDelegate] instance. | ||
*/ | ||
val notificationActionDelegate: NotificationActionDelegate by inject() | ||
} |