Skip to content
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
16 changes: 14 additions & 2 deletions example/flutter_example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ android {
multiDexEnabled true
}

signingConfigs {
debug {
storePassword "android"
keyAlias "androiddebugkey"
storeFile file("debug.keystore")
keyPassword "android"
}
}

buildTypes {
release {
signingConfig signingConfigs.debug
Expand All @@ -63,7 +72,7 @@ flutter {
source '../..'
}

ext.mindbox_version = "2.11.0"
ext.mindbox_version = "2.13.0"

dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
Expand All @@ -73,10 +82,13 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:32.8.1')
implementation 'com.google.firebase:firebase-messaging:23.4.1'
//https://developers.mindbox.ru/docs/huawei-send-push-notifications-flutter
implementation "cloud.mindbox:mindbox-huawei"
implementation 'cloud.mindbox:mindbox-huawei'
implementation 'com.huawei.hms:push:6.11.0.300'
implementation 'com.google.code.gson:gson:2.8.8'

implementation 'cloud.mindbox:mindbox-rustore'
implementation 'ru.rustore.sdk:pushclient:6.5.1'

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1"
}
11 changes: 11 additions & 0 deletions example/flutter_example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="cloud.mindbox.flutter_example">

<application
Expand All @@ -18,6 +19,12 @@
</intent-filter>
</service>

<service android:name=".MindboxRuStoreMessagingService" android:exported="true" tools:ignore="ExportedService">
<intent-filter>
<action android:name="ru.rustore.sdk.pushclient.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down Expand Up @@ -45,6 +52,10 @@
android:name="flutterEmbedding"
android:value="2" />

<meta-data
android:name="ru.rustore.sdk.pushclient.project_id"
android:value="MPYu6sSEZy8Vl-wYVkqFwwuaFNVlsBvx" />

</application>
<queries>
<intent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mindbox_firebase.MindboxFirebase
import cloud.mindbox.mindbox_huawei.MindboxHuawei
import cloud.mindbox.mindbox_rustore.MindboxRuStore
import cloud.mindbox.mobile_sdk.pushes.MindboxRemoteMessage
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
Expand All @@ -20,7 +21,7 @@ class MainApplication : Application() {
private val gson = Gson()
override fun onCreate() {
super.onCreate()
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase, MindboxHuawei))
Mindbox.initPushServices(applicationContext, listOf(MindboxFirebase, MindboxHuawei, MindboxRuStore))
}

fun setupEventChannel(flutterEngine: FlutterEngine) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cloud.mindbox.flutter_example

import cloud.mindbox.mindbox_rustore.MindboxRuStore
import cloud.mindbox.mobile_sdk.Mindbox
import kotlinx.coroutines.*
import ru.rustore.sdk.pushclient.messaging.model.RemoteMessage
import ru.rustore.sdk.pushclient.messaging.service.RuStoreMessagingService

class MindboxRuStoreMessagingService: RuStoreMessagingService() {

private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

override fun onNewToken(token: String) {
super.onNewToken(token)
Mindbox.updatePushToken(applicationContext, token, MindboxRuStore)
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
val channelId = "default_channel_id"
val channelName = "default_channel_name"
val channelDescription = "default_channel_description"
val pushSmallIcon = android.R.drawable.ic_dialog_info

// On some devices, onMessageReceived may be executed on the main thread
// We recommend handling push messages asynchronously
coroutineScope.launch {
val messageWasHandled = Mindbox.handleRemoteMessage(
context = applicationContext,
message = remoteMessage,
activities = mapOf(),
channelId = channelId,
channelName = channelName,
pushSmallIcon = pushSmallIcon,
defaultActivity = MainActivity::class.java,
channelDescription = channelDescription
)

// Method for checking if push is from Mindbox
val isMindboxPush = MindboxRuStore.isMindboxPush(remoteMessage = remoteMessage)

// Method for getting info from Mindbox push
val mindboxMessage =
MindboxRuStore.convertToMindboxRemoteMessage(remoteMessage = remoteMessage)
// If you want to save the notification you can call your save function from here.
mindboxMessage?.let {
val app = applicationContext as MainApplication
app.saveNotification(it)
}

if (!messageWasHandled) {
//If the push notification was not from Mindbox or it contains incorrect data, then you can write a fallback to process it
}
}
}

override fun onDestroy() {
super.onDestroy()
coroutineScope.cancel()
}
}
4 changes: 4 additions & 0 deletions example/flutter_example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ buildscript {
google()
mavenCentral()
maven {url 'https://developer.huawei.com/repo/'}
maven {url 'https://artifactory-external.vkpartner.ru/artifactory/maven'}
mavenLocal()
}

