Skip to content

Commit 5a83bb8

Browse files
committed
added all form options
added feedbackOptions to SentryOptions added callbacks to SentryUserFeedbackDialog
1 parent 79052ad commit 5a83bb8

File tree

6 files changed

+598
-115
lines changed

6 files changed

+598
-115
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ public final class io/sentry/android/core/SentryPerformanceProvider {
397397
public fun shutdown ()V
398398
}
399399

400+
public final class io/sentry/android/core/SentryUserFeedbackDialog : android/app/AlertDialog {
401+
public fun <init> (Landroid/content/Context;)V
402+
public fun <init> (Landroid/content/Context;I)V
403+
public fun <init> (Landroid/content/Context;ZLandroid/content/DialogInterface$OnCancelListener;)V
404+
public fun setCancelable (Z)V
405+
}
406+
400407
public class io/sentry/android/core/SpanFrameMetricsCollector : io/sentry/IPerformanceContinuousCollector, io/sentry/android/core/internal/util/SentryFrameMetricsCollector$FrameMetricsCollectorListener {
401408
protected final field lock Lio/sentry/util/AutoClosableReentrantLock;
402409
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V

sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackDialog.java

Lines changed: 136 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,163 @@
22

33
import android.app.AlertDialog;
44
import android.content.Context;
5+
import android.content.res.ColorStateList;
6+
import android.graphics.Color;
57
import android.os.Bundle;
68
import android.view.View;
79
import android.widget.Button;
810
import android.widget.EditText;
911
import android.widget.ImageView;
1012
import android.widget.TextView;
1113
import android.widget.Toast;
12-
14+
import io.sentry.Sentry;
15+
import io.sentry.SentryFeedbackOptions;
16+
import io.sentry.protocol.Feedback;
17+
import io.sentry.protocol.SentryId;
18+
import io.sentry.protocol.User;
1319
import org.jetbrains.annotations.NotNull;
1420
import org.jetbrains.annotations.Nullable;
1521

16-
public class SentryUserFeedbackDialog extends AlertDialog {
17-
18-
private boolean isCancelable = false;
19-
20-
protected SentryUserFeedbackDialog(@NotNull final Context context) {
21-
super(context);
22-
isCancelable = false;
22+
public final class SentryUserFeedbackDialog extends AlertDialog {
23+
24+
private boolean isCancelable = false;
25+
26+
public SentryUserFeedbackDialog(final @NotNull Context context) {
27+
super(context);
28+
isCancelable = false;
29+
}
30+
31+
public SentryUserFeedbackDialog(
32+
final @NotNull Context context,
33+
final boolean cancelable,
34+
@Nullable final OnCancelListener cancelListener) {
35+
super(context, cancelable, cancelListener);
36+
isCancelable = cancelable;
37+
}
38+
39+
public SentryUserFeedbackDialog(final @NotNull Context context, final int themeResId) {
40+
super(context, themeResId);
41+
isCancelable = false;
42+
}
43+
44+
@Override
45+
public void setCancelable(boolean cancelable) {
46+
super.setCancelable(cancelable);
47+
isCancelable = cancelable;
48+
}
49+
50+
@Override
51+
protected void onCreate(Bundle savedInstanceState) {
52+
super.onCreate(savedInstanceState);
53+
setContentView(R.layout.sentry_dialog_user_feedback);
54+
setCancelable(isCancelable);
55+
56+
final @NotNull SentryFeedbackOptions feedbackOptions =
57+
Sentry.getCurrentScopes().getOptions().getFeedbackOptions();
58+
final @NotNull TextView lblTitle = findViewById(R.id.sentry_dialog_user_feedback_title);
59+
final @NotNull ImageView imgLogo = findViewById(R.id.sentry_dialog_user_feedback_logo);
60+
final @NotNull TextView lblName = findViewById(R.id.sentry_dialog_user_feedback_txt_name);
61+
final @NotNull EditText edtName = findViewById(R.id.sentry_dialog_user_feedback_edt_name);
62+
final @NotNull TextView lblEmail = findViewById(R.id.sentry_dialog_user_feedback_txt_email);
63+
final @NotNull EditText edtEmail = findViewById(R.id.sentry_dialog_user_feedback_edt_email);
64+
final @NotNull TextView lblMessage =
65+
findViewById(R.id.sentry_dialog_user_feedback_txt_description);
66+
final @NotNull EditText edtMessage =
67+
findViewById(R.id.sentry_dialog_user_feedback_edt_description);
68+
final @NotNull Button btnSend = findViewById(R.id.sentry_dialog_user_feedback_btn_send);
69+
final @NotNull Button btnCancel = findViewById(R.id.sentry_dialog_user_feedback_btn_cancel);
70+
71+
if (feedbackOptions.isShowBranding()) {
72+
imgLogo.setVisibility(View.VISIBLE);
73+
} else {
74+
imgLogo.setVisibility(View.GONE);
2375
}
24-
25-
protected SentryUserFeedbackDialog(@NotNull final Context context, final boolean cancelable, @Nullable final OnCancelListener cancelListener) {
26-
super(context, cancelable, cancelListener);
27-
isCancelable = cancelable;
76+
imgLogo.setImageTintList(ColorStateList.valueOf(lblTitle.getTextColors().getDefaultColor()));
77+
78+
if (!feedbackOptions.isShowName() && !feedbackOptions.isNameRequired()) {
79+
lblName.setVisibility(View.GONE);
80+
edtName.setVisibility(View.GONE);
81+
} else {
82+
lblName.setVisibility(View.VISIBLE);
83+
edtName.setVisibility(View.VISIBLE);
84+
lblName.setText(feedbackOptions.getNameLabel());
85+
edtName.setHint(feedbackOptions.getNamePlaceholder());
86+
if (feedbackOptions.isNameRequired()) {
87+
lblName.append(feedbackOptions.getIsRequiredLabel());
88+
}
2889
}
2990

30-
protected SentryUserFeedbackDialog(@NotNull final Context context, final int themeResId) {
31-
super(context, themeResId);
32-
isCancelable = false;
91+
if (!feedbackOptions.isShowEmail() && !feedbackOptions.isEmailRequired()) {
92+
lblEmail.setVisibility(View.GONE);
93+
edtEmail.setVisibility(View.GONE);
94+
} else {
95+
lblEmail.setVisibility(View.VISIBLE);
96+
edtEmail.setVisibility(View.VISIBLE);
97+
lblEmail.setText(feedbackOptions.getEmailLabel());
98+
edtEmail.setHint(feedbackOptions.getEmailPlaceholder());
99+
if (feedbackOptions.isEmailRequired()) {
100+
lblEmail.append(feedbackOptions.getIsRequiredLabel());
101+
}
33102
}
34103

35-
@Override
36-
public void setCancelable(boolean cancelable) {
37-
super.setCancelable(cancelable);
38-
isCancelable = cancelable;
104+
if (feedbackOptions.isUseSentryUser()) {
105+
final @Nullable User user = Sentry.getCurrentScopes().getScope().getUser();
106+
if (user != null) {
107+
edtName.setText(user.getName());
108+
edtEmail.setText(user.getEmail());
109+
}
39110
}
40111

41-
@Override
42-
protected void onCreate(Bundle savedInstanceState) {
43-
super.onCreate(savedInstanceState);
44-
setContentView(R.layout.sentry_dialog_user_feedback);
45-
setCancelable(isCancelable);
46-
47-
@NotNull final TextView lblTitle = findViewById(R.id.sentry_dialog_user_feedback_title);
48-
@NotNull final ImageView imgLogo = findViewById(R.id.sentry_dialog_user_feedback_logo);
49-
@NotNull final TextView lblName = findViewById(R.id.sentry_dialog_user_feedback_txt_name);
50-
@NotNull final EditText edtName = findViewById(R.id.sentry_dialog_user_feedback_edt_name);
51-
@NotNull final TextView lblEmail = findViewById(R.id.sentry_dialog_user_feedback_txt_email);
52-
@NotNull final EditText edtEmail = findViewById(R.id.sentry_dialog_user_feedback_edt_email);
53-
@NotNull final TextView lblMessage = findViewById(R.id.sentry_dialog_user_feedback_txt_description);
54-
@NotNull final EditText edtMessage = findViewById(R.id.sentry_dialog_user_feedback_edt_description);
55-
@NotNull final Button btnSend = findViewById(R.id.sentry_dialog_user_feedback_btn_send);
56-
@NotNull final Button btnCancel = findViewById(R.id.sentry_dialog_user_feedback_btn_cancel);
57-
58-
if (showBranding) {
59-
imgLogo.setVisibility(View.VISIBLE);
60-
} else {
61-
imgLogo.setVisibility(View.GONE);
62-
}
63-
64-
if (!showName && !isNameRequired) {
65-
lblName.setVisibility(View.GONE);
66-
edtName.setVisibility(View.GONE);
67-
} else {
68-
lblName.setVisibility(View.VISIBLE);
69-
edtName.setVisibility(View.VISIBLE);
70-
lblName.setText(nameLabel);
71-
edtName.setHint(namePlaceholder);
72-
if (isNameRequired) {
73-
lblName.append(isRequiredLabel);
112+
lblMessage.setText(feedbackOptions.getMessageLabel());
113+
edtMessage.setHint(feedbackOptions.getMessagePlaceholder());
114+
lblTitle.setText(feedbackOptions.getFormTitle());
115+
116+
btnSend.setBackgroundColor(Color.parseColor(feedbackOptions.getSubmitBackgroundHex()));
117+
btnSend.setTextColor(Color.parseColor(feedbackOptions.getSubmitForegroundHex()));
118+
btnSend.setText(feedbackOptions.getSubmitButtonLabel());
119+
btnSend.setOnClickListener(
120+
v -> {
121+
final @NotNull Feedback feedback = new Feedback(edtMessage.getText().toString());
122+
feedback.setName(edtName.getText().toString());
123+
feedback.setContactEmail(edtEmail.getText().toString());
124+
125+
SentryId id = Sentry.captureFeedback(feedback);
126+
if (!id.equals(SentryId.EMPTY_ID)) {
127+
Toast.makeText(
128+
getContext(), feedbackOptions.getSuccessMessageText(), Toast.LENGTH_SHORT)
129+
.show();
130+
final @Nullable SentryFeedbackOptions.SentryFeedbackCallback onSubmitSuccess =
131+
feedbackOptions.getOnSubmitSuccess();
132+
if (onSubmitSuccess != null) {
133+
onSubmitSuccess.call(feedback);
74134
}
75-
}
76-
77-
if (!showEmail && !isEmailRequired) {
78-
lblEmail.setVisibility(View.GONE);
79-
edtEmail.setVisibility(View.GONE);
80-
} else {
81-
lblEmail.setVisibility(View.VISIBLE);
82-
edtEmail.setVisibility(View.VISIBLE);
83-
lblEmail.setText(emailLabel);
84-
edtEmail.setHint(emailPlaceholder);
85-
if (isEmailRequired) {
86-
lblEmail.append(isRequiredLabel);
135+
} else {
136+
final @Nullable SentryFeedbackOptions.SentryFeedbackCallback onSubmitError =
137+
feedbackOptions.getOnSubmitError();
138+
if (onSubmitError != null) {
139+
onSubmitError.call(feedback);
87140
}
88-
}
89-
90-
if (useSentryUser) {
91-
edtName.setText();
92-
edtEmail.setText();
93-
}
94-
95-
lblMessage.setText(messageLabel);
96-
edtMessage.setHint(messagePlaceholder);
97-
lblTitle.setText(formTitle);
98-
99-
btnSend.setText(submitButtonLabel);
100-
btnSend.setOnClickListener(v -> {
101-
Toast.makeText(getContext(), successMessageText, Toast.LENGTH_SHORT).show();
102-
cancel();
141+
}
142+
cancel();
103143
});
104144

105-
btnCancel.setText(cancelButtonLabel);
106-
btnCancel.setOnClickListener(v -> cancel());
107-
}
145+
btnCancel.setText(feedbackOptions.getCancelButtonLabel());
146+
btnCancel.setOnClickListener(v -> cancel());
108147

109-
@Override
110-
protected void onStart() {
111-
super.onStart();
148+
final @Nullable Runnable onFormClose = feedbackOptions.getOnFormClose();
149+
if (onFormClose != null) {
150+
setOnDismissListener(dialog -> onFormClose.run());
151+
}
152+
}
153+
154+
@Override
155+
protected void onStart() {
156+
super.onStart();
157+
final @NotNull SentryFeedbackOptions feedbackOptions =
158+
Sentry.getCurrentScopes().getOptions().getFeedbackOptions();
159+
final @Nullable Runnable onFormOpen = feedbackOptions.getOnFormOpen();
160+
if (onFormOpen != null) {
161+
onFormOpen.run();
112162
}
163+
}
113164
}

sentry-android-core/src/main/res/layout/sentry_dialog_user_feedback.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="match_parent"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
45
android:layout_height="match_parent"
6+
tools:ignore="HardcodedText"
57
android:padding="24dp">
68

79

810
<TextView
911
android:id="@+id/sentry_dialog_user_feedback_title"
1012
android:layout_width="match_parent"
1113
android:layout_height="wrap_content"
12-
android:text="Give Feedback"
14+
android:text="Report a Bug"
1315
style="@android:style/TextAppearance.DialogWindowTitle"
1416
android:textStyle="bold"
1517
android:layout_marginBottom="16dp"
1618
android:layout_alignParentTop="true"
17-
android:layout_alignEnd="@+id/sentry_dialog_user_feedback_logo"/>
19+
android:layout_alignEnd="@+id/sentry_dialog_user_feedback_logo" />
1820

1921
<ImageView
2022
android:id="@+id/sentry_dialog_user_feedback_logo"
@@ -29,7 +31,7 @@
2931
android:id="@+id/sentry_dialog_user_feedback_txt_name"
3032
android:layout_width="match_parent"
3133
android:layout_height="wrap_content"
32-
android:text="Full Name"
34+
android:text="Name"
3335
android:layout_marginTop="4dp"
3436
style="@android:style/TextAppearance.Widget.TextView"
3537
android:layout_below="@id/sentry_dialog_user_feedback_title" />
@@ -38,7 +40,7 @@
3840
android:id="@+id/sentry_dialog_user_feedback_edt_name"
3941
android:layout_width="match_parent"
4042
android:layout_height="wrap_content"
41-
android:hint="Full Name"
43+
android:hint="Your Name"
4244
android:inputType="textPersonName"
4345
style="@android:style/TextAppearance.Widget.EditText"
4446
android:background="@drawable/edit_text_border"
@@ -50,15 +52,15 @@
5052
android:layout_width="match_parent"
5153
android:layout_height="wrap_content"
5254
android:text="Email"
53-
android:layout_marginTop="4dp"
55+
android:layout_marginTop="8dp"
5456
style="@android:style/TextAppearance.Widget.TextView"
5557
android:layout_below="@id/sentry_dialog_user_feedback_edt_name" />
5658

5759
<EditText
5860
android:id="@+id/sentry_dialog_user_feedback_edt_email"
5961
android:layout_width="match_parent"
6062
android:layout_height="wrap_content"
61-
android:hint="Email"
63+
android:hint="your.email@example.org"
6264
android:inputType="textEmailAddress"
6365
style="@android:style/TextAppearance.Widget.EditText"
6466
android:background="@drawable/edit_text_border"
@@ -70,7 +72,7 @@
7072
android:layout_width="match_parent"
7173
android:layout_height="wrap_content"
7274
android:text="Description (Required)"
73-
android:layout_marginTop="4dp"
75+
android:layout_marginTop="8dp"
7476
style="@android:style/TextAppearance.Widget.TextView"
7577
android:layout_below="@id/sentry_dialog_user_feedback_edt_email" />
7678

@@ -81,7 +83,7 @@
8183
android:lines="6"
8284
android:inputType="textMultiLine"
8385
android:gravity="top|start"
84-
android:hint="What did you expect?"
86+
android:hint="What's the bug? What did you expect?"
8587
style="@android:style/TextAppearance.Widget.EditText"
8688
android:background="@drawable/edit_text_border"
8789
android:paddingHorizontal="8dp"
@@ -91,7 +93,7 @@
9193
android:id="@+id/sentry_dialog_user_feedback_btn_send"
9294
android:layout_width="match_parent"
9395
android:layout_height="wrap_content"
94-
android:backgroundTint="#362d59"
96+
android:backgroundTint="#584AC0"
9597
android:textColor="@android:color/white"
9698
android:layout_marginTop="32dp"
9799
android:text="Send Bug Report"

0 commit comments

Comments
 (0)