mirror of https://github.com/ThmmyNoLife/mTHMMY
Thodoris1999
6 years ago
6 changed files with 51 additions and 72 deletions
@ -1,62 +1,39 @@ |
|||||
package gr.thmmy.mthmmy.activities.topic.tasks; |
package gr.thmmy.mthmmy.activities.topic.tasks; |
||||
|
|
||||
import android.os.AsyncTask; |
import org.jsoup.nodes.Document; |
||||
|
|
||||
import java.io.IOException; |
import java.io.IOException; |
||||
|
|
||||
import gr.thmmy.mthmmy.activities.topic.Posting; |
import gr.thmmy.mthmmy.utils.parsing.NetworkTask; |
||||
import gr.thmmy.mthmmy.base.BaseApplication; |
import gr.thmmy.mthmmy.utils.parsing.Parcel; |
||||
import okhttp3.OkHttpClient; |
import okhttp3.OkHttpClient; |
||||
import okhttp3.Request; |
import okhttp3.Request; |
||||
import okhttp3.Response; |
import okhttp3.Response; |
||||
import timber.log.Timber; |
|
||||
|
|
||||
public class DeleteTask extends AsyncTask<String, Void, Boolean> { |
public class DeleteTask extends NetworkTask<Void> { |
||||
private DeleteTaskCallbacks listener; |
|
||||
|
|
||||
public DeleteTask(DeleteTaskCallbacks listener) { |
public DeleteTask(OnParseTaskStartedListener onParseTaskStartedListener, OnParseTaskFinishedListener<Void> onParseTaskFinishedListener) { |
||||
this.listener = listener; |
super(onParseTaskStartedListener, onParseTaskFinishedListener); |
||||
} |
} |
||||
|
|
||||
@Override |
@Override |
||||
protected void onPreExecute() { |
protected Response sendRequest(OkHttpClient client, String... input) throws IOException { |
||||
listener.onDeleteTaskStarted(); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Boolean doInBackground(String... args) { |
|
||||
Request delete = new Request.Builder() |
Request delete = new Request.Builder() |
||||
.url(args[0]) |
.url(input[0]) |
||||
.header("User-Agent", |
.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") |
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36") |
||||
.build(); |
.build(); |
||||
|
|
||||
try { |
|
||||
OkHttpClient client = BaseApplication.getInstance().getClient(); |
|
||||
client.newCall(delete).execute(); |
client.newCall(delete).execute(); |
||||
Response response = client.newCall(delete).execute(); |
return client.newCall(delete).execute(); |
||||
//Response response = client.newCall(delete).execute();
|
|
||||
switch (Posting.replyStatus(response)) { |
|
||||
case SUCCESSFUL: |
|
||||
BaseApplication.getInstance().logFirebaseAnalyticsEvent("post_deletion", null); |
|
||||
return true; |
|
||||
default: |
|
||||
Timber.e("Something went wrong. Request string: %s", delete.toString()); |
|
||||
return false; |
|
||||
} |
|
||||
} catch (IOException e) { |
|
||||
Timber.e(e, "Delete failed."); |
|
||||
return false; |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
@Override |
@Override |
||||
protected void onPostExecute(Boolean result) { |
protected Void performTask(Document document) { |
||||
listener.onDeleteTaskFinished(result); |
return null; |
||||
} |
} |
||||
|
|
||||
public interface DeleteTaskCallbacks { |
@Override |
||||
void onDeleteTaskStarted(); |
protected int getResultCode(Response response, Void data) { |
||||
void onDeleteTaskFinished(boolean result); |
return Parcel.ResultCode.SUCCESSFUL; |
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue