Use DefaultCallback abstract class for upload response.
@@ -108,6 +108,7 @@ import com.zulip.android.networking.AsyncStatusUpdate;
import com.zulip.android.networking.ZulipAsyncPushTask;
import com.zulip.android.networking.response.UploadResponse;
import com.zulip.android.util.ActivityTransitionAnim;
+import com.zulip.android.networking.util.DefaultCallback;
import com.zulip.android.util.AnimationHelper;
import com.zulip.android.util.CommonProgressDialog;
import com.zulip.android.util.Constants;
@@ -133,7 +134,6 @@ import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
-import retrofit2.Callback;
import retrofit2.Response;
/**
@@ -1108,11 +1108,9 @@ public class ZulipActivity extends BaseActivity implements
// finally, execute the request
// create upload service client
Call<UploadResponse> call = ((ZulipApp) getApplicationContext()).getZulipServices().upload(body);
- call.enqueue(new Callback<UploadResponse>() {
+ call.enqueue(new DefaultCallback<UploadResponse>() {
@Override
- public void onResponse(Call<UploadResponse> call,
- Response<UploadResponse> response) {
- if (response.isSuccessful()) {
+ public void onSuccess(Call<UploadResponse> call, Response<UploadResponse> response) {
String filePathOnServer = "";
UploadResponse uploadResponse = response.body();
filePathOnServer = uploadResponse.getUri();
@@ -1128,14 +1126,15 @@ public class ZulipActivity extends BaseActivity implements
sendingMessage(false, loadingMsg);
Toast.makeText(ZulipActivity.this, R.string.failed_to_upload, Toast.LENGTH_SHORT).show();
}
- } else {
+ }
+
+ @Override
+ public void onError(Call<UploadResponse> call, Response<UploadResponse> response) {
// remove loading message from the screen
sendingMessage(false, loadingMsg);
Toast.makeText(ZulipActivity.this, R.string.failed_to_upload, Toast.LENGTH_SHORT).show();
}
- }
-
@Override
public void onFailure(Call<UploadResponse> call, Throwable t) {
// remove loading message from the screen
