Skip to content

Commit ad503d6

Browse files
committed
WMRUSTORE-38: Add Rustore
1 parent 59cf0c3 commit ad503d6

File tree

14 files changed

+145
-8
lines changed

14 files changed

+145
-8
lines changed

example/flutter_example/android/app/build.gradle

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ android {
5151
multiDexEnabled true
5252
}
5353

54+
signingConfigs {
55+
debug {
56+
storePassword "android"
57+
keyAlias "androiddebugkey"
58+
storeFile file("debug.keystore")
59+
keyPassword "android"
60+
}
61+
}
62+
5463
buildTypes {
5564
release {
5665
signingConfig signingConfigs.debug
@@ -63,7 +72,7 @@ flutter {
6372
source '../..'
6473
}
6574

66-
ext.mindbox_version = "2.11.0"
75+
ext.mindbox_version = "2.13.0"
6776

6877
dependencies {
6978
implementation 'androidx.multidex:multidex:2.0.1'
@@ -73,10 +82,13 @@ dependencies {
7382
implementation platform('com.google.firebase:firebase-bom:32.8.1')
7483
implementation 'com.google.firebase:firebase-messaging:23.4.1'
7584
//https://developers.mindbox.ru/docs/huawei-send-push-notifications-flutter
76-
implementation "cloud.mindbox:mindbox-huawei"
85+
implementation 'cloud.mindbox:mindbox-huawei'
7786
implementation 'com.huawei.hms:push:6.11.0.300'
7887
implementation 'com.google.code.gson:gson:2.8.8'
7988

89+
implementation 'cloud.mindbox:mindbox-rustore'
90+
implementation 'ru.rustore.sdk:pushclient:6.5.1'
91+
8092
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1"
8193
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1"
8294
}

example/flutter_example/android/app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="cloud.mindbox.flutter_example">
34

45
<application
@@ -18,6 +19,12 @@
1819
</intent-filter>
1920
</service>
2021

22+
<service android:name=".MindboxRuStoreMessagingService" android:exported="true" tools:ignore="ExportedService">
23+
<intent-filter>
24+
<action android:name="ru.rustore.sdk.pushclient.MESSAGING_EVENT" />
25+
</intent-filter>
26+
</service>
27+
2128
<activity
2229
android:name=".MainActivity"
2330
android:exported="true"
@@ -45,6 +52,10 @@
4552
android:name="flutterEmbedding"
4653
android:value="2" />
4754

55+
<meta-data
56+
android:name="ru.rustore.sdk.pushclient.project_id"
57+
android:value="MPYu6sSEZy8Vl-wYVkqFwwuaFNVlsBvx" />
58+
4859
</application>
4960
<queries>
5061
<intent>

example/flutter_example/android/app/src/main/kotlin/cloud/mindbox/flutter_example/MainApplication.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.util.Log
66
import cloud.mindbox.mobile_sdk.Mindbox
77
import cloud.mindbox.mindbox_firebase.MindboxFirebase
88
import cloud.mindbox.mindbox_huawei.MindboxHuawei
9+
import cloud.mindbox.mindbox_rustore.MindboxRuStore
910
import cloud.mindbox.mobile_sdk.pushes.MindboxRemoteMessage
1011
import io.flutter.embedding.engine.FlutterEngine
1112
import io.flutter.plugin.common.EventChannel
@@ -20,7 +21,7 @@ class MainApplication : Application() {
2021
private val gson = Gson()
2122
override fun onCreate() {
2223
super.onCreate()
23-
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase, MindboxHuawei))
24+
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase, MindboxHuawei, MindboxRuStore))
2425
}
2526

2627
fun setupEventChannel(flutterEngine: FlutterEngine) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package cloud.mindbox.flutter_example
2+
3+
import cloud.mindbox.mindbox_rustore.MindboxRuStore
4+
import cloud.mindbox.mobile_sdk.Mindbox
5+
import kotlinx.coroutines.*
6+
import ru.rustore.sdk.pushclient.messaging.model.RemoteMessage
7+
import ru.rustore.sdk.pushclient.messaging.service.RuStoreMessagingService
8+
9+
class MindboxRuStoreMessagingService: RuStoreMessagingService() {
10+
11+
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
12+
13+
override fun onNewToken(token: String) {
14+
super.onNewToken(token)
15+
Mindbox.updatePushToken(applicationContext, token, MindboxRuStore)
16+
}
17+
18+
override fun onMessageReceived(remoteMessage: RemoteMessage) {
19+
super.onMessageReceived(remoteMessage)
20+
val channelId = "default_channel_id"
21+
val channelName = "default_channel_name"
22+
val channelDescription = "default_channel_description"
23+
val pushSmallIcon = android.R.drawable.ic_dialog_info
24+
25+
// On some devices, onMessageReceived may be executed on the main thread
26+
// We recommend handling push messages asynchronously
27+
coroutineScope.launch {
28+
val messageWasHandled = Mindbox.handleRemoteMessage(
29+
context = applicationContext,
30+
message = remoteMessage,
31+
activities = mapOf(),
32+
channelId = channelId,
33+
channelName = channelName,
34+
pushSmallIcon = pushSmallIcon,
35+
defaultActivity = MainActivity::class.java,
36+
channelDescription = channelDescription
37+
)
38+
39+
// Method for checking if push is from Mindbox
40+
val isMindboxPush = MindboxRuStore.isMindboxPush(remoteMessage = remoteMessage)
41+
42+
// Method for getting info from Mindbox push
43+
val mindboxMessage =
44+
MindboxRuStore.convertToMindboxRemoteMessage(remoteMessage = remoteMessage)
45+
// If you want to save the notification you can call your save function from here.
46+
mindboxMessage?.let {
47+
val app = applicationContext as MainApplication
48+
app.saveNotification(it)
49+
}
50+
51+
if (!messageWasHandled) {
52+
//If the push notification was not from Mindbox or it contains incorrect data, then you can write a fallback to process it
53+
}
54+
}
55+
}
56+
57+
override fun onDestroy() {
58+
super.onDestroy()
59+
coroutineScope.cancel()
60+
}
61+
}

