Skip to content

Commit

Permalink
Add ability to customize title and message of shaky dialog (linkedin#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
kahrendsen-li authored Jul 17, 2020
1 parent 283aba2 commit fcd42fe
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.os.Handler;
import android.view.View;

import android.widget.TextView;
import java.util.concurrent.TimeUnit;

import androidx.annotation.NonNull;
Expand All @@ -38,6 +39,8 @@ public class SendFeedbackDialog extends DialogFragment {
public static final String ACTION_START_FEEDBACK_FLOW = "StartFeedbackFlow";
public static final String ACTION_DIALOG_DISMISSED_BY_USER = "DialogDismissedByUser";
public static final String SHOULD_DISPLAY_SETTING_UI = "ShouldDisplaySettingUI";
public static final String CUSTOM_TITLE = "CustomTitle";
public static final String CUSTOM_MESSAGE = "CustomMessage";

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

Expand All @@ -54,8 +57,23 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

View popupView = View.inflate(getActivity().getApplicationContext(),
R.layout.shaky_popup, null);
builder.setView(popupView);

String customTitle = getArguments().getString(CUSTOM_TITLE);
if (customTitle != null) {
TextView titleView = (TextView) popupView.findViewById(R.id.shaky_dialog_title);
if (titleView != null) {
titleView.setText(customTitle);
}
}
String customMessage = getArguments().getString(CUSTOM_MESSAGE);
if (customMessage != null) {
TextView messageView = (TextView) popupView.findViewById(R.id.shaky_dialog_message);
if (messageView != null) {
messageView.setText(customMessage);
}
}

builder.setView(popupView);
builder.setPositiveButton(R.string.shaky_dialog_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
19 changes: 19 additions & 0 deletions shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import androidx.annotation.IntDef;
import androidx.annotation.MenuRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -64,6 +65,24 @@ public boolean shouldShowSettingsUI() {
return false;
}

/**
* @return the title of the dialog that appears on shake, or null if the default title should be
* used
*/
@Nullable
public String getDialogTitle() {
return null;
}

/**
* @return the message of the dialog that appears on shake, or null if the default message should
* be used
*/
@Nullable
public String getDialogMessage() {
return null;
}

/**
* @return desired sensitivity level, defaults to 'medium'
*/
Expand Down
6 changes: 6 additions & 0 deletions shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public void hearShake() {
}

Bundle arguments = new Bundle();
if (delegate.getDialogTitle() != null) {
arguments.putString(SendFeedbackDialog.CUSTOM_TITLE, delegate.getDialogTitle());
}
if (delegate.getDialogMessage() != null) {
arguments.putString(SendFeedbackDialog.CUSTOM_MESSAGE, delegate.getDialogMessage());
}
arguments.putBoolean(SendFeedbackDialog.SHOULD_DISPLAY_SETTING_UI, delegate.shouldShowSettingsUI());
arguments.putInt(ShakySettingDialog.SHAKY_CURRENT_SENSITIVITY, delegate.getSensitivityLevel());
SendFeedbackDialog sendFeedbackDialog = new SendFeedbackDialog();
Expand Down
6 changes: 4 additions & 2 deletions shaky/src/main/res/layout-v17/shaky_popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
android:textAlignment="textStart"
android:paddingBottom="@dimen/title_padding"
android:textSize="@dimen/title_textsize"
android:textColor="@color/title"/>
android:textColor="@color/title"
android:id="@+id/shaky_dialog_title"/>

<TextView
android:layout_width="wrap_content"
Expand All @@ -54,7 +55,8 @@
android:gravity="start"
android:textAlignment="textStart"
android:textSize="@dimen/content_textsize"
android:textColor="@color/content"/>
android:textColor="@color/content"
android:id="@+id/shaky_dialog_message"/>

</LinearLayout>

Expand Down
6 changes: 4 additions & 2 deletions shaky/src/main/res/layout/shaky_popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@
android:gravity="start"
android:paddingBottom="@dimen/title_padding"
android:textSize="@dimen/title_textsize"
android:textColor="@color/title"/>
android:textColor="@color/title"
android:id="@+id/shaky_dialog_title"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shaky_dialog_message"
android:gravity="start"
android:textSize="@dimen/content_textsize"
android:textColor="@color/content"/>
android:textColor="@color/content"
android:id="@+id/shaky_dialog_message"/>

</LinearLayout>

Expand Down

0 comments on commit fcd42fe

Please sign in to comment.