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>
This commit is contained in:
Madhur Gupta 2022-08-05 12:50:26 +05:30 committed by GitHub
parent 3f759a8436
commit c53befc102
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 2 deletions

View file

@ -110,6 +110,10 @@ public class CommonsApplication extends MultiDexApplication {
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App Feedback"; public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App Feedback";
public static final String REPORT_EMAIL = "commons-app-android-private@googlegroups.com";
public static final String REPORT_EMAIL_SUBJECT = "Report a violation";
public static final String NOTIFICATION_CHANNEL_ID_ALL = "CommonsNotificationAll"; public static final String NOTIFICATION_CHANNEL_ID_ALL = "CommonsNotificationAll";
public static final String FEEDBACK_EMAIL_TEMPLATE_HEADER = "-- Technical information --"; public static final String FEEDBACK_EMAIL_TEMPLATE_HEADER = "-- Technical information --";

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.media;
import static fr.free.nrw.commons.Utils.handleWebUrl; import static fr.free.nrw.commons.Utils.handleWebUrl;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -12,7 +13,9 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -22,6 +25,7 @@ import androidx.viewpager.widget.ViewPager;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.SessionManager; import fr.free.nrw.commons.auth.SessionManager;
@ -33,7 +37,6 @@ import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient; import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import fr.free.nrw.commons.profile.ProfileActivity; import fr.free.nrw.commons.profile.ProfileActivity;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.DownloadUtils; import fr.free.nrw.commons.utils.DownloadUtils;
import fr.free.nrw.commons.utils.ImageUtils; import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.utils.NetworkUtils;
@ -211,11 +214,83 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
ProfileActivity.startYourself(getActivity(), m.getUser(), ProfileActivity.startYourself(getActivity(), m.getUser(),
!Objects.equals(sessionManager.getUserName(), m.getUser())); !Objects.equals(sessionManager.getUserName(), m.getUser()));
} }
return true;
case R.id.menu_view_report:
showReportDialog(m);
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
private void showReportDialog(final Media media) {
if (media == null) {
return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
final String[] values = requireContext().getResources()
.getStringArray(R.array.report_violation_options);
builder.setTitle(R.string.report_violation);
builder.setItems(R.array.report_violation_options, (dialog, which) -> {
sendReportEmail(media, values[which]);
});
builder.show();
}
private void sendReportEmail(final Media media, final String type) {
final String technicalInfo = getTechInfo(media, type);
final Intent feedbackIntent = new Intent(Intent.ACTION_SENDTO);
feedbackIntent.setType("message/rfc822");
feedbackIntent.setData(Uri.parse("mailto:"));
feedbackIntent.putExtra(Intent.EXTRA_EMAIL,
new String[]{CommonsApplication.REPORT_EMAIL});
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT,
CommonsApplication.REPORT_EMAIL_SUBJECT);
feedbackIntent.putExtra(Intent.EXTRA_TEXT, technicalInfo);
try {
startActivity(feedbackIntent);
} catch (final ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show();
}
}
private String getTechInfo(final Media media, final String type) {
final StringBuilder builder = new StringBuilder();
builder.append("Report type: ")
.append(type)
.append("\n\n");
builder.append("Image that you want to report: ")
.append(media.getImageUrl())
.append("\n\n");
builder.append("User that you want to report: ")
.append(media.getAuthor())
.append("\n\n");
if (sessionManager.getUserName() != null) {
builder.append("Your username: ")
.append(sessionManager.getUserName())
.append("\n\n");
}
builder.append("Violation reason: ")
.append("\n");
builder.append("----------------------------------------------")
.append("\n")
.append("(please write reason here)")
.append("\n")
.append("----------------------------------------------")
.append("\n\n")
.append("Thank you for your report! Our team will investigate as soon as possible.")
.append("\n")
.append("Please note that images also have a `Nominate for deletion` button.");
return builder.toString();
}
/** /**
* Set the media as the device's wallpaper if the imageUrl is not null * Set the media as the device's wallpaper if the imageUrl is not null
* Fails silently if setting the wallpaper fails * Fails silently if setting the wallpaper fails

View file

@ -34,5 +34,9 @@
android:id="@+id/menu_view_user_page" android:id="@+id/menu_view_user_page"
android:title="@string/menu_view_user_page" android:title="@string/menu_view_user_page"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_view_report"
android:title="@string/menu_view_report"
app:showAsAction="never" />
</menu> </menu>

View file

@ -70,5 +70,10 @@
<item>yearly</item> <item>yearly</item>
<item>all_time</item> <item>all_time</item>
</string-array> </string-array>
<string-array name="report_violation_options" >
<item>@string/report_user</item>
<item>@string/report_content</item>
<item>@string/request_user_block</item>
</string-array>
</resources> </resources>

View file

@ -717,4 +717,9 @@ Upload your first media by tapping on the add button.</string>
<string name="error_feedback">Error while sending feedback</string> <string name="error_feedback">Error while sending feedback</string>
<string name="enter_description">What is your feedback?</string> <string name="enter_description">What is your feedback?</string>
<string name="your_feedback">Your feedback</string> <string name="your_feedback">Your feedback</string>
<string name="menu_view_report">Report</string>
<string name="report_violation">Report violation</string>
<string name="report_user">Report this user</string>
<string name="report_content">Report this content</string>
<string name="request_user_block">Request to block this user</string>
</resources> </resources>