use of com.getcapacitor.JSObject in project capacitor-file-picker by robingenz.
the class FilePickerPlugin method createPickFilesResult.
private JSObject createPickFilesResult(@Nullable Intent data, boolean readData) {
JSObject callResult = new JSObject();
List<JSObject> filesResultList = new ArrayList<>();
if (data == null) {
callResult.put("files", JSArray.from(filesResultList));
return callResult;
}
List<Uri> uris = new ArrayList<>();
if (data.getClipData() == null) {
Uri uri = data.getData();
uris.add(uri);
} else {
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
Uri uri = data.getClipData().getItemAt(i).getUri();
uris.add(uri);
}
}
for (int i = 0; i < uris.size(); i++) {
Uri uri = uris.get(i);
JSObject fileResult = new JSObject();
fileResult.put("path", implementation.getPathFromUri(uri));
fileResult.put("name", implementation.getNameFromUri(uri));
if (readData) {
fileResult.put("data", implementation.getDataFromUri(uri));
}
fileResult.put("mimeType", implementation.getMimeTypeFromUri(uri));
fileResult.put("size", implementation.getSizeFromUri(uri));
filesResultList.add(fileResult);
}
callResult.put("files", JSArray.from(filesResultList.toArray()));
return callResult;
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class AppleAuthProviderHandler method applySignInConfig.
private void applySignInConfig(PluginCall call, OAuthProvider.Builder provider) {
JSArray customParameters = call.getArray("customParameters");
if (customParameters != null) {
try {
List<Object> customParametersList = customParameters.toList();
for (int i = 0; i < customParametersList.size(); i++) {
JSObject customParameter = JSObject.fromJSONObject((JSONObject) customParametersList.get(i));
String key = customParameter.getString("key");
String value = customParameter.getString("value");
if (key == null || value == null) {
continue;
}
provider.addCustomParameter(key, value);
}
} catch (JSONException exception) {
Log.e(FirebaseAuthenticationPlugin.TAG, "applySignInConfig failed.", exception);
}
}
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class PhoneAuthProviderHandler method createCallbacks.
private PhoneAuthProvider.OnVerificationStateChangedCallbacks createCallbacks(PluginCall call) {
return new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
pluginImplementation.handleSuccessfulSignIn(call, credential, null);
}
@Override
public void onVerificationFailed(FirebaseException exception) {
pluginImplementation.handleFailedSignIn(call, null, exception);
}
@Override
public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
JSObject result = FirebaseAuthenticationHelper.createSignInResult(null, null, null);
result.put("verificationId", verificationId);
call.resolve(result);
}
};
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAppPlugin method getName.
@PluginMethod
public void getName(PluginCall call) {
JSObject ret = new JSObject();
ret.put("name", firebaseAppInstance.getName());
call.resolve(ret);
}
use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.
the class FirebaseAuthentication method signInWithCustomToken.
public void signInWithCustomToken(PluginCall call) {
boolean skipNativeAuth = this.config.getSkipNativeAuth();
if (skipNativeAuth) {
call.reject(ERROR_CUSTOM_TOKEN_SKIP_NATIVE_AUTH);
return;
}
String token = call.getString("token", "");
firebaseAuthInstance.signInWithCustomToken(token).addOnCompleteListener(plugin.getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken succeeded.");
FirebaseUser user = getCurrentUser();
JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(user, null, null);
call.resolve(signInResult);
} else {
Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken failed.", task.getException());
call.reject(ERROR_SIGN_IN_FAILED);
}
}
}).addOnFailureListener(plugin.getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken failed.", exception);
call.reject(ERROR_SIGN_IN_FAILED);
}
});
}
Aggregations