Skip to content

Commit

Permalink
Added custom theme to Veriff plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Dec 19, 2020
1 parent 0ea05f9 commit 16f6887
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/android/VeriffCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package org.apache.cordova.csantosm;

import android.content.Intent;
import android.graphics.Color;
import android.util.Log;

import androidx.annotation.Nullable;
Expand All @@ -14,6 +15,8 @@
import org.json.JSONObject;

// Veriff imports
import com.veriff.VeriffBranding;
import com.veriff.VeriffConfiguration;
import com.veriff.VeriffResult;
import com.veriff.VeriffSdk;

Expand All @@ -24,6 +27,8 @@ public class VeriffCordovaPlugin extends CordovaPlugin {

private static final int REQUEST_CODE = 800;
private static CallbackContext callbackContextApp;
private static JSONObject veriffConfig = new JSONObject();


@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Expand All @@ -33,6 +38,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.callbackContextApp.error("Error: Session token is required");
return false;
}
if (!args.isNull(1)) {
veriffConfig = new JSONObject(args.getString(1));
}
String sessionUrl = args.getString(0);
this.launchVeriffSDK(sessionUrl);
return true;
Expand All @@ -44,7 +52,20 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

private void launchVeriffSDK(String sessionUrl) {
cordova.setActivityResultCallback(this);
Intent intent = VeriffSdk.createLaunchIntent(cordova.getActivity(), sessionUrl);
VeriffBranding.Builder branding = new VeriffBranding.Builder();

if(veriffConfig.length() > 0) {
try {
branding.themeColor(Color.parseColor(veriffConfig.getString("themeColor")));
} catch (JSONException e) {
e.printStackTrace();
}
}

VeriffConfiguration configuration = new VeriffConfiguration.Builder()
.branding(branding.build())
.build();
Intent intent = VeriffSdk.createLaunchIntent(cordova.getActivity(), sessionUrl, configuration);
cordova.startActivityForResult(this, intent, REQUEST_CODE);
}

Expand Down

0 comments on commit 16f6887

Please sign in to comment.