Merge pull request #2844 from TeamAmaze/bugfix/2015

2015 Fix file create / rename ops
This commit is contained in:
Vishal Nehra
2021-09-27 21:11:58 +05:30
committed by GitHub
4 changed files with 11 additions and 37 deletions
@@ -103,9 +103,11 @@ public class HybridFile {
public HybridFile(OpenMode mode, String path, String name, boolean isDirectory) {
this(mode, path);
this.name = name;
if (path.startsWith(SMB_URI_PREFIX) || isSmb()) {
if (path.startsWith(SMB_URI_PREFIX) || isSmb() || isDocumentFile() || isOtgFile()) {
Uri.Builder pathBuilder = Uri.parse(this.path).buildUpon().appendEncodedPath(name);
if (isDirectory) pathBuilder.appendEncodedPath("/");
if ((path.startsWith(SMB_URI_PREFIX) || isSmb()) && isDirectory) {
pathBuilder.appendEncodedPath("/");
}
this.path = pathBuilder.build().toString();
} else if (path.startsWith(SSH_URI_PREFIX) || isSftp()) {
this.path += "/" + name;
@@ -135,9 +135,7 @@ public class Operations {
@Override
protected Void doInBackground(Void... params) {
// checking whether filename is valid or a recursive call possible
if (!Operations.isFileNameValid(file.getName(context))
&& !(file.getMode().equals(OpenMode.OTG)
|| file.getMode().equals(OpenMode.DOCUMENT_FILE))) {
if (!Operations.isFileNameValid(file.getName(context))) {
errorCallBack.invalidName(file);
return null;
}
@@ -280,9 +278,7 @@ public class Operations {
@Override
protected Void doInBackground(Void... params) {
// check whether filename is valid or not
if (!Operations.isFileNameValid(file.getName(context))
&& !(file.getMode().equals(OpenMode.OTG)
|| file.getMode().equals(OpenMode.DOCUMENT_FILE))) {
if (!Operations.isFileNameValid(file.getName(context))) {
errorCallBack.invalidName(file);
return null;
}
@@ -449,10 +445,7 @@ public class Operations {
protected Void doInBackground(Void... params) {
// check whether file names for new file are valid or recursion occurs.
// If rename is on OTG, we are skipping
if (!(oldFile.getMode().equals(newFile.getMode())
&& (oldFile.getMode().equals(OpenMode.OTG)
|| oldFile.getMode().equals(OpenMode.DOCUMENT_FILE)))
&& !Operations.isFileNameValid(newFile.getName(context))) {
if (!Operations.isFileNameValid(newFile.getName(context))) {
errorCallBack.invalidName(newFile);
return null;
}
@@ -1312,11 +1312,7 @@ public class MainFragment extends Fragment
.rename(
mainFragmentViewModel.getOpenMode(),
f.getPath(),
Uri.parse(mainFragmentViewModel.getCurrentPath())
.buildUpon()
.appendEncodedPath(name1)
.build()
.toString(),
mainFragmentViewModel.getCurrentPath(),
name1,
f.isDirectory(),
getActivity(),
@@ -1414,7 +1410,7 @@ public class MainFragment extends Fragment
loadlist(currentFile.getPath(), false, mainFragmentViewModel.getOpenMode());
} else {
List<String> pathSegments = Uri.parse(currentFile.getPath()).getPathSegments();
if (pathSegments.size() < 4) {
if (pathSegments.size() < 3) {
mainFragmentViewModel.setOpenMode(OpenMode.FILE);
String subPath = pathSegments.get(1);
currentFile.setMode(OpenMode.FILE);
@@ -69,7 +69,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@@ -162,15 +161,7 @@ public class MainActivityHelper {
EditText textfield = dialog.getCustomView().findViewById(R.id.singleedittext_input);
mkDir(
new HybridFile(openMode, path),
new HybridFile(
openMode,
Uri.parse(path)
.buildUpon()
.appendEncodedPath(textfield.getText().toString().trim())
.build()
.toString(),
textfield.getText().toString().trim(),
true),
new HybridFile(openMode, path, textfield.getText().toString().trim(), true),
ma);
dialog.dismiss();
},
@@ -203,15 +194,7 @@ public class MainActivityHelper {
EditText textfield = dialog.getCustomView().findViewById(R.id.singleedittext_input);
mkFile(
new HybridFile(openMode, path),
new HybridFile(
openMode,
Uri.parse(path)
.buildUpon()
.appendEncodedPath(textfield.getText().toString().trim())
.build()
.toString(),
textfield.getText().toString().trim(),
false),
new HybridFile(openMode, path, textfield.getText().toString().trim(), false),
ma);
dialog.dismiss();
},