mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-19 01:37:22 +02:00
save note to file at pause, if its a file note
This commit is contained in:
parent
6585cf0b2f
commit
c5fc3d2bd5
@ -186,32 +186,39 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
|
|
||||||
private fun saveAsFile() {
|
private fun saveAsFile() {
|
||||||
SaveAsDialog(this, mCurrentNote.title) {
|
SaveAsDialog(this, mCurrentNote.title) {
|
||||||
val file = File(it)
|
saveNoteValueToFile(it, getCurrentNoteText())
|
||||||
if (file.isDirectory) {
|
}
|
||||||
toast(R.string.directory_exists)
|
|
||||||
return@SaveAsDialog
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val text = getCurrentNoteText()
|
fun saveNoteValueToFile(path: String, content: String) {
|
||||||
if (needsStupidWritePermissions(it)) {
|
try {
|
||||||
if (isShowingPermDialog(file))
|
val file = File(path)
|
||||||
return@SaveAsDialog
|
if (file.isDirectory) {
|
||||||
|
toast(R.string.directory_exists)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var document = getFileDocument(it, config.treeUri) ?: return@SaveAsDialog
|
if (needsStupidWritePermissions(path)) {
|
||||||
|
if (isShowingPermDialog(file))
|
||||||
|
return
|
||||||
|
|
||||||
|
var document = getFileDocument(path, config.treeUri) ?: return
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
document = document.createFile("", file.name)
|
document = document.createFile("", file.name)
|
||||||
}
|
}
|
||||||
contentResolver.openOutputStream(document.uri).apply {
|
contentResolver.openOutputStream(document.uri).apply {
|
||||||
write(text.toByteArray(Charset.forName("UTF-8")))
|
write(content.toByteArray(Charset.forName("UTF-8")))
|
||||||
flush()
|
flush()
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file.printWriter().use { out ->
|
file.printWriter().use { out ->
|
||||||
out.write(text)
|
out.write(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import com.simplemobiletools.notes.R
|
import com.simplemobiletools.notes.R
|
||||||
|
import com.simplemobiletools.notes.activities.MainActivity
|
||||||
import com.simplemobiletools.notes.extensions.config
|
import com.simplemobiletools.notes.extensions.config
|
||||||
import com.simplemobiletools.notes.extensions.getTextGravity
|
import com.simplemobiletools.notes.extensions.getTextGravity
|
||||||
import com.simplemobiletools.notes.extensions.getTextSize
|
import com.simplemobiletools.notes.extensions.getTextSize
|
||||||
@ -76,7 +77,7 @@ class NoteFragment : Fragment() {
|
|||||||
if (note.path.isEmpty()) {
|
if (note.path.isEmpty()) {
|
||||||
mDb.updateNoteValue(note)
|
mDb.updateNoteValue(note)
|
||||||
} else {
|
} else {
|
||||||
|
(activity as MainActivity).saveNoteValueToFile(note.path, getCurrentNoteViewText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user