Skip to content

Commit cb9293c

Browse files
authored
Merge pull request #55 from kaczmarkiewiczp/dev
Bug fixes
2 parents 6e758a6 + 95a142c commit cb9293c

File tree

6 files changed

+95
-51
lines changed

6 files changed

+95
-51
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "ca.pkay.rcloneexplorer"
77
minSdkVersion 21
88
targetSdkVersion 27
9-
versionCode 7
10-
versionName "1.1.0"
9+
versionCode 8
10+
versionName "1.1.1"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/src/main/assets/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 1.1.1
2+
* **Fix:** Hide hash calculations for crypt remotes
3+
* **Fix:** Crash when rclone fails
4+
5+
***
6+
17
### 1.1.0
28
* **New:** Support password protected configurations
39
* **New:** Calculate file MD5 & SHA1

app/src/main/java/ca/pkay/rcloneexplorer/FilePropertiesDialog.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public class FilePropertiesDialog extends DialogFragment {
2828
private AsyncTask[] asyncTasks;
2929
private String md5String;
3030
private String sha1String;
31+
private Boolean showHash;
3132
private Context context;
3233

34+
public FilePropertiesDialog() {
35+
showHash = true;
36+
}
37+
3338
@NonNull
3439
@Override
3540
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -43,15 +48,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
4348
if (fileItem.isDir()) {
4449
view.findViewById(R.id.file_size).setVisibility(View.GONE);
4550
view.findViewById(R.id.file_size_label).setVisibility(View.GONE);
46-
47-
view.findViewById(R.id.file_md5_container).setVisibility(View.GONE);
48-
view.findViewById(R.id.file_sha1_container).setVisibility(View.GONE);
49-
view.findViewById(R.id.hash_separator).setVisibility(View.GONE);
5051
} else {
5152
view.findViewById(R.id.file_size).setVisibility(View.VISIBLE);
5253
view.findViewById(R.id.file_size_label).setVisibility(View.VISIBLE);
5354
((TextView)view.findViewById(R.id.file_size)).setText(fileItem.getHumanReadableSize());
55+
}
5456

57+
if (showHash && !fileItem.isDir()) {
5558
view.findViewById(R.id.file_md5_container).setVisibility(View.VISIBLE);
5659
view.findViewById(R.id.file_sha1_container).setVisibility(View.VISIBLE);
5760
view.findViewById(R.id.hash_separator).setVisibility(View.VISIBLE);
@@ -68,6 +71,10 @@ public void onClick(View v) {
6871
calculateSHA1();
6972
}
7073
});
74+
} else {
75+
view.findViewById(R.id.file_md5_container).setVisibility(View.GONE);
76+
view.findViewById(R.id.file_sha1_container).setVisibility(View.GONE);
77+
view.findViewById(R.id.hash_separator).setVisibility(View.GONE);
7178
}
7279

7380
builder.setView(view)
@@ -95,6 +102,11 @@ public FilePropertiesDialog setRclone(Rclone rclone) {
95102
return this;
96103
}
97104

