mirror of
https://github.com/TeamAmaze/AmazeFileManager.git
synced 2026-10-17 05:08:00 +08:00
Merge pull request #4343 from TeamAmaze/bookmark-dialog-fix
better input validation for bookmarks dialog
This commit is contained in:
+14
-1
@@ -152,7 +152,7 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
|
||||
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)
|
||||
@@ -190,6 +190,19 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
|
||||
.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(
|
||||
requireContext(),
|
||||
requireContext().getString(result.second),
|
||||
Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
|
||||
@Suppress("LabeledExpression")
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
dataUtils.removeBook(position[p]!!)
|
||||
position.remove(p)
|
||||
bookmarksList?.removePreference(p)
|
||||
|
||||
@@ -284,20 +284,25 @@ public class DataUtils {
|
||||
clear();
|
||||
}
|
||||
|
||||
int contains(String a, ArrayList<String[]> b) {
|
||||
/**
|
||||
* 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[1].equals(a)) return i;
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int contains(String[] a, ArrayList<String[]> b) {
|
||||
if (b == 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;
|
||||
|
||||
Reference in New Issue
Block a user