Skip to content

Commit

Permalink
adding a custom dialog (#74)
Browse files Browse the repository at this point in the history
* adding a custom dialog

* changing DialogFragment to dialog

* Updating shaky flow for custom dialog

* moving custom dialog to ShakeDelegate

---------

Co-authored-by: dsanghi <dsanghi@linkedin.com>
  • Loading branch information
Devansh111 and dsanghi authored May 8, 2024
1 parent 83285b2 commit e97ee45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.linkedin.android.shaky;

import android.app.Activity;
import android.app.DialogFragment;

import androidx.annotation.IntDef;
import androidx.annotation.MenuRes;
Expand Down Expand Up @@ -131,6 +132,14 @@ public Integer getPopupTheme() {
public void collectData(@NonNull Activity activity, @NonNull Result data) {
}

/**
* @return a custom dialog to be shown before the feedback flow
*/
@Nullable
public DialogFragment getCustomDialog() {
return null;
}

/**
* Called when the user submits the Feedback form. Creates and starts an email Intent.
* This method can be overridden to send data to a custom URL endpoint, etc.
Expand Down
8 changes: 6 additions & 2 deletions shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class Shaky implements ShakeDetector.Listener {

private static final String SEND_FEEDBACK_TAG = "SendFeedback";
private static final String COLLECT_DATA_TAG = "CollectFeedbackData";
private static final String CUSTOM_DIALOG_TAG = "CustomDialog";

private static final long SHAKE_COOLDOWN_MS = TimeUnit.SECONDS.toMillis(5);

private final ShakeDelegate delegate;
private final ShakeDetector shakeDetector;
@Nullable
Expand Down Expand Up @@ -186,7 +186,11 @@ public void hearShake() {
arguments.putInt(ShakySettingDialog.SHAKY_CURRENT_SENSITIVITY, delegate.getSensitivityLevel());
SendFeedbackDialog sendFeedbackDialog = new SendFeedbackDialog();
sendFeedbackDialog.setArguments(arguments);
sendFeedbackDialog.show(activity.getFragmentManager(), SEND_FEEDBACK_TAG);
if (delegate.getCustomDialog() != null) {
delegate.getCustomDialog().show(activity.getFragmentManager(), CUSTOM_DIALOG_TAG);
} else {
sendFeedbackDialog.show(activity.getFragmentManager(), SEND_FEEDBACK_TAG);
}
if (shakyFlowCallback != null) {
shakyFlowCallback.onUserPromptShown();
}
Expand Down

0 comments on commit e97ee45

Please sign in to comment.