Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean>() {
.build(ThreadDisplayFragment.this, new AwfulRequest.AwfulResultCallback<ReportCheckResult>() {
@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() : "");
}
}

Expand All @@ -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:";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the strings.xml please

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean>(context, FUNCTION_REPORT) {
: AwfulRequest<ReportCheckResult>(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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions Awful.apk/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<color name="self_thread_dark">#1A2800</color>
<color name="self_thread_oled">#1E0E00</color>

<color name="popup_warning_text">#FF0000</color>


<!-- Bookmark colours for stars/unread counters -->
<integer-array name="bookmarkColors">
Expand Down