diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java b/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java index 6fb083bec..7d2c55f22 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java @@ -46,8 +46,11 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; +import android.text.SpannableString; +import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.format.Formatter; +import android.text.style.ForegroundColorSpan; import android.view.InflateException; import android.view.LayoutInflater; import android.view.Menu; @@ -84,6 +87,7 @@ import com.ferg.awfulapp.task.RedirectTask; import com.ferg.awfulapp.task.RefreshUserProfileRequest; import com.ferg.awfulapp.task.ReportCheckRequest; +import com.ferg.awfulapp.task.ReportCheckResult; import com.ferg.awfulapp.task.ReportRequest; import com.ferg.awfulapp.task.SinglePostRequest; import com.ferg.awfulapp.task.ThreadLockUnlockRequest; @@ -770,14 +774,14 @@ public void toggleUserPosts(int aPostId, int aUserId, String aUsername){ */ public void reportUser(int postId){ queueRequest(new ReportCheckRequest(getActivity(), postId) - .build(ThreadDisplayFragment.this, new AwfulRequest.AwfulResultCallback() { + .build(ThreadDisplayFragment.this, new AwfulRequest.AwfulResultCallback() { @Override - public void success(Boolean alreadyReported) { - if (alreadyReported) { + public void success(ReportCheckResult result) { + if (result.getAlreadyReported()) { getAlertView().setTitle("This post has already been reported recently") .setIcon(R.drawable.ic_mood).show(); } else { - showReportDialog(postId); + showReportDialog(postId, result.getWarning() != null ? result.getWarning() : ""); } } @@ -789,12 +793,27 @@ public void failure(VolleyError error) { })); } - private void showReportDialog(int postId) { + private void showReportDialog(int postId, String warning) { final EditText reportReason = new EditText(this.getActivity()); + String body = "Did this post break the forum rules? If so, please report it by clicking below. If you would like to add any comments explaining why you submitted this post, please do so here:"; + CharSequence message; + if (warning.isEmpty()) { + message = body; + } else { + int warningColor = getResources().getColor(R.color.popup_warning_text); + SpannableString warningSpan = new SpannableString(warning); + warningSpan.setSpan(new ForegroundColorSpan(warningColor), 0, warning.length(), 0); + SpannableStringBuilder sb = new SpannableStringBuilder(); + sb.append(warningSpan); + sb.append("\n\n"); + sb.append(body); + message = sb; + } + new AlertDialog.Builder(this.getActivity()) .setTitle("Report inappropriate post") - .setMessage("Did this post break the forum rules? If so, please report it by clicking below. If you would like to add any comments explaining why you submitted this post, please do so here:") + .setMessage(message) .setView(reportReason) .setPositiveButton("Report", (dialog, whichButton) -> { String reason = reportReason.getText().toString(); diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/constants/Constants.java b/Awful.apk/src/main/java/com/ferg/awfulapp/constants/Constants.java index 1678b15b8..f4a919394 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/constants/Constants.java +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/constants/Constants.java @@ -88,7 +88,6 @@ public class Constants { public static final String PARAM_VOTE = "vote"; public static final String PARAM_POST_ID = "postid"; public static final String PARAM_USERLIST = "userlist"; - public static final String PARAM_COMMENTS = "comments"; public static final String PARAM_FORMKEY = "formkey"; public static final String PARAM_FORM_COOKIE = "form_cookie"; public static final String PARAM_ATTACHMENT = "attachment"; diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportCheckRequest.kt b/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportCheckRequest.kt index 94a31f7b7..0009c925a 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportCheckRequest.kt +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportCheckRequest.kt @@ -2,20 +2,39 @@ package com.ferg.awfulapp.task import android.content.Context import com.ferg.awfulapp.constants.Constants.* +import com.ferg.awfulapp.util.AwfulError import org.jsoup.nodes.Document /** - * A request that checks whether a post has already been reported recently. + * Checks whether a post has already been reported, and if it hasn't it grabs the warning + * text above the report editor (e.g. the post is more than two weeks old). + * + * Overrides [handleCriticalError] since the already-reported page triggers the base + * class's standarderror detection. */ class ReportCheckRequest(context: Context, postId: Int) - : AwfulRequest(context, FUNCTION_REPORT) { + : AwfulRequest(context, FUNCTION_REPORT) { init { parameters.add(PARAM_POST_ID, postId.toString()) } - override fun handleResponse(doc: Document): Boolean { + override fun handleCriticalError(error: AwfulError, doc: Document): Boolean = true + + override fun handleResponse(doc: Document): ReportCheckResult { val body = doc.body() - return body != null && body.hasClass("standarderror") + if (body.hasClass("standarderror")) { + return ReportCheckResult(alreadyReported = true) + } + val warning = body.select("span.warningsmalltext") + ?.mapNotNull { it.text().takeIf(String::isNotBlank) } + ?.joinToString("\n") + ?.takeIf(String::isNotEmpty) + return ReportCheckResult(alreadyReported = false, warning = warning) } } + +data class ReportCheckResult( + val alreadyReported: Boolean, + val warning: String? = null +) diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportRequest.kt b/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportRequest.kt index c1d616ff0..4b5ce95e7 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportRequest.kt +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/task/ReportRequest.kt @@ -18,7 +18,7 @@ class ReportRequest(context: Context, private val postId: Int, private val comme init { with(parameters) { - add(PARAM_COMMENTS, comments) + add(PARAM_MESSAGE, comments) add(PARAM_POST_ID, postId.toString()) add(PARAM_ACTION, "submit") } diff --git a/Awful.apk/src/main/res/values/colors.xml b/Awful.apk/src/main/res/values/colors.xml index 76dcc83f1..ae5779bd0 100644 --- a/Awful.apk/src/main/res/values/colors.xml +++ b/Awful.apk/src/main/res/values/colors.xml @@ -57,6 +57,8 @@ #1A2800 #1E0E00 + #FF0000 +