fix #247, add an extra check about write permissions when saving note content

This commit is contained in:
tibbi 2018-12-27 15:41:56 +01:00
parent 30fcf9d0f4
commit f153b78b42
2 changed files with 13 additions and 5 deletions

View File

@ -467,7 +467,7 @@ class MainActivity : SimpleActivity() {
} else if (mCurrentNote.type == TYPE_TEXT) { } else if (mCurrentNote.type == TYPE_TEXT) {
showExportFilePickUpdateDialog(it, textToExport) showExportFilePickUpdateDialog(it, textToExport)
} else { } else {
exportNoteValueToFile(it, textToExport, true) tryExportNoteValueToFile(it, textToExport, true)
} }
} }
} }
@ -479,7 +479,7 @@ class MainActivity : SimpleActivity() {
RadioGroupDialog(this, items) { RadioGroupDialog(this, items) {
val syncFile = it as Int == EXPORT_FILE_SYNC val syncFile = it as Int == EXPORT_FILE_SYNC
exportNoteValueToFile(exportPath, textToExport, true) { tryExportNoteValueToFile(exportPath, textToExport, true) {
if (syncFile) { if (syncFile) {
mCurrentNote.path = exportPath mCurrentNote.path = exportPath
@ -512,7 +512,7 @@ class MainActivity : SimpleActivity() {
if (!filename.isAValidFilename()) { if (!filename.isAValidFilename()) {
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename))) toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
} else { } else {
exportNoteValueToFile(file.absolutePath, note.value, false) { tryExportNoteValueToFile(file.absolutePath, note.value, false) {
if (!it) { if (!it) {
failCount++ failCount++
} }
@ -527,7 +527,15 @@ class MainActivity : SimpleActivity() {
} }
} }
fun exportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) { fun tryExportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
exportNoteValueToFile(path, content, showSuccessToasts, callback)
}
}
}
private fun exportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
try { try {
if (getIsPathDirectory(path)) { if (getIsPathDirectory(path)) {
toast(R.string.name_taken) toast(R.string.name_taken)

View File

@ -194,7 +194,7 @@ class TextFragment : NoteFragment() {
val currentText = getCurrentNoteViewText() val currentText = getCurrentNoteViewText()
if (currentText != null) { if (currentText != null) {
val displaySuccess = activity?.config?.displaySuccess ?: false val displaySuccess = activity?.config?.displaySuccess ?: false
(activity as? MainActivity)?.exportNoteValueToFile(note.path, currentText, displaySuccess) (activity as? MainActivity)?.tryExportNoteValueToFile(note.path, currentText, displaySuccess)
} }
} }
} }