Browse Source

Work on uploads retry

uploads
Apostolos Fanakis 6 years ago
parent
commit
b27a836cc6
  1. 10
      app/build.gradle
  2. 27
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  3. 47
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  4. 29
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  5. 50
      app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java
  6. 6
      build.gradle
  7. 4
      gradle/wrapper/gradle-wrapper.properties

10
app/build.gradle

@ -43,11 +43,11 @@ dependencies {
implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1' implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.google.firebase:firebase-core:16.0.3' implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.0' implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'com.snatik:storage:2.1.0' implementation 'com.snatik:storage:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff!
@ -61,7 +61,7 @@ dependencies {
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated!
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.jakewharton.timber:timber:4.7.0' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice:3.4.2'
implementation 'net.gotev:uploadservice-okhttp:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2'
implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'android.arch.lifecycle:extensions:1.1.1'

27
app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java

@ -394,7 +394,11 @@ public class UploadActivity extends BaseActivity {
String uploadID = UUID.randomUUID().toString(); String uploadID = UUID.randomUUID().toString();
if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID, if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID,
editTextFilename), categorySelected, uploadTitleText, editTextFilename, categorySelected, uploadTitleText, uploadDescriptionText[0],
fileIcon, uploaderProfileIndex, tempFileUri == null
? filesList.get(0).getFileUri()
: tempFileUri),
categorySelected, uploadTitleText,
uploadDescriptionText[0], fileIcon, uploaderProfileIndex, uploadDescriptionText[0], fileIcon, uploaderProfileIndex,
tempFileUri == null tempFileUri == null
? filesList.get(0).getFileUri() ? filesList.get(0).getFileUri()
@ -668,7 +672,11 @@ public class UploadActivity extends BaseActivity {
filesListView.setVisibility(View.VISIBLE); filesListView.setVisibility(View.VISIBLE);
} }
private static UploadNotificationConfig getConfigForUpload(Context context, String uploadID, String filename) { public static UploadNotificationConfig getConfigForUpload(Context context, String uploadID,
String filename, String retryCategory,
String retryTitleText, String retryDescription,
String retryIcon, String retryUploaderProfile,
Uri retryFileUri) {
UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig();
uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload);
uploadNotificationConfig.setTitleForAllStatuses("Uploading " + filename); uploadNotificationConfig.setTitleForAllStatuses("Uploading " + filename);
@ -685,8 +693,17 @@ public class UploadActivity extends BaseActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD); Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD);
combinedActionsIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_FILENAME, filename);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_CATEGORY, retryCategory);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_TITLE, retryTitleText);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_DESCRIPTION, retryDescription);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_ICON, retryIcon);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_UPLOADER, retryUploaderProfile);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_FILE_URI, retryFileUri);
uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context, uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context,
1, combinedActionsIntent, PendingIntent.FLAG_UPDATE_CURRENT)); 1, combinedActionsIntent, PendingIntent.FLAG_UPDATE_CURRENT));
} }
@ -716,7 +733,7 @@ public class UploadActivity extends BaseActivity {
return uploadNotificationConfig; return uploadNotificationConfig;
} }
private static boolean uploadFile(Context context, String uploadID, public static boolean uploadFile(Context context, String uploadID,
UploadNotificationConfig uploadNotificationConfig, UploadNotificationConfig uploadNotificationConfig,
String categorySelected, String uploadTitleText, String categorySelected, String uploadTitleText,
String uploadDescriptionText, String fileIcon, String uploadDescriptionText, String fileIcon,
@ -1013,7 +1030,9 @@ public class UploadActivity extends BaseActivity {
String uploadID = UUID.randomUUID().toString(); String uploadID = UUID.randomUUID().toString();
if (!uploadFile(weakActivity.get(), uploadID, if (!uploadFile(weakActivity.get(), uploadID,
getConfigForUpload(weakActivity.get(), uploadID, zipFilename), categorySelected, getConfigForUpload(weakActivity.get(), uploadID, zipFilename, categorySelected,
uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex,
zipFileUri), categorySelected,
uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex, uploadTitleText, uploadDescriptionText, fileIcon, uploaderProfileIndex,
zipFileUri)) { zipFileUri)) {
Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show(); Toast.makeText(weakActivity.get(), "Couldn't initiate upload.", Toast.LENGTH_SHORT).show();

47
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.base; package gr.thmmy.mthmmy.base;
import android.Manifest; import android.Manifest;
import android.app.PendingIntent;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -21,6 +22,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -77,6 +79,13 @@ import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB;
import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_ID_KEY; import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_ID_KEY;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_CATEGORY;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_DESCRIPTION;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_FILENAME;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_FILE_URI;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_ICON;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_TITLE;
import static gr.thmmy.mthmmy.services.UploadsReceiver.UPLOAD_RETRY_UPLOADER;
import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS; import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS;
import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType;
@ -771,9 +780,25 @@ public abstract class BaseActivity extends AppCompatActivity {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
String dialogUploadID = intentBundle.getString(UPLOAD_ID_KEY); String dialogUploadID = intentBundle.getString(UPLOAD_ID_KEY);
String retryFilename = intentBundle.getString(UPLOAD_RETRY_FILENAME);
String retryCategory = intentBundle.getString(UPLOAD_RETRY_CATEGORY);
String retryTitleText = intentBundle.getString(UPLOAD_RETRY_TITLE);
String retryDescription = intentBundle.getString(UPLOAD_RETRY_DESCRIPTION);
String retryIcon = intentBundle.getString(UPLOAD_RETRY_ICON);
String retryUploaderProfile = intentBundle.getString(UPLOAD_RETRY_UPLOADER);
Uri retryFileUri = (Uri) intentBundle.get(UPLOAD_RETRY_FILE_URI);
Intent retryIntent = new Intent(context, UploadsReceiver.class); Intent retryIntent = new Intent(context, UploadsReceiver.class);
retryIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD); retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD);
retryIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, dialogUploadID);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_FILENAME, retryFilename);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_CATEGORY, retryCategory);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_TITLE, retryTitleText);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_DESCRIPTION, retryDescription);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_ICON, retryIcon);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_UPLOADER, retryUploaderProfile);
retryIntent.putExtra(UploadsReceiver.UPLOAD_RETRY_FILE_URI, retryFileUri);
if (uploadsProgressDialog == null) { if (uploadsProgressDialog == null) {
AlertDialog.Builder progressDialogBuilder = new AlertDialog.Builder(activityContext); AlertDialog.Builder progressDialogBuilder = new AlertDialog.Builder(activityContext);
@ -786,6 +811,25 @@ public abstract class BaseActivity extends AppCompatActivity {
progressDialogBuilder.setView(progressDialogLayout); progressDialogBuilder.setView(progressDialogLayout);
uploadsProgressDialog = progressDialogBuilder.create(); uploadsProgressDialog = progressDialogBuilder.create();
if (!UploadService.getTaskList().contains("" + dialogUploadID)) {
//Upload probably failed at this point
uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Retry", (progressDialog, progressWhich) -> {
/*LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context.getApplicationContext());
localBroadcastManager.sendBroadcast(multipartUploadRetryIntent);
uploadProgressDialog.dismiss();*/
context.sendBroadcast(retryIntent);
});
uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", (progressDialog, progressWhich) -> {
uploadsProgressDialog.dismiss();
});
TextView dialogProgressText = progressDialogLayout.findViewById(R.id.dialog_upload_progress_text);
dialogProgressBar.setVisibility(View.GONE);
dialogProgressText.setText("Upload failed.");
uploadsProgressDialog.show();
} else {
//Empty buttons are needed, they are updated with correct values in the receiver //Empty buttons are needed, they are updated with correct values in the receiver
uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "placeholder", (progressDialog, progressWhich) -> { uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "placeholder", (progressDialog, progressWhich) -> {
}); });
@ -794,6 +838,7 @@ public abstract class BaseActivity extends AppCompatActivity {
UploadsReceiver.setDialogDisplay(uploadsProgressDialog, dialogUploadID, retryIntent); UploadsReceiver.setDialogDisplay(uploadsProgressDialog, dialogUploadID, retryIntent);
uploadsProgressDialog.show(); uploadsProgressDialog.show();
}
} else { } else {
UploadsReceiver.setDialogDisplay(uploadsProgressDialog, dialogUploadID, retryIntent); UploadsReceiver.setDialogDisplay(uploadsProgressDialog, dialogUploadID, retryIntent);
uploadsProgressDialog.show(); uploadsProgressDialog.show();

29
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -26,6 +27,9 @@ import com.squareup.picasso.Picasso;
import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack; import net.gotev.uploadservice.okhttp.OkHttpStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -34,6 +38,8 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CrashReportingTree; import gr.thmmy.mthmmy.utils.CrashReportingTree;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import okhttp3.CipherSuite;
import okhttp3.ConnectionSpec;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -82,7 +88,7 @@ public class BaseApplication extends Application {
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext());
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor);
client = new OkHttpClient.Builder() OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar) .cookieJar(cookieJar)
.addInterceptor(chain -> { .addInterceptor(chain -> {
Request request = chain.request(); Request request = chain.request();
@ -95,12 +101,25 @@ public class BaseApplication extends Application {
} }
} }
return chain.proceed(request); return chain.proceed(request);
}) })
.connectTimeout(30, TimeUnit.SECONDS) .callTimeout(30, TimeUnit.SECONDS);
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats
// Necessary because our servers don't have the right cipher suites.
// https://github.com/square/okhttp/issues/4053
List<CipherSuite> cipherSuites = new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites());
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
ConnectionSpec legacyTls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
.build(); .build();
builder.connectionSpecs(Arrays.asList(legacyTls, ConnectionSpec.CLEARTEXT));
}
client = builder.build();
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs); sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs);
Picasso picasso = new Picasso.Builder(getApplicationContext()) Picasso picasso = new Picasso.Builder(getApplicationContext())
.downloader(new OkHttp3Downloader(client)) .downloader(new OkHttp3Downloader(client))