dependencies {
Expand All @@ -19,6 +21,8 @@ allprojects {
google()
mavenCentral()
maven {url 'https://developer.huawei.com/repo/'}
maven {url 'https://artifactory-external.vkpartner.ru/artifactory/maven'}
mavenLocal()
}
}

Expand Down
6 changes: 5 additions & 1 deletion mindbox/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ linter:
prefer_typing_uninitialized_variables: true
public_member_api_docs: true
always_put_control_body_on_new_line: true
curly_braces_in_flow_control_structures: true
curly_braces_in_flow_control_structures: true

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
9 changes: 9 additions & 0 deletions mindbox/lib/mindbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ class Mindbox {
/// Method to obtain token.
///
/// Callback returns token when Mindbox SDK is initialized. See also [init].
@Deprecated('Use method getTokens')
void getToken(Function(String token) callback) {
MindboxPlatform.instance.getToken(callback: callback);
}

/// Method to obtain all push tokens as json string like
/// {"FCM":"token1","HMS":"token2","RuStore":"token3"}
///
/// Callback returns tokens when Mindbox SDK is initialized. See also [init].
void getTokens(Function(String token) callback) {
MindboxPlatform.instance.getTokens(callback: callback);
}

/// Method for managing sdk logging
void setLogLevel({required LogLevel logLevel}) {
MindboxPlatform.instance.setLogLevel(logLevel: logLevel);
Expand Down
2 changes: 1 addition & 1 deletion mindbox/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mindbox
description: Flutter Mindbox SDK. Plugin wrapper over of Mindbox iOS/Android SDK.
version: 2.11.0
version: 2.13.0
homepage: https://mindbox.cloud/
repository: https://github.com/mindbox-cloud/flutter-sdk/tree/master/mindbox
documentation: https://developers.mindbox.ru/docs/flutter-sdk-integration
Expand Down
18 changes: 17 additions & 1 deletion mindbox/test/mindbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,27 @@ void main() {
expect(await completer.future, equals('dummy-token'));
});

test('When SDK was initialized, getTokens() should return tokens', () async {
final completer = Completer<String>();

Mindbox.instance.getTokens((deviceToken) => completer.complete(deviceToken));

final validConfig = Configuration(
domain: 'domain',
endpointIos: 'endpointIos',
endpointAndroid: 'endpointAndroid',
subscribeCustomerIfCreated: true);

Mindbox.instance.init(configuration: validConfig);

expect(await completer.future, equals('dummy-tokens'));
});

test('When SDK was not initialized, getToken() should not return token',
() async {
final completer = Completer<String>();

Mindbox.instance.getToken((deviceToken) => completer.complete(deviceToken));
Mindbox.instance.getTokens((deviceToken) => completer.complete(deviceToken));

expect(completer.isCompleted, isFalse);
});
Expand Down
6 changes: 5 additions & 1 deletion mindbox_android/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ linter:
prefer_typing_uninitialized_variables: true
public_member_api_docs: true
always_put_control_body_on_new_line: true
curly_braces_in_flow_control_structures: true
curly_braces_in_flow_control_structures: true

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
5 changes: 3 additions & 2 deletions mindbox_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
}

