-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from qonversion/feature/sc-36113/automations
Automations implementation. Along with updated entitlements callback fix.
- Loading branch information
Showing
21 changed files
with
721 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.qonversion.android.sdk; | ||
|
||
import com.appfeel.cordova.annotated.android.plugin.AnnotatedCordovaPlugin; | ||
import com.appfeel.cordova.annotated.android.plugin.ExecutionThread; | ||
import com.appfeel.cordova.annotated.android.plugin.PluginAction; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.PluginResult; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Map; | ||
|
||
import io.qonversion.sandwich.AutomationsEventListener; | ||
import io.qonversion.sandwich.AutomationsSandwich; | ||
import io.qonversion.sandwich.ResultListener; | ||
import io.qonversion.sandwich.SandwichError; | ||
|
||
public class AutomationsPlugin extends AnnotatedCordovaPlugin implements AutomationsEventListener { | ||
|
||
private AutomationsSandwich automationsSandwich; | ||
private @Nullable CallbackContext automationsEventDelegate = null; | ||
|
||
@Override | ||
public void pluginInitialize() { | ||
super.pluginInitialize(); | ||
automationsSandwich = new AutomationsSandwich(); | ||
} | ||
|
||
@PluginAction(thread = ExecutionThread.MAIN, actionName = "subscribe", isAutofinish = false) | ||
public void subscribe(CallbackContext callbackContext) { | ||
automationsEventDelegate = callbackContext; | ||
automationsSandwich.setDelegate(this); | ||
|
||
PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); | ||
result.setKeepCallback(true); | ||
callbackContext.sendPluginResult(result); | ||
} | ||
|
||
@PluginAction(thread = ExecutionThread.UI, actionName = "showScreen", isAutofinish = false) | ||
public void showScreen(String screenId, CallbackContext callbackContext) { | ||
automationsSandwich.showScreen(screenId, new ResultListener() { | ||
@Override | ||
public void onSuccess(@NonNull Map<String, ?> map) { | ||
callbackContext.success(); | ||
} | ||
|
||
@Override | ||
public void onError(@NonNull SandwichError error) { | ||
Utils.rejectWithError(error, callbackContext); | ||
} | ||
}); | ||
} | ||
|
||
@PluginAction(thread = ExecutionThread.WORKER, actionName = "setScreenPresentationConfig") | ||
public void setScreenPresentationConfig(JSONObject configData, @Nullable String screenId, CallbackContext callbackContext) { | ||
try { | ||
final Map<String, Object> config = EntitiesConverter.toMap(configData); | ||
automationsSandwich.setScreenPresentationConfig(config, screenId); | ||
callbackContext.success(); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onAutomationEvent(@NonNull AutomationsEventListener.Event event, @Nullable Map<String, ?> payload) { | ||
if (automationsEventDelegate != null) { | ||
try { | ||
JSONObject payloadJson = null; | ||
if (payload != null) { | ||
payloadJson = EntitiesConverter.convertMapToJson(payload); | ||
} | ||
|
||
JSONObject data = new JSONObject(); | ||
data.put("event", event.getKey()); | ||
data.put("payload", payloadJson); | ||
|
||
PluginResult result = new PluginResult(PluginResult.Status.OK, data); | ||
result.setKeepCallback(true); | ||
automationsEventDelegate.sendPluginResult(result); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// CDVAutomationsPlugin.h | ||
// Qonversion | ||
// | ||
// Created by Kamo Spertsyan on 15.11.2024. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <Cordova/CDVPlugin.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CDVAutomationsPlugin : CDVPlugin | ||
{} | ||
|
||
- (void)subscribe:(CDVInvokedUrlCommand *)command; | ||
- (void)showScreen:(CDVInvokedUrlCommand *)command; | ||
- (void)setScreenPresentationConfig:(CDVInvokedUrlCommand *)command; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// CDVAutomationsPlugin.m | ||
// Qonversion | ||
// | ||
// Created by Kamo Spertsyan on 15.11.2024. | ||
// | ||
|
||
#import "CDVAutomationsPlugin.h" | ||
#import "QCUtils.h" | ||
@import QonversionSandwich; | ||
|
||
@interface CDVAutomationsPlugin () <AutomationsEventListener> | ||
|
||
@property (nonatomic, strong) AutomationsSandwich *automationsSandwich; | ||
@property (nonatomic, strong, nullable) NSString *automationsEventDelegateId; | ||
|
||
@end | ||
|
||
@implementation CDVAutomationsPlugin | ||
|
||
- (void)automationDidTriggerWithEvent:(NSString * _Nonnull)event payload:(NSDictionary<NSString *,id> * _Nullable)payload { | ||
if (self.automationsEventDelegateId) { | ||
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithObject:event forKey:@"event"]; | ||
if (payload) { | ||
[result setObject:payload forKey:@"payload"]; | ||
} | ||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result]; | ||
[pluginResult setKeepCallbackAsBool:true]; | ||
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.automationsEventDelegateId]; | ||
} | ||
} | ||
|
||
- (AutomationsSandwich *)automationsSandwich { | ||
if (!_automationsSandwich) { | ||
_automationsSandwich = [AutomationsSandwich new]; | ||
} | ||
|
||
return _automationsSandwich; | ||
} | ||
|
||
- (void)subscribe:(CDVInvokedUrlCommand *)command { | ||
self.automationsEventDelegateId = command.callbackId; | ||
|
||
[self.automationsSandwich subscribe:self]; | ||
|
||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; | ||
[pluginResult setKeepCallbackAsBool:true]; | ||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | ||
} | ||
|
||
- (void)showScreen:(CDVInvokedUrlCommand *)command { | ||
__block __weak CDVAutomationsPlugin *weakSelf = self; | ||
NSString *screenId = [command argumentAtIndex:0]; | ||
[self.automationsSandwich showScreen:screenId completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) { | ||
[QCUtils returnCordovaResult:result error:error command:command delegate:weakSelf.commandDelegate]; | ||
}]; | ||
} | ||
|
||
- (void)setScreenPresentationConfig:(CDVInvokedUrlCommand *)command { | ||
NSDictionary *config = [command argumentAtIndex:0]; | ||
NSString *screenId = [command argumentAtIndex:1]; | ||
[self.automationsSandwich setScreenPresentationConfig:config forScreenId:screenId]; | ||
} | ||
|
||
@end |
Oops, something went wrong.