From 51e15ef419ce3548aac738c66d847ce0258311bb Mon Sep 17 00:00:00 2001 From: "piyush.kukadiya" Date: Tue, 24 Mar 2020 01:04:21 +0530 Subject: [PATCH 01/16] task: Expose Inbox Message apis and InApp/Inbox Message button click callbacks CLEVER-7001 CLEVER-7007 --- android/build.gradle | 2 +- .../clevertap_plugin/CleverTapPlugin.java | 1891 +++++++++-------- .../com/clevertap/clevertap_plugin/Utils.java | 15 + example/android/app/build.gradle | 4 +- example/lib/main.dart | 159 ++ lib/clevertap_plugin.dart | 55 + 6 files changed, 1235 insertions(+), 891 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c7b68fb3..d8abdc68 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,7 +41,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.clevertap.android:clevertap-android-sdk:3.6.4' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.installreferrer:installreferrer:1.0' } diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java index 7a07be68..8b5c642a 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java @@ -7,6 +7,7 @@ import com.clevertap.android.sdk.CTExperimentsListener; import com.clevertap.android.sdk.CTInboxListener; +import com.clevertap.android.sdk.CTInboxMessage; import com.clevertap.android.sdk.CTInboxStyleConfig; import com.clevertap.android.sdk.CleverTapAPI; import com.clevertap.android.sdk.EventDetail; @@ -33,901 +34,1015 @@ import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry.Registrar; -/** CleverTapPlugin */ +/** + * CleverTapPlugin + */ public class CleverTapPlugin implements MethodCallHandler, SyncListener, InAppNotificationListener, CTInboxListener, CTExperimentsListener, InAppNotificationButtonListener, InboxMessageButtonListener, DisplayUnitListener { - private static final String TAG = "CleverTapPlugin"; - private static final String ERROR_MSG = "CleverTap Instance is not initialized"; - private static final String ERROR_IOS = " method is only applicable for iOS"; - private CleverTapAPI cleverTapAPI; - private Context context; - private MethodChannel channel; - private PluginRegistry.Registrar flutterRegistrar; - - private CleverTapPlugin(Activity activity){ - this.context = activity.getApplicationContext(); - this.cleverTapAPI = CleverTapAPI.getDefaultInstance(activity.getApplicationContext()); - if (this.cleverTapAPI != null) { - this.cleverTapAPI.setCTExperimentsListener(this); - this.cleverTapAPI.setCTNotificationInboxListener(this); - this.cleverTapAPI.setInboxMessageButtonListener(this); - this.cleverTapAPI.setInAppNotificationButtonListener(this); - this.cleverTapAPI.setInAppNotificationListener(this); - this.cleverTapAPI.setSyncListener(this); - this.cleverTapAPI.setDisplayUnitListener(this); - this.cleverTapAPI.setLibrary("Flutter"); - } - } - - /** Plugin registration. */ - public static void registerWith(Registrar registrar) { - CleverTapPlugin plugin = new CleverTapPlugin(registrar.activity()); - plugin.channel = new MethodChannel(registrar.messenger(), "clevertap_plugin"); - plugin.channel.setMethodCallHandler(plugin); - plugin.flutterRegistrar = registrar; - } - - private boolean isCleverTapNotNull(CleverTapAPI cleverTapAPI){ - return cleverTapAPI != null; - } - - @Override - public void onMethodCall(MethodCall call, Result result) { - switch (call.method) { - - case "setDebugLevel": { - int debugLevelValue = call.argument("debugLevel"); - CleverTapAPI.setDebugLevel(debugLevelValue); - result.success(null); - break; - } - // Push Methods - case "setPushToken": { - String token = call.argument("token"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.pushFcmRegistrationId(token, true); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - case "createNotification": { - JSONObject extras = call.argument("extras"); - if(isCleverTapNotNull(cleverTapAPI)) { - try { - CleverTapAPI.createNotification(context,Utils.jsonToBundle(extras)); - } catch (JSONException e) { - result.error(TAG,"Unable to render notification due to JSONException - " + e.getLocalizedMessage(),null); - } - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //UI Editor connection - case "setUIEditorConnectionEnabled": { - boolean enabled = call.argument("value"); - CleverTapAPI.setUIEditorConnectionEnabled(enabled); - result.success(null); - break; - } - - //Notification channel/group methods for Android O - case "createNotificationChannel": { - String channelId = call.argument("channelId"); - String channelName = call.argument("channelName"); - String channelDescription = call.argument("channelDescription"); - int importance = call.argument("importance"); - boolean showBadge = call.argument("showBadge"); - CleverTapAPI.createNotificationChannel(context,channelId,channelName,channelDescription,importance,showBadge); - result.success(null); - break; - } - case "createNotificationChannelWithSound": { - String channelId = call.argument("channelId"); - String channelName = call.argument("channelName"); - String channelDescription = call.argument("channelDescription"); - int importance = call.argument("importance"); - boolean showBadge = call.argument("showBadge"); - String sound = call.argument("sound"); - CleverTapAPI.createNotificationChannel(context,channelId,channelName,channelDescription,importance,showBadge,sound); - result.success(null); - break; - } - case "createNotificationChannelWithGroupId": { - String channelId = call.argument("channelId"); - String channelName = call.argument("channelName"); - String channelDescription = call.argument("channelDescription"); - int importance = call.argument("importance"); - String groupId = call.argument("groupId"); - boolean showBadge = call.argument("showBadge"); - CleverTapAPI.createNotificationChannel(context,channelId,channelName,channelDescription,importance,groupId,showBadge); - result.success(null); - break; - } - case "createNotificationChannelWithGroupIdAndSound": { - String channelId = call.argument("channelId"); - String channelName = call.argument("channelName"); - String channelDescription = call.argument("channelDescription"); - int importance = call.argument("importance"); - String groupId = call.argument("groupId"); - boolean showBadge = call.argument("showBadge"); - String sound = call.argument("sound"); - CleverTapAPI.createNotificationChannel(context,channelId,channelName,channelDescription,importance,groupId,showBadge,sound); - result.success(null); - break; - } - case "createNotificationChannelGroup": { - String groupId = call.argument("groupId"); - String groupName = call.argument("groupName"); - CleverTapAPI.createNotificationChannelGroup(context,groupId,groupName); - result.success(null); - break; - } - case "deleteNotificationChannel": { - String channelId = call.argument("channelId"); - CleverTapAPI.deleteNotificationChannel(context,channelId); - result.success(null); - break; - } - case "deleteNotificationChannelGroup": { - String groupId = call.argument("groupId"); - CleverTapAPI.deleteNotificationChannelGroup(context,groupId); - result.success(null); - break; - } - - //Enables tracking opt out for the currently active user. - case "setOptOut": { - boolean value = call.argument("value"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.setOptOut(value); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Sets the SDK to offline mode - case "setOffline": { - boolean value = call.argument("value"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.setOffline(value); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Enables the reporting of device network-related information, including IP address. This reporting is disabled by default. - case "enableDeviceNetworkInfoReporting": { - boolean value = call.argument("value"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.enableDeviceNetworkInfoReporting(value); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - // Personalization - case "enablePersonalization": { - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.enablePersonalization(); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "disablePersonalization": { - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.disablePersonalization(); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - // Event API - case "recordScreenView": { - String name = call.argument("screenName"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.recordScreen(name); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "recordEvent": { - Map eventData = call.argument("eventData"); - String eventName = call.argument("eventName"); - if(isCleverTapNotNull(cleverTapAPI)) { - this.cleverTapAPI.pushEvent(eventName, eventData); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "recordChargedEvent": { - HashMap chargeDetails = call.argument("chargeDetails"); - ArrayList> items = call.argument("items"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.pushChargedEvent(chargeDetails, items); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "eventGetFirstTime": { - String eventName = call.argument("eventName"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getFirstTime(eventName)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "eventGetLastTime": { - String eventName = call.argument("eventName"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getLastTime(eventName)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "eventGetOccurrences": { - String eventName = call.argument("eventName"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getCount(eventName)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "eventGetDetail": { - String eventName = call.argument("eventName"); - if(isCleverTapNotNull(cleverTapAPI)) { - EventDetail eventDetail = cleverTapAPI.getDetails(eventName); - result.success(Utils.eventDetailToMap(eventDetail)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getEventHistory": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.historyEventDetailToMap(cleverTapAPI.getHistory())); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Profile API - - case "setLocation": { - double lat = call.argument("latitude"); - double lon = call.argument("longitude"); - if(isCleverTapNotNull(cleverTapAPI)) { - Location location = new Location("CleverTapFlutter"); - location.setLatitude(lat); - location.setLongitude(lon); - cleverTapAPI.setLocation(location); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileGetCleverTapAttributionIdentifier": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getCleverTapAttributionIdentifier()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileGetCleverTapID": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getCleverTapID()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "onUserLogin": { - Map profile = call.argument("profile"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.onUserLogin(profile); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileSet": { - Map profile = call.argument("profile"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.pushProfile(profile); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileSetGraphUser": { - Map profileMap = call.argument("profile"); - JSONObject profile = Utils.mapToJSONObject(profileMap); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.pushFacebookUser(profile); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileGetProperty": { - String propertyName = call.argument("propertyName"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getProperty(propertyName)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileRemoveValueForKey": { - String key = call.argument("key"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.removeValueForKey(key); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileSetMultiValues": { - String key = call.argument("key"); - ArrayList values = call.argument("values"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.setMultiValuesForKey(key,values); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileAddMultiValue": { - String key = call.argument("key"); - String value = call.argument("value"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.addMultiValueForKey(key,value); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileAddMultiValues": { - String key = call.argument("key"); - ArrayList values = call.argument("values"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.addMultiValuesForKey(key,values); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileRemoveMultiValue": { - String key = call.argument("key"); - String value = call.argument("value"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.removeMultiValueForKey(key,value); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "profileRemoveMultiValues": { - String key = call.argument("key"); - ArrayList values = call.argument("values"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.removeMultiValuesForKey(key,values); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Session API - - case "pushInstallReferrer": { - String source = call.argument("source"); - String medium = call.argument("medium"); - String campaign = call.argument("campaign"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.pushInstallReferrer(source, medium, campaign); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "sessionGetTimeElapsed": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getTimeElapsed()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "sessionGetTotalVisits": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getTotalVisits()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "sessionGetScreenCount": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getScreenCount()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "sessionGetPreviousVisitTime": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getPreviousVisitTime()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "sessionGetUTMDetails": { - if(isCleverTapNotNull(cleverTapAPI)) { - UTMDetail detail = cleverTapAPI.getUTMDetails(); - result.success(Utils.utmDetailsToMap(detail)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //App Inbox Methods - case "initializeInbox": { - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.initializeInbox(); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "showInbox": { - Map styleConfigMap = call.argument("styleConfig"); - JSONObject styleConfigJson = Utils.mapToJSONObject(styleConfigMap); - CTInboxStyleConfig styleConfig = new CTInboxStyleConfig(); - if (styleConfigJson != null) { - styleConfig = Utils.jsonToStyleConfig(styleConfigJson); - } - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.showAppInbox(styleConfig); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getInboxMessageCount": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getInboxMessageCount()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getInboxMessageUnreadCount": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getInboxMessageUnreadCount()); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Dynamic Variables methods - - case "registerBooleanVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerBooleanVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerDoubleVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerDoubleVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerIntegerVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerIntegerVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerStringVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerStringVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerListOfBooleanVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerListOfBooleanVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerListOfDoubleVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerListOfDoubleVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerListOfIntegerVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerListOfIntegerVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerListOfStringVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerListOfStringVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerMapOfBooleanVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerMapOfBooleanVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerMapOfDoubleVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerMapOfDoubleVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerMapOfIntegerVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerMapOfIntegerVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "registerMapOfStringVariable": { - String varName = call.argument("name"); - if(isCleverTapNotNull(cleverTapAPI)) { - cleverTapAPI.registerMapOfStringVariable(varName); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getBooleanVariable": { - String varName = call.argument("name"); - boolean defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getBooleanVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getDoubleVariable": { - String varName = call.argument("name"); - double defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getDoubleVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getIntegerVariable": { - String varName = call.argument("name"); - int defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getIntegerVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getStringVariable": { - String varName = call.argument("name"); - String defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getStringVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getListOfBooleanVariable": { - String varName = call.argument("name"); - List defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getListOfBooleanVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getListOfDoubleVariable": { - String varName = call.argument("name"); - List defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getListOfDoubleVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getListOfIntegerVariable": { - String varName = call.argument("name"); - List defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getListOfIntegerVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getListOfStringVariable": { - String varName = call.argument("name"); - List defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getListOfStringVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getMapOfBooleanVariable": { - String varName = call.argument("name"); - Map defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getMapOfBooleanVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getMapOfDoubleVariable": { - String varName = call.argument("name"); - Map defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getMapOfDoubleVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getMapOfIntegerVariable": { - String varName = call.argument("name"); - Map defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getMapOfIntegerVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - case "getMapOfStringVariable": { - String varName = call.argument("name"); - Map defaultValue = call.argument("defaultValue"); - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(cleverTapAPI.getMapOfStringVariable(varName,defaultValue)); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - //Native Display - case "getAllDisplayUnits": { - if(isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.displayUnitListToMap(cleverTapAPI.getAllDisplayUnits())); - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - case "getDisplayUnitForId": { - String unitId = call.argument("unitId"); - if(isCleverTapNotNull(cleverTapAPI)) { - if(cleverTapAPI.getDisplayUnitForId(unitId) != null){ - JSONObject displayUnit = cleverTapAPI.getDisplayUnitForId(unitId).getJsonObject(); - if(displayUnit != null){ - result.success(Utils.jsonObjectToMap(displayUnit)); - } - }else{ - result.error(TAG,"Display Unit is NULL",null); - } - }else{ - result.error(TAG,ERROR_MSG,null); - } - break; - } - - case "pushDisplayUnitViewedEvent":{ - String unitId = call.argument("unitId"); - if(isCleverTapNotNull(cleverTapAPI)){ - cleverTapAPI.pushDisplayUnitViewedEventForID(unitId); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); + private static final String TAG = "CleverTapPlugin"; + private static final String ERROR_MSG = "CleverTap Instance is not initialized"; + private static final String ERROR_MSG_ID = "Message Id is null or empty"; + private static final String ERROR_IOS = " method is only applicable for iOS"; + private CleverTapAPI cleverTapAPI; + private Context context; + private MethodChannel channel; + private PluginRegistry.Registrar flutterRegistrar; + + private CleverTapPlugin(Activity activity) { + this.context = activity.getApplicationContext(); + this.cleverTapAPI = CleverTapAPI.getDefaultInstance(activity.getApplicationContext()); + if (this.cleverTapAPI != null) { + this.cleverTapAPI.setCTExperimentsListener(this); + this.cleverTapAPI.setCTNotificationInboxListener(this); + this.cleverTapAPI.setInboxMessageButtonListener(this); + this.cleverTapAPI.setInAppNotificationButtonListener(this); + this.cleverTapAPI.setInAppNotificationListener(this); + this.cleverTapAPI.setSyncListener(this); + this.cleverTapAPI.setDisplayUnitListener(this); + this.cleverTapAPI.setLibrary("Flutter"); } - } - - case "pushDisplayUnitClickedEvent":{ - String unitId = call.argument("unitId"); - if(isCleverTapNotNull(cleverTapAPI)){ - cleverTapAPI.pushDisplayUnitClickedEventForID(unitId); - result.success(null); - }else{ - result.error(TAG,ERROR_MSG,null); + } + + /** + * Plugin registration. + */ + public static void registerWith(Registrar registrar) { + CleverTapPlugin plugin = new CleverTapPlugin(registrar.activity()); + plugin.channel = new MethodChannel(registrar.messenger(), "clevertap_plugin"); + plugin.channel.setMethodCallHandler(plugin); + plugin.flutterRegistrar = registrar; + } + + private boolean isCleverTapNotNull(CleverTapAPI cleverTapAPI) { + return cleverTapAPI != null; + } + + @Override + public void onMethodCall(MethodCall call, Result result) { + switch (call.method) { + + case "setDebugLevel": { + int debugLevelValue = call.argument("debugLevel"); + CleverTapAPI.setDebugLevel(debugLevelValue); + result.success(null); + break; + } + // Push Methods + case "setPushToken": { + String token = call.argument("token"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushFcmRegistrationId(token, true); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "createNotification": { + JSONObject extras = call.argument("extras"); + if (isCleverTapNotNull(cleverTapAPI)) { + try { + CleverTapAPI.createNotification(context, Utils.jsonToBundle(extras)); + } catch (JSONException e) { + result.error(TAG, "Unable to render notification due to JSONException - " + e.getLocalizedMessage(), null); + } + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //UI Editor connection + case "setUIEditorConnectionEnabled": { + boolean enabled = call.argument("value"); + CleverTapAPI.setUIEditorConnectionEnabled(enabled); + result.success(null); + break; + } + + //Notification channel/group methods for Android O + case "createNotificationChannel": { + String channelId = call.argument("channelId"); + String channelName = call.argument("channelName"); + String channelDescription = call.argument("channelDescription"); + int importance = call.argument("importance"); + boolean showBadge = call.argument("showBadge"); + CleverTapAPI.createNotificationChannel(context, channelId, channelName, channelDescription, importance, showBadge); + result.success(null); + break; + } + case "createNotificationChannelWithSound": { + String channelId = call.argument("channelId"); + String channelName = call.argument("channelName"); + String channelDescription = call.argument("channelDescription"); + int importance = call.argument("importance"); + boolean showBadge = call.argument("showBadge"); + String sound = call.argument("sound"); + CleverTapAPI.createNotificationChannel(context, channelId, channelName, channelDescription, importance, showBadge, sound); + result.success(null); + break; + } + case "createNotificationChannelWithGroupId": { + String channelId = call.argument("channelId"); + String channelName = call.argument("channelName"); + String channelDescription = call.argument("channelDescription"); + int importance = call.argument("importance"); + String groupId = call.argument("groupId"); + boolean showBadge = call.argument("showBadge"); + CleverTapAPI.createNotificationChannel(context, channelId, channelName, channelDescription, importance, groupId, showBadge); + result.success(null); + break; + } + case "createNotificationChannelWithGroupIdAndSound": { + String channelId = call.argument("channelId"); + String channelName = call.argument("channelName"); + String channelDescription = call.argument("channelDescription"); + int importance = call.argument("importance"); + String groupId = call.argument("groupId"); + boolean showBadge = call.argument("showBadge"); + String sound = call.argument("sound"); + CleverTapAPI.createNotificationChannel(context, channelId, channelName, channelDescription, importance, groupId, showBadge, sound); + result.success(null); + break; + } + case "createNotificationChannelGroup": { + String groupId = call.argument("groupId"); + String groupName = call.argument("groupName"); + CleverTapAPI.createNotificationChannelGroup(context, groupId, groupName); + result.success(null); + break; + } + case "deleteNotificationChannel": { + String channelId = call.argument("channelId"); + CleverTapAPI.deleteNotificationChannel(context, channelId); + result.success(null); + break; + } + case "deleteNotificationChannelGroup": { + String groupId = call.argument("groupId"); + CleverTapAPI.deleteNotificationChannelGroup(context, groupId); + result.success(null); + break; + } + + //Enables tracking opt out for the currently active user. + case "setOptOut": { + boolean value = call.argument("value"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.setOptOut(value); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //Sets the SDK to offline mode + case "setOffline": { + boolean value = call.argument("value"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.setOffline(value); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //Enables the reporting of device network-related information, including IP address. This reporting is disabled by default. + case "enableDeviceNetworkInfoReporting": { + boolean value = call.argument("value"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.enableDeviceNetworkInfoReporting(value); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + // Personalization + case "enablePersonalization": { + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.enablePersonalization(); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "disablePersonalization": { + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.disablePersonalization(); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + // Event API + case "recordScreenView": { + String name = call.argument("screenName"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.recordScreen(name); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "recordEvent": { + Map eventData = call.argument("eventData"); + String eventName = call.argument("eventName"); + if (isCleverTapNotNull(cleverTapAPI)) { + this.cleverTapAPI.pushEvent(eventName, eventData); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "recordChargedEvent": { + HashMap chargeDetails = call.argument("chargeDetails"); + ArrayList> items = call.argument("items"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushChargedEvent(chargeDetails, items); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "eventGetFirstTime": { + String eventName = call.argument("eventName"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getFirstTime(eventName)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "eventGetLastTime": { + String eventName = call.argument("eventName"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getLastTime(eventName)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "eventGetOccurrences": { + String eventName = call.argument("eventName"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getCount(eventName)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "eventGetDetail": { + String eventName = call.argument("eventName"); + if (isCleverTapNotNull(cleverTapAPI)) { + EventDetail eventDetail = cleverTapAPI.getDetails(eventName); + result.success(Utils.eventDetailToMap(eventDetail)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getEventHistory": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(Utils.historyEventDetailToMap(cleverTapAPI.getHistory())); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //Profile API + + case "setLocation": { + double lat = call.argument("latitude"); + double lon = call.argument("longitude"); + if (isCleverTapNotNull(cleverTapAPI)) { + Location location = new Location("CleverTapFlutter"); + location.setLatitude(lat); + location.setLongitude(lon); + cleverTapAPI.setLocation(location); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileGetCleverTapAttributionIdentifier": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getCleverTapAttributionIdentifier()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileGetCleverTapID": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getCleverTapID()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "onUserLogin": { + Map profile = call.argument("profile"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.onUserLogin(profile); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileSet": { + Map profile = call.argument("profile"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushProfile(profile); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileSetGraphUser": { + Map profileMap = call.argument("profile"); + JSONObject profile = Utils.mapToJSONObject(profileMap); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushFacebookUser(profile); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileGetProperty": { + String propertyName = call.argument("propertyName"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getProperty(propertyName)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileRemoveValueForKey": { + String key = call.argument("key"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.removeValueForKey(key); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileSetMultiValues": { + String key = call.argument("key"); + ArrayList values = call.argument("values"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.setMultiValuesForKey(key, values); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileAddMultiValue": { + String key = call.argument("key"); + String value = call.argument("value"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.addMultiValueForKey(key, value); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileAddMultiValues": { + String key = call.argument("key"); + ArrayList values = call.argument("values"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.addMultiValuesForKey(key, values); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileRemoveMultiValue": { + String key = call.argument("key"); + String value = call.argument("value"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.removeMultiValueForKey(key, value); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "profileRemoveMultiValues": { + String key = call.argument("key"); + ArrayList values = call.argument("values"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.removeMultiValuesForKey(key, values); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //Session API + + case "pushInstallReferrer": { + String source = call.argument("source"); + String medium = call.argument("medium"); + String campaign = call.argument("campaign"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushInstallReferrer(source, medium, campaign); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "sessionGetTimeElapsed": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getTimeElapsed()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "sessionGetTotalVisits": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getTotalVisits()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "sessionGetScreenCount": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getScreenCount()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "sessionGetPreviousVisitTime": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getPreviousVisitTime()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "sessionGetUTMDetails": { + if (isCleverTapNotNull(cleverTapAPI)) { + UTMDetail detail = cleverTapAPI.getUTMDetails(); + result.success(Utils.utmDetailsToMap(detail)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //App Inbox Methods + case "initializeInbox": { + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.initializeInbox(); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "showInbox": { + Map styleConfigMap = call.argument("styleConfig"); + JSONObject styleConfigJson = Utils.mapToJSONObject(styleConfigMap); + CTInboxStyleConfig styleConfig = new CTInboxStyleConfig(); + if (styleConfigJson != null) { + styleConfig = Utils.jsonToStyleConfig(styleConfigJson); + } + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.showAppInbox(styleConfig); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getInboxMessageCount": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getInboxMessageCount()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getInboxMessageUnreadCount": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getInboxMessageUnreadCount()); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getAllInboxMessages": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(Utils.getJsonStringList(cleverTapAPI.getAllInboxMessages())); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "getUnreadInboxMessages": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(Utils.getJsonStringList(cleverTapAPI.getUnreadInboxMessages())); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "getInboxMessageForId": { + if (isCleverTapNotNull(cleverTapAPI)) { + String messageId = call.argument("messageId"); + + if (messageId == null || messageId.isEmpty()) { + result.error(TAG, ERROR_MSG_ID, null); + return; + } + + CTInboxMessage inboxMessage = cleverTapAPI.getInboxMessageForId(messageId); + + if (inboxMessage != null && inboxMessage.getData() != null) { + result.success(inboxMessage.getData().toString()); + } else { + result.success(null); + } + + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "deleteInboxMessageForId": { + if (isCleverTapNotNull(cleverTapAPI)) { + String messageId = call.argument("messageId"); + + if (messageId == null || messageId.isEmpty()) { + result.error(TAG, ERROR_MSG_ID, null); + return; + } + + cleverTapAPI.deleteInboxMessage(messageId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "markReadInboxMessageForId": { + if (isCleverTapNotNull(cleverTapAPI)) { + String messageId = call.argument("messageId"); + + if (messageId == null || messageId.isEmpty()) { + result.error(TAG, ERROR_MSG_ID, null); + return; + } + + cleverTapAPI.markReadInboxMessage(messageId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "pushInboxNotificationClickedEventForId": { + if (isCleverTapNotNull(cleverTapAPI)) { + String messageId = call.argument("messageId"); + + if (messageId == null || messageId.isEmpty()) { + result.error(TAG, ERROR_MSG_ID, null); + return; + } + + cleverTapAPI.pushInboxNotificationClickedEvent(messageId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "pushInboxNotificationViewedEventForId": { + if (isCleverTapNotNull(cleverTapAPI)) { + String messageId = call.argument("messageId"); + + if (messageId == null || messageId.isEmpty()) { + result.error(TAG, ERROR_MSG_ID, null); + return; + } + + cleverTapAPI.pushInboxNotificationViewedEvent(messageId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + + //Dynamic Variables methods + + case "registerBooleanVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerBooleanVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerDoubleVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerDoubleVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerIntegerVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerIntegerVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerStringVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerStringVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerListOfBooleanVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerListOfBooleanVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerListOfDoubleVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerListOfDoubleVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerListOfIntegerVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerListOfIntegerVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerListOfStringVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerListOfStringVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerMapOfBooleanVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerMapOfBooleanVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerMapOfDoubleVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerMapOfDoubleVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerMapOfIntegerVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerMapOfIntegerVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "registerMapOfStringVariable": { + String varName = call.argument("name"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.registerMapOfStringVariable(varName); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getBooleanVariable": { + String varName = call.argument("name"); + boolean defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getBooleanVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getDoubleVariable": { + String varName = call.argument("name"); + double defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getDoubleVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getIntegerVariable": { + String varName = call.argument("name"); + int defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getIntegerVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getStringVariable": { + String varName = call.argument("name"); + String defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getStringVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getListOfBooleanVariable": { + String varName = call.argument("name"); + List defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getListOfBooleanVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getListOfDoubleVariable": { + String varName = call.argument("name"); + List defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getListOfDoubleVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getListOfIntegerVariable": { + String varName = call.argument("name"); + List defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getListOfIntegerVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getListOfStringVariable": { + String varName = call.argument("name"); + List defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getListOfStringVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getMapOfBooleanVariable": { + String varName = call.argument("name"); + Map defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getMapOfBooleanVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getMapOfDoubleVariable": { + String varName = call.argument("name"); + Map defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getMapOfDoubleVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getMapOfIntegerVariable": { + String varName = call.argument("name"); + Map defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getMapOfIntegerVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + case "getMapOfStringVariable": { + String varName = call.argument("name"); + Map defaultValue = call.argument("defaultValue"); + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(cleverTapAPI.getMapOfStringVariable(varName, defaultValue)); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + //Native Display + case "getAllDisplayUnits": { + if (isCleverTapNotNull(cleverTapAPI)) { + result.success(Utils.displayUnitListToMap(cleverTapAPI.getAllDisplayUnits())); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "getDisplayUnitForId": { + String unitId = call.argument("unitId"); + if (isCleverTapNotNull(cleverTapAPI)) { + if (cleverTapAPI.getDisplayUnitForId(unitId) != null) { + JSONObject displayUnit = cleverTapAPI.getDisplayUnitForId(unitId).getJsonObject(); + if (displayUnit != null) { + result.success(Utils.jsonObjectToMap(displayUnit)); + } + } else { + result.error(TAG, "Display Unit is NULL", null); + } + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "pushDisplayUnitViewedEvent": { + String unitId = call.argument("unitId"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushDisplayUnitViewedEventForID(unitId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + } + + case "pushDisplayUnitClickedEvent": { + String unitId = call.argument("unitId"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushDisplayUnitClickedEventForID(unitId); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + } + + //no-op for android, methods only for iOS. + case "registerForPush": { + Log.d(TAG, "registerForPush" + ERROR_IOS); + break; + } + + case "getInitialUrl": { + Log.d(TAG, "getInitialUrl" + ERROR_IOS); + break; + } + + default: { + result.notImplemented(); + } } - } - - //no-op for android, methods only for iOS. - case "registerForPush" : { - Log.d(TAG,"registerForPush"+ERROR_IOS); - break; - } - - case "getInitialUrl" : { - Log.d(TAG,"getInitialUrl"+ERROR_IOS); - break; - } - - default: { - result.notImplemented(); - } + } - } - - private void runOnMainThread(final Runnable runnable) { - ((Activity) flutterRegistrar.activeContext()).runOnUiThread(runnable); - } - - private void invokeMethodOnUiThread(final String methodName, final String cleverTapID){ - final MethodChannel channel = this.channel; - runOnMainThread(() -> { - if(!cleverTapID.isEmpty()) { - channel.invokeMethod(methodName, cleverTapID); - }else{ - channel.invokeMethod(methodName,null); - } - }); - } - - private void invokeMethodOnUiThread(final String methodName, final Map map ){ - final MethodChannel channel = this.channel; - runOnMainThread(() -> channel.invokeMethod(methodName,map)); - - } - - - @Override - public void CTExperimentsUpdated() { - invokeMethodOnUiThread("CTExperimentsUpdated",""); - } - - @Override - public void inboxDidInitialize() { - invokeMethodOnUiThread("inboxDidInitialize", ""); - } - - @Override - public void inboxMessagesDidUpdate() { - invokeMethodOnUiThread("inboxMessagesDidUpdate",""); - } - - @Override - public boolean beforeShow(Map extras) { - invokeMethodOnUiThread("beforeShow",extras); - return true; - } - - @Override - public void onDismissed(Map extras, Map actionExtras) { - Map map1 = new HashMap<>(); - map1.put("extras",extras); - map1.put("actionExtras",actionExtras); - invokeMethodOnUiThread("inAppNotificationDismissed",map1); - } - - @Override - public void profileDataUpdated(JSONObject updates) { - invokeMethodOnUiThread("profileDataUpdated",Utils.jsonObjectToMap(updates)); - } - - @Override - public void profileDidInitialize(String CleverTapID) { - invokeMethodOnUiThread("profileDidInitialize",CleverTapID); - } - - @Override - public void onInAppButtonClick(HashMap payload) { - invokeMethodOnUiThread("onInAppButtonClick",payload); - } - - @Override - public void onInboxButtonClick(HashMap payload) { - invokeMethodOnUiThread("onInboxButtonClick",payload); - } - - @Override - public void onDisplayUnitsLoaded(ArrayList units) { - invokeMethodOnUiThread("onDisplayUnitsLoaded",Utils.displayUnitListToMap(units)); - } + private void runOnMainThread(final Runnable runnable) { + ((Activity) flutterRegistrar.activeContext()).runOnUiThread(runnable); + } + + private void invokeMethodOnUiThread(final String methodName, final String cleverTapID) { + final MethodChannel channel = this.channel; + runOnMainThread(() -> { + if (!cleverTapID.isEmpty()) { + channel.invokeMethod(methodName, cleverTapID); + } else { + channel.invokeMethod(methodName, null); + } + }); + } + + private void invokeMethodOnUiThread(final String methodName, final Map map) { + final MethodChannel channel = this.channel; + runOnMainThread(() -> channel.invokeMethod(methodName, map)); + + } + + + @Override + public void CTExperimentsUpdated() { + invokeMethodOnUiThread("CTExperimentsUpdated", ""); + } + + @Override + public void inboxDidInitialize() { + invokeMethodOnUiThread("inboxDidInitialize", ""); + } + + @Override + public void inboxMessagesDidUpdate() { + invokeMethodOnUiThread("inboxMessagesDidUpdate", ""); + } + + @Override + public boolean beforeShow(Map extras) { + invokeMethodOnUiThread("beforeShow", extras); + return true; + } + + @Override + public void onDismissed(Map extras, Map actionExtras) { + Map map1 = new HashMap<>(); + map1.put("extras", extras); + map1.put("actionExtras", actionExtras); + invokeMethodOnUiThread("inAppNotificationDismissed", map1); + } + + @Override + public void profileDataUpdated(JSONObject updates) { + invokeMethodOnUiThread("profileDataUpdated", Utils.jsonObjectToMap(updates)); + } + + @Override + public void profileDidInitialize(String CleverTapID) { + invokeMethodOnUiThread("profileDidInitialize", CleverTapID); + } + + @Override + public void onInAppButtonClick(HashMap payload) { + invokeMethodOnUiThread("onInAppButtonClick", payload); + } + + @Override + public void onInboxButtonClick(HashMap payload) { + invokeMethodOnUiThread("onInboxButtonClick", payload); + } + + @Override + public void onDisplayUnitsLoaded(ArrayList units) { + invokeMethodOnUiThread("onDisplayUnitsLoaded", Utils.displayUnitListToMap(units)); + } } diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java index fa2e5d6e..2d794d91 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java @@ -3,6 +3,7 @@ import android.os.Bundle; import android.util.Log; +import com.clevertap.android.sdk.CTInboxMessage; import com.clevertap.android.sdk.CTInboxStyleConfig; import com.clevertap.android.sdk.EventDetail; import com.clevertap.android.sdk.UTMDetail; @@ -183,4 +184,18 @@ static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { } return bundle; } + + static ArrayList getJsonStringList(List list) { + ArrayList jsonStringList =new ArrayList<>(); + if (list!=null) + { + for (CTInboxMessage item:list) + { + if (item!=null&&item.getData()!=null) { + jsonStringList.add(item.getData().toString()); + } + } + } + return jsonStringList; + } } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index efa94c28..d36bd82f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -32,7 +32,7 @@ android { } defaultConfig { - applicationId "com.clevertap.clevertap_plugin_example" + applicationId "com.example.clevertap_plugin_example" minSdkVersion 16 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() @@ -56,7 +56,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.clevertap.android:clevertap-android-sdk:3.6.4' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.android.support:appcompat-v7:28.0.0'//MANDATORY for App Inbox diff --git a/example/lib/main.dart b/example/lib/main.dart index 322fe4be..ddc8ba31 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -311,6 +311,34 @@ class _MyAppState extends State { onPressed: () => getAdUnits(), child: Text('Get Ad Units') ), + RaisedButton( + onPressed: () => getAllInboxMessages(), + child: Text('Get All Inbox Messages') + ), + RaisedButton( + onPressed: () => getUnreadInboxMessages(), + child: Text('Get Unread Inbox Messages') + ), + RaisedButton( + onPressed: () => getInboxMessageForId(), + child: Text('Get Inbox Message For ID') + ), + RaisedButton( + onPressed: () => deleteInboxMessageForId(), + child: Text('Delete Inbox Message For ID') + ), + RaisedButton( + onPressed: () => markReadInboxMessageForId(), + child: Text('Mark Inbox Message As Read') + ), + RaisedButton( + onPressed: () => pushInboxNotificationClickedEventForId(), + child: Text('pushInboxNotificationClickedEventForId') + ), + RaisedButton( + onPressed: () => pushInboxNotificationViewedEventForId(), + child: Text('pushInboxNotificationViewedEventForId') + ), ], ), ), @@ -367,6 +395,137 @@ class _MyAppState extends State { } } + void getAllInboxMessages(){ + CleverTapPlugin.getAllInboxMessages().then((messageList) { + if (messageList == null || messageList.length==0) return; + + Map itemFirst = jsonDecode(messageList[0]); + Map itemLast = jsonDecode(messageList[messageList.length-1]); + + setState((() { + print("First Inbox Message = ${itemFirst["id"]}"); + print("Last Inbox Message = ${itemLast["id"]}"); + })); + }).catchError((error) { + setState(() { + print("$error"); + }); + }); + } + + void getUnreadInboxMessages() async{ + + var messageList= await CleverTapPlugin.getUnreadInboxMessages(); + + if (messageList == null || messageList.length==0) return; + + Map itemFirst = jsonDecode(messageList[0]); + Map itemLast = jsonDecode(messageList[messageList.length-1]); + + setState((() { + print("First Unread Inbox Message = ${itemFirst["id"]}"); + print("Last Unread Inbox Message = ${itemLast["id"]}"); + })); + } + + void getInboxMessageForId() async{ + var messageId=await getFirstInboxMessageId(); + + if(messageId==null) { + setState((() { + print("Inbox Message id is null"); + })); + return; + } + + var messageForId= await CleverTapPlugin.getInboxMessageForId(messageId); + setState((() { + print("Inbox Message for id = ${messageForId}"); + })); + + } + + void deleteInboxMessageForId() async{ + var messageId=await getFirstInboxMessageId(); + + if(messageId==null) { + setState((() { + print("Inbox Message id is null"); + })); + return; + } + + await CleverTapPlugin.deleteInboxMessageForId(messageId); + + setState((() { + print("Deleted Inbox Message with id = ${messageId}"); + })); + + } + + void markReadInboxMessageForId() async{ + var messageList= await CleverTapPlugin.getUnreadInboxMessages(); + + if (messageList == null || messageList.length==0) return; + + Map itemFirst = jsonDecode(messageList[0]); + + await CleverTapPlugin.markReadInboxMessageForId(itemFirst["id"]); + + setState((() { + print("Marked Inbox Message as read with id = ${itemFirst["id"]}"); + })); + + } + + void pushInboxNotificationClickedEventForId() async{ + var messageId=await getFirstInboxMessageId(); + + if(messageId==null) { + setState((() { + print("Inbox Message id is null"); + })); + return; + } + + await CleverTapPlugin.pushInboxNotificationClickedEventForId(messageId); + + setState((() { + print("Pushed NotificationClickedEvent for Inbox Message with id = ${messageId}"); + })); + + } + + void pushInboxNotificationViewedEventForId() async{ + var messageId=await getFirstInboxMessageId(); + + if(messageId==null) { + setState((() { + print("Inbox Message id is null"); + })); + return; + } + + await CleverTapPlugin.pushInboxNotificationViewedEventForId(messageId); + + setState((() { + print("Pushed NotificationViewedEvent for Inbox Message with id = ${messageId}"); + })); + + } + + Future getFirstInboxMessageId() async{ + + var messageList= await CleverTapPlugin.getAllInboxMessages(); + + if (messageList == null || messageList.length==0) return null; + Map itemFirst = jsonDecode(messageList[0]); + return itemFirst["id"]; + } + + + + void setOptOut(){ if(optOut){ CleverTapPlugin.setOptOut(false); diff --git a/lib/clevertap_plugin.dart b/lib/clevertap_plugin.dart index c147096e..c4eb556f 100644 --- a/lib/clevertap_plugin.dart +++ b/lib/clevertap_plugin.dart @@ -3,19 +3,23 @@ import 'dart:async'; import 'package:flutter/services.dart'; typedef void CleverTapInAppNotificationDismissedHandler(Map mapList); +typedef void CleverTapInAppNotificationButtonClickedHandler(Map mapList); typedef void CleverTapProfileDidInitializeHandler(); typedef void CleverTapProfileSyncHandler(Map map); typedef void CleverTapInboxDidInitializeHandler(); typedef void CleverTapInboxMessagesDidUpdateHandler(); +typedef void CleverTapInboxNotificationButtonClickedHandler(Map mapList); typedef void CleverTapExperimentsDidUpdateHandler(); typedef void CleverTapDisplayUnitsLoadedHandler(Map mapList); class CleverTapPlugin { CleverTapInAppNotificationDismissedHandler cleverTapInAppNotificationDismissedHandler; + CleverTapInAppNotificationButtonClickedHandler cleverTapInAppNotificationButtonClickedHandler; CleverTapProfileDidInitializeHandler cleverTapProfileDidInitializeHandler; CleverTapProfileSyncHandler cleverTapProfileSyncHandler; CleverTapInboxDidInitializeHandler cleverTapInboxDidInitializeHandler; CleverTapInboxMessagesDidUpdateHandler cleverTapInboxMessagesDidUpdateHandler; + CleverTapInboxNotificationButtonClickedHandler cleverTapInboxNotificationButtonClickedHandler; CleverTapExperimentsDidUpdateHandler cleverTapExperimentsDidUpdateHandler; CleverTapDisplayUnitsLoadedHandler cleverTapDisplayUnitsLoadedHandler; @@ -37,6 +41,10 @@ class CleverTapPlugin { Map args = call.arguments; cleverTapInAppNotificationDismissedHandler(args.cast()); break; + case "onInAppButtonClick": + Map args = call.arguments; + cleverTapInAppNotificationButtonClickedHandler(args); + break; case "profileDidInitialize": cleverTapProfileDidInitializeHandler(); break; @@ -49,6 +57,10 @@ class CleverTapPlugin { case "inboxMessagesDidUpdate": cleverTapInboxMessagesDidUpdateHandler(); break; + case "onInboxButtonClick": + Map args = call.arguments; + cleverTapInboxNotificationButtonClickedHandler(args); + break; case "CTExperimentsUpdated": cleverTapExperimentsDidUpdateHandler(); break; @@ -63,6 +75,10 @@ class CleverTapPlugin { void setCleverTapInAppNotificationDismissedHandler(CleverTapInAppNotificationDismissedHandler handler) => cleverTapInAppNotificationDismissedHandler = handler; + /// Define a method to handle inApp notification button clicked + void setCleverTapInAppNotificationButtonClickedHandler(CleverTapInAppNotificationButtonClickedHandler handler) => + cleverTapInAppNotificationButtonClickedHandler = handler; + /// Define a method to handle profile initialization void setCleverTapProfileDidInitializeHandler(CleverTapProfileDidInitializeHandler handler) => cleverTapProfileDidInitializeHandler = handler; @@ -79,6 +95,10 @@ class CleverTapPlugin { void setCleverTapInboxMessagesDidUpdateHandler(CleverTapInboxMessagesDidUpdateHandler handler) => cleverTapInboxMessagesDidUpdateHandler = handler; + /// Define a method to handle inbox notification button clicked + void setCleverTapInboxNotificationButtonClickedHandler(CleverTapInboxNotificationButtonClickedHandler handler) => + cleverTapInboxNotificationButtonClickedHandler = handler; + /// Define a method to handle dynamic variable experiments update void setCleverTapExperimentsDidUpdateHandler(CleverTapExperimentsDidUpdateHandler handler) => cleverTapExperimentsDidUpdateHandler = handler; @@ -382,6 +402,41 @@ class CleverTapPlugin { return await _channel.invokeMethod('getInboxMessageUnreadCount',{}); } + /// Returns a list of json string representation of all CTInboxMessage + static Future getAllInboxMessages() async { + return await _channel.invokeMethod('getAllInboxMessages',{}); + } + + /// Returns a list of json string representation of unread CTInboxMessage + static Future getUnreadInboxMessages() async { + return await _channel.invokeMethod('getUnreadInboxMessages',{}); + } + + /// Returns a json string representation of CTInboxMessage for given messageId + static Future getInboxMessageForId(String messageId) async { + return await _channel.invokeMethod('getInboxMessageForId',{'messageId':messageId}); + } + + /// Deletes the CTInboxMessage object for given messageId + static Future deleteInboxMessageForId(String messageId) async { + return await _channel.invokeMethod('deleteInboxMessageForId',{'messageId':messageId}); + } + + /// Marks the given messageId of CTInboxMessage object as read + static Future markReadInboxMessageForId(String messageId) async { + return await _channel.invokeMethod('markReadInboxMessageForId',{'messageId':messageId}); + } + + /// Pushes the Notification Clicked event for App Inbox to CleverTap. + static Future pushInboxNotificationClickedEventForId(String messageId) async { + return await _channel.invokeMethod('pushInboxNotificationClickedEventForId',{'messageId':messageId}); + } + + /// Pushes the Notification Viewed event for App Inbox to CleverTap. + static Future pushInboxNotificationViewedEventForId(String messageId) async { + return await _channel.invokeMethod('pushInboxNotificationViewedEventForId',{'messageId':messageId}); + } + /// only iOS - If an application is launched from a push notification click, returns the CleverTap deep link included in the push notification static Future getInitialUrl() async { return await _channel.invokeMethod('getInitialUrl',{}); From f1a2cd7de93daa4a2cbbbdeb66f1c7553f1653fa Mon Sep 17 00:00:00 2001 From: "piyush.kukadiya" Date: Tue, 24 Mar 2020 22:35:02 +0530 Subject: [PATCH 02/16] task: Expose Baidu/Xiaomi/Huawei push notifications API --- .../clevertap_plugin/CleverTapPlugin.java | 35 +++++++++++++++++++ lib/clevertap_plugin.dart | 15 ++++++++ 2 files changed, 50 insertions(+) diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java index 8b5c642a..eca1d59f 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java @@ -117,6 +117,41 @@ public void onMethodCall(MethodCall call, Result result) { break; } + //Baidu/Xiaomi/Huawei push notifications + + case "setXiaomiPushToken": { + String token = call.argument("token"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushXiaomiRegistrationId(token, true); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "setBaiduPushToken": { + String token = call.argument("token"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushBaiduRegistrationId(token, true); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + + case "setHuaweiPushToken": { + String token = call.argument("token"); + if (isCleverTapNotNull(cleverTapAPI)) { + cleverTapAPI.pushHuaweiRegistrationId(token, true); + result.success(null); + } else { + result.error(TAG, ERROR_MSG, null); + } + break; + } + //UI Editor connection case "setUIEditorConnectionEnabled": { boolean enabled = call.argument("value"); diff --git a/lib/clevertap_plugin.dart b/lib/clevertap_plugin.dart index c4eb556f..d16ff5f1 100644 --- a/lib/clevertap_plugin.dart +++ b/lib/clevertap_plugin.dart @@ -122,6 +122,21 @@ class CleverTapPlugin { return await _channel.invokeMethod('setPushToken', {'token':value}); } + /// Set the Xiaomi Token for Push Notifications + static Future setXiaomiPushToken(String value) async { + return await _channel.invokeMethod('setXiaomiPushToken', {'token':value}); + } + + /// Set the Baidu Token for Push Notifications + static Future setBaiduPushToken(String value) async { + return await _channel.invokeMethod('setBaiduPushToken', {'token':value}); + } + + /// Set the Huawei Token for Push Notifications + static Future setHuaweiPushToken(String value) async { + return await _channel.invokeMethod('setHuaweiPushToken', {'token':value}); + } + // Set true to connect app to dashboard to see variables defined by app static Future setUIEditorConnectionEnabled(bool value) async { return await _channel.invokeMethod('setUIEditorConnectionEnabled', {'value':value}); From 9648ac68543b4c3f364da947bf76c067edd534ea Mon Sep 17 00:00:00 2001 From: Aditi3 Date: Wed, 25 Mar 2020 12:16:05 +0530 Subject: [PATCH 03/16] task: prepare iOS podspec for v1.1.1 --- example/ios/Podfile.lock | 18 +++++++++--------- ios/clevertap_plugin.podspec | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 61d46191..35e674cc 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,13 +1,13 @@ PODS: - - CleverTap-iOS-SDK (3.7.2): + - CleverTap-iOS-SDK (3.7.3): - SDWebImage (~> 5.1) - - clevertap_plugin (1.1.0): - - CleverTap-iOS-SDK (~> 3.7.2) + - clevertap_plugin (1.1.1): + - CleverTap-iOS-SDK (~> 3.7.3) - Flutter - Flutter (1.0.0) - - SDWebImage (5.4.1): - - SDWebImage/Core (= 5.4.1) - - SDWebImage/Core (5.4.1) + - SDWebImage (5.6.1): + - SDWebImage/Core (= 5.6.1) + - SDWebImage/Core (5.6.1) DEPENDENCIES: - clevertap_plugin (from `.symlinks/plugins/clevertap_plugin/ios`) @@ -25,10 +25,10 @@ EXTERNAL SOURCES: :path: Flutter SPEC CHECKSUMS: - CleverTap-iOS-SDK: 8d6398edb908b888e6413226a863035c388f9c4b - clevertap_plugin: bae9ee058ac0eba3d615bdb681453e3c78427b54 + CleverTap-iOS-SDK: a371ba586348ffdb6bb47fcba556e8490f616434 + clevertap_plugin: 63f4bcbf961df9130fa967156ee2bf5ad8c7f031 Flutter: 0e3d915762c693b495b44d77113d4970485de6ec - SDWebImage: 29c340dbdcef342bb13125553f4e19ce056b07a7 + SDWebImage: 7edb9c3ea661e77a66661f7f044de8c1b55d1120 PODFILE CHECKSUM: 49ec7d4076524b7e225c38b98147173651ac4b9d diff --git a/ios/clevertap_plugin.podspec b/ios/clevertap_plugin.podspec index c2fe0efb..4a44905b 100644 --- a/ios/clevertap_plugin.podspec +++ b/ios/clevertap_plugin.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'clevertap_plugin' - s.version = '1.1.0' + s.version = '1.1.1' s.summary = 'CleverTap Flutter plugin.' s.description = 'The CleverTap iOS SDK for App Analytics and Engagement.' s.homepage = 'https://github.com/CleverTap/clevertap-ios-sdk' @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'CleverTap-iOS-SDK', '~> 3.7.2' + s.dependency 'CleverTap-iOS-SDK', '~> 3.7.3' s.ios.deployment_target = '8.0' end From 6b11d0ec85519188866ce888bd151831257f6e78 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Wed, 25 Mar 2020 17:27:42 +0530 Subject: [PATCH 04/16] feat: Add InApp/Inbox click delegates and custom App Inbox methods CLEVER-7002 CLEVER-7008 --- CHANGELOG.md | 8 ++++ README.md | 2 +- ios/Classes/CleverTapPlugin.h | 2 + ios/Classes/CleverTapPlugin.m | 79 ++++++++++++++++++++++++++++++++++- 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3eeea3..db506c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## CHANGE LOG +### Version 1.1.1 (March 26, 2020) +* Adds support for Custom App Inbox +* Adds support for InApp/Inbox button click listeners +* Adds support for Notification Clicked/Viewed for App Inbox +* Adds support for passing Xiaomi/Baidu tokens. +* Supports CleverTap Android SDK v3.7.1 +* Supports CleverTap iOS SDK v3.7.3 + ### Version 1.1.0 (February 27, 2020) * Adds support for Dynamic Variables & Native Display * Adds support for Google Play Install Referrer Library v1.0 diff --git a/README.md b/README.md index e06d42b6..105ddc5b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Add the following to your `dependencies` section in `project/build.gradle` Add the following to your `dependencies` section in `app/build.gradle` ```groovy - implementation 'com.clevertap.android:clevertap-android-sdk:3.6.4' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.firebase:firebase-messaging:17.3.4'//Mandatory for using FCM push notifications, skip if not using FCM implementation 'com.android.support:appcompat-v7:28.0.0'//MANDATORY for App Inbox diff --git a/ios/Classes/CleverTapPlugin.h b/ios/Classes/CleverTapPlugin.h index b4e16b2b..48d85881 100644 --- a/ios/Classes/CleverTapPlugin.h +++ b/ios/Classes/CleverTapPlugin.h @@ -7,6 +7,8 @@ static NSString *const kCleverTapInboxDidInitialize = @"inboxDidInitiali static NSString *const kCleverTapInboxMessagesDidUpdate = @"inboxMessagesDidUpdate"; static NSString *const kCleverTapExperimentsDidUpdate = @"CTExperimentsUpdated"; static NSString *const kCleverTapDisplayUnitsLoaded = @"onDisplayUnitsLoaded"; +static NSString *const kCleverTapInAppButtonCLicked = @"onInAppButtonClick"; +static NSString *const kCleverTapInboxButtonCLicked = @"onInboxButtonClick"; @interface CleverTapPlugin : NSObject + (instancetype)sharedInstance; diff --git a/ios/Classes/CleverTapPlugin.m b/ios/Classes/CleverTapPlugin.m index 021ff254..20a03621 100644 --- a/ios/Classes/CleverTapPlugin.m +++ b/ios/Classes/CleverTapPlugin.m @@ -8,7 +8,7 @@ #import "CleverTapInAppNotificationDelegate.h" #import "CleverTap+DisplayUnit.h" -@interface CleverTapPlugin () { +@interface CleverTapPlugin () { } @property (strong, nonatomic) FlutterMethodChannel *channel; @@ -145,6 +145,20 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self getInboxMessageCount:call withResult:result]; else if ([@"getInboxMessageUnreadCount" isEqualToString:call.method]) [self getInboxMessageUnreadCount:call withResult:result]; + else if ([@"getAllInboxMessages" isEqualToString:call.method]) + [self getAllInboxMessages:call withResult:result]; + else if ([@"getUnreadInboxMessages" isEqualToString:call.method]) + [self getUnreadInboxMessages:call withResult:result];//TODO + else if ([@"getInboxMessageForId" isEqualToString:call.method]) + [self getInboxMessageForId:call withResult:result];//TODO + else if ([@"deleteInboxMessageForId" isEqualToString:call.method]) + [self deleteInboxMessageForId:call withResult:result];//TODO + else if ([@"markReadInboxMessageForId" isEqualToString:call.method]) + [self markReadInboxMessageForId:call withResult:result];//TODO + else if ([@"pushInboxNotificationClickedEventForId" isEqualToString:call.method]) + [self pushInboxNotificationClickedEventForId:call withResult:result];//TODO + else if ([@"pushInboxNotificationViewedEventForId" isEqualToString:call.method]) + [self pushInboxNotificationViewedEventForId:call withResult:result];//TODO else if ([@"getInitialUrl" isEqualToString:call.method]) [self getInitialUrl:call result:result]; else if ([@"registerBooleanVariable" isEqualToString:call.method]) @@ -219,6 +233,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result(nil); else if ([@"deleteNotificationChannel" isEqualToString:call.method]) result(nil); + else if ([@"setXiaomiPushToken" isEqualToString:call.method]) + result(nil); + else if ([@"setBaiduPushToken" isEqualToString:call.method]) + result(nil); + else if ([@"setHuaweiPushToken" isEqualToString:call.method]) + result(nil); else result(FlutterMethodNotImplemented); } @@ -442,6 +462,44 @@ - (void)sessionGetUTMDetails:(FlutterMethodCall *)call withResult:(FlutterResult #pragma mark - Inbox +- (void)pushInboxNotificationViewedEventForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { + [[CleverTap sharedInstance] recordInboxNotificationViewedEventForID:call.arguments[@"messageId"]]; + result(nil); +} + +- (void)pushInboxNotificationClickedEventForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { + [[CleverTap sharedInstance] recordInboxNotificationClickedEventForID:call.arguments[@"messageId"]]; + result(nil); +} + +- (void)markReadInboxMessageForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { + [[CleverTap sharedInstance] markReadInboxMessageForID:call.arguments[@"messageId"]]; + result(nil); +} + +- (void)deleteInboxMessageForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { + [[CleverTap sharedInstance] deleteInboxMessageForID:call.arguments[@"messageId"]]; + result(nil); +} + +- (void)getInboxMessageForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { + CleverTapInboxMessage *message = [[CleverTap sharedInstance] getInboxMessageForId:call.arguments[@"unitId"]]; + NSDictionary *res = message.json; + result(res); +} + +- (void)getUnreadInboxMessages:(FlutterMethodCall *)call withResult:(FlutterResult)result { + NSArray *messages = [[CleverTap sharedInstance] getUnreadInboxMessages]; + NSArray *results = [self _cleverTapInboxMessagesToArray:messages]; + result(results); +} + +- (void)getAllInboxMessages:(FlutterMethodCall *)call withResult:(FlutterResult)result { + NSArray *messages = [[CleverTap sharedInstance] getAllInboxMessages]; + NSArray *results = [self _cleverTapInboxMessagesToArray:messages]; + result(results); +} + - (void)getInboxMessageCount:(FlutterMethodCall *)call withResult:(FlutterResult)result { int res = (int)[[CleverTap sharedInstance] getInboxMessageCount]; result(@(res)); @@ -693,6 +751,14 @@ - (void)displayUnitsUpdated:(NSArray *)displayUnits { #pragma mark - private/helpers +- (NSArray*)_cleverTapInboxMessagesToArray:(NSArray*) inboxMessages { + NSMutableArray *returnArray = [NSMutableArray new]; + for(CleverTapInboxMessage *unit in inboxMessages){ + [returnArray addObject:unit.json]; + } + return returnArray; +} + - (NSArray*)_cleverTapDisplayUnitToArray:(NSArray*) displayUnits { NSMutableArray *returnArray = [NSMutableArray new]; for(CleverTapDisplayUnit *unit in displayUnits){ @@ -860,4 +926,15 @@ - (void)inAppNotificationDismissedWithExtras:(NSDictionary *)extras andActionExt [self postNotificationWithName:kCleverTapInAppNotificationDismissed andBody:body]; } +- (void)inAppNotificationButtonTappedWithCustomExtras:(NSDictionary *)customExtras { + [self postNotificationWithName:kCleverTapInAppButtonCLicked andBody:customExtras]; +} + +#pragma mark CleverTapInboxViewControllerDelegate + +- (void)messageButtonTappedWithCustomExtras:(NSDictionary *_Nullable)customExtras{ + + [self postNotificationWithName:kCleverTapInboxButtonCLicked andBody:customExtras]; +} + @end From 1376bedefad3d83149fcc17609d349c362ae0232 Mon Sep 17 00:00:00 2001 From: "piyush.kukadiya" Date: Wed, 25 Mar 2020 17:46:37 +0530 Subject: [PATCH 05/16] fix: For inbox message response return map instead of list for iOS compatibility --- .../clevertap_plugin/CleverTapPlugin.java | 8 ++-- .../com/clevertap/clevertap_plugin/Utils.java | 26 ++++++------- example/lib/main.dart | 38 ++++++++++++------- lib/clevertap_plugin.dart | 15 +++++--- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java index eca1d59f..ccbbce0f 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java @@ -589,7 +589,7 @@ public void onMethodCall(MethodCall call, Result result) { } case "getAllInboxMessages": { if (isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.getJsonStringList(cleverTapAPI.getAllInboxMessages())); + result.success(Utils.inboxMessageListToMap(cleverTapAPI.getAllInboxMessages())); } else { result.error(TAG, ERROR_MSG, null); } @@ -598,7 +598,7 @@ public void onMethodCall(MethodCall call, Result result) { case "getUnreadInboxMessages": { if (isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.getJsonStringList(cleverTapAPI.getUnreadInboxMessages())); + result.success(Utils.inboxMessageListToMap(cleverTapAPI.getUnreadInboxMessages())); } else { result.error(TAG, ERROR_MSG, null); } @@ -616,8 +616,8 @@ public void onMethodCall(MethodCall call, Result result) { CTInboxMessage inboxMessage = cleverTapAPI.getInboxMessageForId(messageId); - if (inboxMessage != null && inboxMessage.getData() != null) { - result.success(inboxMessage.getData().toString()); + if (inboxMessage != null) { + result.success(Utils.jsonObjectToMap(inboxMessage.getData())); } else { result.success(null); } diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java index 2d794d91..76e47d6b 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java @@ -172,6 +172,18 @@ static Map>> displayUnitListToMap(ArrayList< return returnMap; } + static Map>> inboxMessageListToMap(ArrayList inboxMessageArrayList){ + Map>> returnMap = new HashMap<>(); + ArrayList> mapList = new ArrayList<>(); + if(inboxMessageArrayList != null) { + for (CTInboxMessage message : inboxMessageArrayList) { + mapList.add(Utils.jsonObjectToMap(message.getData())); + } + } + returnMap.put("inboxMessages",mapList); + return returnMap; + } + static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { Bundle bundle = new Bundle(); if(jsonObject != null) { @@ -184,18 +196,4 @@ static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { } return bundle; } - - static ArrayList getJsonStringList(List list) { - ArrayList jsonStringList =new ArrayList<>(); - if (list!=null) - { - for (CTInboxMessage item:list) - { - if (item!=null&&item.getData()!=null) { - jsonStringList.add(item.getData().toString()); - } - } - } - return jsonStringList; - } } diff --git a/example/lib/main.dart b/example/lib/main.dart index ddc8ba31..6b09c7bd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -396,11 +396,13 @@ class _MyAppState extends State { } void getAllInboxMessages(){ - CleverTapPlugin.getAllInboxMessages().then((messageList) { - if (messageList == null || messageList.length==0) return; + CleverTapPlugin.getAllInboxMessages().then((messageMap) { + if (messageMap == null || messageMap.length==0) return; + var messageList = messageMap["inboxMessages"]; - Map itemFirst = jsonDecode(messageList[0]); - Map itemLast = jsonDecode(messageList[messageList.length-1]); + if (messageList == null || messageList.length==0) return; + Map itemFirst = messageList[0]; + Map itemLast = messageList[messageList.length-1]; setState((() { print("First Inbox Message = ${itemFirst["id"]}"); @@ -415,12 +417,14 @@ class _MyAppState extends State { void getUnreadInboxMessages() async{ - var messageList= await CleverTapPlugin.getUnreadInboxMessages(); + var messageMap= await CleverTapPlugin.getUnreadInboxMessages(); - if (messageList == null || messageList.length==0) return; + if (messageMap == null || messageMap.length==0) return; + var messageList = messageMap["inboxMessages"]; - Map itemFirst = jsonDecode(messageList[0]); - Map itemLast = jsonDecode(messageList[messageList.length-1]); + if (messageList == null || messageList.length==0) return; + Map itemFirst = messageList[0]; + Map itemLast = messageList[messageList.length-1]; setState((() { print("First Unread Inbox Message = ${itemFirst["id"]}"); @@ -440,7 +444,7 @@ class _MyAppState extends State { var messageForId= await CleverTapPlugin.getInboxMessageForId(messageId); setState((() { - print("Inbox Message for id = ${messageForId}"); + print("Inbox Message for id = ${messageForId.toString()}"); })); } @@ -464,11 +468,13 @@ class _MyAppState extends State { } void markReadInboxMessageForId() async{ - var messageList= await CleverTapPlugin.getUnreadInboxMessages(); + var messageMap= await CleverTapPlugin.getUnreadInboxMessages(); - if (messageList == null || messageList.length==0) return; + if (messageMap == null || messageMap.length==0) return; + var messageList = messageMap["inboxMessages"]; - Map itemFirst = jsonDecode(messageList[0]); + if (messageList == null || messageList.length==0) return; + Map itemFirst = messageList[0]; await CleverTapPlugin.markReadInboxMessageForId(itemFirst["id"]); @@ -516,10 +522,14 @@ class _MyAppState extends State { Future getFirstInboxMessageId() async{ - var messageList= await CleverTapPlugin.getAllInboxMessages(); + var messageMap= await CleverTapPlugin.getAllInboxMessages(); + + if (messageMap == null || messageMap.length==0) return null; + var messageList = messageMap["inboxMessages"]; if (messageList == null || messageList.length==0) return null; - Map itemFirst = jsonDecode(messageList[0]); + Map itemFirst = messageList[0]; + return itemFirst["id"]; } diff --git a/lib/clevertap_plugin.dart b/lib/clevertap_plugin.dart index d16ff5f1..7bec1b28 100644 --- a/lib/clevertap_plugin.dart +++ b/lib/clevertap_plugin.dart @@ -418,18 +418,21 @@ class CleverTapPlugin { } /// Returns a list of json string representation of all CTInboxMessage - static Future getAllInboxMessages() async { - return await _channel.invokeMethod('getAllInboxMessages',{}); + static Future> getAllInboxMessages() async { + Map response = await _channel.invokeMethod('getAllInboxMessages',{}); + return response.cast(); } /// Returns a list of json string representation of unread CTInboxMessage - static Future getUnreadInboxMessages() async { - return await _channel.invokeMethod('getUnreadInboxMessages',{}); + static Future> getUnreadInboxMessages() async { + Map response = await _channel.invokeMethod('getUnreadInboxMessages',{}); + return response.cast(); } /// Returns a json string representation of CTInboxMessage for given messageId - static Future getInboxMessageForId(String messageId) async { - return await _channel.invokeMethod('getInboxMessageForId',{'messageId':messageId}); + static Future> getInboxMessageForId(String messageId) async { + Map response = await _channel.invokeMethod('getInboxMessageForId',{'messageId':messageId}); + return response.cast(); } /// Deletes the CTInboxMessage object for given messageId From d67d4801a8ada12096a5fc44174b13fa64077e56 Mon Sep 17 00:00:00 2001 From: Aditi3 Date: Thu, 26 Mar 2020 15:12:57 +0530 Subject: [PATCH 06/16] chore CLEVER-7002: some inapp/ inbox button tapped tweaks --- ios/Classes/CleverTapPlugin.h | 18 +++++++++--------- ios/Classes/CleverTapPlugin.m | 30 ++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ios/Classes/CleverTapPlugin.h b/ios/Classes/CleverTapPlugin.h index 48d85881..ae0cdd09 100644 --- a/ios/Classes/CleverTapPlugin.h +++ b/ios/Classes/CleverTapPlugin.h @@ -1,14 +1,14 @@ #import -static NSString *const kCleverTapProfileDidInitialize = @"profileDidInitialize"; -static NSString *const kCleverTapProfileSync = @"profileDataUpdated"; -static NSString *const kCleverTapInAppNotificationDismissed = @"inAppNotificationDismissed"; -static NSString *const kCleverTapInboxDidInitialize = @"inboxDidInitialize"; -static NSString *const kCleverTapInboxMessagesDidUpdate = @"inboxMessagesDidUpdate"; -static NSString *const kCleverTapExperimentsDidUpdate = @"CTExperimentsUpdated"; -static NSString *const kCleverTapDisplayUnitsLoaded = @"onDisplayUnitsLoaded"; -static NSString *const kCleverTapInAppButtonCLicked = @"onInAppButtonClick"; -static NSString *const kCleverTapInboxButtonCLicked = @"onInboxButtonClick"; +static NSString *const kCleverTapProfileDidInitialize = @"profileDidInitialize"; +static NSString *const kCleverTapProfileSync = @"profileDataUpdated"; +static NSString *const kCleverTapInAppNotificationDismissed = @"inAppNotificationDismissed"; +static NSString *const kCleverTapInboxDidInitialize = @"inboxDidInitialize"; +static NSString *const kCleverTapInboxMessagesDidUpdate = @"inboxMessagesDidUpdate"; +static NSString *const kCleverTapExperimentsDidUpdate = @"CTExperimentsUpdated"; +static NSString *const kCleverTapDisplayUnitsLoaded = @"displayUnitsLoaded"; +static NSString *const kCleverTapInAppNotificationButtonTapped = @"inAppNotificationButtonTapped"; +static NSString *const kCleverTapInboxMessageButtonTapped = @"inboxMessageButtonTapped"; @interface CleverTapPlugin : NSObject + (instancetype)sharedInstance; diff --git a/ios/Classes/CleverTapPlugin.m b/ios/Classes/CleverTapPlugin.m index 20a03621..af6ce72e 100644 --- a/ios/Classes/CleverTapPlugin.m +++ b/ios/Classes/CleverTapPlugin.m @@ -8,7 +8,7 @@ #import "CleverTapInAppNotificationDelegate.h" #import "CleverTap+DisplayUnit.h" -@interface CleverTapPlugin () { +@interface CleverTapPlugin () { } @property (strong, nonatomic) FlutterMethodChannel *channel; @@ -526,7 +526,7 @@ - (void)showInbox:(FlutterMethodCall *)call withResult:(FlutterResult)result { if ([styleConfig isKindOfClass:[NSNull class]]) { styleConfig = nil; } - CleverTapInboxViewController *inboxController = [[CleverTap sharedInstance] newInboxViewControllerWithConfig:[self _dictToInboxStyleConfig:styleConfig ? styleConfig : nil] andDelegate:nil]; + CleverTapInboxViewController *inboxController = [[CleverTap sharedInstance] newInboxViewControllerWithConfig:[self _dictToInboxStyleConfig:styleConfig ? styleConfig : nil] andDelegate:(id )self]; if (inboxController) { UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:inboxController]; UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; @@ -887,6 +887,16 @@ - (void)addObservers { selector:@selector(emitEventInternal:) name:kCleverTapDisplayUnitsLoaded object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(emitEventInternal:) + name:kCleverTapInAppNotificationButtonTapped + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(emitEventInternal:) + name:kCleverTapInboxMessageButtonTapped + object:nil]; } - (void)postNotificationWithName:(NSString *)name andBody:(NSDictionary *)body { @@ -912,9 +922,7 @@ - (void)profileDataUpdated:(NSDictionary *)updates { #pragma mark CleverTapInAppNotificationDelegate - (void)inAppNotificationDismissedWithExtras:(NSDictionary *)extras andActionExtras:(NSDictionary *)actionExtras { - NSMutableDictionary *body = [NSMutableDictionary new]; - if (extras != nil) { body[@"extras"] = extras; } @@ -922,19 +930,25 @@ - (void)inAppNotificationDismissedWithExtras:(NSDictionary *)extras andActionExt if (actionExtras != nil) { body[@"actionExtras"] = actionExtras; } - [self postNotificationWithName:kCleverTapInAppNotificationDismissed andBody:body]; } - (void)inAppNotificationButtonTappedWithCustomExtras:(NSDictionary *)customExtras { - [self postNotificationWithName:kCleverTapInAppButtonCLicked andBody:customExtras]; + NSMutableDictionary *body = [NSMutableDictionary new]; + if (customExtras != nil) { + body[@"customExtras"] = customExtras; + } + [self postNotificationWithName:kCleverTapInAppNotificationButtonTapped andBody:customExtras]; } #pragma mark CleverTapInboxViewControllerDelegate - (void)messageButtonTappedWithCustomExtras:(NSDictionary *_Nullable)customExtras{ - - [self postNotificationWithName:kCleverTapInboxButtonCLicked andBody:customExtras]; + NSMutableDictionary *body = [NSMutableDictionary new]; + if (customExtras != nil) { + body[@"customExtras"] = customExtras; + } + [self postNotificationWithName:kCleverTapInboxMessageButtonTapped andBody:customExtras]; } @end From d5b64326a54d0c4ec2e4f6d732fbc4dc71c3f42e Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Thu, 26 Mar 2020 16:16:19 +0530 Subject: [PATCH 07/16] chore: Update callback names in iOS and comment out FCM plugin for testing CLEVER-7002 CLEVER-7008 --- example/android/app/build.gradle | 2 +- example/android/build.gradle | 2 +- ios/Classes/CleverTapPlugin.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index d36bd82f..4fa55e30 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -70,4 +70,4 @@ dependencies { implementation 'com.android.installreferrer:installreferrer:1.0' } -apply plugin: 'com.google.gms.google-services' +//apply plugin: 'com.google.gms.google-services' diff --git a/example/android/build.gradle b/example/android/build.gradle index 9234dae2..d653045f 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -6,7 +6,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.5.3' - classpath 'com.google.gms:google-services:4.3.3' + //classpath 'com.google.gms:google-services:4.3.3' } } diff --git a/ios/Classes/CleverTapPlugin.h b/ios/Classes/CleverTapPlugin.h index ae0cdd09..d34262d5 100644 --- a/ios/Classes/CleverTapPlugin.h +++ b/ios/Classes/CleverTapPlugin.h @@ -6,9 +6,9 @@ static NSString *const kCleverTapInAppNotificationDismissed = @"inAppNotif static NSString *const kCleverTapInboxDidInitialize = @"inboxDidInitialize"; static NSString *const kCleverTapInboxMessagesDidUpdate = @"inboxMessagesDidUpdate"; static NSString *const kCleverTapExperimentsDidUpdate = @"CTExperimentsUpdated"; -static NSString *const kCleverTapDisplayUnitsLoaded = @"displayUnitsLoaded"; -static NSString *const kCleverTapInAppNotificationButtonTapped = @"inAppNotificationButtonTapped"; -static NSString *const kCleverTapInboxMessageButtonTapped = @"inboxMessageButtonTapped"; +static NSString *const kCleverTapDisplayUnitsLoaded = @"onDisplayUnitsLoaded"; +static NSString *const kCleverTapInAppNotificationButtonTapped = @"onInAppButtonClick"; +static NSString *const kCleverTapInboxMessageButtonTapped = @"onInboxButtonClick"; @interface CleverTapPlugin : NSObject + (instancetype)sharedInstance; From ac3408ef058ab8bea4422c6168b41490ab4d434a Mon Sep 17 00:00:00 2001 From: "piyush.kukadiya" Date: Thu, 26 Mar 2020 16:45:01 +0530 Subject: [PATCH 08/16] task: Add inbox/inapp callbacks to main.dart --- example/lib/main.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6b09c7bd..ca94cf08 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -45,6 +45,8 @@ class _MyAppState extends State { _clevertapPlugin.setCleverTapInboxMessagesDidUpdateHandler(inboxMessagesDidUpdate); _clevertapPlugin.setCleverTapExperimentsDidUpdateHandler(ctExperimentsUpdated); _clevertapPlugin.setCleverTapDisplayUnitsLoadedHandler(onDisplayUnitsLoaded); + _clevertapPlugin.setCleverTapInAppNotificationButtonClickedHandler(inAppNotificationButtonClicked); + _clevertapPlugin.setCleverTapInboxNotificationButtonClickedHandler(inboxNotificationButtonClicked); } void inAppNotificationDismissed(Map map){ @@ -53,6 +55,18 @@ class _MyAppState extends State { }); } + void inAppNotificationButtonClicked(Map map){ + this.setState((){ + print("inAppNotificationButtonClicked called = ${map.toString()}"); + }); + } + + void inboxNotificationButtonClicked(Map map){ + this.setState((){ + print("inboxNotificationButtonClicked called = ${map.toString()}"); + }); + } + void profileDidInitialize(){ this.setState((){ print("profileDidInitialize called"); From 6f6eec527ac9084d024b216a4011fb1ef5843a0d Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Thu, 26 Mar 2020 23:18:10 +0530 Subject: [PATCH 09/16] fix: Fix return type for display units and inbox messages CLEVER-7002 CLEVER-7008 --- .../clevertap_plugin/CleverTapPlugin.java | 12 +++-- .../com/clevertap/clevertap_plugin/Utils.java | 20 ++++---- .../android/app/src/main/AndroidManifest.xml | 4 +- example/ios/Runner/Info.plist | 4 +- example/lib/main.dart | 48 ++++++++++--------- lib/clevertap_plugin.dart | 18 +++---- 6 files changed, 55 insertions(+), 51 deletions(-) diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java index ccbbce0f..b26deae5 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java @@ -589,7 +589,7 @@ public void onMethodCall(MethodCall call, Result result) { } case "getAllInboxMessages": { if (isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.inboxMessageListToMap(cleverTapAPI.getAllInboxMessages())); + result.success(Utils.inboxMessageListToArrayList(cleverTapAPI.getAllInboxMessages())); } else { result.error(TAG, ERROR_MSG, null); } @@ -598,7 +598,7 @@ public void onMethodCall(MethodCall call, Result result) { case "getUnreadInboxMessages": { if (isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.inboxMessageListToMap(cleverTapAPI.getUnreadInboxMessages())); + result.success(Utils.inboxMessageListToArrayList(cleverTapAPI.getUnreadInboxMessages())); } else { result.error(TAG, ERROR_MSG, null); } @@ -943,7 +943,7 @@ public void onMethodCall(MethodCall call, Result result) { //Native Display case "getAllDisplayUnits": { if (isCleverTapNotNull(cleverTapAPI)) { - result.success(Utils.displayUnitListToMap(cleverTapAPI.getAllDisplayUnits())); + result.success(Utils.displayUnitListToArrayList(cleverTapAPI.getAllDisplayUnits())); } else { result.error(TAG, ERROR_MSG, null); } @@ -1023,7 +1023,11 @@ private void invokeMethodOnUiThread(final String methodName, final String clever private void invokeMethodOnUiThread(final String methodName, final Map map) { final MethodChannel channel = this.channel; runOnMainThread(() -> channel.invokeMethod(methodName, map)); + } + private void invokeMethodOnUiThread(final String methodName, final ArrayList list) { + final MethodChannel channel = this.channel; + runOnMainThread(() -> channel.invokeMethod(methodName, list)); } @@ -1078,6 +1082,6 @@ public void onInboxButtonClick(HashMap payload) { @Override public void onDisplayUnitsLoaded(ArrayList units) { - invokeMethodOnUiThread("onDisplayUnitsLoaded", Utils.displayUnitListToMap(units)); + invokeMethodOnUiThread("onDisplayUnitsLoaded", Utils.displayUnitListToArrayList(units)); } } diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java index 76e47d6b..f1918515 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java @@ -160,28 +160,24 @@ private static ArrayList arrayListStringFromJSONArray(JSONArray jsonArra } } - static Map>> displayUnitListToMap(ArrayList units){ - Map>> returnMap = new HashMap<>(); - ArrayList> mapList = new ArrayList<>(); + static ArrayList> displayUnitListToArrayList(ArrayList units){ + ArrayList> displayUnitList = new ArrayList<>(); if(units != null) { for (CleverTapDisplayUnit unit : units) { - mapList.add(Utils.jsonObjectToMap(unit.getJsonObject())); + displayUnitList.add(Utils.jsonObjectToMap(unit.getJsonObject())); } } - returnMap.put("adUnits",mapList); - return returnMap; + return displayUnitList; } - static Map>> inboxMessageListToMap(ArrayList inboxMessageArrayList){ - Map>> returnMap = new HashMap<>(); - ArrayList> mapList = new ArrayList<>(); + static ArrayList> inboxMessageListToArrayList(ArrayList inboxMessageArrayList){ + ArrayList> inboxMessageList = new ArrayList<>(); if(inboxMessageArrayList != null) { for (CTInboxMessage message : inboxMessageArrayList) { - mapList.add(Utils.jsonObjectToMap(message.getData())); + inboxMessageList.add(Utils.jsonObjectToMap(message.getData())); } } - returnMap.put("inboxMessages",mapList); - return returnMap; + return inboxMessageList; } static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 37b7fc60..4b699d81 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -28,10 +28,10 @@ android:value="2" /> + android:value="TEST-46W-WWR-R85Z"/> + android:value="TEST-200-064"/> CFBundleVersion $(FLUTTER_BUILD_NUMBER) CleverTapAccountID - + TEST-46W-WWR-R85Z CleverTapToken - + TEST-200-064 CleverTapUseIFA LSRequiresIPhoneOS diff --git a/example/lib/main.dart b/example/lib/main.dart index ca94cf08..282b3bd8 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -126,13 +126,15 @@ class _MyAppState extends State { }); } - void onDisplayUnitsLoaded(Map map){ + void onDisplayUnitsLoaded(List displayUnits){ this.setState(() async { - print("Display units loaded"); - Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1582792356_20200227"); - //CleverTapPlugin.pushDisplayUnitClickedEvent("1582792356_20200227"); - //CleverTapPlugin.pushDisplayUnitViewedEvent("1582792356_20200227"); - print("Ad Unit = " + adUnit.toString()); + List displayUnits = await CleverTapPlugin.getAllDisplayUnits(); + print("Display Units = "+ displayUnits.toString()); +// print(" on Display units loaded"); +// Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1584623951_20200326"); +// //CleverTapPlugin.pushDisplayUnitClickedEvent("1584623951_20200326"); +// //CleverTapPlugin.pushDisplayUnitViewedEvent("1584623951_20200326"); +// print("Ad Unit = " + adUnit.toString()); }); } @@ -393,7 +395,7 @@ class _MyAppState extends State { void recordUser(){ var stuff = ["bags","shoes"]; var profile = { - 'Name': 'Tony Stark', + 'Name': 'Tony \'Stark', 'Identity': '100', 'Email': 'tony@stark.com', 'Phone': '+14155551234', @@ -410,9 +412,9 @@ class _MyAppState extends State { } void getAllInboxMessages(){ - CleverTapPlugin.getAllInboxMessages().then((messageMap) { - if (messageMap == null || messageMap.length==0) return; - var messageList = messageMap["inboxMessages"]; + CleverTapPlugin.getAllInboxMessages().then((messageList) { +// if (messageMap == null || messageMap.length==0) return; +// var messageList = messageMap["inboxMessages"]; if (messageList == null || messageList.length==0) return; Map itemFirst = messageList[0]; @@ -431,10 +433,10 @@ class _MyAppState extends State { void getUnreadInboxMessages() async{ - var messageMap= await CleverTapPlugin.getUnreadInboxMessages(); + var messageList= await CleverTapPlugin.getUnreadInboxMessages(); - if (messageMap == null || messageMap.length==0) return; - var messageList = messageMap["inboxMessages"]; +// if (messageMap == null || messageMap.length==0) return; +// var messageList = messageMap["inboxMessages"]; if (messageList == null || messageList.length==0) return; Map itemFirst = messageList[0]; @@ -482,10 +484,10 @@ class _MyAppState extends State { } void markReadInboxMessageForId() async{ - var messageMap= await CleverTapPlugin.getUnreadInboxMessages(); + var messageList = await CleverTapPlugin.getUnreadInboxMessages(); - if (messageMap == null || messageMap.length==0) return; - var messageList = messageMap["inboxMessages"]; +// if (messageMap == null || messageMap.length==0) return; +// var messageList = messageMap["inboxMessages"]; if (messageList == null || messageList.length==0) return; Map itemFirst = messageList[0]; @@ -536,10 +538,10 @@ class _MyAppState extends State { Future getFirstInboxMessageId() async{ - var messageMap= await CleverTapPlugin.getAllInboxMessages(); + var messageList = await CleverTapPlugin.getAllInboxMessages(); - if (messageMap == null || messageMap.length==0) return null; - var messageList = messageMap["inboxMessages"]; +// if (messageMap == null || messageMap.length==0) return null; +// var messageList = messageMap["inboxMessages"]; if (messageList == null || messageList.length==0) return null; Map itemFirst = messageList[0]; @@ -891,11 +893,13 @@ class _MyAppState extends State { } void getAdUnits() async{ - print("Display units loaded"); - Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1582792356_20200227"); + List displayUnits = await CleverTapPlugin.getAllDisplayUnits(); + print("Display Units = "+ displayUnits.toString()); + //print("Display units loaded"); + //Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1582792356_20200227"); //CleverTapPlugin.pushDisplayUnitClickedEvent("1582792356_20200227"); //CleverTapPlugin.pushDisplayUnitViewedEvent("1582792356_20200227"); - print("Ad Unit = " + adUnit.toString()); + //print("Ad Unit = " + adUnit.toString()); } } diff --git a/lib/clevertap_plugin.dart b/lib/clevertap_plugin.dart index 7bec1b28..5f97710c 100644 --- a/lib/clevertap_plugin.dart +++ b/lib/clevertap_plugin.dart @@ -10,7 +10,7 @@ typedef void CleverTapInboxDidInitializeHandler(); typedef void CleverTapInboxMessagesDidUpdateHandler(); typedef void CleverTapInboxNotificationButtonClickedHandler(Map mapList); typedef void CleverTapExperimentsDidUpdateHandler(); -typedef void CleverTapDisplayUnitsLoadedHandler(Map mapList); +typedef void CleverTapDisplayUnitsLoadedHandler(List displayUnitList); class CleverTapPlugin { CleverTapInAppNotificationDismissedHandler cleverTapInAppNotificationDismissedHandler; @@ -65,8 +65,8 @@ class CleverTapPlugin { cleverTapExperimentsDidUpdateHandler(); break; case "onDisplayUnitsLoaded": - Map args = call.arguments; - cleverTapDisplayUnitsLoadedHandler(args.cast()); + List args = call.arguments; + cleverTapDisplayUnitsLoadedHandler(args); break; } } @@ -418,15 +418,15 @@ class CleverTapPlugin { } /// Returns a list of json string representation of all CTInboxMessage - static Future> getAllInboxMessages() async { - Map response = await _channel.invokeMethod('getAllInboxMessages',{}); - return response.cast(); + static Future getAllInboxMessages() async { + List response = await _channel.invokeMethod('getAllInboxMessages',{}); + return response; } /// Returns a list of json string representation of unread CTInboxMessage - static Future> getUnreadInboxMessages() async { - Map response = await _channel.invokeMethod('getUnreadInboxMessages',{}); - return response.cast(); + static Future getUnreadInboxMessages() async { + List response = await _channel.invokeMethod('getUnreadInboxMessages',{}); + return response; } /// Returns a json string representation of CTInboxMessage for given messageId From e1259e9285207011985e5fa303db464c8bed2ea4 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Fri, 27 Mar 2020 00:45:29 +0530 Subject: [PATCH 10/16] fix: Fixed parsing of DOB in profile for #6 --- .../clevertap_plugin/CleverTapPlugin.java | 4 +-- .../com/clevertap/clevertap_plugin/Utils.java | 30 +++++++++++++++++++ .../android/app/src/main/AndroidManifest.xml | 4 +-- example/ios/Runner/Info.plist | 4 +-- example/lib/main.dart | 7 +++-- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java index b26deae5..441c4338 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/CleverTapPlugin.java @@ -385,7 +385,7 @@ public void onMethodCall(MethodCall call, Result result) { break; } case "onUserLogin": { - Map profile = call.argument("profile"); + Map profile = Utils.dartMapToProfileMap(call.argument("profile")); if (isCleverTapNotNull(cleverTapAPI)) { cleverTapAPI.onUserLogin(profile); result.success(null); @@ -395,7 +395,7 @@ public void onMethodCall(MethodCall call, Result result) { break; } case "profileSet": { - Map profile = call.argument("profile"); + Map profile = Utils.dartMapToProfileMap(call.argument("profile")); if (isCleverTapNotNull(cleverTapAPI)) { cleverTapAPI.pushProfile(profile); result.success(null); diff --git a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java index f1918515..da0be60c 100644 --- a/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java +++ b/android/src/main/java/com/clevertap/clevertap_plugin/Utils.java @@ -13,10 +13,13 @@ import org.json.JSONException; import org.json.JSONObject; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; public class Utils { @@ -192,4 +195,31 @@ static Bundle jsonToBundle(JSONObject jsonObject) throws JSONException { } return bundle; } + + static HashMap dartMapToProfileMap(Map profileMap){ + if (profileMap == null) return null; + + HashMap profile = new HashMap<>(); + for (Map.Entry stringObjectEntry : profileMap.entrySet()) { + try { + String key = stringObjectEntry.getKey(); + + if ("DOB".equals(key)) { + String dob = profileMap.get(key).toString(); + SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + try { + Date date = format.parse(dob); + profile.put(key, date); + } catch (Throwable t) { + Log.e("CleverTapError", t.getLocalizedMessage()); + } + } else { + profile.put(key, stringObjectEntry.getValue()); + } + } catch (Throwable t) { + Log.e("CleverTapError", t.getLocalizedMessage()); + } + } + return profile; + } } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 4b699d81..31389671 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -28,10 +28,10 @@ android:value="2" /> + android:value="TEST-65R-487-R85Z"/> + android:value="TEST-ab4-256"/> CFBundleVersion $(FLUTTER_BUILD_NUMBER) CleverTapAccountID - TEST-46W-WWR-R85Z + TEST-65R-487-R85Z CleverTapToken - TEST-200-064 + TEST-ab4-256 CleverTapUseIFA LSRequiresIPhoneOS diff --git a/example/lib/main.dart b/example/lib/main.dart index 282b3bd8..17da85c0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -395,10 +395,11 @@ class _MyAppState extends State { void recordUser(){ var stuff = ["bags","shoes"]; var profile = { - 'Name': 'Tony \'Stark', + 'Name': 'Thor', 'Identity': '100', - 'Email': 'tony@stark.com', - 'Phone': '+14155551234', + 'DOB': '22-04-2000', + 'Email': 'thor1@asgard.com', + 'Phone': '14155551234', 'props': 'property1', 'stuff': stuff }; From d2c1942fe42d8f47c6b1605dea8f2ebb7b9fa5c5 Mon Sep 17 00:00:00 2001 From: Aditi3 Date: Fri, 27 Mar 2020 02:55:46 +0530 Subject: [PATCH 11/16] fix CLEVER-7002: custom app inbox apis in iOS --- example/lib/main.dart | 40 ++++++++------------------------------- lib/clevertap_plugin.dart | 8 ++++---- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 17da85c0..7247c705 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -412,41 +412,17 @@ class _MyAppState extends State { } } - void getAllInboxMessages(){ - CleverTapPlugin.getAllInboxMessages().then((messageList) { -// if (messageMap == null || messageMap.length==0) return; -// var messageList = messageMap["inboxMessages"]; - - if (messageList == null || messageList.length==0) return; - Map itemFirst = messageList[0]; - Map itemLast = messageList[messageList.length-1]; - - setState((() { - print("First Inbox Message = ${itemFirst["id"]}"); - print("Last Inbox Message = ${itemLast["id"]}"); - })); - }).catchError((error) { - setState(() { - print("$error"); - }); - }); + void getAllInboxMessages() async{ + List messages = await CleverTapPlugin.getAllInboxMessages(); + print("Inbox Messages = "+ messages.toString()); + } + void getUnreadInboxMessages() async{ - var messageList= await CleverTapPlugin.getUnreadInboxMessages(); - -// if (messageMap == null || messageMap.length==0) return; -// var messageList = messageMap["inboxMessages"]; - - if (messageList == null || messageList.length==0) return; - Map itemFirst = messageList[0]; - Map itemLast = messageList[messageList.length-1]; - - setState((() { - print("First Unread Inbox Message = ${itemFirst["id"]}"); - print("Last Unread Inbox Message = ${itemLast["id"]}"); - })); + List messages = await CleverTapPlugin.getUnreadInboxMessages(); + print("Unread Inbox Messages = "+ messages.toString()); } void getInboxMessageForId() async{ @@ -901,6 +877,6 @@ class _MyAppState extends State { //CleverTapPlugin.pushDisplayUnitClickedEvent("1582792356_20200227"); //CleverTapPlugin.pushDisplayUnitViewedEvent("1582792356_20200227"); //print("Ad Unit = " + adUnit.toString()); - } + } } diff --git a/lib/clevertap_plugin.dart b/lib/clevertap_plugin.dart index 5f97710c..ff78874b 100644 --- a/lib/clevertap_plugin.dart +++ b/lib/clevertap_plugin.dart @@ -418,15 +418,15 @@ class CleverTapPlugin { } /// Returns a list of json string representation of all CTInboxMessage + + static Future getAllInboxMessages() async { - List response = await _channel.invokeMethod('getAllInboxMessages',{}); - return response; + return await _channel.invokeMethod('getAllInboxMessages',{}); } /// Returns a list of json string representation of unread CTInboxMessage static Future getUnreadInboxMessages() async { - List response = await _channel.invokeMethod('getUnreadInboxMessages',{}); - return response; + return await _channel.invokeMethod('getUnreadInboxMessages',{}); } /// Returns a json string representation of CTInboxMessage for given messageId From 463fd8121fe8b482a8e8902cfa7081ac8493c4b3 Mon Sep 17 00:00:00 2001 From: "piyush.kukadiya" Date: Mon, 30 Mar 2020 12:24:40 +0530 Subject: [PATCH 12/16] Updating CT Android SDK to 3.7.2 --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index d8abdc68..9027c0ee 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,7 +41,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.2' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.installreferrer:installreferrer:1.0' } From b05864d675582df9af4c834375f07cb2af4825e1 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Mon, 30 Mar 2020 23:04:48 +0530 Subject: [PATCH 13/16] chore: Ready for release v1.1.1 CLEVER-7002 CLEVER-7008 --- CHANGELOG.md | 4 +-- README.md | 4 +-- example/lib/main.dart | 48 +++++++++++++++-------------------- example/pubspec.lock | 2 +- ios/Classes/CleverTapPlugin.m | 2 +- pubspec.yaml | 12 ++++++--- 6 files changed, 35 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db506c1a..2c5d9c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ ## CHANGE LOG -### Version 1.1.1 (March 26, 2020) +### Version 1.1.1 (March 30, 2020) * Adds support for Custom App Inbox * Adds support for InApp/Inbox button click listeners * Adds support for Notification Clicked/Viewed for App Inbox * Adds support for passing Xiaomi/Baidu tokens. -* Supports CleverTap Android SDK v3.7.1 +* Supports CleverTap Android SDK v3.7.2 * Supports CleverTap iOS SDK v3.7.3 ### Version 1.1.0 (February 27, 2020) diff --git a/README.md b/README.md index 105ddc5b..1f18917e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To add the CleverTap Flutter SDK to your project, edit your project's `pubspec.y ```yaml dependencies: - clevertap_plugin: 1.1.0 + clevertap_plugin: 1.1.1 ``` Run `flutter packages get` to install the SDK @@ -36,7 +36,7 @@ Add the following to your `dependencies` section in `project/build.gradle` Add the following to your `dependencies` section in `app/build.gradle` ```groovy - implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.2' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.firebase:firebase-messaging:17.3.4'//Mandatory for using FCM push notifications, skip if not using FCM implementation 'com.android.support:appcompat-v7:28.0.0'//MANDATORY for App Inbox diff --git a/example/lib/main.dart b/example/lib/main.dart index 7247c705..da4b14d6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'dart:async'; +import 'dart:io' show Platform; import 'package:clevertap_plugin/clevertap_plugin.dart'; @@ -130,11 +131,6 @@ class _MyAppState extends State { this.setState(() async { List displayUnits = await CleverTapPlugin.getAllDisplayUnits(); print("Display Units = "+ displayUnits.toString()); -// print(" on Display units loaded"); -// Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1584623951_20200326"); -// //CleverTapPlugin.pushDisplayUnitClickedEvent("1584623951_20200326"); -// //CleverTapPlugin.pushDisplayUnitViewedEvent("1584623951_20200326"); -// print("Ad Unit = " + adUnit.toString()); }); } @@ -397,7 +393,7 @@ class _MyAppState extends State { var profile = { 'Name': 'Thor', 'Identity': '100', - 'DOB': '22-04-2000', + 'DOB': '22-04-2000',///Key always has to be "DOB" and format should always be dd-MM-yyyy 'Email': 'thor1@asgard.com', 'Phone': '14155551234', 'props': 'property1', @@ -417,7 +413,6 @@ class _MyAppState extends State { print("Inbox Messages = "+ messages.toString()); } - void getUnreadInboxMessages() async{ @@ -463,17 +458,22 @@ class _MyAppState extends State { void markReadInboxMessageForId() async{ var messageList = await CleverTapPlugin.getUnreadInboxMessages(); -// if (messageMap == null || messageMap.length==0) return; -// var messageList = messageMap["inboxMessages"]; - if (messageList == null || messageList.length==0) return; Map itemFirst = messageList[0]; - await CleverTapPlugin.markReadInboxMessageForId(itemFirst["id"]); + if(Platform.isAndroid) { + await CleverTapPlugin.markReadInboxMessageForId(itemFirst["id"]); + setState((() { + print("Marked Inbox Message as read with id = ${itemFirst["id"]}"); + })); + }else if(Platform.isIOS){ + await CleverTapPlugin.markReadInboxMessageForId(itemFirst["_id"]); + setState((() { + print("Marked Inbox Message as read with id = ${itemFirst["_id"]}"); + })); + } + - setState((() { - print("Marked Inbox Message as read with id = ${itemFirst["id"]}"); - })); } @@ -516,19 +516,18 @@ class _MyAppState extends State { Future getFirstInboxMessageId() async{ var messageList = await CleverTapPlugin.getAllInboxMessages(); - -// if (messageMap == null || messageMap.length==0) return null; -// var messageList = messageMap["inboxMessages"]; - + print("inside getFirstInboxMessageId"); if (messageList == null || messageList.length==0) return null; Map itemFirst = messageList[0]; + print(itemFirst.toString()); - return itemFirst["id"]; + if(Platform.isAndroid) { + return itemFirst["id"]; + }else if (Platform.isIOS){ + return itemFirst["_id"]; + } } - - - void setOptOut(){ if(optOut){ CleverTapPlugin.setOptOut(false); @@ -872,11 +871,6 @@ class _MyAppState extends State { void getAdUnits() async{ List displayUnits = await CleverTapPlugin.getAllDisplayUnits(); print("Display Units = "+ displayUnits.toString()); - //print("Display units loaded"); - //Map adUnit = await CleverTapPlugin.getDisplayUnitForId("1582792356_20200227"); - //CleverTapPlugin.pushDisplayUnitClickedEvent("1582792356_20200227"); - //CleverTapPlugin.pushDisplayUnitViewedEvent("1582792356_20200227"); - //print("Ad Unit = " + adUnit.toString()); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index 88276a22..fbc9b2de 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,7 +42,7 @@ packages: path: ".." relative: true source: path - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: diff --git a/ios/Classes/CleverTapPlugin.m b/ios/Classes/CleverTapPlugin.m index af6ce72e..f1676988 100644 --- a/ios/Classes/CleverTapPlugin.m +++ b/ios/Classes/CleverTapPlugin.m @@ -483,7 +483,7 @@ - (void)deleteInboxMessageForId:(FlutterMethodCall *)call withResult:(FlutterRes } - (void)getInboxMessageForId:(FlutterMethodCall *)call withResult:(FlutterResult)result { - CleverTapInboxMessage *message = [[CleverTap sharedInstance] getInboxMessageForId:call.arguments[@"unitId"]]; + CleverTapInboxMessage *message = [[CleverTap sharedInstance] getInboxMessageForId:call.arguments[@"messageId"]]; NSDictionary *res = message.json; result(res); } diff --git a/pubspec.yaml b/pubspec.yaml index fd297851..8027b869 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: clevertap_plugin description: CleverTap Flutter plugin. -version: 1.1.0 -author: http://www.clevertap.com +version: 1.1.1 homepage: https://github.com/CleverTap/clevertap-flutter environment: sdk: ">=2.1.0 <3.0.0" + flutter: ">=1.12.0 <2.0.0" dependencies: flutter: @@ -17,5 +17,9 @@ dev_dependencies: flutter: plugin: - androidPackage: com.clevertap.clevertap_plugin - pluginClass: CleverTapPlugin + platforms: + android: + package: com.clevertap.clevertap_plugin + pluginClass: CleverTapPlugin + ios: + pluginClass: CleverTapPlugin From 852c4a53b7bcadb09cca5e331e6aa69d0429f456 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Mon, 30 Mar 2020 23:59:06 +0530 Subject: [PATCH 14/16] chore: remove account id and token from example app --- example/android/app/src/main/AndroidManifest.xml | 4 ++-- example/ios/Runner/Info.plist | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 31389671..38766138 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -28,10 +28,10 @@ android:value="2" /> + android:value="YOUR-ACCOUNT-ID"/> + android:value="YOUR-ACCOUNT-TOKEN"/> CFBundleVersion $(FLUTTER_BUILD_NUMBER) CleverTapAccountID - TEST-65R-487-R85Z + CleverTapToken - TEST-ab4-256 + CleverTapUseIFA LSRequiresIPhoneOS From eefe1a998f8f66c2d6f65e8ccc9fef7b8a01dae3 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Tue, 31 Mar 2020 00:04:00 +0530 Subject: [PATCH 15/16] chore: update CT Android SDK in example --- example/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 4fa55e30..04dc9000 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -56,7 +56,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'com.clevertap.android:clevertap-android-sdk:3.7.1' + implementation 'com.clevertap.android:clevertap-android-sdk:3.7.2' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.android.support:appcompat-v7:28.0.0'//MANDATORY for App Inbox From 9eee4739b8b27302899ceb32b8ed6dbfabc223f9 Mon Sep 17 00:00:00 2001 From: Darshan Pania Date: Tue, 31 Mar 2020 00:06:35 +0530 Subject: [PATCH 16/16] chore: fix int value in logs --- example/lib/main.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index da4b14d6..72e198f1 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -88,10 +88,10 @@ class _MyAppState extends State { } void inboxMessagesDidUpdate(){ - this.setState((){ + this.setState(() async { print("inboxMessagesDidUpdate called"); - var unread = CleverTapPlugin.getInboxMessageUnreadCount(); - var total = CleverTapPlugin.getInboxMessageCount(); + int unread = await CleverTapPlugin.getInboxMessageUnreadCount(); + int total = await CleverTapPlugin.getInboxMessageCount(); print("Unread count = "+unread.toString()); print("Total count = "+total.toString()); });