Skip to content

Commit ca629b3

Browse files
Fix 409 handling
Set notification thumbnail to a smaller size and set the app icon to the final notification
1 parent 43365d7 commit ca629b3

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

app/src/main/java/fr/s13d/photobackup/PBMediaSender.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import android.content.Context;
2525
import android.content.Intent;
2626
import android.content.SharedPreferences;
27+
import android.graphics.Bitmap;
28+
import android.graphics.BitmapFactory;
2729
import android.net.ConnectivityManager;
2830
import android.net.NetworkInfo;
2931
import android.preference.PreferenceManager;
@@ -68,6 +70,7 @@ public class PBMediaSender {
6870
private static List<PBMediaSenderInterface> interfaces = new ArrayList<>();
6971
private static int successCount = 0;
7072
private static int failureCount = 0;
73+
private final static int timeoutInSeconds = 60;
7174

7275

7376
public PBMediaSender(final Context context) {
@@ -113,7 +116,7 @@ public void send(final PBMedia media, boolean manual) {
113116
private void sendMedia(final PBMedia media) {
114117
this.builder.setContentText(context.getResources().getString(R.string.notif_start_text))
115118
.setLargeIcon(MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
116-
media.getId(), MediaStore.Images.Thumbnails.MINI_KIND, null));
119+
media.getId(), MediaStore.Images.Thumbnails.MICRO_KIND, null));
117120
notificationManager.notify(0, this.builder.build());
118121

119122
final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
@@ -129,7 +132,7 @@ private void sendMedia(final PBMedia media) {
129132
@Override
130133
public void onResponse(Call call, Response response) throws IOException {
131134
Log.i(LOG_TAG, "Get response with code " + response.code());
132-
if (response.code() == 200) {
135+
if (response.code() == 200 || response.code() == 409) {
133136
sendDidSucceed(media);
134137
} else {
135138
sendDidFail(media, new Throwable(response.message()));
@@ -164,7 +167,7 @@ public void test() {
164167
getOkClient().newCall(request).enqueue(new Callback() {
165168
@Override
166169
public void onResponse(Call call, Response response) throws IOException {
167-
if (response.isSuccessful() || response.code() == 409) {
170+
if (response.isSuccessful()) {
168171
testDidSucceed(toast);
169172
} else {
170173
testDidFail(toast, response.message());
@@ -271,19 +274,18 @@ private void testDidFail(final Toast toast, final String message) {
271274

272275

273276
private void updateNotificationText() {
274-
String successContent = context.getResources().getQuantityString(R.plurals.notif_success, successCount, successCount);
275-
String failureContent = context.getResources().getQuantityString(R.plurals.notif_failure, failureCount, failureCount);
277+
final String successContent = context.getResources().getQuantityString(R.plurals.notif_success, successCount, successCount);
278+
final String failureContent = context.getResources().getQuantityString(R.plurals.notif_failure, failureCount, failureCount);
276279

277-
if (successCount != 0 && failureCount != 0) {
278-
this.builder.setContentText(successContent + " ; " + failureContent);
279-
} else {
280-
if (successCount != 0) {
281-
this.builder.setContentText(successContent);
282-
}
283-
if (failureCount != 0) {
284-
this.builder.setContentText(failureContent);
285-
}
280+
String contentText = successContent + " ; " + failureContent;
281+
if (successCount != 0 && failureCount == 0) {
282+
contentText = successContent;
283+
}
284+
if (successCount == 0 && failureCount != 0) {
285+
contentText = failureContent;
286286
}
287+
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
288+
this.builder.setLargeIcon(icon).setContentText(contentText);
287289

288290
notificationManager.notify(0, this.builder.build());
289291
}
@@ -308,9 +310,9 @@ public void run() {
308310
private OkHttpClient getOkClient() {
309311
if (okClient == null) {
310312
okClient = new OkHttpClient.Builder()
311-
.readTimeout(30, TimeUnit.SECONDS)
312-
.connectTimeout(30, TimeUnit.SECONDS)
313-
.writeTimeout(30, TimeUnit.SECONDS)
313+
.readTimeout(timeoutInSeconds, TimeUnit.SECONDS)
314+
.connectTimeout(timeoutInSeconds, TimeUnit.SECONDS)
315+
.writeTimeout(timeoutInSeconds, TimeUnit.SECONDS)
314316
.build();
315317
createAuthCredentials();
316318
buildNotificationBuilder();

0 commit comments

Comments
 (0)