Browse Source

Fix post icons getting messed up

pull/63/head
Apostolos Fanakis 6 years ago
parent
commit
d0a0e763fa
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java
  2. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditResult.java
  4. 22
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java
  5. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java
  6. 2
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

1
app/src/main/java/gr/thmmy/mthmmy/activities/create_content/NewTopicTask.java

@ -61,6 +61,7 @@ public class NewTopicTask extends AsyncTask<String, Void, Boolean> {
.addFormDataPart("sc", sc) .addFormDataPart("sc", sc)
.addFormDataPart("subject", strings[1]) .addFormDataPart("subject", strings[1])
.addFormDataPart("topic", topic) .addFormDataPart("topic", topic)
.addFormDataPart("icon", "xx")
.build(); .build();
Request post = new Request.Builder() Request post = new Request.Builder()

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/EditTask.java

@ -38,6 +38,7 @@ public class EditTask extends AsyncTask<String, Void, Boolean> {
.addFormDataPart("sc", strings[4]) .addFormDataPart("sc", strings[4])
.addFormDataPart("subject", strings[5]) .addFormDataPart("subject", strings[5])
.addFormDataPart("topic", strings[6]) .addFormDataPart("topic", strings[6])
.addFormDataPart("icon", strings[7])
.build(); .build();
Request post = new Request.Builder() Request post = new Request.Builder()
.url(strings[0]) .url(strings[0])

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

@ -1,18 +1,19 @@
package gr.thmmy.mthmmy.activities.topic.tasks; package gr.thmmy.mthmmy.activities.topic.tasks;
public class PrepareForEditResult { public class PrepareForEditResult {
private final String postText, commitEditUrl, numReplies, seqnum, sc, topic; private final String postText, commitEditUrl, numReplies, seqnum, sc, topic, icon;
private int position; private int position;
private boolean successful; private boolean successful;
public PrepareForEditResult(String postText, String commitEditUrl, String numReplies, String seqnum, public PrepareForEditResult(String postText, String commitEditUrl, String numReplies, String seqnum,
String sc, String topic, int position, boolean successful) { String sc, String topic, String icon, int position, boolean successful) {
this.postText = postText; this.postText = postText;
this.commitEditUrl = commitEditUrl; this.commitEditUrl = commitEditUrl;
this.numReplies = numReplies; this.numReplies = numReplies;
this.seqnum = seqnum; this.seqnum = seqnum;
this.sc = sc; this.sc = sc;
this.topic = topic; this.topic = topic;
this.icon = icon;
this.position = position; this.position = position;
this.successful = successful; this.successful = successful;
} }
@ -41,6 +42,10 @@ public class PrepareForEditResult {
return topic; return topic;
} }
public String getIcon() {
return icon;
}
public int getPosition() { public int getPosition() {
return position; return position;
} }

22
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java

@ -38,28 +38,32 @@ public class PrepareForEditTask extends AsyncTask<String, Void, PrepareForEditRe
Document document; Document document;
String url = strings[0]; String url = strings[0];
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url + ";wap2") /*.url(url + ";wap2")*/
.url(url)
.build(); .build();
try { try {
String postText, commitEditURL, numReplies, seqnum, sc, topic; String postText, commitEditURL, numReplies, seqnum, sc, topic, icon;
OkHttpClient client = BaseApplication.getInstance().getClient(); OkHttpClient client = BaseApplication.getInstance().getClient();
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
document = ParseHelpers.parse(response.body().string()); document = ParseHelpers.parse(response.body().string());
Element message = document.select("textarea").first(); Element form = document.select("form#postmodify").first();
Element message = form.select("textarea").first();
postText = message.text(); postText = message.text();
commitEditURL = document.select("form").first().attr("action"); commitEditURL = form.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 = form.select("input[name=seqnum]").first().attr("value");
sc = document.select("input[name=sc]").first().attr("value"); sc = form.select("input[name=sc]").first().attr("value");
topic = document.select("input[name=topic]").first().attr("value"); topic = form.select("input[name=topic]").first().attr("value");
icon = form.select("select[name=icon]>option[selected]").first().attr("value");
return new PrepareForEditResult(postText, commitEditURL, numReplies, seqnum, sc, topic, position, true); return new PrepareForEditResult(postText, commitEditURL, numReplies, seqnum, sc, topic, icon, position, true);
} catch (IOException | Selector.SelectorParseException e) { } catch (IOException | Selector.SelectorParseException e) {
Timber.e(e, "Prepare failed."); Timber.e(e, "Prepare failed.");
return new PrepareForEditResult(null, null, null, null, null, null, position, false); return new PrepareForEditResult(null, null, null, null, null, null, null, position, false);
} }
} }

1
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java

@ -42,6 +42,7 @@ public class ReplyTask extends AsyncTask<String, Void, Posting.REPLY_STATUS> {
.addFormDataPart("sc", args[4]) .addFormDataPart("sc", args[4])
.addFormDataPart("subject", args[0]) .addFormDataPart("subject", args[0])
.addFormDataPart("topic", args[5]) .addFormDataPart("topic", args[5])
.addFormDataPart("icon", "xx")
.build(); .build();
Request post = new Request.Builder() Request post = new Request.Builder()
.url("https://www.thmmy.gr/smf/index.php?action=post2") .url("https://www.thmmy.gr/smf/index.php?action=post2")

2
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -219,7 +219,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
PrepareForEditResult editResult = prepareForEditResult.getValue(); PrepareForEditResult editResult = prepareForEditResult.getValue();
Timber.i("Editing post"); Timber.i("Editing post");
new EditTask(editTaskCallbacks, position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, editResult.getCommitEditUrl(), message, new EditTask(editTaskCallbacks, position).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, editResult.getCommitEditUrl(), message,
editResult.getNumReplies(), editResult.getSeqnum(), editResult.getSc(), subject, editResult.getTopic()); editResult.getNumReplies(), editResult.getSeqnum(), editResult.getSc(), subject, editResult.getTopic(), editResult.getIcon());
} }
/** /**

Loading…
Cancel
Save