mirror of https://github.com/ThmmyNoLife/mTHMMY
Thodoris1999
6 years ago
5 changed files with 224 additions and 28 deletions
@ -0,0 +1,95 @@ |
|||||
|
package gr.thmmy.mthmmy.activities; |
||||
|
|
||||
|
import android.os.AsyncTask; |
||||
|
|
||||
|
import org.jsoup.Jsoup; |
||||
|
import org.jsoup.nodes.Document; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.base.BaseApplication; |
||||
|
import okhttp3.MultipartBody; |
||||
|
import okhttp3.OkHttpClient; |
||||
|
import okhttp3.Request; |
||||
|
import okhttp3.RequestBody; |
||||
|
import okhttp3.Response; |
||||
|
import timber.log.Timber; |
||||
|
|
||||
|
import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; |
||||
|
|
||||
|
public class NewTopicTask extends AsyncTask<String, Void, Boolean> { |
||||
|
|
||||
|
private NewTopicTaskCallbacks listener; |
||||
|
|
||||
|
public NewTopicTask(NewTopicTaskCallbacks listener){ |
||||
|
this.listener = listener; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onPreExecute() { |
||||
|
listener.onNewTopicTaskStarted(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected Boolean doInBackground(String... strings) { |
||||
|
Request request = new Request.Builder() |
||||
|
.url(strings[0] + ";wap2") |
||||
|
.build(); |
||||
|
|
||||
|
OkHttpClient client = BaseApplication.getInstance().getClient(); |
||||
|
|
||||
|
Document document; |
||||
|
String seqnum, sc, topic, createTopicUrl; |
||||
|
try { |
||||
|
Response response = client.newCall(request).execute(); |
||||
|
document = Jsoup.parse(response.body().string()); |
||||
|
|
||||
|
seqnum = document.select("input[name=seqnum]").first().attr("value"); |
||||
|
sc = document.select("input[name=sc]").first().attr("value"); |
||||
|
topic = document.select("input[name=topic]").first().attr("value"); |
||||
|
createTopicUrl = document.select("form").first().attr("action"); |
||||
|
|
||||
|
RequestBody postBody = new MultipartBody.Builder() |
||||
|
.setType(MultipartBody.FORM) |
||||
|
.addFormDataPart("message", strings[2]) |
||||
|
.addFormDataPart("seqnum", seqnum) |
||||
|
.addFormDataPart("sc", sc) |
||||
|
.addFormDataPart("subject", strings[1]) |
||||
|
.addFormDataPart("topic", topic) |
||||
|
.build(); |
||||
|
|
||||
|
Request post = new Request.Builder() |
||||
|
.url(createTopicUrl) |
||||
|
.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) |
||||
|
.build(); |
||||
|
|
||||
|
try { |
||||
|
client.newCall(post).execute(); |
||||
|
Response response2 = client.newCall(post).execute(); |
||||
|
switch (replyStatus(response2)) { |
||||
|
case SUCCESSFUL: |
||||
|
BaseApplication.getInstance().logFirebaseAnalyticsEvent("new_topic_creation", null); |
||||
|
return true; |
||||
|
default: |
||||
|
Timber.e("Malformed post. Request string: %s", post.toString()); |
||||
|
return false; |
||||
|
} |
||||
|
} catch (IOException e) { |
||||
|
return false; |
||||
|
} |
||||
|
} catch (IOException e) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onPostExecute(Boolean success) { |
||||
|
listener.onNewTopicTaskFinished(success); |
||||
|
} |
||||
|
|
||||
|
public interface NewTopicTaskCallbacks { |
||||
|
void onNewTopicTaskStarted(); |
||||
|
void onNewTopicTaskFinished(boolean success); |
||||
|
} |
||||
|
} |
@ -1,33 +1,74 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<RelativeLayout |
<android.support.design.widget.CoordinatorLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
tools:context=".activities.CreateContentActivity" |
||||
android:layout_height="match_parent" |
android:layout_height="match_parent" |
||||
tools:context=".activities.CreateContentActivity"> |
android:layout_width="match_parent"> |
||||
|
|
||||
<android.support.design.widget.TextInputLayout |
|
||||
android:id="@+id/subject_input" |
|
||||
android:layout_width="240dp" |
|
||||
android:layout_height="wrap_content" |
|
||||
android:hint="@string/subject"> |
|
||||
<android.support.design.widget.TextInputEditText |
|
||||
android:layout_width="match_parent" |
|
||||
android:layout_height="wrap_content" /> |
|
||||
</android.support.design.widget.TextInputLayout> |
|
||||
|
|
||||
<gr.thmmy.mthmmy.editorview.EditorView |
<RelativeLayout |
||||
android:id="@+id/main_content_editorview" |
|
||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="match_parent"> |
||||
android:layout_below="@id/subject_input"/> |
|
||||
|
<android.support.design.widget.AppBarLayout |
||||
|
android:id="@+id/appbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:paddingTop="@dimen/appbar_padding_top" |
||||
|
android:theme="@style/ToolbarTheme"> |
||||
|
|
||||
|
<android.support.v7.widget.Toolbar |
||||
|
android:id="@+id/toolbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="?attr/actionBarSize" |
||||
|
android:background="?attr/colorPrimary" |
||||
|
app:contentInsetStartWithNavigation="0dp" |
||||
|
app:popupTheme="@style/ToolbarTheme"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/toolbar_title" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:textColor="@color/white" /> |
||||
|
</android.support.v7.widget.Toolbar> |
||||
|
</android.support.design.widget.AppBarLayout> |
||||
|
|
||||
|
<android.support.design.widget.TextInputLayout |
||||
|
android:id="@+id/subject_input" |
||||
|
android:layout_width="240dp" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:hint="@string/subject"> |
||||
|
|
||||
|
<android.support.design.widget.TextInputEditText |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" /> |
||||
|
</android.support.design.widget.TextInputLayout> |
||||
|
|
||||
|
<gr.thmmy.mthmmy.editorview.EditorView |
||||
|
android:id="@+id/main_content_editorview" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_below="@id/subject_input" /> |
||||
|
|
||||
|
<gr.thmmy.mthmmy.editorview.EmojiKeyboard |
||||
|
android:id="@+id/emoji_keyboard" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_alignParentBottom="true" |
||||
|
android:visibility="gone" /> |
||||
|
</RelativeLayout> |
||||
|
|
||||
<gr.thmmy.mthmmy.editorview.EmojiKeyboard |
<me.zhanghai.android.materialprogressbar.MaterialProgressBar |
||||
android:id="@+id/emoji_keyboard" |
android:id="@+id/progressBar" |
||||
|
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding" |
||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="@dimen/progress_bar_height" |
||||
android:layout_alignParentBottom="true" |
android:indeterminate="true" |
||||
android:visibility="gone"/> |
android:visibility="invisible" |
||||
|
app:layout_anchor="@id/appbar" |
||||
|
app:layout_anchorGravity="bottom|center" |
||||
|
app:mpb_indeterminateTint="@color/accent" |
||||
|
app:mpb_progressStyle="horizontal" /> |
||||
|
|
||||
</RelativeLayout> |
</android.support.design.widget.CoordinatorLayout> |
Loading…
Reference in new issue