From 4995979c5bac50ee802903260fbe6608ebdfe669 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Sat, 30 Dec 2023 14:28:22 +0100 Subject: [PATCH] Fix appending to empty file --- app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt b/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt index 8ba9484..3578ac9 100644 --- a/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt +++ b/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt @@ -49,7 +49,7 @@ class LedgerRepository context.contentResolver.openOutputStream(fileUri, "wa") ?.let { OutputStreamWriter(it) } ?.use { - if (fileContents.value!!.last() != "") { + if (!fileContents.value!!.isEmpty() && fileContents.value!!.last() != "") { it.write("\n") } it.write(text)