use of com.onesignal.sdktest.adapter.EnumSelectionRecyclerViewAdapter in project OneSignal-Android-SDK by OneSignal.
the class Dialog method createSendOutcomeAlertDialog.
public void createSendOutcomeAlertDialog(final String content) {
final View sendOutcomeAlertDialogView = layoutInflater.inflate(R.layout.send_outcome_alert_dialog_layout, null, false);
final CardView sendOutcomeDialogTitleCardView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_card_view);
final RelativeLayout sendOutcomeDialogTitleRelativeLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_relative_layout);
final TextView sendOutcomeDialogTitleTextView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_text_view);
final ImageView sendOutcomeDialogTitleArrowImageView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_arrow_image_view);
final RecyclerView sendOutcomeDialogSelectionRecyclerView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_recycler_view);
final LinearLayout sendOutcomeDialogSelectionContentLinearLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_content_linear_layout);
final TextInputLayout sendOutcomeDialogNameTextInputLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_name_text_input_layout);
final EditText sendOutcomeDialogNameEditText = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_name_edit_text);
final TextInputLayout sendOutcomeDialogValueTextInputLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_value_text_input_layout);
final EditText sendOutcomeDialogValueEditText = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_value_edit_text);
final ProgressBar sendOutcomeDialogProgressBar = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_progress_bar);
sendOutcomeDialogNameTextInputLayout.setHint("Name");
sendOutcomeDialogValueTextInputLayout.setHint("Value");
sendOutcomeDialogTitleTextView.setText(content);
font.applyFont(sendOutcomeDialogTitleTextView, font.saralaBold);
font.applyFont(sendOutcomeDialogNameTextInputLayout, font.saralaBold);
font.applyFont(sendOutcomeDialogValueTextInputLayout, font.saralaBold);
sendOutcomeDialogTitleCardView.setCardElevation(8f);
recyclerViewBuilder.setupRecyclerView(sendOutcomeDialogSelectionRecyclerView, 3, false, true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
sendOutcomeDialogSelectionRecyclerView.setLayoutManager(linearLayoutManager);
EnumSelectionRecyclerViewAdapter enumSelectionRecyclerViewAdapter = new EnumSelectionRecyclerViewAdapter(context, OutcomeEvent.values(), new EnumSelectionCallback() {
@Override
public void onSelection(String title) {
int nameVisibility = View.GONE;
int valueVisibility = View.GONE;
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(title);
if (outcomeEvent == null) {
Drawable arrow = context.getResources().getDrawable(R.drawable.ic_chevron_down_white_48dp);
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(0f);
sendOutcomeDialogSelectionRecyclerView.setVisibility(View.GONE);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.GONE);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
return;
}
switch(outcomeEvent) {
case OUTCOME:
case UNIQUE_OUTCOME:
nameVisibility = View.VISIBLE;
break;
case OUTCOME_WITH_VALUE:
nameVisibility = View.VISIBLE;
valueVisibility = View.VISIBLE;
break;
}
sendOutcomeDialogTitleTextView.setText(outcomeEvent.getTitle());
Drawable arrow = context.getResources().getDrawable(R.drawable.ic_chevron_down_white_48dp);
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(0f);
sendOutcomeDialogSelectionRecyclerView.setVisibility(View.GONE);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.VISIBLE);
sendOutcomeDialogNameTextInputLayout.setVisibility(nameVisibility);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
sendOutcomeDialogValueEditText.setVisibility(valueVisibility);
}
});
sendOutcomeDialogSelectionRecyclerView.setAdapter(enumSelectionRecyclerViewAdapter);
sendOutcomeDialogTitleRelativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean showMenu = sendOutcomeDialogSelectionRecyclerView.getVisibility() == View.GONE;
Drawable arrow = context.getResources().getDrawable(showMenu ? R.drawable.ic_chevron_up_white_48dp : R.drawable.ic_chevron_down_white_48dp);
int menuVisibility = showMenu ? View.VISIBLE : View.GONE;
int contentVisibility = showMenu ? View.GONE : View.VISIBLE;
float shadow = showMenu ? 8f : 0f;
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(shadow);
sendOutcomeDialogSelectionRecyclerView.setVisibility(menuVisibility);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(contentVisibility);
int nameVisibility = View.GONE;
int valueVisibility = View.GONE;
String selectedTitle = sendOutcomeDialogTitleTextView.getText().toString();
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(selectedTitle);
if (outcomeEvent == null) {
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.GONE);
return;
}
if (!showMenu) {
switch(outcomeEvent) {
case OUTCOME:
case UNIQUE_OUTCOME:
nameVisibility = View.VISIBLE;
break;
case OUTCOME_WITH_VALUE:
nameVisibility = View.VISIBLE;
valueVisibility = View.VISIBLE;
break;
}
}
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(nameVisibility);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
sendOutcomeDialogValueEditText.setVisibility(valueVisibility);
}
});
final CustomAlertDialogBuilder sendOutcomeAlertDialog = new CustomAlertDialogBuilder(context, sendOutcomeAlertDialogView);
sendOutcomeAlertDialog.setView(sendOutcomeAlertDialogView);
sendOutcomeAlertDialog.setIsCancelable(true);
sendOutcomeAlertDialog.setCanceledOnTouchOutside(false);
sendOutcomeAlertDialog.setPositiveButton(Text.BUTTON_SEND, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
toggleUpdateAlertDialogAttributes(true);
String selectedTitle = sendOutcomeDialogTitleTextView.getText().toString();
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(selectedTitle);
if (outcomeEvent == null) {
toaster.makeCustomViewToast("Please select an outcome type!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
String name = sendOutcomeDialogNameEditText.getText().toString().trim();
String value = sendOutcomeDialogValueEditText.getText().toString().trim();
if (name.isEmpty()) {
toaster.makeCustomViewToast("Please enter an outcome name!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
switch(outcomeEvent) {
case OUTCOME:
OneSignal.sendOutcome(name, new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
case UNIQUE_OUTCOME:
OneSignal.sendUniqueOutcome(name, new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
case OUTCOME_WITH_VALUE:
if (value.isEmpty()) {
toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
OneSignal.sendOutcomeWithValue(name, Float.parseFloat(value), new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
}
InterfaceUtil.hideKeyboardFrom(context, sendOutcomeAlertDialogView);
}
private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) {
int progressVisibility = disableAttributes ? View.VISIBLE : View.GONE;
sendOutcomeDialogProgressBar.setVisibility(progressVisibility);
int buttonVisibility = disableAttributes ? View.GONE : View.VISIBLE;
sendOutcomeAlertDialog.getPositiveButtonElement().setVisibility(buttonVisibility);
sendOutcomeAlertDialog.getNegativeButtonElement().setVisibility(buttonVisibility);
sendOutcomeAlertDialog.getPositiveButtonElement().setEnabled(!disableAttributes);
sendOutcomeAlertDialog.getNegativeButtonElement().setEnabled(!disableAttributes);
sendOutcomeAlertDialog.setIsCancelable(!disableAttributes);
}
}).setNegativeButton(Text.BUTTON_CANCEL, null);
sendOutcomeAlertDialog.show();
}
Aggregations