Skip to content

Commit

Permalink
feat-deferred-deeplinking-support-updated
Browse files Browse the repository at this point in the history
Added deferred deeplinking support in android
  • Loading branch information
IloveJavaa committed Sep 29, 2022
1 parent 7fa623f commit 035243c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.example.trackierfluttersdk

import android.app.Application
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.annotation.NonNull
import com.trackier.sdk.TrackierEvent
import com.trackier.sdk.TrackierSDK
import com.trackier.sdk.TrackierSDKConfig
import com.trackier.sdk.*
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
Expand Down Expand Up @@ -89,9 +89,28 @@ class TrackierfluttersdkPlugin : FlutterPlugin, MethodCallHandler {
environment = configMap.get("environment") as String
}
trackierSDKConfig = TrackierSDKConfig(context, appToken, environment)
trackierSDKConfig.setSDKVersion("1.6.29")
trackierSDKConfig.setSDKVersion("1.6.30")
trackierSDKConfig.setSDKType("flutter_sdk")
trackierSDKConfig.setAppSecret(secretId, secretKey)

if (configMap.containsKey("deeplinkCallbacks")) {
Log.d("xxxx","deeplinkCallbacks");
val dartMethodName = configMap["deeplinkCallbacks"] as String?
Log.d("xxxx","deeplinkCallbacksname--"+dartMethodName);
if (dartMethodName != null) {
if (channel != null) {
trackierSDKConfig.setDeepLinkListener(object : DeepLinkListener {
override fun onDeepLinking(result: DeepLink) {
// we have deepLink object and we can get any valve from Object
val uriParamsMap = HashMap<String, String>()
uriParamsMap["uri"] = result.getUrl()
Handler(Looper.getMainLooper()).post { channel.invokeMethod(dartMethodName, uriParamsMap) }
Log.d("xxxx","deeplink Logs"+result.getUrl());
}
})
}
}
}
TrackierSDK.initialize(trackierSDKConfig)
}

Expand Down
28 changes: 28 additions & 0 deletions lib/trackierconfig.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
import 'package:flutter/services.dart';

typedef void DeferredDeeplinkCallback(String? uri);

class TrackerSDKConfig {
String appToken = "";
String envirnoment = "";
String secretId = "";
String secretKey = "";

DeferredDeeplinkCallback? deferredDeeplinkCallback;

static const MethodChannel _channel = const MethodChannel('trackierfluttersdk');
static const String _deferredDeeplinkCallbackName = 'deferred-deeplink';

TrackerSDKConfig(String appToken, String envirnoment) {
this.appToken = appToken;
this.envirnoment = envirnoment;
_initCallbackHandlers();
}

void setAppSecret(String secretId, String secretKey) {
this.secretId = secretId;
this.secretKey = secretKey;
}

void _initCallbackHandlers() {
_channel.setMethodCallHandler((MethodCall call) async {
try {
switch (call.method) {
case _deferredDeeplinkCallbackName:
if (deferredDeeplinkCallback != null) {
String? uri = call.arguments['uri'];
if (deferredDeeplinkCallback != null) {
deferredDeeplinkCallback!(uri);
}
}
break;
}
}catch (e) {
print(e.toString());
}
});
}

Map<String, String?> get toMap {
Map<String, String?> configMap = {
'appToken': appToken,
'environment': envirnoment,
'secretId': secretId,
'secretKey': secretKey,
'deeplinkCallbacks' : _deferredDeeplinkCallbackName,
};

return configMap;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: trackier_sdk_flutter
description: This is trackier flutter SDK
version: 1.6.29
version: 1.6.30
homepage: https://github.com/trackier/flutter-sdk

environment:
Expand Down

0 comments on commit 035243c

Please sign in to comment.