Removed onProgress

This commit is contained in:
Agnieszka C 2022-03-08 13:46:44 +01:00
parent 3137d6273b
commit 6bd9500c8c
2 changed files with 2 additions and 6 deletions

View File

@ -16,7 +16,7 @@ class NotesExporter(private val context: Context) {
private val gson = Gson() private val gson = Gson()
fun exportNotes(outputStream: OutputStream?, onProgress: (total: Int, current: Int) -> Unit = { _, _ -> }, callback: (result: ExportResult) -> Unit) { fun exportNotes(outputStream: OutputStream?, callback: (result: ExportResult) -> Unit) {
ensureBackgroundThread { ensureBackgroundThread {
if (outputStream == null) { if (outputStream == null) {
callback.invoke(ExportResult.EXPORT_FAIL) callback.invoke(ExportResult.EXPORT_FAIL)
@ -28,13 +28,11 @@ class NotesExporter(private val context: Context) {
var written = 0 var written = 0
writer.beginArray() writer.beginArray()
val notes = context.notesDB.getNotes() as ArrayList<Note> val notes = context.notesDB.getNotes() as ArrayList<Note>
val totalNotes = notes.size
for (note in notes) { for (note in notes) {
if (note.protectionType === PROTECTION_NONE) { if (note.protectionType === PROTECTION_NONE) {
val noteToSave = getNoteToExport(note) val noteToSave = getNoteToExport(note)
writer.jsonValue(gson.toJson(noteToSave)) writer.jsonValue(gson.toJson(noteToSave))
written++ written++
onProgress.invoke(totalNotes, written)
} }
} }
writer.endArray() writer.endArray()

View File

@ -18,7 +18,7 @@ class NotesImporter(private val context: Context) {
private var notesImported = 0 private var notesImported = 0
private var notesFailed = 0 private var notesFailed = 0
fun importNotes(path: String, onProgress: (total: Int, current: Int) -> Unit = { _, _ -> }, callback: (result: ImportResult) -> Unit) { fun importNotes(path: String, callback: (result: ImportResult) -> Unit) {
ensureBackgroundThread { ensureBackgroundThread {
try { try {
val inputStream = if (path.contains("/")) { val inputStream = if (path.contains("/")) {
@ -37,13 +37,11 @@ class NotesImporter(private val context: Context) {
return@ensureBackgroundThread return@ensureBackgroundThread
} }
onProgress.invoke(totalNotes, notesImported)
for (note in notes) { for (note in notes) {
val exists = context.notesDB.getNoteIdWithTitle(note.title) != null val exists = context.notesDB.getNoteIdWithTitle(note.title) != null
if (!exists) { if (!exists) {
context.notesDB.insertOrUpdate(note) context.notesDB.insertOrUpdate(note)
notesImported++ notesImported++
onProgress.invoke(totalNotes, notesImported)
} }
} }
} }