Browse Source

Uploads minor tweaks

pull/63/head
Ezerous 5 years ago
parent
commit
a6a3280aa8
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/upload/UploadActivity.java
  2. 10
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  3. 41
      app/src/main/java/gr/thmmy/mthmmy/services/UploadsReceiver.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java
  5. 5
      app/src/main/res/values/strings.xml

20
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<Uri, Void, Boolean> {
public class ZipTask extends AsyncTask<Uri, Void, Boolean> {
// Weak references will still allow the Activity to be garbage-collected
private final WeakReference<Activity> weakActivity;
final String zipFilename, categorySelected, uploadTitleText, uploadDescriptionText,

10
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 {

41
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);
}
}

2
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;

5
app/src/main/res/values/strings.xml

@ -13,7 +13,7 @@
<string name="bookmark">Bookmarks</string>
<string name="info">Info</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="cancel">"Cancel"</string>
<string name="user_agreement_dialog_text">"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.</string>
<string name="user_consent_shared_preference_key">user_consent_shared_preference_key</string>
@ -145,9 +145,8 @@
<string name="upload_progress_dialog_title">Uploading</string>
<string name="upload_progress_dialog_bytes_uploaded">Uploading: %1$.2f Kbit/s, %2$d/%3$d KBytes</string>
<string name="upload_failed">"Upload failed"</string>
<string name="upload_canceled">"Upload canceled"</string>
<string name="upload_cancelled">"Upload canceled"</string>
<string name="upload_resume_in_background">"Resume in background"</string>
<string name="upload_cancel">"Cancel"</string>
<string name="upload_retry">"Retry"</string>
<!--Upload Fields Builder Activity-->

Loading…
Cancel
Save