dependencies {
Expand Down Expand Up @@ -42,12 +43,12 @@ android {
}

defaultConfig {
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 34
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api 'cloud.mindbox:mobile-sdk:2.11.0'
api 'cloud.mindbox:mobile-sdk:2.13.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class MindboxAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, Ne
result.success(token)
}
}
"getTokens" -> {
if (tokenSubscription != null) {
Mindbox.disposePushTokenSubscription(tokenSubscription!!)
}
tokenSubscription = Mindbox.subscribePushTokens { token ->
result.success(token)
}
}
"executeAsyncOperation" -> {
if (call.arguments is List<*>) {
val args = call.arguments as List<*>
Expand Down
6 changes: 6 additions & 0 deletions mindbox_android/lib/src/mindbox_android_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class MindboxAndroidPlatform extends MindboxPlatform {
_methodHandler.getToken(callback: callback);
}

/// Returns tokens to callback.
@override
void getTokens({required Function(String token) callback}) {
_methodHandler.getTokens(callback: callback);
}

/// Method for managing sdk logging
@override
void setLogLevel({required LogLevel logLevel}) {
Expand Down
2 changes: 1 addition & 1 deletion mindbox_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mindbox_android
description: The implementation of 'mindbox' plugin for the Android platform.
version: 2.11.0
version: 2.13.0
homepage: https://mindbox.cloud/
repository: https://github.com/mindbox-cloud/flutter-sdk/tree/master/mindbox_android

Expand Down
6 changes: 5 additions & 1 deletion mindbox_ios/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ linter:
prefer_typing_uninitialized_variables: true
public_member_api_docs: true
always_put_control_body_on_new_line: true
curly_braces_in_flow_control_structures: true
curly_braces_in_flow_control_structures: true

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
4 changes: 4 additions & 0 deletions mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public class SwiftMindboxIosPlugin: NSObject, FlutterPlugin {
Mindbox.shared.getDeviceUUID {
deviceUUID in result(deviceUUID)
}
case "getTokens":
Mindbox.shared.getAPNSToken {
token in result("{\"APNS\":\"\(token)\"}")
}
case "getToken":
Mindbox.shared.getAPNSToken {
token in result(token)
Expand Down
6 changes: 3 additions & 3 deletions mindbox_ios/ios/mindbox_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'mindbox_ios'
s.version = '2.11.0'
s.version = '2.13.0'
s.summary = 'Mindbox Flutter SDK'
s.description = <<-DESC
The implementation of 'mindbox' plugin for the iOS platform
Expand All @@ -15,8 +15,8 @@ The implementation of 'mindbox' plugin for the iOS platform
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'Mindbox', '2.11.0'
s.dependency 'MindboxNotifications', '2.11.0'
s.dependency 'Mindbox', '2.13.0'
s.dependency 'MindboxNotifications', '2.13.0'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice.
Expand Down
6 changes: 6 additions & 0 deletions mindbox_ios/lib/src/mindbox_ios_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class MindboxIosPlatform extends MindboxPlatform {
_methodHandler.getToken(callback: callback);
}

/// Returns token to callback.
@override
void getTokens({required Function(String token) callback}) {
_methodHandler.getTokens(callback: callback);
}

/// Method for managing sdk logging
@override
void setLogLevel({required LogLevel logLevel}) {
Expand Down
2 changes: 1 addition & 1 deletion mindbox_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mindbox_ios
description: The implementation of 'mindbox' plugin for the iOS platform.
version: 2.11.0
version: 2.13.0
homepage: https://mindbox.cloud/
repository: https://github.com/mindbox-cloud/flutter-sdk/tree/master/mindbox_ios

Expand Down
6 changes: 5 additions & 1 deletion mindbox_platform_interface/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ linter:
prefer_typing_uninitialized_variables: true
public_member_api_docs: true
always_put_control_body_on_new_line: true
curly_braces_in_flow_control_structures: true
curly_braces_in_flow_control_structures: true

analyzer:
errors:
deprecated_member_use_from_same_package: ignore
4 changes: 4 additions & 0 deletions mindbox_platform_interface/lib/src/mindbox_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ abstract class MindboxPlatform {
void getToken({required Function(String) callback}) =>
throw UnimplementedError('getToken() has not been implemented.');

/// Method to obtain tokens.
void getTokens({required Function(String) callback}) =>
throw UnimplementedError('getToken() has not been implemented.');

/// Method for handling push-notification click. Returns link and payload to
/// callback.
void onPushClickReceived({
Expand Down
Loading