Browse Source

use the correct edit url when commit the edit

pull/30/head
Thodoris1999 7 years ago
parent
commit
9b54c39abb
  1. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/EditTaskDTO.java
  2. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

9
app/src/main/java/gr/thmmy/mthmmy/activities/topic/EditTaskDTO.java

@ -2,10 +2,11 @@ package gr.thmmy.mthmmy.activities.topic;
public class EditTaskDTO { public class EditTaskDTO {
private int position; private int position;
private final String subject, message, numReplies, seqnum, sc, topic; private final String url, subject, message, numReplies, seqnum, sc, topic;
public EditTaskDTO(int position, String subject, String message, String numReplies, String seqnum, String sc, String topic) { public EditTaskDTO(int position, String url, String subject, String message, String numReplies, String seqnum, String sc, String topic) {
this.position = position; this.position = position;
this.url = url;
this.subject = subject; this.subject = subject;
this.message = message; this.message = message;
this.numReplies = numReplies; this.numReplies = numReplies;
@ -18,6 +19,10 @@ public class EditTaskDTO {
return position; return position;
} }
public String getUrl() {
return url;
}
public String getSubject() { public String getSubject() {
return subject; return subject;
} }

7
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -1039,7 +1039,7 @@ public class TopicActivity extends BaseActivity {
class PrepareForEdit extends AsyncTask<Integer, Void, Boolean> { class PrepareForEdit extends AsyncTask<Integer, Void, Boolean> {
int position; int position;
String numReplies, seqnum, sc, topic, postText = ""; String commitEditURL, numReplies, seqnum, sc, topic, postText = "";
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
@ -1066,6 +1066,7 @@ public class TopicActivity extends BaseActivity {
Element message = document.select("textarea").first(); Element message = document.select("textarea").first();
postText = message.html(); postText = message.html();
commitEditURL = document.select("form").first().attr("action");
numReplies = replyPageUrl.substring(replyPageUrl.indexOf("num_replies=") + 12); numReplies = replyPageUrl.substring(replyPageUrl.indexOf("num_replies=") + 12);
seqnum = document.select("input[name=seqnum]").first().attr("value"); seqnum = document.select("input[name=seqnum]").first().attr("value");
sc = document.select("input[name=sc]").first().attr("value"); sc = document.select("input[name=sc]").first().attr("value");
@ -1083,7 +1084,7 @@ public class TopicActivity extends BaseActivity {
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
postsList.get(position).setPostType(Post.TYPE_EDIT); postsList.get(position).setPostType(Post.TYPE_EDIT);
topicAdapter.notifyItemChanged(position); topicAdapter.notifyItemChanged(position);
topicAdapter.prepareForEdit(new EditTask(), numReplies, seqnum, sc, topic, postText); topicAdapter.prepareForEdit(new EditTask(), commitEditURL, numReplies, seqnum, sc, topic, postText);
recyclerView.scrollToPosition(position); recyclerView.scrollToPosition(position);
progressBar.setVisibility(ProgressBar.GONE); progressBar.setVisibility(ProgressBar.GONE);
} }
@ -1112,7 +1113,7 @@ public class TopicActivity extends BaseActivity {
.addFormDataPart("topic", dto.getTopic()) .addFormDataPart("topic", dto.getTopic())
.build(); .build();
Request post = new Request.Builder() Request post = new Request.Builder()
.url(postsList.get(dto.getPosition()).getPostEditURL()) .url(dto.getUrl())
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36") .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
.post(postBody) .post(postBody)
.build(); .build();

8
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -38,7 +38,6 @@ import com.squareup.picasso.Picasso;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutionException;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity; import gr.thmmy.mthmmy.activities.board.BoardActivity;
@ -97,7 +96,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final String[] replyDataHolder = new String[2]; private final String[] replyDataHolder = new String[2];
private final int replySubject = 0, replyText = 1; private final int replySubject = 0, replyText = 1;
private String numReplies, seqnum, sc, topic, buildedQuotes, postText; private String commitEditURL, numReplies, seqnum, sc, topic, buildedQuotes, postText;
private boolean canReply = false; private boolean canReply = false;
/** /**
@ -138,8 +137,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
this.deleteTask = deleteTask; this.deleteTask = deleteTask;
} }
void prepareForEdit(TopicActivity.EditTask editTask, String numReplies, String seqnum, String sc, void prepareForEdit(TopicActivity.EditTask editTask, String commitEditURL, String numReplies, String seqnum, String sc,
String topic, String postText) { String topic, String postText) {
this.commitEditURL = commitEditURL;
this.editTask = editTask; this.editTask = editTask;
this.numReplies = numReplies; this.numReplies = numReplies;
this.seqnum = seqnum; this.seqnum = seqnum;
@ -583,7 +583,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (holder.quickReplySubject.getText().toString().isEmpty()) return; if (holder.quickReplySubject.getText().toString().isEmpty()) return;
if (holder.quickReply.getText().toString().isEmpty()) return; if (holder.quickReply.getText().toString().isEmpty()) return;
holder.submitButton.setEnabled(false); holder.submitButton.setEnabled(false);
editTask.execute(new EditTaskDTO(position, holder.quickReplySubject.getText().toString(), editTask.execute(new EditTaskDTO(position, commitEditURL, holder.quickReplySubject.getText().toString(),
holder.quickReply.getText().toString(), numReplies, seqnum, sc, topic)); holder.quickReply.getText().toString(), numReplies, seqnum, sc, topic));
holder.quickReplySubject.getText().clear(); holder.quickReplySubject.getText().clear();

Loading…
Cancel
Save