|
@ -50,6 +50,7 @@ import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.base.BaseApplication; |
|
|
import gr.thmmy.mthmmy.base.BaseApplication; |
|
|
import gr.thmmy.mthmmy.model.UploadCategory; |
|
|
import gr.thmmy.mthmmy.model.UploadCategory; |
|
|
|
|
|
import gr.thmmy.mthmmy.model.UploadFile; |
|
|
import gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault; |
|
|
import gr.thmmy.mthmmy.utils.AppCompatSpinnerWithoutDefault; |
|
|
import gr.thmmy.mthmmy.utils.FileUtils; |
|
|
import gr.thmmy.mthmmy.utils.FileUtils; |
|
|
import gr.thmmy.mthmmy.utils.TakePhoto; |
|
|
import gr.thmmy.mthmmy.utils.TakePhoto; |
|
@ -84,10 +85,6 @@ public class UploadActivity extends BaseActivity { |
|
|
*/ |
|
|
*/ |
|
|
private static final int UPLOAD_REQUEST_CODE = 42; //Arbitrary, application specific
|
|
|
private static final int UPLOAD_REQUEST_CODE = 42; //Arbitrary, application specific
|
|
|
|
|
|
|
|
|
private static final int NO_UPLOAD_METHOD_SELECTED = 0; |
|
|
|
|
|
private static final int SELECT_FILE_METHOD_SELECTED = 1; |
|
|
|
|
|
private static final int TAKE_PHOTO_METHOD_SELECTED = 2; |
|
|
|
|
|
|
|
|
|
|
|
private static final int MAX_FILE_SIZE_SUPPORTED = 45000000; |
|
|
private static final int MAX_FILE_SIZE_SUPPORTED = 45000000; |
|
|
|
|
|
|
|
|
private ArrayList<UploadCategory> uploadRootCategories = new ArrayList<>(); |
|
|
private ArrayList<UploadCategory> uploadRootCategories = new ArrayList<>(); |
|
@ -96,9 +93,7 @@ public class UploadActivity extends BaseActivity { |
|
|
private String categorySelected = "-1"; |
|
|
private String categorySelected = "-1"; |
|
|
private String uploaderProfileIndex = "1"; |
|
|
private String uploaderProfileIndex = "1"; |
|
|
|
|
|
|
|
|
private int uploadMethodSelected = NO_UPLOAD_METHOD_SELECTED; |
|
|
private ArrayList<UploadFile> filesList = new ArrayList<>(); |
|
|
private Uri fileUri; |
|
|
|
|
|
private File photoFileSelected = null; |
|
|
|
|
|
private File photoFileCreated = null; |
|
|
private File photoFileCreated = null; |
|
|
private String fileIcon; |
|
|
private String fileIcon; |
|
|
|
|
|
|
|
@ -110,6 +105,7 @@ public class UploadActivity extends BaseActivity { |
|
|
private EditText uploadFilename; |
|
|
private EditText uploadFilename; |
|
|
private EditText uploadDescription; |
|
|
private EditText uploadDescription; |
|
|
private AppCompatButton titleDescriptionBuilderButton; |
|
|
private AppCompatButton titleDescriptionBuilderButton; |
|
|
|
|
|
private LinearLayout filesListView; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
@ -247,21 +243,24 @@ public class UploadActivity extends BaseActivity { |
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|
|
oldFilename = s.toString(); |
|
|
oldFilename = s.toString(); |
|
|
|
|
|
|
|
|
if (fileUri != null) { |
|
|
String uriExtension; |
|
|
String uriExtension = FileUtils.getFileExtension(FileUtils. |
|
|
if (filesList.isEmpty()) { |
|
|
filenameFromUri(getApplicationContext(), fileUri)); |
|
|
|
|
|
|
|
|
|
|
|
if (fileExtension == null || !fileExtension.equals(uriExtension)) { |
|
|
|
|
|
//New file selected
|
|
|
|
|
|
//Changes the extension of the saved filename instance
|
|
|
|
|
|
oldFilename = FileUtils.getFilenameWithoutExtension(oldFilename) + |
|
|
|
|
|
uriExtension; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fileExtension = uriExtension; |
|
|
|
|
|
} else { |
|
|
|
|
|
fileExtension = null; |
|
|
fileExtension = null; |
|
|
|
|
|
return; |
|
|
|
|
|
} else if (filesList.size() == 1) { |
|
|
|
|
|
uriExtension = FileUtils.getFileExtension(FileUtils. |
|
|
|
|
|
filenameFromUri(getApplicationContext(), filesList.get(0).getFileUri())); |
|
|
|
|
|
} else { |
|
|
|
|
|
uriExtension = ".zip"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fileExtension == null || !fileExtension.equals(uriExtension)) { |
|
|
|
|
|
//New file selected
|
|
|
|
|
|
//Changes the extension of the saved filename instance
|
|
|
|
|
|
oldFilename = FileUtils.getFilenameWithoutExtension(oldFilename) + |
|
|
|
|
|
uriExtension; |
|
|
|
|
|
} |
|
|
|
|
|
fileExtension = uriExtension; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -293,6 +292,8 @@ public class UploadActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
filesListView = findViewById(R.id.upload_files_list); |
|
|
|
|
|
|
|
|
AppCompatButton selectFileButton = findViewById(R.id.upload_select_file_button); |
|
|
AppCompatButton selectFileButton = findViewById(R.id.upload_select_file_button); |
|
|
Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp); |
|
|
Drawable selectStartDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_insert_drive_file_white_24dp); |
|
|
selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null); |
|
|
selectFileButton.setCompoundDrawablesRelativeWithIntrinsicBounds(selectStartDrawable, null, null, null); |
|
@ -335,7 +336,7 @@ public class UploadActivity extends BaseActivity { |
|
|
uploadTitle.setError("Required"); |
|
|
uploadTitle.setError("Required"); |
|
|
shouldReturn = true; |
|
|
shouldReturn = true; |
|
|
} |
|
|
} |
|
|
if (fileUri == null) { |
|
|
if (filesList.isEmpty()) { |
|
|
Toast.makeText(view.getContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show(); |
|
|
Toast.makeText(view.getContext(), "Please choose a file to upload or take a photo", Toast.LENGTH_LONG).show(); |
|
|
shouldReturn = true; |
|
|
shouldReturn = true; |
|
|
} |
|
|
} |
|
@ -343,11 +344,18 @@ public class UploadActivity extends BaseActivity { |
|
|
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(view.getContext(), "Please choose category first", Toast.LENGTH_SHORT).show(); |
|
|
shouldReturn = true; |
|
|
shouldReturn = true; |
|
|
} |
|
|
} |
|
|
if (fileUri != null && FileUtils.sizeFromUri(this, fileUri) > MAX_FILE_SIZE_SUPPORTED) { |
|
|
if (!filesList.isEmpty()) { |
|
|
Toast.makeText(view.getContext(), "Your files are too powerful for thmmy. Reduce size or split!", Toast.LENGTH_LONG).show(); |
|
|
long totalFilesSize = 0; |
|
|
shouldReturn = true; |
|
|
for (UploadFile file : filesList) { |
|
|
|
|
|
totalFilesSize += FileUtils.sizeFromUri(this, file.getFileUri()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (totalFilesSize > MAX_FILE_SIZE_SUPPORTED) { |
|
|
|
|
|
Toast.makeText(view.getContext(), "Your files are too powerful for thmmy. Reduce size or split!", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
shouldReturn = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (!editTextFilename.matches("(.+\\.)+.+")){ |
|
|
if (!editTextFilename.matches("(.+\\.)+.+")) { |
|
|
uploadFilename.setError("Invalid filename"); |
|
|
uploadFilename.setError("Invalid filename"); |
|
|
shouldReturn = true; |
|
|
shouldReturn = true; |
|
|
} |
|
|
} |
|
@ -363,42 +371,51 @@ public class UploadActivity extends BaseActivity { |
|
|
uploadDescriptionText += uploadedFromThmmyPromptHtml; |
|
|
uploadDescriptionText += uploadedFromThmmyPromptHtml; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Checks if a file renaming is necessary
|
|
|
|
|
|
Uri tempFileUri = null; |
|
|
Uri tempFileUri = null; |
|
|
{ |
|
|
if (filesList.size() == 1) { |
|
|
String selectedFileFilename = FileUtils.filenameFromUri(this, fileUri); |
|
|
//Checks if the file needs renaming
|
|
|
|
|
|
UploadFile uploadFile = filesList.get(0); |
|
|
|
|
|
String selectedFileFilename = FileUtils.filenameFromUri(this, uploadFile.getFileUri()); |
|
|
|
|
|
|
|
|
if (!editTextFilename.equals(selectedFileFilename)) { |
|
|
if (!editTextFilename.equals(selectedFileFilename)) { |
|
|
//File should be uploaded with a different name
|
|
|
//File should be uploaded with a different name
|
|
|
switch (uploadMethodSelected) { |
|
|
if (!uploadFile.isCameraPhoto()) { |
|
|
case SELECT_FILE_METHOD_SELECTED: |
|
|
//Temporarily copies the file to a another location and renames it
|
|
|
//Temporarily copies the file to a another location and renames it
|
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, |
|
|
tempFileUri = UploadsHelper.createTempFile(this, storage, fileUri, |
|
|
uploadFile.getFileUri(), |
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename)); |
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename)); |
|
|
break; |
|
|
} else { |
|
|
case TAKE_PHOTO_METHOD_SELECTED: |
|
|
//Renames the photo taken
|
|
|
//Renames the photo taken
|
|
|
String photoPath = uploadFile.getPhotoFile().getPath(); |
|
|
String photoPath = photoFileSelected.getPath(); |
|
|
photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); |
|
|
photoPath = photoPath.substring(0, photoPath.lastIndexOf(File.separator)); |
|
|
String destinationFilename = photoPath + File.separator + |
|
|
String destinationFilename = photoPath + File.separator + |
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; |
|
|
FileUtils.getFilenameWithoutExtension(editTextFilename) + ".jpg"; |
|
|
|
|
|
|
|
|
if (!storage.rename(uploadFile.getPhotoFile().getAbsolutePath(), destinationFilename)) { |
|
|
if (!storage.rename(photoFileSelected.getAbsolutePath(), destinationFilename)) { |
|
|
//Something went wrong, abort
|
|
|
//Something went wrong, abort
|
|
|
Toast.makeText(this, "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(this, "Could not create temporary file for renaming", Toast.LENGTH_SHORT).show(); |
|
|
progressBar.setVisibility(View.GONE); |
|
|
progressBar.setVisibility(View.GONE); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Points photoFile and fileUri to the new copied and renamed file
|
|
|
//Points photoFile and fileUri to the new copied and renamed file
|
|
|
photoFileSelected = storage.getFile(destinationFilename); |
|
|
uploadFile.setPhotoFile(storage.getFile(destinationFilename)); |
|
|
fileUri = FileProvider.getUriForFile(this, getPackageName() + |
|
|
uploadFile.setFileUri(FileProvider.getUriForFile(this, getPackageName() + |
|
|
".provider", photoFileSelected); |
|
|
".provider", uploadFile.getPhotoFile())); |
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
Uri[] filesListArray = new Uri[filesList.size()]; |
|
|
|
|
|
for (int i = 0; i < filesList.size(); ++i) { |
|
|
|
|
|
filesListArray[i] = filesList.get(i).getFileUri(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File zipFile = UploadsHelper.createZipFile(this); |
|
|
|
|
|
assert zipFile != null; |
|
|
|
|
|
tempFileUri = FileProvider.getUriForFile(this, getPackageName() + |
|
|
|
|
|
".provider", zipFile); |
|
|
|
|
|
|
|
|
|
|
|
UploadsHelper.zip(this, filesListArray, tempFileUri); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
@ -408,7 +425,7 @@ public class UploadActivity extends BaseActivity { |
|
|
.addParameter("tp-dluploadcat", categorySelected) |
|
|
.addParameter("tp-dluploadcat", categorySelected) |
|
|
.addParameter("tp-dluploadtext", uploadDescriptionText) |
|
|
.addParameter("tp-dluploadtext", uploadDescriptionText) |
|
|
.addFileToUpload(tempFileUri == null |
|
|
.addFileToUpload(tempFileUri == null |
|
|
? fileUri.toString() |
|
|
? filesList.get(0).getFileUri().toString() |
|
|
: tempFileUri.toString() |
|
|
: tempFileUri.toString() |
|
|
, "tp-dluploadfile") |
|
|
, "tp-dluploadfile") |
|
|
.addParameter("tp_dluploadicon", fileIcon) |
|
|
.addParameter("tp_dluploadicon", fileIcon) |
|
@ -434,15 +451,18 @@ public class UploadActivity extends BaseActivity { |
|
|
UploadsHelper.deleteTempFiles(); |
|
|
UploadsHelper.deleteTempFiles(); |
|
|
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); |
|
|
BaseApplication.getInstance().logFirebaseAnalyticsEvent("file_upload", null); |
|
|
|
|
|
|
|
|
if (uploadMethodSelected == TAKE_PHOTO_METHOD_SELECTED) { |
|
|
for (UploadFile file : filesList) { |
|
|
TakePhoto.galleryAddPic(context, photoFileSelected); |
|
|
if (file.isCameraPhoto()) { |
|
|
|
|
|
TakePhoto.galleryAddPic(context, file.getPhotoFile()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uploadTitle.setText(null); |
|
|
uploadTitle.setText(null); |
|
|
uploadFilename.setText(null); |
|
|
uploadFilename.setText(null); |
|
|
uploadDescription.setText(null); |
|
|
uploadDescription.setText(null); |
|
|
fileUri = null; |
|
|
filesList.clear(); |
|
|
|
|
|
filesListView.removeAllViews(); |
|
|
photoFileCreated = null; |
|
|
photoFileCreated = null; |
|
|
photoFileSelected = null; |
|
|
|
|
|
progressBar.setVisibility(View.GONE); |
|
|
progressBar.setVisibility(View.GONE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -497,9 +517,6 @@ public class UploadActivity extends BaseActivity { |
|
|
if (photoFileCreated != null) { |
|
|
if (photoFileCreated != null) { |
|
|
storage.deleteFile(photoFileCreated.getAbsolutePath()); |
|
|
storage.deleteFile(photoFileCreated.getAbsolutePath()); |
|
|
} |
|
|
} |
|
|
if (photoFileSelected != null) { |
|
|
|
|
|
storage.deleteFile(photoFileSelected.getAbsolutePath()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -509,62 +526,45 @@ public class UploadActivity extends BaseActivity { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Keeps the filename between different file selections if it has been modified
|
|
|
Uri newFileUri = data.getData(); |
|
|
boolean hasCustomFilename = false; |
|
|
if (newFileUri != null) { |
|
|
{ |
|
|
String filename = FileUtils.filenameFromUri(this, newFileUri); |
|
|
String editTextFilename = FileUtils. |
|
|
|
|
|
getFilenameWithoutExtension(uploadFilename.getText().toString()); |
|
|
|
|
|
String previousFilename = ""; |
|
|
|
|
|
if (fileUri != null) { |
|
|
|
|
|
previousFilename = FileUtils. |
|
|
|
|
|
getFilenameWithoutExtension(FileUtils.filenameFromUri(this, fileUri)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (editTextFilename != null && !editTextFilename.isEmpty() && |
|
|
if (filesList.isEmpty()) { |
|
|
!editTextFilename.equals(previousFilename)) { |
|
|
if (uploadFilename.getText().toString().isEmpty()) { |
|
|
hasCustomFilename = true; |
|
|
uploadFilename.setText(filename); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Deletes any photo file previously created, as it is not going to be used
|
|
|
|
|
|
if (photoFileCreated != null) { |
|
|
|
|
|
storage.deleteFile(photoFileCreated.getAbsolutePath()); |
|
|
|
|
|
} |
|
|
|
|
|
if (photoFileSelected != null) { |
|
|
|
|
|
storage.deleteFile(photoFileSelected.getAbsolutePath()); |
|
|
|
|
|
} |
|
|
|
|
|
uploadMethodSelected = SELECT_FILE_METHOD_SELECTED; |
|
|
|
|
|
|
|
|
|
|
|
fileUri = data.getData(); |
|
|
filename = filename.toLowerCase(); |
|
|
if (fileUri != null) { |
|
|
if (filename.endsWith(".jpg")) { |
|
|
String filename = FileUtils.filenameFromUri(this, fileUri); |
|
|
fileIcon = "jpg_image.gif"; |
|
|
if (!hasCustomFilename) { |
|
|
} else if (filename.endsWith(".gif")) { |
|
|
uploadFilename.setText(filename); |
|
|
fileIcon = "gif_image.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".png")) { |
|
|
|
|
|
fileIcon = "png_image.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".html") || filename.endsWith(".htm")) { |
|
|
|
|
|
fileIcon = "html_file.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".pdf") || filename.endsWith(".doc") || |
|
|
|
|
|
filename.endsWith("djvu")) { |
|
|
|
|
|
fileIcon = "text_file.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".zip") || filename.endsWith(".rar") || |
|
|
|
|
|
filename.endsWith(".tar") || filename.endsWith(".tar.gz") || |
|
|
|
|
|
filename.endsWith(".gz")) { |
|
|
|
|
|
fileIcon = "archive.gif"; |
|
|
|
|
|
} else { |
|
|
|
|
|
fileIcon = "blank.gif"; |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
//Causes the EditText watcher to detect the fileUri change in case the extension changed
|
|
|
|
|
|
String badHack = "stringThatIntentionallyInvalidatesFilename"; |
|
|
|
|
|
uploadFilename.setText(badHack); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
filename = filename.toLowerCase(); |
|
|
|
|
|
if (filename.endsWith(".jpg")) { |
|
|
|
|
|
fileIcon = "jpg_image.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".gif")) { |
|
|
|
|
|
fileIcon = "gif_image.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".png")) { |
|
|
|
|
|
fileIcon = "png_image.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".html") || filename.endsWith(".htm")) { |
|
|
|
|
|
fileIcon = "html_file.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".pdf") || filename.endsWith(".doc") || |
|
|
|
|
|
filename.endsWith("djvu")) { |
|
|
|
|
|
fileIcon = "text_file.gif"; |
|
|
|
|
|
} else if (filename.endsWith(".zip") || filename.endsWith(".rar") || |
|
|
|
|
|
filename.endsWith(".tar") || filename.endsWith(".tar.gz") || |
|
|
|
|
|
filename.endsWith(".gz")) { |
|
|
|
|
|
fileIcon = "archive.gif"; |
|
|
fileIcon = "archive.gif"; |
|
|
} else { |
|
|
|
|
|
fileIcon = "blank.gif"; |
|
|
String currentFilename = uploadFilename.getText().toString(); |
|
|
|
|
|
String newFilename = FileUtils.getFilenameWithoutExtension(currentFilename) + |
|
|
|
|
|
".zip"; |
|
|
|
|
|
uploadFilename.setText(newFilename); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addFileViewToList(filename); |
|
|
|
|
|
filesList.add(new UploadFile(false, newFileUri, null)); |
|
|
} |
|
|
} |
|
|
} else if (requestCode == AFR_REQUEST_CODE_CAMERA) { |
|
|
} else if (requestCode == AFR_REQUEST_CODE_CAMERA) { |
|
|
if (resultCode == Activity.RESULT_CANCELED) { |
|
|
if (resultCode == Activity.RESULT_CANCELED) { |
|
@ -572,41 +572,27 @@ public class UploadActivity extends BaseActivity { |
|
|
storage.deleteFile(photoFileCreated.getAbsolutePath()); |
|
|
storage.deleteFile(photoFileCreated.getAbsolutePath()); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
uploadMethodSelected = TAKE_PHOTO_METHOD_SELECTED; |
|
|
|
|
|
|
|
|
|
|
|
//Keeps the filename between different file selections if it has been modified
|
|
|
|
|
|
boolean hasCustomFilename = false; |
|
|
|
|
|
{ |
|
|
|
|
|
String editTextFilename = FileUtils. |
|
|
|
|
|
getFilenameWithoutExtension(uploadFilename.getText().toString()); |
|
|
|
|
|
String previousFilename = ""; |
|
|
|
|
|
if (fileUri != null) { |
|
|
|
|
|
previousFilename = FileUtils. |
|
|
|
|
|
getFilenameWithoutExtension(FileUtils.filenameFromUri(this, fileUri)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (editTextFilename != null && !editTextFilename.isEmpty() && |
|
|
if (filesList.isEmpty()) { |
|
|
!editTextFilename.equals(previousFilename)) { |
|
|
if (uploadFilename.getText().toString().isEmpty()) { |
|
|
hasCustomFilename = true; |
|
|
uploadFilename.setText(photoFileCreated.getName()); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (photoFileSelected != null) { |
|
|
|
|
|
storage.deleteFile(photoFileSelected.getAbsolutePath()); |
|
|
|
|
|
} |
|
|
|
|
|
photoFileSelected = photoFileCreated; |
|
|
|
|
|
|
|
|
|
|
|
fileUri = TakePhoto.processResult(this, photoFileSelected); |
|
|
fileIcon = "jpg_image.gif"; |
|
|
|
|
|
|
|
|
if (!hasCustomFilename) { |
|
|
|
|
|
uploadFilename.setText(photoFileSelected.getName()); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
//Causes the EditText watcher to detect the fileUri change in case the extension changed
|
|
|
fileIcon = "archive.gif"; |
|
|
String badHack = "stringThatIntentionallyInvalidatesFilename"; |
|
|
|
|
|
uploadFilename.setText(badHack); |
|
|
String currentFilename = uploadFilename.getText().toString(); |
|
|
|
|
|
String newFilename = FileUtils.getFilenameWithoutExtension(currentFilename) + |
|
|
|
|
|
".zip"; |
|
|
|
|
|
uploadFilename.setText(newFilename); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fileIcon = "jpg_image.gif"; |
|
|
UploadFile newFile = new UploadFile(true, TakePhoto.processResult(this, |
|
|
|
|
|
photoFileCreated), photoFileCreated); |
|
|
|
|
|
addFileViewToList(FileUtils.getFilenameWithoutExtension(FileUtils. |
|
|
|
|
|
filenameFromUri(this, newFile.getFileUri()))); |
|
|
|
|
|
filesList.add(newFile); |
|
|
} else if (requestCode == AFR_REQUEST_CODE_FIELDS_BUILDER) { |
|
|
} else if (requestCode == AFR_REQUEST_CODE_FIELDS_BUILDER) { |
|
|
if (resultCode == Activity.RESULT_CANCELED) { |
|
|
if (resultCode == Activity.RESULT_CANCELED) { |
|
|
return; |
|
|
return; |
|
@ -651,6 +637,30 @@ public class UploadActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addFileViewToList(String filename) { |
|
|
|
|
|
LayoutInflater layoutInflater = getLayoutInflater(); |
|
|
|
|
|
LinearLayout newFileRow = (LinearLayout) layoutInflater. |
|
|
|
|
|
inflate(R.layout.activity_upload_file_list_row, null); |
|
|
|
|
|
|
|
|
|
|
|
TextView itemText = newFileRow.findViewById(R.id.upload_file_item_text); |
|
|
|
|
|
Drawable filenameDrawable = AppCompatResources.getDrawable(this, R.drawable.ic_attach_file_white_24dp); |
|
|
|
|
|
itemText.setCompoundDrawablesRelativeWithIntrinsicBounds(filenameDrawable, null, null, null); |
|
|
|
|
|
itemText.setText(filename); |
|
|
|
|
|
|
|
|
|
|
|
newFileRow.findViewById(R.id.upload_file_item_remove). |
|
|
|
|
|
setOnClickListener(view -> { |
|
|
|
|
|
int fileIndex = filesListView.indexOfChild(newFileRow); |
|
|
|
|
|
filesListView.removeViewAt(fileIndex); |
|
|
|
|
|
filesList.remove(fileIndex); |
|
|
|
|
|
if (filesList.isEmpty()) { |
|
|
|
|
|
filesListView.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
filesListView.addView(newFileRow); |
|
|
|
|
|
filesListView.setVisibility(View.VISIBLE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener { |
|
|
private class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener { |
|
|
private ArrayList<UploadCategory> parentCategories, childCategories; |
|
|
private ArrayList<UploadCategory> parentCategories, childCategories; |
|
|
|
|
|
|
|
|