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

Adding setListener to set one listener or to remove existing listeners #94

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ public object NotifierManager {
}

/**
* For listening updates such as push notification token changes
* For listening updates such as push notification token changes. This will add new listener to listener list.
*/
public fun addListener(listener: Listener) {
NotifierManagerImpl.addListener(listener)
}

/**
* For listening updates such as push notification token changes. This will set one listener only.
* You can set null to remove listener.
*/
public fun setListener(listener: Listener?) {
NotifierManagerImpl.setListener(listener)
}

/**
*
* Returns permission util that can be used to check and ask notification permission
Expand Down Expand Up @@ -72,7 +80,7 @@ public object NotifierManager {
* @param title Notification title
* @param body Notification body message
*/
public fun onPushNotification(title:String?,body:String?) {}
public fun onPushNotification(title: String?, body: String?) {}

/**
* Called when notification is clicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ internal object NotifierManagerImpl : KMPKoinComponent() {
listeners.add(listener)
}

fun setListener(listener: NotifierManager.Listener?) {
listeners.clear()
listener?.let { listeners.add(it) }
}

fun onNewToken(token: String) {
listeners.forEach { it.onNewToken(token) }
}
Expand Down