Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 1752e34

Browse files
Sam1301kunall17
authored andcommitted
Use DefaultCallback abstract class for upload response.
1 parent 66ed138 commit 1752e34

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import com.zulip.android.networking.ZulipAsyncPushTask;
109109
import com.zulip.android.networking.response.UploadResponse;
110110
import com.zulip.android.util.ActivityTransitionAnim;
111+
import com.zulip.android.networking.util.DefaultCallback;
111112
import com.zulip.android.util.AnimationHelper;
112113
import com.zulip.android.util.CommonProgressDialog;
113114
import com.zulip.android.util.Constants;
@@ -133,7 +134,6 @@
133134
import okhttp3.MultipartBody;
134135
import okhttp3.RequestBody;
135136
import retrofit2.Call;
136-
import retrofit2.Callback;
137137
import retrofit2.Response;
138138

139139
/**
@@ -1108,32 +1108,31 @@ private void uploadFile(final File file) {
11081108
// finally, execute the request
11091109
// create upload service client
11101110
Call<UploadResponse> call = ((ZulipApp) getApplicationContext()).getZulipServices().upload(body);
1111-
call.enqueue(new Callback<UploadResponse>() {
1111+
call.enqueue(new DefaultCallback<UploadResponse>() {
11121112
@Override
1113-
public void onResponse(Call<UploadResponse> call,
1114-
Response<UploadResponse> response) {
1115-
if (response.isSuccessful()) {
1116-
String filePathOnServer = "";
1117-
UploadResponse uploadResponse = response.body();
1118-
filePathOnServer = uploadResponse.getUri();
1119-
if (!filePathOnServer.equals("")) {
1120-
// remove loading message from the screen
1121-
sendingMessage(false, loadingMsg);
1122-
1123-
// print message to compose box
1124-
messageEt.append(" [" + file.getName() + "](" +
1125-
UrlHelper.addHost(filePathOnServer) + ")");
1126-
} else {
1127-
// remove loading message from the screen
1128-
sendingMessage(false, loadingMsg);
1129-
Toast.makeText(ZulipActivity.this, R.string.failed_to_upload, Toast.LENGTH_SHORT).show();
1130-
}
1113+
public void onSuccess(Call<UploadResponse> call, Response<UploadResponse> response) {
1114+
String filePathOnServer = "";
1115+
UploadResponse uploadResponse = response.body();
1116+
filePathOnServer = uploadResponse.getUri();
1117+
if (!filePathOnServer.equals("")) {
1118+
// remove loading message from the screen
1119+
sendingMessage(false, loadingMsg);
1120+
1121+
// print message to compose box
1122+
messageEt.append(" [" + file.getName() + "](" +
1123+
UrlHelper.addHost(filePathOnServer) + ")");
11311124
} else {
11321125
// remove loading message from the screen
11331126
sendingMessage(false, loadingMsg);
11341127
Toast.makeText(ZulipActivity.this, R.string.failed_to_upload, Toast.LENGTH_SHORT).show();
11351128
}
1129+
}
11361130

1131+
@Override
1132+
public void onError(Call<UploadResponse> call, Response<UploadResponse> response) {
1133+
// remove loading message from the screen
1134+
sendingMessage(false, loadingMsg);
1135+
Toast.makeText(ZulipActivity.this, R.string.failed_to_upload, Toast.LENGTH_SHORT).show();
11371136
}
11381137

11391138
@Override

0 commit comments

Comments
 (0)