Skip to content

Commit

Permalink
moving custom dialog to ShakeDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanghi committed May 8, 2024
1 parent ce3f481 commit 9c8fd24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 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
13 changes: 2 additions & 11 deletions shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.app.Activity;
import android.app.Application;
import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -54,7 +53,6 @@ public class Shaky implements ShakeDetector.Listener {
private static final String CUSTOM_DIALOG_TAG = "CustomDialog";

private static final long SHAKE_COOLDOWN_MS = TimeUnit.SECONDS.toMillis(5);
private DialogFragment customFragment;
private final ShakeDelegate delegate;
private final ShakeDetector shakeDetector;
@Nullable
Expand Down Expand Up @@ -188,8 +186,8 @@ public void hearShake() {
arguments.putInt(ShakySettingDialog.SHAKY_CURRENT_SENSITIVITY, delegate.getSensitivityLevel());
SendFeedbackDialog sendFeedbackDialog = new SendFeedbackDialog();
sendFeedbackDialog.setArguments(arguments);
if (customFragment != null) {
customFragment.show(activity.getFragmentManager(), CUSTOM_DIALOG_TAG);
if (delegate.getCustomDialog() != null) {
delegate.getCustomDialog().show(activity.getFragmentManager(), CUSTOM_DIALOG_TAG);
} else {
sendFeedbackDialog.show(activity.getFragmentManager(), SEND_FEEDBACK_TAG);
}
Expand All @@ -198,13 +196,6 @@ public void hearShake() {
}
}

/**
* Custom dialog to be shown before the feedback flow
*/
public void setCustomDialog(@NonNull DialogFragment fragment) {
customFragment = fragment;
}

/**
* @return true if a shake happened in the last {@link #SHAKE_COOLDOWN_MS}, false otherwise.
*/
Expand Down

0 comments on commit 9c8fd24

Please sign in to comment.