|
3 | 3 | import static fr.free.nrw.commons.Utils.handleWebUrl; |
4 | 4 |
|
5 | 5 | import android.annotation.SuppressLint; |
| 6 | +import android.content.ActivityNotFoundException; |
6 | 7 | import android.content.Intent; |
7 | 8 | import android.net.Uri; |
8 | 9 | import android.os.Bundle; |
|
12 | 13 | import android.view.MenuItem; |
13 | 14 | import android.view.View; |
14 | 15 | import android.view.ViewGroup; |
| 16 | +import android.widget.Toast; |
15 | 17 | import androidx.appcompat.app.ActionBar; |
| 18 | +import androidx.appcompat.app.AlertDialog; |
16 | 19 | import androidx.appcompat.app.AppCompatActivity; |
17 | 20 | import androidx.annotation.NonNull; |
18 | 21 | import androidx.fragment.app.Fragment; |
|
22 | 25 | import butterknife.BindView; |
23 | 26 | import butterknife.ButterKnife; |
24 | 27 | import com.google.android.material.snackbar.Snackbar; |
| 28 | +import fr.free.nrw.commons.CommonsApplication; |
25 | 29 | import fr.free.nrw.commons.Media; |
26 | 30 | import fr.free.nrw.commons.R; |
27 | 31 | import fr.free.nrw.commons.auth.SessionManager; |
|
33 | 37 | import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; |
34 | 38 | import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient; |
35 | 39 | import fr.free.nrw.commons.profile.ProfileActivity; |
36 | | -import fr.free.nrw.commons.theme.BaseActivity; |
37 | 40 | import fr.free.nrw.commons.utils.DownloadUtils; |
38 | 41 | import fr.free.nrw.commons.utils.ImageUtils; |
39 | 42 | import fr.free.nrw.commons.utils.NetworkUtils; |
@@ -211,11 +214,83 @@ public boolean onOptionsItemSelected(MenuItem item) { |
211 | 214 | ProfileActivity.startYourself(getActivity(), m.getUser(), |
212 | 215 | !Objects.equals(sessionManager.getUserName(), m.getUser())); |
213 | 216 | } |
| 217 | + return true; |
| 218 | + case R.id.menu_view_report: |
| 219 | + showReportDialog(m); |
214 | 220 | default: |
215 | 221 | return super.onOptionsItemSelected(item); |
216 | 222 | } |
217 | 223 | } |
218 | 224 |
|
| 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 | + |
219 | 294 | /** |
220 | 295 | * Set the media as the device's wallpaper if the imageUrl is not null |
221 | 296 | * Fails silently if setting the wallpaper fails |
|
0 commit comments