Skip to content

Commit e19d122

Browse files
committed
started SentryFeedbackOptions
added first draft of SentryUserFeedbackDialog
1 parent 986772d commit e19d122

File tree

2 files changed

+322
-0
lines changed

2 files changed

+322
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package io.sentry.android.core;
2+
3+
import android.app.AlertDialog;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.EditText;
9+
import android.widget.ImageView;
10+
import android.widget.TextView;
11+
import android.widget.Toast;
12+
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
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;
23+
}
24+
25+
protected SentryUserFeedbackDialog(@NotNull final Context context, final boolean cancelable, @Nullable final OnCancelListener cancelListener) {
26+
super(context, cancelable, cancelListener);
27+
isCancelable = cancelable;
28+
}
29+
30+
protected SentryUserFeedbackDialog(@NotNull final Context context, final int themeResId) {
31+
super(context, themeResId);
32+
isCancelable = false;
33+
}
34+
35+
@Override
36+
public void setCancelable(boolean cancelable) {
37+
super.setCancelable(cancelable);
38+
isCancelable = cancelable;
39+
}
40+
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);
74+
}
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);
87+
}
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();
103+
});
104+
105+
btnCancel.setText(cancelButtonLabel);
106+
btnCancel.setOnClickListener(v -> cancel());
107+
}
108+
109+
@Override
110+
protected void onStart() {
111+
super.onStart();
112+
}
113+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
package io.sentry;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
public class SentryFeedbackOptions {
6+
7+
// User and Form
8+
/** Requires the name field on the feedback form to be filled in. */
9+
private boolean isNameRequired = false;
10+
/** Displays the name field on the feedback form. Ignored if isNameRequired is true. */
11+
private boolean showName = true;
12+
/** Requires the email field on the feedback form to be filled in. */
13+
private boolean isEmailRequired = false;
14+
/** Displays the email field on the feedback form. Ignored if isEmailRequired is true. */
15+
private boolean showEmail = true;
16+
/** Sets the email and name fields to the corresponding Sentry SDK user fields that were called with SentrySDK.setUser. */
17+
private boolean useSentryUser = true;
18+
/** Displays the Sentry logo inside of the form */
19+
private boolean showBranding = true;
20+
21+
// Text Customization
22+
/** The title of the feedback form. */
23+
private @NotNull String formTitle = "Report a Bug";
24+
/** The label of the submit button. */
25+
private @NotNull String submitButtonLabel = "Send Bug Report";
26+
/** The label of the cancel button. */
27+
private @NotNull String cancelButtonLabel = "Cancel";
28+
/** The label of the confirm button. */
29+
private @NotNull String confirmButtonLabel = "Confirm";
30+
/** The label next to the name input field. */
31+
private @NotNull String nameLabel = "Name";
32+
/** The placeholder in the name input field. */
33+
private @NotNull String namePlaceholder = "Your Name";
34+
/** The label next to the email input field. */
35+
private @NotNull String emailLabel = "Email";
36+
/** The placeholder in the email input field. */
37+
private @NotNull String emailPlaceholder = "your.email@example.org";
38+
/** The text to attach to the title label for a required field. */
39+
private @NotNull String isRequiredLabel = "(Required)";
40+
/** The label of the feedback description input field. */
41+
private @NotNull String messageLabel = "Description";
42+
/** The placeholder in the feedback description input field. */
43+
private @NotNull String messagePlaceholder = "What's the bug? What did you expect?";
44+
/** The message displayed after a successful feedback submission. */
45+
private @NotNull String successMessageText = "Thank you for your report!";
46+
47+
public boolean isNameRequired() {
48+
return isNameRequired;
49+
}
50+
public void setNameRequired(boolean isNameRequired) {
51+
this.isNameRequired = isNameRequired;
52+
}
53+
public boolean isShowName() {
54+
return showName;
55+
}
56+
public void setShowName(boolean showName) {
57+
this.showName = showName;
58+
}
59+
public boolean isEmailRequired() {
60+
return isEmailRequired;
61+
}
62+
public void setEmailRequired(boolean isEmailRequired) {
63+
this.isEmailRequired = isEmailRequired;
64+
}
65+
public boolean isShowEmail() {
66+
return showEmail;
67+
}
68+
public void setShowEmail(boolean showEmail) {
69+
this.showEmail = showEmail;
70+
}
71+
72+
public boolean isUseSentryUser() {
73+
return useSentryUser;
74+
}
75+
public void setUseSentryUser(boolean useSentryUser) {
76+
this.useSentryUser = useSentryUser;
77+
}
78+
public boolean isShowBranding() {
79+
return showBranding;
80+
}
81+
public void setShowBranding(boolean showBranding) {
82+
this.showBranding = showBranding;
83+
}
84+
85+
CONTINUE
86+
public @NotNull String getFormTitle() {
87+
return formTitle;
88+
}
89+
public void setFormTitle(@NotNull String formTitle) {
90+
this.formTitle = formTitle;
91+
}
92+
public @NotNull String getSubmitButtonLabel() {
93+
return submitButtonLabel;
94+
}
95+
public void setSubmitButtonLabel(@NotNull String submitButtonLabel) {
96+
this.submitButtonLabel = submitButtonLabel;
97+
}
98+
public @NotNull String getCancelButtonLabel() {
99+
return cancelButtonLabel;
100+
}
101+
public void setCancelButtonLabel(@NotNull String cancelButtonLabel) {
102+
this.cancelButtonLabel = cancelButtonLabel;
103+
}
104+
public @NotNull String getConfirmButtonLabel() {
105+
return confirmButtonLabel;
106+
}
107+
public void setConfirmButtonLabel(@NotNull String confirmButtonLabel) {
108+
this.confirmButtonLabel = confirmButtonLabel;
109+
}
110+
public @NotNull String getNameLabel() {
111+
return nameLabel;
112+
}
113+
public void setNameLabel(@NotNull String nameLabel) {
114+
this.nameLabel = nameLabel;
115+
}
116+
public @NotNull String getNamePlaceholder() {
117+
return namePlaceholder;
118+
}
119+
public void setNamePlaceholder(@NotNull String namePlaceholder) {
120+
this.namePlaceholder = namePlaceholder;
121+
}
122+
public @NotNull String getEmailLabel() {
123+
return emailLabel;
124+
}
125+
public void setEmailLabel(@NotNull String emailLabel) {
126+
this.emailLabel = emailLabel;
127+
}
128+
public @NotNull String getEmailPlaceholder() {
129+
return emailPlaceholder;
130+
}
131+
public void setEmailPlaceholder(@NotNull String emailPlaceholder) {
132+
this.emailPlaceholder = emailPlaceholder;
133+
}
134+
public @NotNull String getIsRequiredLabel() {
135+
return isRequiredLabel;
136+
}
137+
public void setIsRequiredLabel(@NotNull String isRequiredLabel) {
138+
this.isRequiredLabel = isRequiredLabel;
139+
}
140+
141+
public @NotNull String getMessageLabel() {
142+
return messageLabel;
143+
}
144+
public void setMessageLabel(@NotNull String messageLabel) {
145+
this.messageLabel = messageLabel;
146+
}
147+
public @NotNull String getMessagePlaceholder() {
148+
return messagePlaceholder;
149+
}
150+
public void setMessagePlaceholder(@NotNull String messagePlaceholder) {
151+
this.messagePlaceholder = messagePlaceholder;
152+
}
153+
public @NotNull String getSuccessMessageText() {
154+
return successMessageText;
155+
}
156+
public void setSuccessMessageText(@NotNull String successMessageText) {
157+
this.successMessageText = successMessageText;
158+
}
159+
@Override
160+
public String toString() {
161+
return "SentryFeedbackOptions{"
162+
+ "isNameRequired="
163+
+ isNameRequired
164+
+ ", showName="
165+
+ showName
166+
+ ", isEmailRequired="
167+
+ isEmailRequired
168+
+ ", showEmail="
169+
+ showEmail
170+
+ ", useSentryUser="
171+
+ useSentryUser
172+
+ ", showBranding="
173+
+ showBranding
174+
+ ", formTitle='"
175+
+ formTitle
176+
+ '\''
177+
+ ", submitButtonLabel='"
178+
+ submitButtonLabel
179+
+ '\''
180+
+ ", cancelButtonLabel='"
181+
+ cancelButtonLabel
182+
+ '\''
183+
+ ", confirmButtonLabel='"
184+
+ confirmButtonLabel
185+
+ '\''
186+
+ ", nameLabel='"
187+
+ nameLabel
188+
+ '\''
189+
+ ", namePlaceholder='"
190+
+ namePlaceholder
191+
+ '\''
192+
+ ", emailLabel='"
193+
+ emailLabel
194+
+ '\''
195+
+ ", emailPlaceholder='"
196+
+ emailPlaceholder
197+
+ '\''
198+
+ ", isRequiredLabel='"
199+
+ isRequiredLabel
200+
+ '\''
201+
+ ", messageLabel='"
202+
+ messageLabel
203+
+ '\''
204+
+ ", messagePlaceholder='"
205+
+ messagePlaceholder
206+
+ '\''
207+
+ '}';
208+
}
209+
}

0 commit comments

Comments
 (0)