Skip to content

Commit fa03704

Browse files
In app feedback (commons-app#4845)
* rebase * Progress * Completed UI and POST Request * removed invalid string resource * Removed unused code & Added string resources * Resolved Code style issues * Javadoc for getters & setters * Codestyle fixes * Minor Fixes * wip * Tests * Comments * Fixed Tests * Minor changes * minor change * Comments * Minor Fixes * fixed tests * Removed Butterknife * Fixed tests * Removed Unecessary strings * Minor chnages * Minor fix * Minor changes * Minor changes * Implemented Suggestions * Removed Redundant Toast
1 parent 00760ba commit fa03704

File tree

12 files changed

+777
-5
lines changed

12 files changed

+777
-5
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package fr.free.nrw.commons.feedback;
2+
3+
import android.content.Context;
4+
import fr.free.nrw.commons.R;
5+
import fr.free.nrw.commons.feedback.model.Feedback;
6+
import fr.free.nrw.commons.utils.LangCodeUtils;
7+
import java.util.Locale;
8+
9+
/**
10+
* Creates a wikimedia recognizable format
11+
* from feedback information
12+
*/
13+
public class FeedbackContentCreator {
14+
private StringBuilder stringBuilder;
15+
private Feedback feedback;
16+
private Context context;
17+
18+
public FeedbackContentCreator(Context context, Feedback feedback) {
19+
this.feedback = feedback;
20+
this.context = context;
21+
init();
22+
}
23+
24+
/**
25+
* Initializes the string buffer object to append content from feedback object
26+
*/
27+
public void init() {
28+
// Localization is not needed here, because this ends up on a page where developers read the feedback, so English is the most convenient.
29+
30+
stringBuilder = new StringBuilder();
31+
stringBuilder.append("== ");
32+
stringBuilder.append("Feedback from ~~~ for version ");
33+
stringBuilder.append(feedback.getVersion());
34+
stringBuilder.append(" ==");
35+
stringBuilder.append("\n");
36+
stringBuilder.append(feedback.getTitle());
37+
stringBuilder.append("\n");
38+
stringBuilder.append("\n");
39+
if (feedback.getApiLevel() != null) {
40+
stringBuilder.append("* ");
41+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
42+
Locale.ENGLISH).getString(R.string.api_level));
43+
stringBuilder.append(": ");
44+
stringBuilder.append(feedback.getApiLevel());
45+
stringBuilder.append("\n");
46+
}
47+
if (feedback.getAndroidVersion() != null) {
48+
stringBuilder.append("* ");
49+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
50+
Locale.ENGLISH).getString(R.string.android_version));
51+
stringBuilder.append(": ");
52+
stringBuilder.append(feedback.getAndroidVersion());
53+
stringBuilder.append("\n");
54+
}
55+
if (feedback.getDeviceManufacturer() != null) {
56+
stringBuilder.append("* ");
57+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
58+
Locale.ENGLISH).getString(R.string.device_manufacturer));
59+
stringBuilder.append(": ");
60+
stringBuilder.append(feedback.getDeviceManufacturer());
61+
stringBuilder.append("\n");
62+
}
63+
if (feedback.getDeviceModel() != null) {
64+
stringBuilder.append("* ");
65+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
66+
Locale.ENGLISH).getString(R.string.device_model));
67+
stringBuilder.append(": ");
68+
stringBuilder.append(feedback.getDeviceModel());
69+
stringBuilder.append("\n");
70+
}
71+
if (feedback.getDevice() != null) {
72+
stringBuilder.append("* ");
73+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
74+
Locale.ENGLISH).getString(R.string.device_name));
75+
stringBuilder.append(": ");
76+
stringBuilder.append(feedback.getDevice());
77+
stringBuilder.append("\n");
78+
}
79+
if (feedback.getNetworkType() != null) {
80+
stringBuilder.append("* ");
81+
stringBuilder.append(LangCodeUtils.getLocalizedResources(context,
82+
Locale.ENGLISH).getString(R.string.network_type));
83+
stringBuilder.append(": ");
84+
stringBuilder.append(feedback.getNetworkType());
85+
stringBuilder.append("\n");
86+
}
87+
stringBuilder.append("~~~~");
88+
stringBuilder.append("\n");
89+
}
90+
91+
@Override
92+
public String toString() {
93+
return stringBuilder.toString();
94+
}
95+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package fr.free.nrw.commons.feedback;
2+
3+
import android.app.Dialog;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.view.View.OnClickListener;
8+
import android.widget.Toast;
9+
import fr.free.nrw.commons.R;
10+
import fr.free.nrw.commons.databinding.DialogFeedbackBinding;
11+
import fr.free.nrw.commons.feedback.model.Feedback;
12+
import fr.free.nrw.commons.utils.ConfigUtils;
13+
import fr.free.nrw.commons.utils.DeviceInfoUtil;
14+
15+
/**
16+
* Feedback dialog that asks user for message and
17+
* other device specifications
18+
*/
19+
public class FeedbackDialog extends Dialog {
20+
DialogFeedbackBinding dialogFeedbackBinding;
21+
22+
private OnFeedbackSubmitCallback onFeedbackSubmitCallback;
23+
24+
public FeedbackDialog(Context context, OnFeedbackSubmitCallback onFeedbackSubmitCallback) {
25+
super(context);
26+
this.onFeedbackSubmitCallback = onFeedbackSubmitCallback;
27+
}
28+
29+
@Override
30+
protected void onCreate(final Bundle savedInstanceState) {
31+
super.onCreate(savedInstanceState);
32+
dialogFeedbackBinding = DialogFeedbackBinding.inflate(getLayoutInflater());
33+
final View view = dialogFeedbackBinding.getRoot();
34+
setContentView(view);
35+
dialogFeedbackBinding.btnSubmitFeedback.setOnClickListener(new View.OnClickListener() {
36+
@Override
37+
public void onClick(View v) {
38+
submitFeedback();
39+
}
40+
});
41+
}
42+
43+
/**
44+
* When the button is clicked, it will create a feedback object
45+
* and give a callback to calling activity/fragment
46+
*/
47+
void submitFeedback() {
48+
if(dialogFeedbackBinding.feedbackItemEditText.getText().toString().equals("")) {
49+
dialogFeedbackBinding.feedbackItemEditText.setError(getContext().getString(R.string.enter_description));
50+
return;
51+
}
52+
String appVersion = ConfigUtils.getVersionNameWithSha(getContext());
53+
String androidVersion = dialogFeedbackBinding.androidVersionCheckbox.isChecked() ? DeviceInfoUtil.getAndroidVersion() : null;
54+
String apiLevel = dialogFeedbackBinding.apiLevelCheckbox.isChecked() ? DeviceInfoUtil.getAPILevel() : null;
55+
String deviceManufacturer = dialogFeedbackBinding.deviceManufacturerCheckbox.isChecked() ? DeviceInfoUtil.getDeviceManufacturer() : null;
56+
String deviceModel = dialogFeedbackBinding.deviceModelCheckbox.isChecked() ? DeviceInfoUtil.getDeviceModel() : null;
57+
String deviceName = dialogFeedbackBinding.deviceNameCheckbox.isChecked() ? DeviceInfoUtil.getDevice() : null;
58+
String networkType = dialogFeedbackBinding.networkTypeCheckbox.isChecked() ? DeviceInfoUtil.getConnectionType(getContext()).toString() : null;
59+
Feedback feedback = new Feedback(appVersion, apiLevel
60+
, dialogFeedbackBinding.feedbackItemEditText.getText().toString()
61+
, androidVersion, deviceModel, deviceManufacturer, deviceName, networkType);
62+
onFeedbackSubmitCallback.onFeedbackSubmit(feedback);
63+
dismiss();
64+
}
65+
66+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fr.free.nrw.commons.feedback;
2+
3+
import fr.free.nrw.commons.feedback.model.Feedback;
4+
5+
/**
6+
* This interface is used to provide callback
7+
* from Feedback dialog whenever submit button is clicked
8+
*/
9+
public interface OnFeedbackSubmitCallback {
10+
11+
/**
12+
* callback function, called when user clicks on submit
13+
*/
14+
void onFeedbackSubmit(Feedback feedback);
15+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package fr.free.nrw.commons.feedback.model;
2+
3+
/**
4+
* Pojo class for storing information that are required while uploading a feedback
5+
*/
6+
public class Feedback {
7+
/**
8+
* Version of app
9+
*/
10+
private String version;
11+
/**
12+
* API level of user's phone
13+
*/
14+
private String apiLevel;
15+
/**
16+
* Title/Description entered by user
17+
*/
18+
private String title;
19+
/**
20+
* Android version of user's device
21+
*/
22+
private String androidVersion;
23+
/**
24+
* Device Model of user's device
25+
*/
26+
private String deviceModel;
27+
/**
28+
* Device manufacturer name
29+
*/
30+
private String deviceManufacturer;
31+
/**
32+
* Device name stored on user's device
33+
*/
34+
private String device;
35+
/**
36+
* network type user is having (Ex: Wifi)
37+
*/
38+
private String networkType;
39+
40+
public Feedback(final String version, final String apiLevel, final String title, final String androidVersion,
41+
final String deviceModel, final String deviceManufacturer, final String device, final String networkType
42+
) {
43+
this.version = version;
44+
this.apiLevel = apiLevel;
45+
this.title = title;
46+
this.androidVersion = androidVersion;
47+
this.deviceModel = deviceModel;
48+
this.deviceManufacturer = deviceManufacturer;
49+
this.device = device;
50+
this.networkType = networkType;
51+
}
52+
53+
/**
54+
* Get the version from which this piece of feedback is being sent.
55+
* Ex: 3.0.1
56+
*/
57+
public String getVersion() {
58+
return version;
59+
}
60+
61+
/**
62+
* Set the version of app to given version
63+
*/
64+
public void setVersion(final String version) {
65+
this.version = version;
66+
}
67+
68+
/**
69+
* gets api level of device
70+
* Ex: 28
71+
*/
72+
public String getApiLevel() {
73+
return apiLevel;
74+
}
75+
76+
/**
77+
* sets api level value to given value
78+
*/
79+
public void setApiLevel(final String apiLevel) {
80+
this.apiLevel = apiLevel;
81+
}
82+
83+
/**
84+
* gets feedback text entered by user
85+
*/
86+
public String getTitle() {
87+
return title;
88+
}
89+
90+
/**
91+
* sets feedback text
92+
*/
93+
public void setTitle(final String title) {
94+
this.title = title;
95+
}
96+
97+
/**
98+
* gets android version of device
99+
* Ex: 9
100+
*/
101+
public String getAndroidVersion() {
102+
return androidVersion;
103+
}
104+
105+
/**
106+
* sets value of android version
107+
*/
108+
public void setAndroidVersion(final String androidVersion) {
109+
this.androidVersion = androidVersion;
110+
}
111+
112+
/**
113+
* get device model of current device
114+
* Ex: Redmi 6 Pro
115+
*/
116+
public String getDeviceModel() {
117+
return deviceModel;
118+
}
119+
120+
/**
121+
* sets value of device model to a given value
122+
*/
123+
public void setDeviceModel(final String deviceModel) {
124+
this.deviceModel = deviceModel;
125+
}
126+
127+
/**
128+
* get device manufacturer of user's device
129+
* Ex: Redmi
130+
*/
131+
public String getDeviceManufacturer() {
132+
return deviceManufacturer;
133+
}
134+
135+
/**
136+
* set device manufacturer value to a given value
137+
*/
138+
public void setDeviceManufacturer(final String deviceManufacturer) {
139+
this.deviceManufacturer = deviceManufacturer;
140+
}
141+
142+
/**
143+
* get device name of user's device
144+
*/
145+
public String getDevice() {
146+
return device;
147+
}
148+
149+
/**
150+
* sets device name value to a given value
151+
*/
152+
public void setDevice(final String device) {
153+
this.device = device;
154+
}
155+
156+
/**
157+
* get network type of user's network
158+
* Ex: wifi
159+
*/
160+
public String getNetworkType() {
161+
return networkType;
162+
}
163+
164+
/**
165+
* sets network type to a given value
166+
*/
167+
public void setNetworkType(final String networkType) {
168+
this.networkType = networkType;
169+
}
170+
171+
}

0 commit comments

Comments
 (0)