Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
path: String,
): Pair<Boolean, Int> {
return when {
name.isEmpty() -> Pair(false, R.string.invalid_name)
name.isEmpty() || path.isEmpty() -> Pair(false, R.string.invalid_name)
dataUtils.containsBooks(arrayOf(name, path)) != -1 -> Pair(false, R.string.bookmark_exists)
!FileUtils.isPathAccessible(path, activity.prefs) -> Pair(false, R.string.ftp_path_change_error_invalid)
else -> Pair(true, 0)
Expand Down Expand Up @@ -190,6 +190,17 @@
.setOnClickListener {
val oldName = p.title.toString()
val oldPath = p.summary.toString()

val result = isValidBookmark(editText1.text.toString(), editText2.text.toString())
if (!result.first) {
Toast.makeText(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a snackbar per Android guidelines https://developer.android.com/guide/topics/ui/notifiers/toasts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I feel like a toast is better in this scenario since snackbar appears below the keyboard. WDYT?

(ideally we should surface this to the dialog box itself like the create dialog - which I guess can be tracked later)

requireContext(),
requireContext().getString(result.second),
Toast.LENGTH_SHORT,
).show()
return@setOnClickListener

Check warning on line 201 in app/src/main/java/com/amaze/filemanager/ui/fragments/preferencefragments/BookmarksPrefsFragment.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/amaze/filemanager/ui/fragments/preferencefragments/BookmarksPrefsFragment.kt#L201

Expression with labels increase complexity and affect maintainability.
}

dataUtils.removeBook(position[p]!!)
position.remove(p)
bookmarksList?.removePreference(p)
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/java/com/amaze/filemanager/utils/DataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,25 @@ public void registerOnDataChangedListener(DataChangeListener l) {
clear();
}

int contains(String a, ArrayList<String[]> b) {
int i = 0;
for (String[] x : b) {
if (x[1].equals(a)) return i;
i++;
}
return -1;
}

int contains(String[] a, ArrayList<String[]> b) {
if (b == null) return -1;
/**
* Searches pair list of {@code {name, path}} pairs for an entry that matches the given pair by
* <em>either</em> name or path. An entry is considered pair match when its name (index 0) equals
* {@code pair[0]} or its path (index 1) equals {@code pair[1]}.
*
* <p>Both should be unique since we cannot have two items with the same name. But this prevents
* two bookmarks / servers pointing to the same path with different names.
*
* @param pair the {@code {name, path}} pair to search for
* @param list the list to search; each element is expected to be pair two-element {@code {name,
* path}} array. May be {@code null}.
* @return the index of the first matching entry, or {@code -1} if {@code list} is {@code null} or
* no entry matches
*/
int contains(String[] pair, ArrayList<String[]> list) {
if (list == null) return -1;
int i = 0;
for (String[] x : b) {
if (x[0].equals(a[0]) && x[1].equals(a[1])) return i;
for (String[] item : list) {
if (item[0].equals(pair[0]) || item[1].equals(pair[1])) return i;
i++;
}
return -1;
Expand Down
Loading