example/flutter_example/android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ buildscript {
44
google()
55
mavenCentral()
66
maven {url 'https://developer.huawei.com/repo/'}
7+
maven {url 'https://artifactory-external.vkpartner.ru/artifactory/maven'}
8+
mavenLocal()
79
}
810

911
dependencies {
@@ -19,6 +21,8 @@ allprojects {
1921
google()
2022
mavenCentral()
2123
maven {url 'https://developer.huawei.com/repo/'}
24+
maven {url 'https://artifactory-external.vkpartner.ru/artifactory/maven'}
25+
mavenLocal()
2226
}
2327
}
2428

mindbox/lib/mindbox.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,19 @@ class Mindbox {
6868
/// Method to obtain token.
6969
///
7070
/// Callback returns token when Mindbox SDK is initialized. See also [init].
71+
@Deprecated('Use method getTokens')
7172
void getToken(Function(String token) callback) {
7273
MindboxPlatform.instance.getToken(callback: callback);
7374
}
7475

76+
/// Method to obtain all push tokens as json string like
77+
/// {"FCM":"token1","HMS":"token2","RuStore":"token3"}
78+
///
79+
/// Callback returns tokens when Mindbox SDK is initialized. See also [init].
80+
void getTokens(Function(String token) callback) {
81+
MindboxPlatform.instance.getTokens(callback: callback);
82+
}
83+
7584
/// Method for managing sdk logging
7685
void setLogLevel({required LogLevel logLevel}) {
7786
MindboxPlatform.instance.setLogLevel(logLevel: logLevel);

mindbox_android/android/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ buildscript {
66
repositories {
77
google()
88
mavenCentral()
9+
mavenLocal()
910
}
1011

1112
dependencies {
@@ -42,12 +43,12 @@ android {
4243
}
4344

4445
defaultConfig {
45-
minSdkVersion 19
46+
minSdkVersion 21
4647
targetSdkVersion 34
4748
}
4849
}
4950

5051
dependencies {
5152
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
52-
api 'cloud.mindbox:mobile-sdk:2.11.0'
53+
api 'cloud.mindbox:mobile-sdk:2.13.0'
5354
}

mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class MindboxAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, Ne
9898
result.success(token)
9999
}
100100
}
101+
"getTokens" -> {
102+
if (tokenSubscription != null) {
103+
Mindbox.disposePushTokenSubscription(tokenSubscription!!)
104+
}
105+
tokenSubscription = Mindbox.subscribePushTokens { token ->
106+
result.success(token)
107+
}
108+
}
101109
"executeAsyncOperation" -> {
102110
if (call.arguments is List<*>) {
103111
val args = call.arguments as List<*>

mindbox_android/lib/src/mindbox_android_platform.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class MindboxAndroidPlatform extends MindboxPlatform {
3737
_methodHandler.getToken(callback: callback);
3838
}
3939

40+
/// Returns tokens to callback.
41+
@override
42+
void getTokens({required Function(String token) callback}) {
43+
_methodHandler.getTokens(callback: callback);
44+
}
45+
4046
/// Method for managing sdk logging
4147
@override
4248
void setLogLevel({required LogLevel logLevel}) {

mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public class SwiftMindboxIosPlugin: NSObject, FlutterPlugin {
9898
Mindbox.shared.getDeviceUUID {
9999
deviceUUID in result(deviceUUID)
100100
}
101+
case "getTokens":
102+
Mindbox.shared.getAPNSToken {
103+
token in result("{\"APNS\":\"\(token)\"}")
104+
}
101105
case "getToken":
102106
Mindbox.shared.getAPNSToken {
103107
token in result(token)

0 commit comments

Comments
 (0)