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

Commit 04d0e04

Browse files
Sam1301kunall17
authored andcommitted
Change okhttp log level to HEADERS for uploads.
1 parent 6c4fb6c commit 04d0e04

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class ZulipApp extends Application {
105105
private int max_message_id;
106106
private DatabaseHelper databaseHelper;
107107
private ZulipServices zulipServices;
108+
private ZulipServices uploadServices;
108109
private ReferenceObjectCache objectCache;
109110
private ZulipActivity zulipActivity;
110111
/**
@@ -212,6 +213,22 @@ public ZulipServices getZulipServices() {
212213
return zulipServices;
213214
}
214215

216+
public ZulipServices getUploadServices() {
217+
if (uploadServices == null) {
218+
HttpLoggingInterceptor logging = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.HEADERS);
219+
uploadServices = new Retrofit.Builder()
220+
.client(new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS)
221+
.addInterceptor(new ZulipInterceptor())
222+
.addInterceptor(logging)
223+
.build())
224+
.addConverterFactory(GsonConverterFactory.create(getGson()))
225+
.baseUrl(getServerURI())
226+
.build()
227+
.create(ZulipServices.class);
228+
}
229+
return uploadServices;
230+
}
231+
215232
public void setZulipServices(ZulipServices zulipServices) {
216233
this.zulipServices = zulipServices;
217234
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ public void onProgressUpdate(int percentage, String progress, int notificationId
12261226

12271227
// finally, execute the request
12281228
// create upload service client
1229-
Call<UploadResponse> call = ((ZulipApp) getApplicationContext()).getZulipServices().upload(body);
1229+
Call<UploadResponse> call = ((ZulipApp) getApplicationContext()).getUploadServices().upload(body);
12301230
call.enqueue(new DefaultCallback<UploadResponse>() {
12311231
@Override
12321232
public void onSuccess(Call<UploadResponse> call, Response<UploadResponse> response) {
@@ -2476,8 +2476,8 @@ protected void onDestroy() {
24762476
}
24772477
if (mNotificationManager == null) {
24782478
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
2479-
mNotificationManager.cancelAll();
24802479
}
2480+
mNotificationManager.cancelAll();
24812481
}
24822482

24832483
/**

app/src/main/java/com/zulip/android/networking/UploadProgressRequest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class UploadProgressRequest extends RequestBody {
2020
private File mFile;
2121
private UploadCallbacks mListener;
2222
private int mNotificationId;
23-
int counter = 0;
2423

2524
private static final int DEFAULT_BUFFER_SIZE = 2048;
2625

@@ -46,21 +45,15 @@ public void writeTo(BufferedSink sink) throws IOException {
4645
FileInputStream in = new FileInputStream(mFile);
4746
long uploaded = 0;
4847

49-
// workaround logging interceptor disturbing progress update
50-
counter++;
51-
5248
try {
5349
int read;
5450
Handler handler = new Handler(Looper.getMainLooper());
5551
while ((read = in.read(buffer)) != -1) {
5652
uploaded += read;
5753
sink.write(buffer, 0, read);
5854

59-
// update progress on UI thread only when httpLoggingInterceptor
60-
// is not calling writeTo()
61-
if (counter % 2 == 0) {
62-
handler.post(new ProgressUpdater(uploaded, fileLength));
63-
}
55+
// update progress on UI thread only
56+
handler.post(new ProgressUpdater(uploaded, fileLength));
6457
}
6558
} finally {
6659
in.close();

0 commit comments

Comments
 (0)