Browse Source

include app signature in new topic

pull/51/head
Thodoris1999 6 years ago
parent
commit
3c58f5c823
  1. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/CreateContentActivity.java
  2. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/NewTopicTask.java
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/ReplyTask.java

14
app/src/main/java/gr/thmmy/mthmmy/activities/CreateContentActivity.java

@ -1,7 +1,9 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.TextInputLayout; import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -11,8 +13,11 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.editorview.EditorView; import gr.thmmy.mthmmy.editorview.EditorView;
import gr.thmmy.mthmmy.editorview.EmojiKeyboard; import gr.thmmy.mthmmy.editorview.EmojiKeyboard;
import gr.thmmy.mthmmy.session.SessionManager;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber; import timber.log.Timber;
@ -55,7 +60,14 @@ public class CreateContentActivity extends AppCompatActivity implements EmojiKey
contentEditor.setEmojiKeyboardOwner(this); contentEditor.setEmojiKeyboardOwner(this);
contentEditor.setOnSubmitListener(v -> { contentEditor.setOnSubmitListener(v -> {
if (newTopicUrl != null) { if (newTopicUrl != null) {
new NewTopicTask(this).execute(newTopicUrl, subjectInput.getEditText().getText().toString(), boolean includeAppSignature = true;
SessionManager sessionManager = BaseActivity.getSessionManager();
if (sessionManager.isLoggedIn()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
includeAppSignature = prefs.getBoolean(SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY, true);
}
new NewTopicTask(this, includeAppSignature).execute(newTopicUrl, subjectInput.getEditText().getText().toString(),
contentEditor.getText().toString()); contentEditor.getText().toString());
} }
}); });

9
app/src/main/java/gr/thmmy/mthmmy/activities/NewTopicTask.java

@ -20,9 +20,11 @@ import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus;
public class NewTopicTask extends AsyncTask<String, Void, Boolean> { public class NewTopicTask extends AsyncTask<String, Void, Boolean> {
private NewTopicTaskCallbacks listener; private NewTopicTaskCallbacks listener;
private boolean includeAppSignature;
public NewTopicTask(NewTopicTaskCallbacks listener){ public NewTopicTask(NewTopicTaskCallbacks listener, boolean includeAppSignature){
this.listener = listener; this.listener = listener;
this.includeAppSignature = includeAppSignature;
} }
@Override @Override
@ -49,9 +51,12 @@ public class NewTopicTask extends AsyncTask<String, Void, Boolean> {
topic = document.select("input[name=topic]").first().attr("value"); topic = document.select("input[name=topic]").first().attr("value");
createTopicUrl = document.select("form").first().attr("action"); createTopicUrl = document.select("form").first().attr("action");
final String appSignature = "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/" +
"details?id=gr.thmmy.mthmmy]mTHMMY[/url][/i][/size][/right]";
RequestBody postBody = new MultipartBody.Builder() RequestBody postBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("message", strings[2]) .addFormDataPart("message", strings[2] + (includeAppSignature ? appSignature : ""))
.addFormDataPart("seqnum", seqnum) .addFormDataPart("seqnum", seqnum)
.addFormDataPart("sc", sc) .addFormDataPart("sc", sc)
.addFormDataPart("subject", strings[1]) .addFormDataPart("subject", strings[1])

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

@ -31,7 +31,7 @@ public class ReplyTask extends AsyncTask<String, Void, Boolean> {
@Override @Override
protected Boolean doInBackground(String... args) { protected Boolean doInBackground(String... args) {
final String sentFrommTHMMY = includeAppSignature final String sentFrommTHMMY = includeAppSignature
? "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY[/url][/i] [/size][/right]" ? "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY[/url][/i][/size][/right]"
: ""; : "";
RequestBody postBody = new MultipartBody.Builder() RequestBody postBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)

Loading…
Cancel
Save