-
Notifications
You must be signed in to change notification settings - Fork 8
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 #47 from psuzn/develop
develop -> main
- Loading branch information
Showing
44 changed files
with
808 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="iosApp" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="ADE463A4-513B-4388-B613-3ED01A8C7598" XCODE_PROJECT="$PROJECT_DIR$/iosApp/iosApp.xcworkspace" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp"> | ||
<configuration default="false" name="iosApp" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="E03FCF7C-99D3-4C80-8793-0DE2C2CD6295" XCODE_PROJECT="$PROJECT_DIR$/iosApp/iosApp.xcworkspace" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp"> | ||
<method v="2"> | ||
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> | ||
</component> |
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
Binary file not shown.
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
74 changes: 74 additions & 0 deletions
74
androidApp/src/androidMain/kotlin/me/sujanpoudel/playdeals/FcmService.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,74 @@ | ||
package me.sujanpoudel.playdeals | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import com.google.firebase.messaging.CommonNotificationBuilder | ||
import com.google.firebase.messaging.Constants.MessageNotificationKeys | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.ImageDownload | ||
import com.google.firebase.messaging.NotificationParams | ||
import com.google.firebase.messaging.RemoteMessage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withTimeoutOrNull | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
@SuppressLint("MissingFirebaseInstanceTokenRefresh") | ||
class FcmService : FirebaseMessagingService() { | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
val data = message.toIntent().extras | ||
|
||
if (!NotificationParams.isNotification(data)) { | ||
return super.onMessageReceived(message) | ||
} | ||
|
||
showNotification(NotificationParams(data!!)) | ||
} | ||
} | ||
|
||
private fun Context.manifestMetadata() = try { | ||
applicationContext.packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA) | ||
.metaData | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
null | ||
} | ||
|
||
@SuppressLint("VisibleForTests") | ||
private fun Context.showNotification(notificationParams: NotificationParams) { | ||
val manifestMetadata = manifestMetadata() | ||
val channel = CommonNotificationBuilder.getOrCreateChannel( | ||
this, | ||
notificationParams.notificationChannelId, | ||
manifestMetadata, | ||
) | ||
|
||
val info = CommonNotificationBuilder.createNotificationInfo( | ||
this, | ||
this, | ||
notificationParams, | ||
channel, | ||
manifestMetadata, | ||
) | ||
|
||
val url = notificationParams.getString(MessageNotificationKeys.IMAGE_URL) | ||
|
||
CoroutineScope(Dispatchers.IO).launch { | ||
if (url != null) { | ||
val image = withTimeoutOrNull(10.seconds) { | ||
try { | ||
ImageDownload.create(url)?.blockingDownload() | ||
} catch (_: Exception) { | ||
null | ||
} | ||
} | ||
info.notificationBuilder.setLargeIcon(image) | ||
} | ||
|
||
val notificationManager = getSystemService(FirebaseMessagingService.NOTIFICATION_SERVICE) as NotificationManager | ||
notificationManager.notify(info.tag, info.id, info.notificationBuilder.build()) | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
androidApp/src/androidMain/res/drawable-anydpi/ic_notification.xml
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,21 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="226" | ||
android:viewportHeight="226" | ||
android:tint="#FFFFFF"> | ||
<group android:scaleX="0.6104844" | ||
android:scaleY="0.6104844" | ||
android:translateX="44.015263" | ||
android:translateY="44.015263"> | ||
<path | ||
android:pathData="M209.65,16.25L209.65,16.25A22.98,22.98 45.26,0 1,209.65 48.74L48.74,209.65A22.98,22.98 45.26,0 1,16.25 209.65L16.25,209.65A22.98,22.98 45.26,0 1,16.25 177.16L177.16,16.25A22.98,22.98 45.26,0 1,209.65 16.25z" | ||
android:fillColor="#ffffff"/> | ||
<path | ||
android:pathData="M53.03,49.42m-36.18,0a36.18,36.18 0,1 1,72.36 0a36.18,36.18 0,1 1,-72.36 0" | ||
android:fillColor="#ffffff"/> | ||
<path | ||
android:pathData="M173.15,179.66m-36.18,0a36.18,36.18 0,1 1,72.36 0a36.18,36.18 0,1 1,-72.36 0" | ||
android:fillColor="#ffffff"/> | ||
</group> | ||
</vector> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#7477CC</color> | ||
</resources> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "408920570359", | ||
"firebase_url": "https://play-deals.firebaseio.com", | ||
"project_id": "play-deals", | ||
"storage_bucket": "play-deals.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:408920570359:android:73507efea95268337b16f2", | ||
"android_client_info": { | ||
"package_name": "me.sujanpoudel.playdeals" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "408920570359-vcp440gf1q7gm4ae8mnv9k0v1hsoqfcj.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyAc5FcH3QJ3tlgqwXJDHrApEegd-CzB654" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "408920570359-i6c0bhijsqshb1ok3d9v6ucvpj0p44vq.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
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
Oops, something went wrong.