Always export latest notes

This commit is contained in:
Naveen 2023-03-15 02:38:38 +05:30
parent 3cda2eb234
commit 36c4746829
2 changed files with 58 additions and 53 deletions

View File

@ -907,19 +907,23 @@ class MainActivity : SimpleActivity() {
private fun requestUnlockNotes(callback: (List<Long>) -> Unit) {
val lockedNotes = mNotes.filter { it.isLocked() }
if (lockedNotes.isNotEmpty()) {
runOnUiThread {
UnlockNotesDialog(this, lockedNotes, callback)
}
} else {
callback(emptyList())
}
}
private fun exportNotesTo(outputStream: OutputStream?) {
ensureBackgroundThread {
NotesHelper(this).getNotes {
mNotes = it
requestUnlockNotes { unlockedIds ->
toast(R.string.exporting)
ensureBackgroundThread {
val notesExporter = NotesExporter(this)
notesExporter.exportNotes(outputStream, unlockedIds) {
val toastId = when (it) {
notesExporter.exportNotes(mNotes, unlockedIds, outputStream) { result ->
val toastId = when (result) {
NotesExporter.ExportResult.EXPORT_OK -> R.string.exporting_successful
else -> R.string.exporting_failed
}
@ -929,6 +933,7 @@ class MainActivity : SimpleActivity() {
}
}
}
}
private fun tryImportNotes() {
hideKeyboard()
@ -1022,6 +1027,9 @@ class MainActivity : SimpleActivity() {
}
private fun exportAllNotesBelowQ() {
ensureBackgroundThread {
NotesHelper(this).getNotes { notes ->
mNotes = notes
requestUnlockNotes { unlockedIds ->
ExportFilesDialog(this, mNotes) { parent, extension ->
val items = arrayListOf(
@ -1032,8 +1040,6 @@ class MainActivity : SimpleActivity() {
RadioGroupDialog(this, items) { any ->
val syncFile = any as Int == EXPORT_FILE_SYNC
var failCount = 0
NotesHelper(this).getNotes { notes ->
mNotes = notes
mNotes.filter { !it.isLocked() || it.id in unlockedIds }.forEachIndexed { index, note ->
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
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) {
if (path.startsWith("content://")) {

View File

@ -5,7 +5,6 @@ import com.google.gson.Gson
import com.google.gson.stream.JsonWriter
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.notes.pro.extensions.notesDB
import com.simplemobiletools.notes.pro.models.Note
import java.io.OutputStream
@ -16,7 +15,7 @@ class NotesExporter(private val context: Context) {
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 {
if (outputStream == null) {
callback.invoke(ExportResult.EXPORT_FAIL)
@ -27,7 +26,6 @@ class NotesExporter(private val context: Context) {
try {
var written = 0
writer.beginArray()
val notes = context.notesDB.getNotes() as ArrayList<Note>
for (note in notes) {
if (!note.isLocked() || note.id in unlockedNoteIds) {
val noteToSave = getNoteToExport(note)