Browse Source

Improved uploads error handling

pull/63/head
Ezerous 5 years ago
parent
commit
d49651fdcc
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 8
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadException.java
  3. 16
      app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java
  4. 5
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseException.java

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

@ -58,6 +58,7 @@ import java.util.Locale;
import java.util.UUID;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.upload.multipart.MultipartUploadRequest;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.UploadCategory;
@ -66,7 +67,6 @@ import gr.thmmy.mthmmy.services.UploadsReceiver;
import gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault;
import gr.thmmy.mthmmy.utils.FileUtils;
import gr.thmmy.mthmmy.utils.TakePhoto;
import gr.thmmy.mthmmy.activities.upload.multipart.MultipartUploadRequest;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseTask;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;

8
app/src/main/java/gr/thmmy/mthmmy/activities/upload/multipart/MultipartUploadException.java

@ -0,0 +1,8 @@
package gr.thmmy.mthmmy.activities.upload.multipart;
public class MultipartUploadException extends RuntimeException {
public MultipartUploadException(String message) {
super(message);
}
}

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

@ -22,8 +22,10 @@ import net.gotev.uploadservice.UploadServiceBroadcastReceiver;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.upload.UploadsHelper;
import gr.thmmy.mthmmy.activities.upload.multipart.MultipartUploadException;
import gr.thmmy.mthmmy.base.BaseApplication;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
public class UploadsReceiver extends UploadServiceBroadcastReceiver {
public static final String UPLOAD_ID_KEY = "UPLOAD_ID_KEY";
@ -153,7 +155,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
TextView dialogProgressText = progressWindow.findViewById(R.id.dialog_upload_progress_text);
dialogProgressBar.setVisibility(View.GONE);
dialogProgressText.setText("Upload failed.");
dialogProgressText.setText("Upload failed");
}
if (uploadInfo.getUploadedBytes() == uploadInfo.getTotalBytes()) {
@ -185,12 +187,20 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
dialogUploadID = null;
}
Toast.makeText(context.getApplicationContext(), "Upload completed successfully", Toast.LENGTH_SHORT).show();
String response = serverResponse.getBodyAsString();
if(response.contains("Η προσθήκη του αρχείου ήταν επιτυχημένη.")||response.contains("The upload was successful.")){
Toast.makeText(context.getApplicationContext(), "Upload completed successfully", Toast.LENGTH_SHORT).show();
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
}
else {
Timber.e(new MultipartUploadException(response));
onError(context,uploadInfo,serverResponse,new MultipartUploadException(response));
}
if (storage == null) {
storage = new Storage(context.getApplicationContext());
}
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null);
UploadsHelper.deleteTempFiles(storage);
}

5
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseException.java

@ -1,13 +1,12 @@
package gr.thmmy.mthmmy.utils.parsing;
/**
* ParseException is to be used for errors while parsing.
* Use ParseException for errors while parsing.
*/
public class ParseException extends RuntimeException {
public ParseException() {}
public ParseException(String message)
{
public ParseException(String message) {
super(message);
}

Loading…
Cancel
Save