|
@ -360,29 +360,37 @@ public class UploadActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
if (!editTextFilename.equals(selectedFileFilename)) { |
|
|
if (!editTextFilename.equals(selectedFileFilename)) { |
|
|
//File should be uploaded with a different name
|
|
|
//File should be uploaded with a different name
|
|
|
if (!uploadFile.isCameraPhoto()) { |
|
|
|
|
|
//Temporarily copies the file to a another location and renames it
|
|
|
|
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, |
|
|
|
|
|
uploadFile.getFileUri(), |
|
|
|
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename)); |
|
|
|
|
|
} else { |
|
|
|
|
|
//Renames the photo taken
|
|
|
|
|
|
String photoPath = uploadFile.getPhotoFile().getPath(); |
|
|
|
|
|
photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); |
|
|
|
|
|
String destinationFilename = photoPath + File.separator + |
|
|
|
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; |
|
|
|
|
|
|
|
|
|
|
|
if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { |
|
|
|
|
|
//Something went wrong, abort
|
|
|
|
|
|
Toast.makeText(this, "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
|
|
|
if (checkPerms()) { |
|
|
uploadFile.setPhotoFile(storage.getFile(destinationFilename)); |
|
|
if (!uploadFile.isCameraPhoto()) { |
|
|
uploadFile.setFileUri(FileProvider.getUriForFile(this, getPackageName() + |
|
|
//Temporarily copies the file to a another location and renames it
|
|
|
".provider", uploadFile.getPhotoFile())); |
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, |
|
|
|
|
|
uploadFile.getFileUri(), |
|
|
|
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename)); |
|
|
|
|
|
} else { |
|
|
|
|
|
//Renames the photo taken
|
|
|
|
|
|
String photoPath = uploadFile.getPhotoFile().getPath(); |
|
|
|
|
|
photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); |
|
|
|
|
|
String destinationFilename = photoPath + File.separator + |
|
|
|
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; |
|
|
|
|
|
|
|
|
|
|
|
if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { |
|
|
|
|
|
//Something went wrong, abort
|
|
|
|
|
|
Toast.makeText(this, "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 { |
|
|
|
|
|
requestPerms(UPLOAD_REQUEST_STORAGE_CODE); |
|
|
|
|
|
zipTask = null; |
|
|
|
|
|
dialog.cancel(); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
@ -586,8 +594,9 @@ public class UploadActivity extends BaseActivity { |
|
|
if (previousName.isEmpty()) { |
|
|
if (previousName.isEmpty()) { |
|
|
uploadFilename.setText(data.getStringExtra(RESULT_FILENAME)); |
|
|
uploadFilename.setText(data.getStringExtra(RESULT_FILENAME)); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
String extractedExtension = FileUtils.getFileExtension(previousName); |
|
|
String filenameWithExtension = data.getStringExtra(RESULT_FILENAME) + |
|
|
String filenameWithExtension = data.getStringExtra(RESULT_FILENAME) + |
|
|
FileUtils.getFileExtension(previousName); |
|
|
(extractedExtension != null ? extractedExtension : ""); |
|
|
uploadFilename.setText(filenameWithExtension); |
|
|
uploadFilename.setText(filenameWithExtension); |
|
|
} |
|
|
} |
|
|
hasModifiedFilename = true; |
|
|
hasModifiedFilename = true; |
|
@ -609,7 +618,7 @@ public class UploadActivity extends BaseActivity { |
|
|
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 && |
|
|
zipTask != null) { |
|
|
zipTask != null) { |
|
|
Uri[] filesListArray = new Uri[filesList.size()]; |
|
|
Uri[] filesListArray = new Uri[filesList.size()]; |
|
|
for (int i = 0; i < filesList.size(); ++i) { |
|
|
for (int i = 0; i < filesList.size(); ++i) { |
|
|
filesListArray[i] = filesList.get(i).getFileUri(); |
|
|
filesListArray[i] = filesList.get(i).getFileUri(); |
|
@ -617,6 +626,8 @@ public class UploadActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
zipTask.execute(filesListArray); |
|
|
zipTask.execute(filesListArray); |
|
|
finish(); |
|
|
finish(); |
|
|
|
|
|
} else { |
|
|
|
|
|
Toast.makeText(this, "Please retry uploading.", Toast.LENGTH_SHORT).show(); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|