Skip to content

Commit

Permalink
Merge pull request #57 from mirzemehdi/rel_v1.2.0-alpha02
Browse files Browse the repository at this point in the history
Release v1.2.0 alpha02
  • Loading branch information
mirzemehdi authored Aug 6, 2024
2 parents acf5e45 + cb33f36 commit 01b77e4
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {

allprojects {
group = "io.github.mirzemehdi"
version = "1.2.0-alpha"
version = "1.2.0-alpha02"
val sonatypeUsername = gradleLocalProperties(rootDir).getProperty("sonatypeUsername")
val sonatypePassword = gradleLocalProperties(rootDir).getProperty("sonatypePassword")
val gpgKeySecret = gradleLocalProperties(rootDir).getProperty("gpgKeySecret")
Expand Down
4 changes: 2 additions & 2 deletions kmpnotifier/api/android/kmpnotifier.api
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public final class com/mmk/kmpnotifier/permission/AndroidPermissionUtilKt {
}

public abstract interface class com/mmk/kmpnotifier/permission/PermissionUtil {
public abstract fun askNotificationPermission (Lkotlin/jvm/functions/Function0;)V
public abstract fun askNotificationPermission (Lkotlin/jvm/functions/Function1;)V
public abstract fun hasNotificationPermission (Lkotlin/jvm/functions/Function1;)V
}

public final class com/mmk/kmpnotifier/permission/PermissionUtil$DefaultImpls {
public static synthetic fun askNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static synthetic fun askNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static synthetic fun hasNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
}

4 changes: 2 additions & 2 deletions kmpnotifier/api/jvm/kmpnotifier.api
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public final class com/mmk/kmpnotifier/notification/configuration/NotificationPl
}

public abstract interface class com/mmk/kmpnotifier/permission/PermissionUtil {
public abstract fun askNotificationPermission (Lkotlin/jvm/functions/Function0;)V
public abstract fun askNotificationPermission (Lkotlin/jvm/functions/Function1;)V
public abstract fun hasNotificationPermission (Lkotlin/jvm/functions/Function1;)V
}

public final class com/mmk/kmpnotifier/permission/PermissionUtil$DefaultImpls {
public static synthetic fun askNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V
public static synthetic fun askNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static synthetic fun hasNotificationPermission$default (Lcom/mmk/kmpnotifier/permission/PermissionUtil;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class AndroidMockPermissionUtil(private val context: Context) : Permiss
onPermissionResult(context.hasNotificationPermission())
}

override fun askNotificationPermission(onPermissionGranted: () -> Unit) = Unit.also {
override fun askNotificationPermission(onPermissionResult: (Boolean) -> Unit) = Unit.also {
println(
"In Android this function is just a mock. You need to ask permission in Activity " +
"using like below: \n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ internal class EmptyPermissionUtilImpl : PermissionUtil {
onPermissionResult(true)
}

override fun askNotificationPermission(onPermissionGranted: () -> Unit) {
override fun askNotificationPermission(onPermissionResult: (Boolean) -> Unit) {
println("Not implemented: granted permission by default")
onPermissionGranted()
onPermissionResult(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ package com.mmk.kmpnotifier.permission
public interface PermissionUtil {


public fun hasNotificationPermission(onPermissionResult: (Boolean) -> Unit = {})
public fun askNotificationPermission(onPermissionGranted: () -> Unit = {})
public fun hasNotificationPermission(onPermissionResult: (isGranted: Boolean) -> Unit = {})
public fun askNotificationPermission(onPermissionResult: (isGranted: Boolean) -> Unit = {})
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public fun NotifierManager.onApplicationDidReceiveRemoteNotification(userInfo: M

internal fun NotifierManager.onUserNotification(notificationContent: UNNotificationContent) {
val userInfo = notificationContent.userInfo
if (notificationContent.isPushNotification()) NotifierManagerImpl.onPushNotification(
val hasNotification = notificationContent.title != null || notificationContent.body != null
if (notificationContent.isPushNotification() && hasNotification) NotifierManagerImpl.onPushNotification(
title = notificationContent.title,
body = notificationContent.body
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import kotlin.coroutines.suspendCoroutine
@OptIn(ExperimentalForeignApi::class)
internal class FirebasePushNotifierImpl : PushNotifier {

private val firebaseMessageDelegate by lazy { FirebaseMessageDelegate() }

init {
MainScope().launch {
println("FirebasePushNotifier is initialized")
FIRMessaging.messaging().delegate = firebaseMessageDelegate
UIApplication.sharedApplication.registerForRemoteNotifications()
FIRMessaging.messaging().delegate = FirebaseMessageDelegate()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import platform.UserNotifications.UNAuthorizationOptionSound
import platform.UserNotifications.UNAuthorizationStatusAuthorized
import platform.UserNotifications.UNUserNotificationCenter

internal class IosPermissionUtil(private val notificationCenter: UNUserNotificationCenter) : PermissionUtil {
internal class IosPermissionUtil(private val notificationCenter: UNUserNotificationCenter) :
PermissionUtil {
companion object {
val NOTIFICATION_PERMISSIONS =
UNAuthorizationOptionAlert or
Expand All @@ -21,13 +22,13 @@ internal class IosPermissionUtil(private val notificationCenter: UNUserNotificat
}
}

override fun askNotificationPermission(onPermissionGranted: () -> Unit) {
override fun askNotificationPermission(onPermissionResult: (Boolean) -> Unit) {
notificationCenter.requestAuthorizationWithOptions(NOTIFICATION_PERMISSIONS) { isGranted, _ ->
if (isGranted) {
UNUserNotificationCenter.currentNotificationCenter().delegate =
IosNotifier.NotificationDelegate()
onPermissionGranted()
}
onPermissionResult(isGranted)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class WebPermissionUtilImpl : PermissionUtil {
onPermissionResult(permission == NotificationPermission.GRANTED)
}

override fun askNotificationPermission(onPermissionGranted: () -> Unit) {
override fun askNotificationPermission(onPermissionResult: (Boolean) -> Unit) {
Notification.requestPermission().then {
onPermissionGranted()
onPermissionResult(it == NotificationPermission.GRANTED)
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class WebPermissionUtilImpl : PermissionUtil {
onPermissionResult(permission == NotificationPermission.GRANTED)
}

override fun askNotificationPermission(onPermissionGranted: () -> Unit) {
override fun askNotificationPermission(onPermissionResult: (Boolean) -> Unit) {
Notification.requestPermission().then {
onPermissionGranted()
onPermissionResult(it == NotificationPermission.GRANTED)
null
}
}
Expand Down

0 comments on commit 01b77e4

Please sign in to comment.