[android] add short link suffix support

This commit is contained in:
Omer Levy 2017-09-04 18:35:21 +03:00
parent 012f8b79b1
commit 5728fa76bc
1 changed files with 56 additions and 45 deletions

View File

@ -91,7 +91,9 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
@ReactMethod
public void createDynamicLink(final ReadableMap parameters, final Promise promise) {
try {
DynamicLink.Builder builder = setDynamicLinkBuilderFromMap(parameters);
Map<String, Object> m = Utils.recursivelyDeconstructReadableMap(parameters);
DynamicLink.Builder builder = setDynamicLinkBuilderFromMap(m);
Uri link = builder.buildDynamicLink().getUri();
Log.d(TAG, "created dynamic link: " + link.toString());
@ -106,8 +108,11 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
@ReactMethod
public void createShortDynamicLink(final ReadableMap parameters, final Promise promise) {
try {
DynamicLink.Builder builder = setDynamicLinkBuilderFromMap(parameters);
Task<ShortDynamicLink> shortLinkTask = builder.buildShortDynamicLink()
Map<String, Object> m = Utils.recursivelyDeconstructReadableMap(parameters);
DynamicLink.Builder builder = setDynamicLinkBuilderFromMap(m);
Task<ShortDynamicLink> shortLinkTask = getShortDynamicLinkTask(builder, m)
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
@ -128,18 +133,24 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
}
}
/**
* Converts a RN ReadableMap into a set DynamicLink.Builder instance
*
* @param parameters
* @return
*/
private DynamicLink.Builder setDynamicLinkBuilderFromMap(ReadableMap parameters) {
private Task<ShortDynamicLink> getShortDynamicLinkTask(final DynamicLink.Builder builder ,final Map<String, Object> m) {
Map<String, Object> suffixParameters = (Map<String, Object>) m.get("suffix");
if (suffixParameters != null) {
String option = (String) suffixParameters.get("option");
if (option.equals("SHORT")) {
return builder.buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT);
}
else if (option.equals("UNGUESSABLE")) {
return builder.buildShortDynamicLink(ShortDynamicLink.Suffix.UNGUESSABLE);
}
}
return builder.buildShortDynamicLink();
}
private DynamicLink.Builder setDynamicLinkBuilderFromMap(final Map<String, Object> m) {
DynamicLink.Builder parametersBuilder = FirebaseDynamicLinks.getInstance().createDynamicLink();
try {
Map<String, Object> m = Utils.recursivelyDeconstructReadableMap(parameters);
parametersBuilder.setLink(Uri.parse((String)m.get("link")));
parametersBuilder.setDynamicLinkDomain((String)m.get("dynamicLinkDomain"));