|
@ -9,6 +9,7 @@ import android.content.pm.PackageManager; |
|
|
import android.graphics.drawable.Drawable; |
|
|
import android.graphics.drawable.Drawable; |
|
|
import android.net.Uri; |
|
|
import android.net.Uri; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
|
|
|
import android.os.Build; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
@ -50,6 +51,7 @@ import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.Locale; |
|
|
import java.util.Locale; |
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
@ -153,9 +155,6 @@ public class UploadActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
progressBar = findViewById(R.id.progressBar); |
|
|
progressBar = findViewById(R.id.progressBar); |
|
|
|
|
|
|
|
|
/*uploadsReceiver.setDelegate(uploadDelegate); |
|
|
|
|
|
uploadsReceiver.provideStorage(storage);*/ |
|
|
|
|
|
|
|
|
|
|
|
findViewById(R.id.upload_outer_scrollview).setVerticalScrollBarEnabled(false); |
|
|
findViewById(R.id.upload_outer_scrollview).setVerticalScrollBarEnabled(false); |
|
|
categoriesSpinners = findViewById(R.id.upload_spinners); |
|
|
categoriesSpinners = findViewById(R.id.upload_spinners); |
|
|
rootCategorySpinner = findViewById(R.id.upload_spinner_category_root); |
|
|
rootCategorySpinner = findViewById(R.id.upload_spinner_category_root); |
|
@ -388,36 +387,11 @@ public class UploadActivity extends BaseActivity { |
|
|
uploadTitleText, uploadDescriptionText[0], fileIcon, |
|
|
uploadTitleText, uploadDescriptionText[0], fileIcon, |
|
|
uploaderProfileIndex).execute(filesListArray); |
|
|
uploaderProfileIndex).execute(filesListArray); |
|
|
finish(); |
|
|
finish(); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Intent retryIntent = new Intent(this, UploadsReceiver.class); |
|
|
String uploadID = UUID.randomUUID().toString(); |
|
|
retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD); |
|
|
if (uploadFile(this, uploadID, getConfigForUpload(this, uploadID), categorySelected, |
|
|
|
|
|
|
|
|
Intent cancelIntent = new Intent(this, UploadsReceiver.class); |
|
|
|
|
|
cancelIntent.setAction(UploadsReceiver.ACTION_CANCEL_UPLOAD); |
|
|
|
|
|
|
|
|
|
|
|
UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); |
|
|
|
|
|
uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; |
|
|
|
|
|
uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconColorResourceID = R.color.error_red; |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_cancel_accent_24dp, |
|
|
|
|
|
this.getString(R.string.upload_notification_cancel), |
|
|
|
|
|
PendingIntent.getBroadcast(this, 0, cancelIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
uploadNotificationConfig.getError().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_cached_accent_24dp, |
|
|
|
|
|
this.getString(R.string.upload_notification_retry), |
|
|
|
|
|
PendingIntent.getBroadcast(this, 0, retryIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
if (uploadFile(this, uploadNotificationConfig, categorySelected, |
|
|
|
|
|
uploadTitleText, uploadDescriptionText[0], fileIcon, uploaderProfileIndex, |
|
|
uploadTitleText, uploadDescriptionText[0], fileIcon, uploaderProfileIndex, |
|
|
tempFileUri == null |
|
|
tempFileUri == null |
|
|
? filesList.get(0).getFileUri() |
|
|
? filesList.get(0).getFileUri() |
|
@ -465,15 +439,11 @@ public class UploadActivity extends BaseActivity { |
|
|
protected void onResume() { |
|
|
protected void onResume() { |
|
|
drawer.setSelection(UPLOAD_ID); |
|
|
drawer.setSelection(UPLOAD_ID); |
|
|
super.onResume(); |
|
|
super.onResume(); |
|
|
/*uploadsReceiver.setDelegate(uploadDelegate); |
|
|
|
|
|
uploadsReceiver.provideStorage(storage); |
|
|
|
|
|
uploadsReceiver.register(this);*/ |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onPause() { |
|
|
protected void onPause() { |
|
|
super.onPause(); |
|
|
super.onPause(); |
|
|
//uploadsReceiver.unregister(this);
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -699,13 +669,56 @@ public class UploadActivity extends BaseActivity { |
|
|
filesListView.setVisibility(View.VISIBLE); |
|
|
filesListView.setVisibility(View.VISIBLE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static boolean uploadFile(Context context, |
|
|
private static UploadNotificationConfig getConfigForUpload(Context context, String uploadID) { |
|
|
|
|
|
UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); |
|
|
|
|
|
uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; |
|
|
|
|
|
uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconColorResourceID = R.color.error_red; |
|
|
|
|
|
uploadNotificationConfig.getCancelled().iconColorResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
|
|
|
|
|
|
Intent combinedActionsIntent = new Intent(UploadsReceiver.ACTION_COMBINED_UPLOAD); |
|
|
|
|
|
//combinedActionsIntent.setAction(UploadsReceiver.ACTION_COMBINED_UPLOAD);
|
|
|
|
|
|
combinedActionsIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.setClickIntentForAllStatuses(PendingIntent.getBroadcast(context, |
|
|
|
|
|
1, combinedActionsIntent, PendingIntent.FLAG_UPDATE_CURRENT)); |
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
Intent retryIntent = new Intent(context, UploadsReceiver.class); |
|
|
|
|
|
retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD); |
|
|
|
|
|
retryIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); |
|
|
|
|
|
|
|
|
|
|
|
Intent cancelIntent = new Intent(context, UploadsReceiver.class); |
|
|
|
|
|
cancelIntent.setAction(UploadsReceiver.ACTION_CANCEL_UPLOAD); |
|
|
|
|
|
cancelIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_cancel_accent_24dp, |
|
|
|
|
|
context.getString(R.string.upload_notification_cancel), |
|
|
|
|
|
PendingIntent.getBroadcast(context, 0, cancelIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
uploadNotificationConfig.getError().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_notification, |
|
|
|
|
|
context.getString(R.string.upload_notification_retry), |
|
|
|
|
|
PendingIntent.getBroadcast(context, 0, retryIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return uploadNotificationConfig; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private 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, |
|
|
String uploaderProfileIndex, Uri fileUri) { |
|
|
String uploaderProfileIndex, Uri fileUri) { |
|
|
try { |
|
|
try { |
|
|
new MultipartUploadRequest(context, uploadIndexUrl) |
|
|
new MultipartUploadRequest(context, uploadID, uploadIndexUrl) |
|
|
.setUtf8Charset() |
|
|
.setUtf8Charset() |
|
|
.setNotificationConfig(uploadNotificationConfig) |
|
|
.setNotificationConfig(uploadNotificationConfig) |
|
|
.addParameter("tp-dluploadtitle", uploadTitleText) |
|
|
.addParameter("tp-dluploadtitle", uploadTitleText) |
|
@ -718,6 +731,8 @@ public class UploadActivity extends BaseActivity { |
|
|
.setNotificationConfig(uploadNotificationConfig) |
|
|
.setNotificationConfig(uploadNotificationConfig) |
|
|
.setMaxRetries(2) |
|
|
.setMaxRetries(2) |
|
|
.startUpload(); |
|
|
.startUpload(); |
|
|
|
|
|
|
|
|
|
|
|
Toast.makeText(context, "Uploading files in the background.", Toast.LENGTH_SHORT).show(); |
|
|
return true; |
|
|
return true; |
|
|
} catch (Exception exception) { |
|
|
} catch (Exception exception) { |
|
|
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); |
|
|
Timber.e(exception, "AndroidUploadService: %s", exception.getMessage()); |
|
@ -992,34 +1007,9 @@ public class UploadActivity extends BaseActivity { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Intent retryIntent = new Intent(weakActivity.get(), UploadsReceiver.class); |
|
|
String uploadID = UUID.randomUUID().toString(); |
|
|
retryIntent.setAction(UploadsReceiver.ACTION_RETRY_UPLOAD); |
|
|
if (!uploadFile(weakActivity.get(), uploadID, |
|
|
|
|
|
getConfigForUpload(weakActivity.get(), uploadID), categorySelected, |
|
|
Intent cancelIntent = new Intent(weakActivity.get(), UploadsReceiver.class); |
|
|
|
|
|
cancelIntent.setAction(UploadsReceiver.ACTION_CANCEL_UPLOAD); |
|
|
|
|
|
|
|
|
|
|
|
UploadNotificationConfig uploadNotificationConfig = new UploadNotificationConfig(); |
|
|
|
|
|
uploadNotificationConfig.setIconForAllStatuses(android.R.drawable.stat_sys_upload); |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().iconResourceID = android.R.drawable.stat_sys_upload; |
|
|
|
|
|
uploadNotificationConfig.getCompleted().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconResourceID = android.R.drawable.stat_sys_upload_done; |
|
|
|
|
|
uploadNotificationConfig.getError().iconColorResourceID = R.color.error_red; |
|
|
|
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_cancel_accent_24dp, |
|
|
|
|
|
weakActivity.get().getString(R.string.upload_notification_cancel), |
|
|
|
|
|
PendingIntent.getBroadcast(weakActivity.get(), 0, cancelIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
uploadNotificationConfig.getError().actions.add(new UploadNotificationAction( |
|
|
|
|
|
R.drawable.ic_cached_accent_24dp, |
|
|
|
|
|
weakActivity.get().getString(R.string.upload_notification_retry), |
|
|
|
|
|
PendingIntent.getBroadcast(weakActivity.get(), 0, retryIntent, |
|
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
if (!uploadFile(weakActivity.get(), uploadNotificationConfig, 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(); |
|
|