Merge pull request #514 from Aga-C/fix-export-toast

Fixed wrong title in export toast
This commit is contained in:
Tibor Kaputa 2022-03-08 18:21:03 +01:00 committed by GitHub
commit 4f24a2d93e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -864,7 +864,7 @@ class MainActivity : SimpleActivity() {
} else if (mCurrentNote.type == NoteType.TYPE_TEXT.value) {
showExportFilePickUpdateDialog(it, textToExport)
} else {
tryExportNoteValueToFile(it, textToExport, true)
tryExportNoteValueToFile(it, mCurrentNote.title, textToExport, true)
}
}
}
@ -949,7 +949,7 @@ class MainActivity : SimpleActivity() {
RadioGroupDialog(this, items) {
val syncFile = it as Int == EXPORT_FILE_SYNC
tryExportNoteValueToFile(exportPath, textToExport, true) { exportedSuccessfully ->
tryExportNoteValueToFile(exportPath, mCurrentNote.title, textToExport, true) { exportedSuccessfully ->
if (exportedSuccessfully) {
if (syncFile) {
mCurrentNote.path = exportPath
@ -995,7 +995,7 @@ class MainActivity : SimpleActivity() {
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
} else {
val noteStoredValue = note.getNoteStoredValue(this) ?: ""
tryExportNoteValueToFile(file.absolutePath, note.value, false) { exportedSuccessfully ->
tryExportNoteValueToFile(file.absolutePath, mCurrentNote.title, note.value, false) { exportedSuccessfully ->
if (exportedSuccessfully) {
if (syncFile) {
note.path = file.absolutePath
@ -1029,9 +1029,9 @@ class MainActivity : SimpleActivity() {
}
}
fun tryExportNoteValueToFile(path: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
fun tryExportNoteValueToFile(path: String, title: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
if (path.startsWith("content://")) {
exportNoteValueToUri(Uri.parse(path), content, callback)
exportNoteValueToUri(Uri.parse(path), title, content, showSuccessToasts, callback)
} else {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
@ -1084,13 +1084,15 @@ class MainActivity : SimpleActivity() {
}
}
private fun exportNoteValueToUri(uri: Uri, content: String, callback: ((success: Boolean) -> Unit)? = null) {
private fun exportNoteValueToUri(uri: Uri, title: String, content: String, showSuccessToasts: Boolean, callback: ((success: Boolean) -> Unit)? = null) {
try {
val outputStream = contentResolver.openOutputStream(uri, "rwt")
outputStream!!.bufferedWriter().use { out ->
out.write(content)
}
noteExportedSuccessfully(mCurrentNote.title)
if (showSuccessToasts) {
noteExportedSuccessfully(title)
}
callback?.invoke(true)
} catch (e: Exception) {
showErrorToast(e)

View File

@ -43,7 +43,7 @@ abstract class NoteFragment : Fragment() {
} else {
if (content != null) {
val displaySuccess = activity?.config?.displaySuccess ?: false
(activity as? MainActivity)?.tryExportNoteValueToFile(note.path, content, displaySuccess)
(activity as? MainActivity)?.tryExportNoteValueToFile(note.path, note.title, content, displaySuccess)
}
}
}