Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 74 additions and 124 deletions
-
80app/src/main/java/awais/instagrabber/asyncs/CreateThreadAction.java
-
24app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
-
28app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
@ -1,80 +0,0 @@ |
|||
package awais.instagrabber.asyncs; |
|||
|
|||
import android.os.AsyncTask; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.Collections; |
|||
import java.util.Locale; |
|||
|
|||
import awais.instagrabber.repositories.responses.directmessages.DirectThread; |
|||
import awais.instagrabber.utils.Constants; |
|||
import awais.instagrabber.utils.CookieUtils; |
|||
import awais.instagrabber.utils.Utils; |
|||
import awais.instagrabber.webservices.DirectMessagesService; |
|||
import retrofit2.Call; |
|||
import retrofit2.Callback; |
|||
import retrofit2.Response; |
|||
|
|||
public class CreateThreadAction extends AsyncTask<Void, Void, Void> { |
|||
private static final String TAG = "CommentAction"; |
|||
|
|||
private final String cookie; |
|||
private final long userId; |
|||
private final OnTaskCompleteListener onTaskCompleteListener; |
|||
private final DirectMessagesService directMessagesService; |
|||
|
|||
public CreateThreadAction(final String cookie, final long userId, final OnTaskCompleteListener onTaskCompleteListener) { |
|||
this.cookie = cookie; |
|||
this.userId = userId; |
|||
this.onTaskCompleteListener = onTaskCompleteListener; |
|||
directMessagesService = DirectMessagesService.getInstance(CookieUtils.getCsrfTokenFromCookie(cookie), |
|||
CookieUtils.getUserIdFromCookie(cookie), |
|||
Utils.settingsHelper.getString(Constants.DEVICE_UUID)); |
|||
} |
|||
|
|||
protected Void doInBackground(Void... lmao) { |
|||
final Call<DirectThread> createThreadRequest = directMessagesService.createThread(Collections.singletonList(userId), null); |
|||
createThreadRequest.enqueue(new Callback<DirectThread>() { |
|||
@Override |
|||
public void onResponse(@NonNull final Call<DirectThread> call, @NonNull final Response<DirectThread> response) { |
|||
if (!response.isSuccessful()) { |
|||
if (response.errorBody() != null) { |
|||
try { |
|||
final String string = response.errorBody().string(); |
|||
final String msg = String.format(Locale.US, |
|||
"onResponse: url: %s, responseCode: %d, errorBody: %s", |
|||
call.request().url().toString(), |
|||
response.code(), |
|||
string); |
|||
Log.e(TAG, msg); |
|||
} catch (IOException e) { |
|||
Log.e(TAG, "onResponse: ", e); |
|||
} |
|||
} |
|||
Log.e(TAG, "onResponse: request was not successful and response error body was null"); |
|||
} |
|||
onTaskCompleteListener.onTaskComplete(response.body()); |
|||
if (response.body() == null) { |
|||
Log.e(TAG, "onResponse: thread is null"); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onFailure(@NonNull final Call<DirectThread> call, @NonNull final Throwable t) { |
|||
onTaskCompleteListener.onTaskComplete(null); |
|||
} |
|||
}); |
|||
return null; |
|||
} |
|||
|
|||
// @Override |
|||
// protected void onPostExecute() { |
|||
// } |
|||
|
|||
public interface OnTaskCompleteListener { |
|||
void onTaskComplete(final DirectThread thread); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue