diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java index dd728db4..0d9135a4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java @@ -372,7 +372,6 @@ public class UploadActivity extends BaseActivity { requestPerms(UPLOAD_REQUEST_STORAGE_CODE); dialog.cancel(); } - return; } @@ -667,7 +666,7 @@ public class UploadActivity extends BaseActivity { filesListView.setVisibility(View.VISIBLE); } - public static UploadNotificationConfig getConfigForUpload(Context context, String uploadID, + public UploadNotificationConfig getConfigForUpload(Context context, String uploadID, String filename) { UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); @@ -699,7 +698,7 @@ public class UploadActivity extends BaseActivity { uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context, 1, combinedActionsIntent, PendingIntent.FLAG_UPDATE_CURRENT)); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + else { Intent retryIntent = new Intent(context, UploadsReceiver.class); retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD); retryIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); @@ -710,7 +709,7 @@ public class UploadActivity extends BaseActivity { uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( R.drawable.ic_cancel_accent_24dp, - context.getString(R.string.upload_cancel), + context.getString(R.string.cancel), PendingIntent.getBroadcast(context, 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT) )); @@ -731,7 +730,7 @@ public class UploadActivity extends BaseActivity { String uploadDescriptionText, String fileIcon, String uploaderProfileIndex, Uri fileUri) { try { - new MultipartUploadRequest(context, uploadID, uploadIndexUrl) + MultipartUploadRequest multipartUploadRequest = new MultipartUploadRequest(context, uploadID, uploadIndexUrl) .setUtf8Charset() .setNotificationConfig(uploadNotificationConfig) .addParameter("tp-dluploadtitle", uploadTitleText) @@ -743,10 +742,11 @@ public class UploadActivity extends BaseActivity { .addParameter("tp_dluploadpic", "") .addParameter("tp-uploaduser", uploaderProfileIndex) .setNotificationConfig(uploadNotificationConfig) - .setMaxRetries(2) - .startUpload(); - - Toast.makeText(context, "Uploading files in the background.", Toast.LENGTH_SHORT).show(); + .setMaxRetries(2); + Timber.d("Uploading a file with properties: \nTitle: %s\nCategory: %s\nDescription: %s\nIcon: %s\nUploader: %s", + uploadTitleText, categorySelected, uploadDescriptionText, fileIcon, uploaderProfileIndex); + multipartUploadRequest.startUpload(); + Toast.makeText(context, "Uploading file(s) in the background...", Toast.LENGTH_SHORT).show(); return true; } catch (Exception exception) { Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); @@ -1006,7 +1006,7 @@ public class UploadActivity extends BaseActivity { } } - public static class ZipTask extends AsyncTask { + public class ZipTask extends AsyncTask { // Weak references will still allow the Activity to be garbage-collected private final WeakReference weakActivity; final String zipFilename, categorySelected, uploadTitleText, uploadDescriptionText, diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 0671b7e3..a4ea57dd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -921,22 +921,22 @@ public abstract class BaseActivity extends AppCompatActivity { progressDialogBuilder.setView(progressDialogLayout); uploadsProgressDialog = progressDialogBuilder.create(); - if (!UploadService.getTaskList().contains("" + dialogUploadID)) { + if (!UploadService.getTaskList().contains(dialogUploadID)) { //Upload probably failed at this point - uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Retry", (progressDialog, progressWhich) -> { + uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "", (progressDialog, progressWhich) -> { /*LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context.getApplicationContext()); localBroadcastManager.sendBroadcast(multipartUploadRetryIntent);*/ - uploadsProgressDialog.dismiss(); + //uploadsProgressDialog.dismiss(); //context.sendBroadcast(retryIntent); }); - uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", (progressDialog, progressWhich) -> { + uploadsProgressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), (progressDialog, progressWhich) -> { uploadsProgressDialog.dismiss(); }); TextView dialogProgressText = progressDialogLayout.findViewById(R.id.dialog_upload_progress_text); dialogProgressBar.setVisibility(View.GONE); - dialogProgressText.setText("Upload failed."); + dialogProgressText.setText(getString(R.string.upload_failed)); uploadsProgressDialog.show(); } else { diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java b/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java index 6c978dda..1406eb57 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java @@ -59,6 +59,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { switch (intentAction) { case ACTION_CANCEL_UPLOAD: String uploadID = intentBundle.getString(UPLOAD_ID_KEY); + Timber.d("Received ACTION_CANCEL_UPLOAD (id: %s)", uploadID); UploadService.stopUpload(uploadID); break; /*case ACTION_RETRY_UPLOAD: @@ -86,6 +87,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { @Override public void onProgress(Context context, UploadInfo uploadInfo) { + Timber.i("Upload in progress (id: %s)",uploadInfo.getUploadId()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && uploadInfo.getUploadId().equals(dialogUploadID) && uploadProgressDialog != null) { @@ -94,8 +96,9 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { alertDialogNeutral.setOnClickListener(v -> uploadProgressDialog.dismiss()); Button alertDialogNegative = uploadProgressDialog.getButton(AlertDialog.BUTTON_NEGATIVE); - alertDialogNegative.setText(R.string.upload_cancel); + alertDialogNegative.setText(R.string.cancel); alertDialogNegative.setOnClickListener(v -> { + Timber.d("Cancelling upload (id: %s)", dialogUploadID); UploadService.stopUpload(dialogUploadID); uploadProgressDialog.dismiss(); }); @@ -124,6 +127,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { @Override public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) { + Timber.i("Error while uploading (id: %s)",uploadInfo.getUploadId()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && uploadInfo.getUploadId().equals(dialogUploadID) && uploadProgressDialog != null) { @@ -137,13 +141,9 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { });*/ Button alertDialogNegative = uploadProgressDialog.getButton(AlertDialog.BUTTON_NEGATIVE); - alertDialogNegative.setText(R.string.upload_cancel); + alertDialogNegative.setText(R.string.cancel); alertDialogNegative.setOnClickListener(v -> { - NotificationManager notificationManager = (NotificationManager) context.getApplicationContext(). - getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null) { - notificationManager.cancel(uploadInfo.getNotificationID()); - } + cancelNotification(context, uploadInfo.getNotificationID()); UploadsHelper.deleteTempFiles(storage); uploadProgressDialog.dismiss(); }); @@ -163,12 +163,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { } } } else { - NotificationManager notificationManager = (NotificationManager) context.getApplicationContext(). - getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null) { - notificationManager.cancel(uploadInfo.getNotificationID()); - } - + cancelNotification(context, uploadInfo.getNotificationID()); Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD); combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadInfo.getUploadId()); context.sendBroadcast(combinedActionsIntent); @@ -189,6 +184,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { String response = serverResponse.getBodyAsString(); if(response.contains("Η προσθήκη του αρχείου ήταν επιτυχημένη.")||response.contains("The upload was successful.")){ + Timber.i("Upload completed successfully (id: %s)",uploadInfo.getUploadId()); Toast.makeText(context.getApplicationContext(), "Upload completed successfully", Toast.LENGTH_SHORT).show(); BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); } @@ -207,21 +203,17 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { @Override public void onCancelled(Context context, UploadInfo uploadInfo) { + Timber.i("Upload cancelled (id: %s)", uploadInfo.getUploadId()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { uploadProgressDialog = null; dialogUploadID = null; } - Toast.makeText(context.getApplicationContext(), R.string.upload_canceled, Toast.LENGTH_SHORT).show(); - if (storage == null) { + Toast.makeText(context.getApplicationContext(), R.string.upload_cancelled, Toast.LENGTH_SHORT).show(); + if (storage == null) storage = new Storage(context.getApplicationContext()); - } - /*NotificationManager notificationManager = (NotificationManager) context.getApplicationContext(). - getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null) { - notificationManager.cancel(uploadInfo.getNotificationID()); - }*/ + //cancelNotification(context, uploadInfo.getNotificationID()); UploadsHelper.deleteTempFiles(storage); } @@ -231,4 +223,11 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver { UploadsReceiver.dialogUploadID = dialogUploadID; //UploadsReceiver.multipartUploadRetryIntent = multipartUploadRetryIntent; } + + private void cancelNotification(Context context, int notificationId){ + NotificationManager notificationManager = (NotificationManager) context.getApplicationContext(). + getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager != null) + notificationManager.cancel(notificationId); + } } \ No newline at end of file diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index 6c23115e..bac3952a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -17,8 +17,8 @@ import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask; import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditTask; -import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyResult; +import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForReplyTask; import gr.thmmy.mthmmy.activities.topic.tasks.RemoveVoteTask; import gr.thmmy.mthmmy.activities.topic.tasks.ReplyTask; import gr.thmmy.mthmmy.activities.topic.tasks.SubmitVoteTask; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2a32d992..fabd3e8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,7 +13,7 @@ Bookmarks Info OK - Cancel + "Cancel" "To use mTHMMY you have to agree to our Privacy Policy by choosing one of the options below. Choose \"Yes, I want to help\", if you consent to the collection of anonymized data that will help us improve the app. Otherwise, choose \"Nope, leave me alone\". You can change your preferences any time through the app's Settings. user_consent_shared_preference_key @@ -145,9 +145,8 @@ Uploading Uploading: %1$.2f Kbit/s, %2$d/%3$d KBytes "Upload failed" - "Upload canceled" + "Upload canceled" "Resume in background" - "Cancel" "Retry"