105+
public FilePropertiesDialog withHashCalculations(Boolean showHash) {
106+
this.showHash = showHash;
107+
return this;
108+
}
109+
98110
private void calculateMD5() {
99111
// md5 already calculated
100112
if (md5String != null && !md5String.isEmpty()) {

app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java

+48-28
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ private void showFileProperties() {
295295
.setFile(fileItem)
296296
.setRclone(rclone)
297297
.setRemote(remote);
298+
if (remoteType.equals("crypt")) {
299+
filePropertiesDialog.withHashCalculations(false);
300+
}
298301
if (getFragmentManager() != null) {
299302
filePropertiesDialog.show(getFragmentManager(), "file properties");
300303
}
@@ -817,6 +820,10 @@ protected List<FileItem> doInBackground(Void... voids) {
817820
@Override
818821
protected void onPostExecute(List<FileItem> fileItems) {
819822
super.onPostExecute(fileItems);
823+
if (fileItems == null) {
824+
Toasty.error(context, getString(R.string.error_getting_dir_content), Toast.LENGTH_SHORT, true).show();
825+
fileItems = new ArrayList<>();
826+
}
820827
directoryContent = fileItems;
821828
sortDirectory();
822829
directoryCache.put(path, new ArrayList<>(directoryContent));
@@ -840,7 +847,7 @@ protected void onCancelled() {
840847
}
841848

842849
@SuppressLint("StaticFieldLeak")
843-
private class RenameFileTask extends AsyncTask<String, Void, Void> {
850+
private class RenameFileTask extends AsyncTask<String, Void, Boolean> {
844851

845852
private String pathWhenTaskStarted;
846853

@@ -852,21 +859,25 @@ protected void onPreExecute() {
852859
}
853860

854861
@Override
855-
protected Void doInBackground(String... strings) {
862+
protected Boolean doInBackground(String... strings) {
856863
String oldFileName = strings[0];
857864
String newFileName = strings[1];
858865

859-
rclone.moveTo(remote, oldFileName, newFileName);
860-
return null;
866+
return rclone.moveTo(remote, oldFileName, newFileName);
861867
}
862868

863869
@Override
864-
protected void onPostExecute(Void aVoid) {
865-
super.onPostExecute(aVoid);
870+
protected void onPostExecute(Boolean result) {
871+
super.onPostExecute(result);
866872
if (!isRunning) {
867873
return;
868874
}
869-
Toasty.success(context, getString(R.string.file_renamed_success), Toast.LENGTH_SHORT, true).show();
875+
if (result) {
876+
Toasty.success(context, getString(R.string.file_renamed_success), Toast.LENGTH_SHORT, true).show();
877+
} else {
878+
Toasty.error(context, getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
879+
880+
}
870881
if (!pathWhenTaskStarted.equals(path)) {
871882
directoryCache.remove(pathWhenTaskStarted);
872883
return;
@@ -881,7 +892,7 @@ protected void onPostExecute(Void aVoid) {
881892
}
882893

883894
@SuppressLint("StaticFieldLeak")
884-
private class MoveTask extends AsyncTask<Void, Void, Void> {
895+
private class MoveTask extends AsyncTask<Void, Void, Boolean> {
885896

886897
private String pathWhenTaskStarted;
887898

@@ -893,18 +904,21 @@ protected void onPreExecute() {
893904
}
894905

895906
@Override
896-
protected Void doInBackground(Void... voids) {
897-
rclone.moveTo(remote, moveList, path);
898-
return null;
907+
protected Boolean doInBackground(Void... voids) {
908+
return rclone.moveTo(remote, moveList, path);
899909
}
900910

901911
@Override
902-
protected void onPostExecute(Void aVoid) {
903-
super.onPostExecute(aVoid);
912+
protected void onPostExecute(Boolean result) {
913+
super.onPostExecute(result);
904914
if (!isRunning) {
905915
return;
906916
}
907-
Toasty.success(context, getString(R.string.files_moved_success), Toast.LENGTH_SHORT, true).show();
917+
if (result) {
918+
Toasty.success(context, getString(R.string.files_moved_success), Toast.LENGTH_SHORT, true).show();
919+
} else {
920+
Toasty.error(context, getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
921+
}
908922
if (!pathWhenTaskStarted.equals(path)) {
909923
directoryCache.remove(pathWhenTaskStarted);
910924
return;
@@ -920,7 +934,7 @@ protected void onPostExecute(Void aVoid) {
920934
}
921935

922936
@SuppressLint("StaticFieldLeak")
923-
private class DeleteFilesTask extends AsyncTask<List, Void, Void> {
937+
private class DeleteFilesTask extends AsyncTask<List, Void, Boolean> {
924938

925939
private String pathWhenTaskStarted;
926940

@@ -933,19 +947,22 @@ protected void onPreExecute() {
933947
}
934948

935949
@Override
936-
protected Void doInBackground(List[] lists) {
950+
protected Boolean doInBackground(List[] lists) {
937951
List<FileItem> list = lists[0];
938-
rclone.deleteItems(remote, list);
939-
return null;
952+
return rclone.deleteItems(remote, list);
940953
}
941954

942955
@Override
943-
protected void onPostExecute(Void aVoid) {
944-
super.onPostExecute(aVoid);
956+
protected void onPostExecute(Boolean result) {
957+
super.onPostExecute(result);
945958
if (!isRunning) {
946959
return;
947960
}
948-
Toasty.success(context, getString(R.string.files_deleted_success), Toast.LENGTH_SHORT, true).show();
961+
if (result) {
962+
Toasty.success(context, getString(R.string.files_deleted_success), Toast.LENGTH_SHORT, true).show();
963+
} else {
964+
Toasty.error(context, getString(R.string.error_deleting_file), Toast.LENGTH_SHORT, true).show();
965+
}
949966
if (!pathWhenTaskStarted.equals(path)) {
950967
directoryCache.remove(pathWhenTaskStarted);
951968
return;
@@ -960,7 +977,7 @@ protected void onPostExecute(Void aVoid) {
960977
}
961978

962979
@SuppressLint("StaticFieldLeak")
963-
private class MakeDirectoryTask extends AsyncTask<String, Void, Void> {
980+
private class MakeDirectoryTask extends AsyncTask<String, Void, Boolean> {
964981

965982
private String pathWhenTaskStarted;
966983

@@ -972,19 +989,22 @@ protected void onPreExecute() {
972989
}
973990

974991
@Override
975-
protected Void doInBackground(String... strings) {
992+
protected Boolean doInBackground(String... strings) {
976993
String newDir = strings[0];
977-
rclone.makeDirectory(remote, newDir);
978-
return null;
994+
return rclone.makeDirectory(remote, newDir);
979995
}
980996

981997
@Override
982-
protected void onPostExecute(Void aVoid) {
983-
super.onPostExecute(aVoid);
998+
protected void onPostExecute(Boolean result) {
999+
super.onPostExecute(result);
9841000
if (!isRunning) {
9851001
return;
9861002
}
987-
Toasty.success(context, getString(R.string.make_directory_success), Toast.LENGTH_SHORT, true).show();
1003+
if (result) {
1004+
Toasty.success(context, getString(R.string.make_directory_success), Toast.LENGTH_SHORT, true).show();
1005+
} else {
1006+
Toasty.error(context, getString(R.string.error_mkdir), Toast.LENGTH_SHORT, true).show();
1007+
}
9881008
if (!pathWhenTaskStarted.equals(path)) {
9891009
directoryCache.remove(pathWhenTaskStarted);
9901010
return;

app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public List<FileItem> getDirectoryContent(String remote, String path) {
6565
process = Runtime.getRuntime().exec(command);
6666
process.waitFor();
6767
if (process.exitValue() != 0) {
68-
Toasty.error(context, context.getString(R.string.error_getting_dir_content), Toast.LENGTH_SHORT, true).show();
69-
return new ArrayList<>();
68+
return null;
7069
}
7170

7271
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
@@ -80,7 +79,7 @@ public List<FileItem> getDirectoryContent(String remote, String path) {
8079

8180
} catch (IOException | InterruptedException | JSONException e) {
8281
e.printStackTrace();
83-
return new ArrayList<>();
82+
return null;
8483
}
8584

8685
List<FileItem> fileItemList = new ArrayList<>();
@@ -98,8 +97,7 @@ public List<FileItem> getDirectoryContent(String remote, String path) {
9897
fileItemList.add(fileItem);
9998
} catch (JSONException e) {
10099
e.printStackTrace();
101-
Toasty.error(context, context.getString(R.string.error_getting_dir_content), Toast.LENGTH_SHORT, true).show();
102-
return new ArrayList<>();
100+
return null;
103101
}
104102
}
105103
return fileItemList;
@@ -226,9 +224,10 @@ public List<Process> uploadFiles(String remote, String uploadPath, ArrayList<Str
226224
return runningProcesses;
227225
}
228226

229-
public void deleteItems(String remote, List<FileItem> deleteList) {
227+
public Boolean deleteItems(String remote, List<FileItem> deleteList) {
230228
String[] command;
231229
String filePath;
230+
Boolean result = true;
232231

233232
for (FileItem item : deleteList) {
234233
filePath = remote + ":" + item.getPath();
@@ -242,34 +241,37 @@ public void deleteItems(String remote, List<FileItem> deleteList) {
242241
Process process = Runtime.getRuntime().exec(command);
243242
process.waitFor();
244243
if (process.exitValue() != 0) {
245-
Toasty.error(context, context.getString(R.string.error_deleting_file), Toast.LENGTH_SHORT, true).show();
244+
result = false;
246245
}
247246
} catch (IOException | InterruptedException e) {
248247
e.printStackTrace();
249-
Toasty.error(context, context.getString(R.string.error_deleting_file), Toast.LENGTH_SHORT, true).show();
248+
result = false;
250249
}
251250
}
251+
return result;
252252
}
253253

254-
public void makeDirectory(String remote, String path) {
254+
public Boolean makeDirectory(String remote, String path) {
255255
String newDir = remote + ":" + path;
256256
String[] command = createCommand("mkdir", newDir);
257257
try {
258258
Process process = Runtime.getRuntime().exec(command);
259259
process.waitFor();
260260
if (process.exitValue() != 0) {
261-
Toasty.error(context, context.getString(R.string.error_mkdir), Toast.LENGTH_SHORT, true).show();
261+
return false;
262262
}
263263
} catch (IOException | InterruptedException e) {
264264
e.printStackTrace();
265-
Toasty.error(context, context.getString(R.string.error_mkdir), Toast.LENGTH_SHORT, true).show();
265+
return false;
266266
}
267+
return true;
267268
}
268269

269-
public void moveTo(String remote, List<FileItem> moveList, String newLocation) {
270+
public Boolean moveTo(String remote, List<FileItem> moveList, String newLocation) {
270271
String[] command;
271272
String oldFilePath;
272273
String newFilePath;
274+
Boolean result = true;
273275

274276
for (FileItem fileItem : moveList) {
275277
oldFilePath = remote + ":" + fileItem.getPath();
@@ -279,27 +281,31 @@ public void moveTo(String remote, List<FileItem> moveList, String newLocation) {
279281
Process process = Runtime.getRuntime().exec(command);
280282
process.waitFor();
281283
if (process.exitValue() != 0) {
282-
Toasty.error(context, context.getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
284+
result = false;
283285
}
284286
} catch (IOException | InterruptedException e) {
285287
e.printStackTrace();
286-
Toasty.error(context, context.getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
288+
result = false;
287289
}
288290
}
291+
return result;
289292
}
290293

291-
public void moveTo(String remote, String oldFile, String newFile) {
294+
public Boolean moveTo(String remote, String oldFile, String newFile) {
292295
String oldFilePath = remote + ":" + oldFile;
293296
String newFilePath = remote + ":" + newFile;
294297
String[] command = createCommand("moveto", oldFilePath, newFilePath);
295298
try {
296299
Process process = Runtime.getRuntime().exec(command);
297300
process.waitFor();
298-
Toasty.error(context, context.getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
301+
if (process.exitValue() != 0) {
302+
return false;
303+
}
299304
} catch (IOException | InterruptedException e) {
300305
e.printStackTrace();
301-
Toasty.error(context, context.getString(R.string.error_moving_file), Toast.LENGTH_SHORT, true).show();
306+
return false;
302307
}
308+
return true;
303309
}
304310

305311
public String calculateMD5(String remote, FileItem fileItem) {

0 commit comments

Comments
 (0)