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

Commit 6c4fb6c

Browse files
Sam1301kunall17
authored andcommitted
Update progress notifications after every second.
1 parent 3247542 commit 6c4fb6c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,15 +1113,9 @@ private void startFileUpload() {
11131113
}
11141114

11151115
@NonNull
1116-
private MultipartBody.Part prepareFilePart(String partName, final File file, int notificationId) {
1116+
private MultipartBody.Part prepareFilePart(String partName, final File file, int notificationId, UploadProgressRequest.UploadCallbacks callbacks) {
11171117
// create UploadProgressRequest instance from file
1118-
UploadProgressRequest request = new UploadProgressRequest(file, new UploadProgressRequest.UploadCallbacks() {
1119-
@Override
1120-
public void onProgressUpdate(int percentage, String progress, int notificationId) {
1121-
// update notification
1122-
progressNotification(notificationId, percentage, progress, file.getName());
1123-
}
1124-
}, notificationId);
1118+
UploadProgressRequest request = new UploadProgressRequest(file, callbacks, notificationId);
11251119

11261120
// MultipartBody.Part is used to send also the actual file name
11271121
return MultipartBody.Part.createFormData(partName, file.getName(), request);
@@ -1210,8 +1204,22 @@ private void uploadFile(final File file) {
12101204
// generate unique notification Id for this upload
12111205
final int notifId = (int) (new Date().getTime() % Integer.MAX_VALUE);
12121206

1207+
// update notification after every one second
1208+
final long startTime = System.currentTimeMillis();
1209+
final int[] counter = {0};
1210+
UploadProgressRequest.UploadCallbacks progressListener = new UploadProgressRequest.UploadCallbacks() {
1211+
@Override
1212+
public void onProgressUpdate(int percentage, String progress, int notificationId) {
1213+
if (System.currentTimeMillis() - startTime >= 1000 * counter[0]) {
1214+
// update notification
1215+
progressNotification(notificationId, percentage, progress, file.getName());
1216+
counter[0]++;
1217+
}
1218+
}
1219+
};
1220+
12131221
// MultipartBody.Part is used to send also the actual file name
1214-
MultipartBody.Part body = prepareFilePart("file", file, notifId);
1222+
MultipartBody.Part body = prepareFilePart("file", file, notifId, progressListener);
12151223

12161224
// start notification
12171225
setNotification(notifId, getString(R.string.init_notif_title));

0 commit comments

Comments
 (0)