Skip to content

Commit 36798bf

Browse files
authored
Merge pull request #139 from mindbox-cloud/feature/WMRUSTORE-38
WMRUSTORE-38: Add Rustore
2 parents 18db1e6 + 0de47e0 commit 36798bf

File tree

24 files changed

+190
-17
lines changed

24 files changed

+190
-17
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/analysis_options.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ linter:
2626
prefer_typing_uninitialized_variables: true
2727
public_member_api_docs: true
2828
always_put_control_body_on_new_line: true
29-
curly_braces_in_flow_control_structures: true
29+
curly_braces_in_flow_control_structures: true
30+
31+
analyzer:
32+
errors:
33+
deprecated_member_use_from_same_package: ignore

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/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: mindbox
22
description: Flutter Mindbox SDK. Plugin wrapper over of Mindbox iOS/Android SDK.
3-
version: 2.11.0
3+
version: 2.13.0
44
homepage: https://mindbox.cloud/
55
repository: https://github.com/mindbox-cloud/flutter-sdk/tree/master/mindbox
66
documentation: https://developers.mindbox.ru/docs/flutter-sdk-integration

mindbox/test/mindbox_test.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,27 @@ void main() {
7777
expect(await completer.future, equals('dummy-token'));
7878
});
7979

80+
test('When SDK was initialized, getTokens() should return tokens', () async {
81+
final completer = Completer<String>();
82+
83+
Mindbox.instance.getTokens((deviceToken) => completer.complete(deviceToken));
84+
85+
final validConfig = Configuration(
86+
domain: 'domain',
87+
endpointIos: 'endpointIos',
88+
endpointAndroid: 'endpointAndroid',
89+
subscribeCustomerIfCreated: true);
90+
91+
Mindbox.instance.init(configuration: validConfig);
92+
93+
expect(await completer.future, equals('dummy-tokens'));
94+
});
95+
8096
test('When SDK was not initialized, getToken() should not return token',
8197
() async {
8298
final completer = Completer<String>();
8399

84-
Mindbox.instance.getToken((deviceToken) => completer.complete(deviceToken));
100+
Mindbox.instance.getTokens((deviceToken) => completer.complete(deviceToken));
85101

86102
expect(completer.isCompleted, isFalse);
87103
});

mindbox_android/analysis_options.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ linter:
2626
prefer_typing_uninitialized_variables: true
2727
public_member_api_docs: true
2828
always_put_control_body_on_new_line: true
29-
curly_braces_in_flow_control_structures: true
29+
curly_braces_in_flow_control_structures: true
30+
31+
analyzer:
32+
errors:
33+
deprecated_member_use_from_same_package: ignore

0 commit comments

Comments
 (0)