Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookmark Crashed Issue Fixed #4154

Open
wants to merge 2 commits into
base: release/4.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package com.amaze.filemanager.ui.fragments.preferencefragments
import android.os.Bundle
import android.text.Editable
import android.view.LayoutInflater
import android.widget.Toast
import androidx.appcompat.widget.AppCompatEditText
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
Expand Down Expand Up @@ -114,29 +115,50 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
disableButtonIfNotPath(txtShortcutPath, dialog)
dialog.getActionButton(DialogAction.POSITIVE)
.setOnClickListener {
val p = PathSwitchPreference(activity, itemOnEditListener, itemOnDeleteListener)
p.title = txtShortcutName.text
p.summary = txtShortcutPath.text
position[p] = dataUtils.books.size
bookmarksList?.addPreference(p)
val values =
arrayOf(
txtShortcutName.text.toString(),
txtShortcutPath.text.toString(),
val result = isValidBookmark(txtShortcutName.text.toString(), txtShortcutPath.text.toString())
if (!result.first) {
Toast.makeText(
requireContext(),
requireContext().getString(result.second),
Toast.LENGTH_SHORT,
).show()
} else {
val p = PathSwitchPreference(activity, itemOnEditListener, itemOnDeleteListener)
p.title = txtShortcutName.text
p.summary = txtShortcutPath.text
position[p] = dataUtils.books.size
bookmarksList?.addPreference(p)
val values =
arrayOf(
txtShortcutName.text.toString(),
txtShortcutPath.text.toString(),
)
dataUtils.addBook(values)
utilsHandler.saveToDatabase(
OperationData(
UtilsHandler.Operation.BOOKMARKS,
txtShortcutName.text.toString(),
txtShortcutPath.text.toString(),
),
)
dataUtils.addBook(values)
utilsHandler.saveToDatabase(
OperationData(
UtilsHandler.Operation.BOOKMARKS,
txtShortcutName.text.toString(),
txtShortcutPath.text.toString(),
),
)
dialog.dismiss()
dialog.dismiss()
}
}
dialog.show()
}

private fun isValidBookmark(
name: String,
path: String,
): Pair<Boolean, Int> {
return when {
name.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)
}
}

private fun showEditDialog(p: PathSwitchPreference) {
val fabSkin = activity.accent
val utilsHandler = AppConfig.getInstance().utilsHandler
Expand Down