Skip to content

Commit

Permalink
Fixes for renamed remotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Jul 15, 2020
1 parent 6bcca4c commit 9beaaaf
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 28 deletions.
13 changes: 8 additions & 5 deletions app/src/main/java/ca/pkay/rcloneexplorer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import static ca.pkay.rcloneexplorer.ActivityHelper.tryStartActivity;
import static ca.pkay.rcloneexplorer.ActivityHelper.tryStartActivityForResult;
Expand Down Expand Up @@ -742,7 +743,7 @@ protected boolean isRequired() {
FLog.d(TAG, "Storage volumes not changed, no refresh required");
return false;
} else {
FLog.d(TAG, "Storage volumnes changed, refresh required");
FLog.d(TAG, "Storage volumes changed, refresh required");
externalVolumes = current;
persisted = TextUtils.join("|", current);
PreferenceManager.getDefaultSharedPreferences(context).edit()
Expand Down Expand Up @@ -815,18 +816,19 @@ private File getVolumeRoot(File file) {
private void addLocalRemote(File root) throws IOException {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
String name = root.getCanonicalPath();
String id = UUID.randomUUID().toString();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StorageManager storageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
StorageVolume storageVolume = storageManager.getStorageVolume(root);
String description = storageVolume != null ? storageVolume.getDescription(context) : null;
if (description != null) {
name = rclone.getUniqueRemoteName(description);
name = description;
}
}

String path = root.getAbsolutePath();
ArrayList<String> options = new ArrayList<>();
options.add(name);
options.add(id);
options.add("alias");
options.add("remote");
options.add(path);
Expand All @@ -842,10 +844,11 @@ private void addLocalRemote(File root) throws IOException {
FLog.e(TAG, "addLocalRemote: process error", e);
return;
}
rclone.renameRemote(id, name);
Set<String> pinnedRemotes = pref.getStringSet(getString(R.string.shared_preferences_drawer_pinned_remotes), new HashSet<>());
Set<String> generatedRemotes = pref.getStringSet(getString(R.string.pref_key_local_alias_remotes), new HashSet<>());
pinnedRemotes.add(name);
generatedRemotes.add(name);
pinnedRemotes.add(id);
generatedRemotes.add(id);
pref.edit()
.putStringSet(getString(R.string.shared_preferences_drawer_pinned_remotes), pinnedRemotes)
.putStringSet(getString(R.string.pref_key_local_alias_remotes), generatedRemotes)
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.github.x0b.safdav.SafDAVServer;
import io.github.x0b.safdav.file.SafConstants;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -1186,23 +1185,6 @@ public void renameRemote(String remoteName, String displayName) {
.apply();
}

public String getUniqueRemoteName(String desiredName) {
List<RemoteItem> remotes = getRemotes();
Set<String> remoteNames = new HashSet<>(remotes.size());
for (RemoteItem remoteItem : remotes) {
remoteNames.add(remoteItem.getName());
}
if (!remoteNames.contains(desiredName)) {
return desiredName;
}
for (int i = 1;;++i) {
String remoteName = desiredName + " " + i;
if (!remoteNames.contains(remoteName)) {
return remoteName;
}
}
}

/**
* Prefixes local remotes with a base path on the primary external storage.
* @param item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void setRemote() {
String[] options = new String[remotes.size()];
int i = 0;
for (RemoteItem remote : remotes) {
options[i++] = remote.getName();
options[i++] = remote.getDisplayName();
}

AlertDialog.Builder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void setRemote() {
String[] options = new String[remotes.size()];
int i = 0;
for (RemoteItem remote : remotes) {
options[i++] = remote.getName();
options[i++] = remote.getDisplayName();
}

AlertDialog.Builder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void setRemote() {
String[] options = new String[remotes.size()];
int i = 0;
for (RemoteItem remote : remotes) {
options[i++] = remote.getName();
options[i++] = remote.getDisplayName();
}

AlertDialog.Builder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void addRemote() {
String[] options = new String[configuredRemotes.size()];
int i = 0;
for (RemoteItem remote : configuredRemotes) {
options[i++] = remote.getName();
options[i++] = remote.getDisplayName();
}

AlertDialog.Builder builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private void showAppShortcutDialog() {
final CharSequence[] options = new CharSequence[remotes.size()];
int i = 0;
for (RemoteItem remoteItem : remotes) {
options[i++] = remoteItem.getName();
options[i++] = remoteItem.getDisplayName();
}

final ArrayList<String> userSelected = new ArrayList<>();
Expand Down

0 comments on commit 9beaaaf

Please sign in to comment.