mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-24 04:20:07 +01:00
Always export latest notes
This commit is contained in:
parent
3cda2eb234
commit
36c4746829
@ -907,19 +907,23 @@ class MainActivity : SimpleActivity() {
|
|||||||
private fun requestUnlockNotes(callback: (List<Long>) -> Unit) {
|
private fun requestUnlockNotes(callback: (List<Long>) -> Unit) {
|
||||||
val lockedNotes = mNotes.filter { it.isLocked() }
|
val lockedNotes = mNotes.filter { it.isLocked() }
|
||||||
if (lockedNotes.isNotEmpty()) {
|
if (lockedNotes.isNotEmpty()) {
|
||||||
|
runOnUiThread {
|
||||||
UnlockNotesDialog(this, lockedNotes, callback)
|
UnlockNotesDialog(this, lockedNotes, callback)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(emptyList())
|
callback(emptyList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun exportNotesTo(outputStream: OutputStream?) {
|
private fun exportNotesTo(outputStream: OutputStream?) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
NotesHelper(this).getNotes {
|
||||||
|
mNotes = it
|
||||||
requestUnlockNotes { unlockedIds ->
|
requestUnlockNotes { unlockedIds ->
|
||||||
toast(R.string.exporting)
|
toast(R.string.exporting)
|
||||||
ensureBackgroundThread {
|
|
||||||
val notesExporter = NotesExporter(this)
|
val notesExporter = NotesExporter(this)
|
||||||
notesExporter.exportNotes(outputStream, unlockedIds) {
|
notesExporter.exportNotes(mNotes, unlockedIds, outputStream) { result ->
|
||||||
val toastId = when (it) {
|
val toastId = when (result) {
|
||||||
NotesExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
NotesExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
|
||||||
else -> R.string.exporting_failed
|
else -> R.string.exporting_failed
|
||||||
}
|
}
|
||||||
@ -929,6 +933,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun tryImportNotes() {
|
private fun tryImportNotes() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
@ -1022,6 +1027,9 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun exportAllNotesBelowQ() {
|
private fun exportAllNotesBelowQ() {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
NotesHelper(this).getNotes { notes ->
|
||||||
|
mNotes = notes
|
||||||
requestUnlockNotes { unlockedIds ->
|
requestUnlockNotes { unlockedIds ->
|
||||||
ExportFilesDialog(this, mNotes) { parent, extension ->
|
ExportFilesDialog(this, mNotes) { parent, extension ->
|
||||||
val items = arrayListOf(
|
val items = arrayListOf(
|
||||||
@ -1032,8 +1040,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
RadioGroupDialog(this, items) { any ->
|
RadioGroupDialog(this, items) { any ->
|
||||||
val syncFile = any as Int == EXPORT_FILE_SYNC
|
val syncFile = any as Int == EXPORT_FILE_SYNC
|
||||||
var failCount = 0
|
var failCount = 0
|
||||||
NotesHelper(this).getNotes { notes ->
|
|
||||||
mNotes = notes
|
|
||||||
mNotes.filter { !it.isLocked() || it.id in unlockedIds }.forEachIndexed { index, note ->
|
mNotes.filter { !it.isLocked() || it.id in unlockedIds }.forEachIndexed { index, note ->
|
||||||
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
|
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
|
||||||
val file = File(parent, filename)
|
val file = File(parent, filename)
|
||||||
@ -1075,6 +1081,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun tryExportNoteValueToFile(path: String, title: 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://")) {
|
if (path.startsWith("content://")) {
|
||||||
|
@ -5,7 +5,6 @@ import com.google.gson.Gson
|
|||||||
import com.google.gson.stream.JsonWriter
|
import com.google.gson.stream.JsonWriter
|
||||||
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.notes.pro.extensions.notesDB
|
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ class NotesExporter(private val context: Context) {
|
|||||||
|
|
||||||
private val gson = Gson()
|
private val gson = Gson()
|
||||||
|
|
||||||
fun exportNotes(outputStream: OutputStream?, unlockedNoteIds: List<Long>, callback: (result: ExportResult) -> Unit) {
|
fun exportNotes(notes: List<Note>, unlockedNoteIds: List<Long>, outputStream: OutputStream?, callback: (result: ExportResult) -> Unit) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
if (outputStream == null) {
|
if (outputStream == null) {
|
||||||
callback.invoke(ExportResult.EXPORT_FAIL)
|
callback.invoke(ExportResult.EXPORT_FAIL)
|
||||||
@ -27,7 +26,6 @@ class NotesExporter(private val context: Context) {
|
|||||||
try {
|
try {
|
||||||
var written = 0
|
var written = 0
|
||||||
writer.beginArray()
|
writer.beginArray()
|
||||||
val notes = context.notesDB.getNotes() as ArrayList<Note>
|
|
||||||
for (note in notes) {
|
for (note in notes) {
|
||||||
if (!note.isLocked() || note.id in unlockedNoteIds) {
|
if (!note.isLocked() || note.id in unlockedNoteIds) {
|
||||||
val noteToSave = getNoteToExport(note)
|
val noteToSave = getNoteToExport(note)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user