50
app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java

@ -3,10 +3,11 @@ package gr.thmmy.mthmmy.services;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.widget.Button; import android.widget.Button;
@ -15,25 +16,34 @@ import android.widget.Toast;
import com.snatik.storage.Storage; import com.snatik.storage.Storage;
import net.gotev.uploadservice.MultipartUploadRequest;
import net.gotev.uploadservice.ServerResponse; import net.gotev.uploadservice.ServerResponse;
import net.gotev.uploadservice.UploadInfo; import net.gotev.uploadservice.UploadInfo;
import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.UploadServiceBroadcastReceiver; import net.gotev.uploadservice.UploadServiceBroadcastReceiver;
import java.util.UUID;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.activities.upload.UploadsHelper; import gr.thmmy.mthmmy.activities.upload.UploadsHelper;
import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.base.BaseApplication;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
public class UploadsReceiver extends UploadServiceBroadcastReceiver { public class UploadsReceiver extends UploadServiceBroadcastReceiver {
public static final String UPLOAD_ID_KEY = "UPLOAD_ID_KEY"; public static final String UPLOAD_ID_KEY = "UPLOAD_ID_KEY";
public static final String UPLOAD_REQUEST_KEY = "UPLOAD_REQUEST_KEY";
public static final String ACTION_COMBINED_UPLOAD = "ACTION_COMBINED_UPLOAD"; public static final String ACTION_COMBINED_UPLOAD = "ACTION_COMBINED_UPLOAD";
public static final String ACTION_CANCEL_UPLOAD = "ACTION_CANCEL_UPLOAD"; public static final String ACTION_CANCEL_UPLOAD = "ACTION_CANCEL_UPLOAD";
public static final String ACTION_RETRY_UPLOAD = "ACTION_RETRY_UPLOAD"; public static final String ACTION_RETRY_UPLOAD = "ACTION_RETRY_UPLOAD";
public static final String UPLOAD_RETRY_FILENAME = "UPLOAD_RETRY_FILENAME";
public static final String UPLOAD_RETRY_CATEGORY = "UPLOAD_RETRY_CATEGORY";
public static final String UPLOAD_RETRY_TITLE = "UPLOAD_RETRY_TITLE";
public static final String UPLOAD_RETRY_DESCRIPTION = "UPLOAD_RETRY_DESCRIPTION";
public static final String UPLOAD_RETRY_ICON = "UPLOAD_RETRY_ICON";
public static final String UPLOAD_RETRY_UPLOADER = "UPLOAD_RETRY_UPLOADER";
public static final String UPLOAD_RETRY_FILE_URI = "UPLOAD_RETRY_FILE_URI";
private Storage storage; private Storage storage;
private static AlertDialog uploadProgressDialog; private static AlertDialog uploadProgressDialog;
private static String dialogUploadID; private static String dialogUploadID;
@ -54,12 +64,21 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
UploadService.stopUpload(uploadID); UploadService.stopUpload(uploadID);
break; break;
case ACTION_RETRY_UPLOAD: case ACTION_RETRY_UPLOAD:
MultipartUploadRequest multipartUploadRequest = (MultipartUploadRequest) intentBundle.get(UPLOAD_REQUEST_KEY); String retryFilename = intentBundle.getString(UPLOAD_RETRY_FILENAME);
if (multipartUploadRequest != null) { String retryCategory = intentBundle.getString(UPLOAD_RETRY_CATEGORY);
multipartUploadRequest.startUpload(); String retryTitleText = intentBundle.getString(UPLOAD_RETRY_TITLE);
} else { String retryDescription = intentBundle.getString(UPLOAD_RETRY_DESCRIPTION);
Toast.makeText(context.getApplicationContext(), "Couldn't retry upload.", Toast.LENGTH_SHORT).show(); String retryIcon = intentBundle.getString(UPLOAD_RETRY_ICON);
} String retryUploaderProfile = intentBundle.getString(UPLOAD_RETRY_UPLOADER);
Uri retryFileUri = (Uri) intentBundle.get(UPLOAD_RETRY_FILE_URI);
String retryUploadID = UUID.randomUUID().toString();
UploadActivity.uploadFile(context, retryUploadID,
UploadActivity.getConfigForUpload(context, retryUploadID, retryFilename, retryCategory,
retryTitleText, retryDescription, retryIcon, retryUploaderProfile, retryFileUri),
retryCategory, retryTitleText, retryDescription, retryIcon,
retryUploaderProfile, retryFileUri);
break; break;
default: default:
super.onReceive(context, intent); super.onReceive(context, intent);
@ -114,8 +133,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
alertDialogNeutral.setText("Retry"); alertDialogNeutral.setText("Retry");
alertDialogNeutral.setOnClickListener(v -> { alertDialogNeutral.setOnClickListener(v -> {
if (multipartUploadRetryIntent != null) { if (multipartUploadRetryIntent != null) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context.getApplicationContext()); context.sendBroadcast(multipartUploadRetryIntent);
localBroadcastManager.sendBroadcast(multipartUploadRetryIntent);
} }
uploadProgressDialog.dismiss(); uploadProgressDialog.dismiss();
}); });
@ -146,6 +164,16 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
uploadProgressDialog.dismiss(); uploadProgressDialog.dismiss();
} }
} }
} else {
NotificationManager notificationManager = (NotificationManager) context.getApplicationContext().
getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.cancel(uploadInfo.getNotificationID());
}
Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD);
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadInfo.getUploadId());
context.sendBroadcast(combinedActionsIntent);
} }
Toast.makeText(context.getApplicationContext(), "Upload failed", Toast.LENGTH_SHORT).show(); Toast.makeText(context.getApplicationContext(), "Upload failed", Toast.LENGTH_SHORT).show();

6
build.gradle

@ -8,9 +8,9 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.1.4' classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.0.1' classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.25.4' classpath 'io.fabric.tools:gradle:1.26.1'
} }
} }

4
gradle/wrapper/gradle-wrapper.properties

@ -1,6 +1,6 @@
#Sat Apr 07 11:11:36 EEST 2018 #Wed Jun 12 09:00:17 EEST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

Loading…
Cancel
Save