Skip to content

Commit

Permalink
Next button loads the correct content for step 2 based on the user's …
Browse files Browse the repository at this point in the history
…choice

Next button loads the correct content for step 2 based on the user's choice
  • Loading branch information
rob-gioia-branch committed Oct 11, 2024
1 parent e0a0ce0 commit 0dfcb59
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import android.content.Context;
import android.view.WindowManager;
import android.widget.Button;

import java.util.Objects;

public class LinkingValidator {
private static LinkingValidator instance;
private LinkingValidatorDialog linkingValidatorDialog;

private LinkingValidator(Context context) { }
private LinkingValidator(Context context) {}

public static void validate(Context context) {
if (instance == null) {
Expand All @@ -26,5 +27,6 @@ private void validateDeepLinkRouting(Context context) {
lp.height = 1000;
instance.linkingValidatorDialog.show();
instance.linkingValidatorDialog.getWindow().setAttributes(lp);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.branch.referral.validators;

public class LinkingValidatorConstants {
public static final String canonicalURLPromptText = "Please paste in a web link for the $canonical_url";
public static final String deeplinkPathPromptText = "Please paste in a value for the $deeplink_path";
public static final String customKeyPromptText = "Please enter your custom key and value for routing";
public static final String step1ButtonText = "Next";
public static final String step2ButtonText = " Generate Links for Testing ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,28 +19,93 @@

public class LinkingValidatorDialog extends Dialog implements AdapterView.OnItemSelectedListener {

private enum ROUTING_TYPE { CANONICAL_URL, DEEPLINK_PATH, CUSTOM }
private ROUTING_TYPE routingType;
private Button ctaButton;
private Spinner linkingValidatorDropdownMenu;
private TextView linkingValidatorText;
private EditText linkingValidatorEditText;
private LinearLayout customKVPField;
private int step = 1;

public LinkingValidatorDialog(final Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.dialog_linking_validator);

Spinner spinner = findViewById(R.id.spinner);
linkingValidatorDropdownMenu = findViewById(R.id.linkingValidatorDropdownMenu);
List<String> choices = new ArrayList<>();
choices.add("$canonical_url");
choices.add("$deeplink_path");
choices.add("other (custom)");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, choices);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
linkingValidatorDropdownMenu.setAdapter(dataAdapter);
linkingValidatorDropdownMenu.setOnItemSelectedListener(this);

ctaButton = findViewById(R.id.linkingValidatorButton);
ctaButton.setText(LinkingValidatorConstants.step1ButtonText);
ctaButton.setOnClickListener(view -> {
if(step == 1) {
LoadStep2Screen();
} else {
GenerateBranchLinks();
}
});

linkingValidatorText = findViewById(R.id.linkingValidatorText);
linkingValidatorEditText = findViewById(R.id.linkingValidatorEditText);
customKVPField = findViewById(R.id.customKVPField);

linkingValidatorEditText.setVisibility(View.GONE);
customKVPField.setVisibility(View.GONE);

routingType = ROUTING_TYPE.CANONICAL_URL;
}

@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

String item = adapterView.getItemAtPosition(i).toString();
switch (item) {
case "$canonical_url":
routingType = ROUTING_TYPE.CANONICAL_URL;
break;
case "$deeplink_path":
routingType = ROUTING_TYPE.DEEPLINK_PATH;
break;
case "other (custom)":
routingType = ROUTING_TYPE.CUSTOM;
break;
}
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}

void LoadStep2Screen() {
step++;
ctaButton.setText(LinkingValidatorConstants.step2ButtonText);
linkingValidatorDropdownMenu.setVisibility(View.GONE);

switch(routingType) {
case CANONICAL_URL:
linkingValidatorEditText.setVisibility(View.VISIBLE);
linkingValidatorText.setText(LinkingValidatorConstants.canonicalURLPromptText);
break;
case DEEPLINK_PATH:
linkingValidatorEditText.setVisibility(View.VISIBLE);
linkingValidatorText.setText(LinkingValidatorConstants.deeplinkPathPromptText);
break;
case CUSTOM:
customKVPField.setVisibility(View.VISIBLE);
linkingValidatorText.setText(LinkingValidatorConstants.customKeyPromptText);
break;
}
}

void GenerateBranchLinks() {

}
}
77 changes: 68 additions & 9 deletions Branch-SDK/src/main/res/layout/dialog_linking_validator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:background="#FFFFFF">

<LinearLayout
android:id="@+id/linearLayout"
android:id="@+id/linkingValidatorHeader"
android:layout_width="409dp"
android:layout_height="100dp"
android:orientation="horizontal"
Expand All @@ -21,15 +21,15 @@
android:layout_weight="0.1" />

<ImageView
android:id="@+id/imageView"
android:id="@+id/branchLogoImage"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="0.15"
android:src="@drawable/branch_icon" />

<TextView
android:id="@+id/textView"
android:id="@+id/linkingValidatorTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.65"
Expand All @@ -44,16 +44,16 @@
</LinearLayout>

<Spinner
android:id="@+id/spinner"
android:id="@+id/linkingValidatorDropdownMenu"
android:layout_width="351dp"
android:layout_height="50dp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintBottom_toTopOf="@+id/linkingValidatorButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
app:layout_constraintTop_toBottomOf="@+id/linkingValidatorText" />

<TextView
android:id="@+id/textView2"
android:id="@+id/linkingValidatorText"
android:layout_width="312dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
Expand All @@ -62,10 +62,22 @@
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
app:layout_constraintTop_toBottomOf="@+id/linkingValidatorHeader" />

<EditText
android:id="@+id/linkingValidatorEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter a value"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/linkingValidatorButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linkingValidatorText" />

<Button
android:id="@+id/button"
android:id="@+id/linkingValidatorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
Expand All @@ -75,4 +87,51 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<LinearLayout
android:id="@+id/customKVPField"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/linkingValidatorButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linkingValidatorText">

<Space
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.1" />

<EditText
android:id="@+id/keyEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:ems="10"
android:hint="key"
android:inputType="text"
android:text="" />

<Space
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.1" />

<EditText
android:id="@+id/valueEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:ems="10"
android:hint="value"
android:inputType="text"
android:text="" />

<Space
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.1" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 0dfcb59

Please sign in to comment.