|
@ -10,6 +10,7 @@ import android.graphics.Typeface; |
|
|
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.text.Editable; |
|
|
import android.text.Editable; |
|
|
import android.text.Spannable; |
|
|
import android.text.Spannable; |
|
@ -327,30 +328,20 @@ public class UploadActivity extends BaseActivity { |
|
|
//File should be uploaded with a different name
|
|
|
//File should be uploaded with a different name
|
|
|
|
|
|
|
|
|
if (checkPerms()) { |
|
|
if (checkPerms()) { |
|
|
if (!uploadFile.isCameraPhoto()) { |
|
|
String newFileName = FileUtils.getFilenameWithoutExtension(editTextFilename); |
|
|
//Temporarily copies the file to a another location and renames it
|
|
|
|
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, |
|
|
if(uploadFile.isCameraPhoto()) |
|
|
uploadFile.getFileUri(), |
|
|
newFileName = newFileName + ".jpg"; |
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename)); |
|
|
|
|
|
} |
|
|
//Temporarily copies the file to another location (external cache) and renames it
|
|
|
else { |
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, |
|
|
//Renames the photo taken
|
|
|
uploadFile.getFileUri(), |
|
|
String photoPath = uploadFile.getPhotoFile().getPath(); |
|
|
newFileName); |
|
|
photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); |
|
|
|
|
|
String destinationFilename = photoPath + File.separator + |
|
|
//Something went wrong while creating temporary file, abort
|
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; |
|
|
if(tempFileUri == null){ |
|
|
|
|
|
progressBar.setVisibility(View.GONE); |
|
|
if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { |
|
|
return; |
|
|
//Something went wrong, abort
|
|
|
|
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
progressBar.setVisibility(View.GONE); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Points photoFile and fileUri to the new copied and renamed file
|
|
|
|
|
|
uploadFile.setPhotoFile(storage.getFile(destinationFilename)); |
|
|
|
|
|
uploadFile.setFileUri(FileProvider.getUriForFile(this, getPackageName() + |
|
|
|
|
|
".provider", uploadFile.getPhotoFile())); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
@ -561,7 +552,7 @@ public class UploadActivity extends BaseActivity { |
|
|
UploadFile newFile = new UploadFile(true, TakePhoto.processResult(this, |
|
|
UploadFile newFile = new UploadFile(true, TakePhoto.processResult(this, |
|
|
photoFileCreated), photoFileCreated); |
|
|
photoFileCreated), photoFileCreated); |
|
|
addFileViewToList(FileUtils.getFilenameWithoutExtension(FileUtils. |
|
|
addFileViewToList(FileUtils.getFilenameWithoutExtension(FileUtils. |
|
|
filenameFromUri(this, newFile.getFileUri()))); |
|
|
filenameFromUri(this, newFile.getFileUri())) + ".jpg"); |
|
|
filesList.add(newFile); |
|
|
filesList.add(newFile); |
|
|
} |
|
|
} |
|
|
else if (requestCode == AFR_REQUEST_CODE_FIELDS_BUILDER) { |
|
|
else if (requestCode == AFR_REQUEST_CODE_FIELDS_BUILDER) { |
|
@ -596,6 +587,10 @@ public class UploadActivity extends BaseActivity { |
|
|
case UPLOAD_REQUEST_CAMERA_CODE: |
|
|
case UPLOAD_REQUEST_CAMERA_CODE: |
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) |
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) |
|
|
takePhoto(); |
|
|
takePhoto(); |
|
|
|
|
|
else { |
|
|
|
|
|
Timber.w("Take photo failed (permission denied)."); |
|
|
|
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Take photo failed (storage permission denied)", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
} |
|
|
break; |
|
|
break; |
|
|
case UPLOAD_REQUEST_STORAGE_CODE: |
|
|
case UPLOAD_REQUEST_STORAGE_CODE: |
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && |
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && |
|
@ -609,6 +604,7 @@ public class UploadActivity extends BaseActivity { |
|
|
finish(); |
|
|
finish(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
Timber.w("Zip task failed (permission denied)."); |
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please retry uploading.", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Please retry uploading.", Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
@ -720,17 +716,23 @@ public class UploadActivity extends BaseActivity { |
|
|
cancelIntent.setAction(UploadsReceiver.ACTION_CANCEL_UPLOAD); |
|
|
cancelIntent.setAction(UploadsReceiver.ACTION_CANCEL_UPLOAD); |
|
|
cancelIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); |
|
|
cancelIntent.putExtra(UploadsReceiver.UPLOAD_ID_KEY, uploadID); |
|
|
|
|
|
|
|
|
|
|
|
int pendingIntentFlags; |
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) |
|
|
|
|
|
pendingIntentFlags = PendingIntent.FLAG_MUTABLE |PendingIntent.FLAG_UPDATE_CURRENT; |
|
|
|
|
|
else |
|
|
|
|
|
pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; |
|
|
|
|
|
|
|
|
uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( |
|
|
uploadNotificationConfig.getProgress().actions.add(new UploadNotificationAction( |
|
|
R.drawable.ic_cancel_accent_24dp, |
|
|
R.drawable.ic_cancel_accent_24dp, |
|
|
context.getString(R.string.cancel), |
|
|
context.getString(R.string.cancel), |
|
|
PendingIntent.getBroadcast(context, 0, cancelIntent, |
|
|
PendingIntent.getBroadcast(context, 0, cancelIntent, |
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
pendingIntentFlags) |
|
|
)); |
|
|
)); |
|
|
uploadNotificationConfig.getError().actions.add(new UploadNotificationAction( |
|
|
uploadNotificationConfig.getError().actions.add(new UploadNotificationAction( |
|
|
R.drawable.ic_notification, |
|
|
R.drawable.ic_notification, |
|
|
context.getString(R.string.upload_retry), |
|
|
context.getString(R.string.upload_retry), |
|
|
PendingIntent.getBroadcast(context, 0, retryIntent, |
|
|
PendingIntent.getBroadcast(context, 0, retryIntent, |
|
|
PendingIntent.FLAG_UPDATE_CURRENT) |
|
|
pendingIntentFlags) |
|
|
)); |
|
|
)); |
|
|
|
|
|
|
|
|
return uploadNotificationConfig; |
|
|
return uploadNotificationConfig; |
|
@ -1069,7 +1071,7 @@ public class UploadActivity extends BaseActivity { |
|
|
@Override |
|
|
@Override |
|
|
protected void onPreExecute() { |
|
|
protected void onPreExecute() { |
|
|
assert weakActivity != null; |
|
|
assert weakActivity != null; |
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Zipping files", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Zipping files...", Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -1077,7 +1079,7 @@ public class UploadActivity extends BaseActivity { |
|
|
if (weakActivity == null || zipFilename == null) |
|
|
if (weakActivity == null || zipFilename == null) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
File zipFile = UploadsHelper.createZipFile(zipFilename); |
|
|
File zipFile = UploadsHelper.createZipFile(weakActivity.get(), zipFilename); |
|
|
|
|
|
|
|
|
if (zipFile == null) |
|
|
if (zipFile == null) |
|
|
return false; |
|
|
return false; |
|
|