Skip to content

Commit c53befc

Browse files
Add "Report Violation" menu option (#5025)
* Add "Report Violation" menu option * Update email template * Update email address * Fixed typo Co-authored-by: Josephine Lim <josephinelim86@gmail.com>
1 parent 3f759a8 commit c53befc

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public class CommonsApplication extends MultiDexApplication {
110110

111111
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App Feedback";
112112

113+
public static final String REPORT_EMAIL = "commons-app-android-private@googlegroups.com";
114+
115+
public static final String REPORT_EMAIL_SUBJECT = "Report a violation";
116+
113117
public static final String NOTIFICATION_CHANNEL_ID_ALL = "CommonsNotificationAll";
114118

115119
public static final String FEEDBACK_EMAIL_TEMPLATE_HEADER = "-- Technical information --";

app/src/main/java/fr/free/nrw/commons/media/MediaDetailPagerFragment.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static fr.free.nrw.commons.Utils.handleWebUrl;
44

55
import android.annotation.SuppressLint;
6+
import android.content.ActivityNotFoundException;
67
import android.content.Intent;
78
import android.net.Uri;
89
import android.os.Bundle;
@@ -12,7 +13,9 @@
1213
import android.view.MenuItem;
1314
import android.view.View;
1415
import android.view.ViewGroup;
16+
import android.widget.Toast;
1517
import androidx.appcompat.app.ActionBar;
18+
import androidx.appcompat.app.AlertDialog;
1619
import androidx.appcompat.app.AppCompatActivity;
1720
import androidx.annotation.NonNull;
1821
import androidx.fragment.app.Fragment;
@@ -22,6 +25,7 @@
2225
import butterknife.BindView;
2326
import butterknife.ButterKnife;
2427
import com.google.android.material.snackbar.Snackbar;
28+
import fr.free.nrw.commons.CommonsApplication;
2529
import fr.free.nrw.commons.Media;
2630
import fr.free.nrw.commons.R;
2731
import fr.free.nrw.commons.auth.SessionManager;
@@ -33,7 +37,6 @@
3337
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
3438
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
3539
import fr.free.nrw.commons.profile.ProfileActivity;
36-
import fr.free.nrw.commons.theme.BaseActivity;
3740
import fr.free.nrw.commons.utils.DownloadUtils;
3841
import fr.free.nrw.commons.utils.ImageUtils;
3942
import fr.free.nrw.commons.utils.NetworkUtils;
@@ -211,11 +214,83 @@ public boolean onOptionsItemSelected(MenuItem item) {
211214
ProfileActivity.startYourself(getActivity(), m.getUser(),
212215
!Objects.equals(sessionManager.getUserName(), m.getUser()));
213216
}
217+
return true;
218+
case R.id.menu_view_report:
219+
showReportDialog(m);
214220
default:
215221
return super.onOptionsItemSelected(item);
216222
}
217223
}
218224

225+
private void showReportDialog(final Media media) {
226+
if (media == null) {
227+
return;
228+
}
229+
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
230+
final String[] values = requireContext().getResources()
231+
.getStringArray(R.array.report_violation_options);
232+
builder.setTitle(R.string.report_violation);
233+
builder.setItems(R.array.report_violation_options, (dialog, which) -> {
234+
sendReportEmail(media, values[which]);
235+
});
236+
builder.show();
237+
}
238+
239+
private void sendReportEmail(final Media media, final String type) {
240+
final String technicalInfo = getTechInfo(media, type);
241+
242+
final Intent feedbackIntent = new Intent(Intent.ACTION_SENDTO);
243+
feedbackIntent.setType("message/rfc822");
244+
feedbackIntent.setData(Uri.parse("mailto:"));
245+
feedbackIntent.putExtra(Intent.EXTRA_EMAIL,
246+
new String[]{CommonsApplication.REPORT_EMAIL});
247+
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT,
248+
CommonsApplication.REPORT_EMAIL_SUBJECT);
249+
feedbackIntent.putExtra(Intent.EXTRA_TEXT, technicalInfo);
250+
try {
251+
startActivity(feedbackIntent);
252+
} catch (final ActivityNotFoundException e) {
253+
Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show();
254+
}
255+
}
256+
257+
private String getTechInfo(final Media media, final String type) {
258+
final StringBuilder builder = new StringBuilder();
259+
260+
builder.append("Report type: ")
261+
.append(type)
262+
.append("\n\n");
263+
264+
builder.append("Image that you want to report: ")
265+
.append(media.getImageUrl())
266+
.append("\n\n");
267+
268+
builder.append("User that you want to report: ")
269+
.append(media.getAuthor())
270+
.append("\n\n");
271+
272+
if (sessionManager.getUserName() != null) {
273+
builder.append("Your username: ")
274+
.append(sessionManager.getUserName())
275+
.append("\n\n");
276+
}
277+
278+
builder.append("Violation reason: ")
279+
.append("\n");
280+
281+
builder.append("----------------------------------------------")
282+
.append("\n")
283+
.append("(please write reason here)")
284+
.append("\n")
285+
.append("----------------------------------------------")
286+
.append("\n\n")
287+
.append("Thank you for your report! Our team will investigate as soon as possible.")
288+
.append("\n")
289+
.append("Please note that images also have a `Nominate for deletion` button.");
290+
291+
return builder.toString();
292+
}
293+
219294
/**
220295
* Set the media as the device's wallpaper if the imageUrl is not null
221296
* Fails silently if setting the wallpaper fails

app/src/main/res/menu/fragment_image_detail.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
android:id="@+id/menu_view_user_page"
3535
android:title="@string/menu_view_user_page"
3636
app:showAsAction="never" />
37+
<item
38+
android:id="@+id/menu_view_report"
39+
android:title="@string/menu_view_report"
40+
app:showAsAction="never" />
3741

3842
</menu>

app/src/main/res/values/arrays.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@
7070
<item>yearly</item>
7171
<item>all_time</item>
7272
</string-array>
73-
73+
<string-array name="report_violation_options" >
74+
<item>@string/report_user</item>
75+
<item>@string/report_content</item>
76+
<item>@string/request_user_block</item>
77+
</string-array>
78+
7479
</resources>

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,9 @@ Upload your first media by tapping on the add button.</string>
717717
<string name="error_feedback">Error while sending feedback</string>
718718
<string name="enter_description">What is your feedback?</string>
719719
<string name="your_feedback">Your feedback</string>
720+
<string name="menu_view_report">Report</string>
721+
<string name="report_violation">Report violation</string>
722+
<string name="report_user">Report this user</string>
723+
<string name="report_content">Report this content</string>
724+
<string name="request_user_block">Request to block this user</string>
720725
</resources>

0 commit comments

Comments
 (0)