mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 22:25:44 +03:00
Check file name before add new file
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
199cd2bbd8
commit
15f9fcce25
3 changed files with 25 additions and 4 deletions
|
@ -53,7 +53,7 @@ object FileNameValidator {
|
|||
reservedWindowsNames.contains(name.removeFileExtension().uppercase())
|
||||
)
|
||||
) {
|
||||
return context.getString(R.string.file_name_validator_error_reserved_names)
|
||||
return context.getString(R.string.file_name_validator_error_reserved_names, name.substringBefore("."))
|
||||
}
|
||||
|
||||
if (capability.forbiddenFilenameExtension.isTrue) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker;
|
|||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.utils.extensions.ActivityExtensionsKt;
|
||||
import com.nextcloud.utils.extensions.FileExtensionsKt;
|
||||
import com.nextcloud.utils.fileNameValidator.FileNameValidator;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.databinding.UploadFilesLayoutBinding;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -642,8 +643,15 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
|
|||
|
||||
finish();
|
||||
} else {
|
||||
new CheckAvailableSpaceTask(this, mFileListFragment.getCheckedFilePaths())
|
||||
.execute(binding.uploadFilesSpinnerBehaviour.getSelectedItemPosition() == 0);
|
||||
String[] selectedFilePaths = mFileListFragment.getCheckedFilePaths();
|
||||
String filenameErrorMessage = checkFileNameBeforeUpload(selectedFilePaths);
|
||||
if (filenameErrorMessage != null) {
|
||||
DisplayUtils.showSnackMessage(this, filenameErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isPositionZero = (binding.uploadFilesSpinnerBehaviour.getSelectedItemPosition() == 0);
|
||||
new CheckAvailableSpaceTask(this, selectedFilePaths).execute(isPositionZero);
|
||||
}
|
||||
} else {
|
||||
requestPermissions();
|
||||
|
@ -651,6 +659,19 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
|
|||
}
|
||||
}
|
||||
|
||||
private String checkFileNameBeforeUpload(String[] selectedFilePaths) {
|
||||
for (String filePath : selectedFilePaths) {
|
||||
File file = new File(filePath);
|
||||
String filenameErrorMessage = FileNameValidator.INSTANCE.isValid(file.getName(), getCapabilities(), this, null);
|
||||
|
||||
if (filenameErrorMessage != null) {
|
||||
return filenameErrorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirmation(String callerTag) {
|
||||
Log_OC.d(TAG, "Positive button in dialog was clicked; dialog tag is " + callerTag);
|
||||
|
|
|
@ -1222,6 +1222,6 @@
|
|||
|
||||
<string name="file_name_validator_error_copy_or_move">Folder path contains reserved names or invalid character</string>
|
||||
<string name="file_name_validator_error_invalid_character">File name contains invalid characters: %s</string>
|
||||
<string name="file_name_validator_error_reserved_names">File name is a reserved name</string>
|
||||
<string name="file_name_validator_error_reserved_names">%s is a reserved name</string>
|
||||
<string name="file_name_validator_error_ends_with_space_period">File name ends with a space or a period</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue