diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fd8f95b..b19869c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,7 +12,7 @@ android { defaultConfig { applicationId = "be.chvp.nanoledger" - minSdk = 26 + minSdk = 21 targetSdk = 34 versionCode = 10700 versionName = "0.1.6" @@ -47,9 +47,10 @@ android { quiet = true disable.addAll( arrayOf( - "NewerVersionAvailable", "GradleDependency", + "NewerVersionAvailable", "ObsoleteLintCustomCheck", + "SimpleDateFormat", ), ) checkAllWarnings = true 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 3578ac9..773fa47 100644 --- a/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt +++ b/app/src/main/java/be/chvp/nanoledger/data/LedgerRepository.kt @@ -70,7 +70,13 @@ class LedgerRepository fileUri ?.let { context.contentResolver.openInputStream(it) } ?.let { BufferedReader(InputStreamReader(it)) } - ?.use { it.lines().forEach { result.add(it) } } + ?.use { reader -> + var line = reader.readLine() + while (line != null) { + result.add(line) + line = reader.readLine() + } + } val extracted = extractTransactions(result) _fileContents.postValue(result) _transactions.postValue(extracted) diff --git a/app/src/main/java/be/chvp/nanoledger/ui/add/AddActivity.kt b/app/src/main/java/be/chvp/nanoledger/ui/add/AddActivity.kt index 71e8de7..a91dc4f 100644 --- a/app/src/main/java/be/chvp/nanoledger/ui/add/AddActivity.kt +++ b/app/src/main/java/be/chvp/nanoledger/ui/add/AddActivity.kt @@ -74,8 +74,6 @@ import be.chvp.nanoledger.ui.theme.NanoLedgerTheme import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter @AndroidEntryPoint class AddActivity() : ComponentActivity() { @@ -283,9 +281,10 @@ fun DateSelector( ) { val focusManager = LocalFocusManager.current val date by addViewModel.date.observeAsState() + val formattedDate by addViewModel.formattedDate.observeAsState() var dateDialogOpen by rememberSaveable { mutableStateOf(false) } OutlinedTextField( - value = date?.format(DateTimeFormatter.ISO_DATE) ?: "", + value = formattedDate ?: "", readOnly = true, singleLine = true, onValueChange = {}, @@ -303,14 +302,7 @@ fun DateSelector( }, ) if (dateDialogOpen) { - val datePickerState = - rememberDatePickerState( - initialSelectedDateMillis = - date - ?.atStartOfDay() - ?.toInstant(ZoneOffset.UTC) - ?.toEpochMilli(), - ) + val datePickerState = rememberDatePickerState(initialSelectedDateMillis = date?.getTime()) DatePickerDialog( onDismissRequest = { dateDialogOpen = false }, confirmButton = { diff --git a/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt b/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt index 1243c80..a164c24 100644 --- a/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt +++ b/app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt @@ -15,10 +15,8 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import java.io.IOException import java.math.BigDecimal -import java.time.Instant -import java.time.LocalDate -import java.time.ZoneId -import java.time.format.DateTimeFormatter +import java.text.SimpleDateFormat +import java.util.Date import javax.inject.Inject @HiltViewModel @@ -32,8 +30,9 @@ class AddViewModel private val _saving = MutableLiveData(false) val saving: LiveData = _saving - private val _date = MutableLiveData(LocalDate.now()) - val date: LiveData = _date + private val _date = MutableLiveData(Date()) + val date: LiveData = _date + val formattedDate: LiveData = _date.map { SimpleDateFormat("yyyy-MM-dd").format(it) } private val _status = MutableLiveData(preferencesDataSource.getDefaultStatus()) val status: LiveData = _status @@ -114,7 +113,7 @@ class AddViewModel _saving.value = true viewModelScope.launch(IO) { val transaction = StringBuilder() - transaction.append(date.value!!.format(DateTimeFormatter.ISO_DATE)) + transaction.append(SimpleDateFormat("yyyy-MM-dd").format(date.value!!)) if (status.value!! != " ") { transaction.append(" ${status.value}") } @@ -166,7 +165,7 @@ class AddViewModel } fun setDate(dateMillis: Long) { - _date.value = Instant.ofEpochMilli(dateMillis).atZone(ZoneId.of("UTC")).toLocalDate() + _date.value = Date(dateMillis) } fun setStatus(newStatus: String) { @@ -187,9 +186,14 @@ class AddViewModel ) { val result = ArrayList(postings.value!!) result[index] = Triple(newAccount, result[index].second, result[index].third) - result.removeIf { it.first == "" && it.third == "" } - result.add(emptyPosting()) - _postings.value = result + val filteredResult = ArrayList>() + for (triple in result) { + if (triple.first != "" || triple.third != "") { + filteredResult.add(triple) + } + } + filteredResult.add(emptyPosting()) + _postings.value = filteredResult } fun setCurrency( @@ -207,9 +211,14 @@ class AddViewModel ) { val result = ArrayList(postings.value!!) result[index] = Triple(result[index].first, result[index].second, newAmount) - result.removeIf { it.first == "" && it.third == "" } - result.add(emptyPosting()) - _postings.value = result + val filteredResult = ArrayList>() + for (triple in result) { + if (triple.first != "" || triple.third != "") { + filteredResult.add(triple) + } + } + filteredResult.add(emptyPosting()) + _postings.value = filteredResult } fun emptyPosting(): Triple { diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from app/src/main/res/mipmap-anydpi/ic_launcher.xml rename to app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from app/src/main/res/mipmap-anydpi/ic_launcher_round.xml rename to app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..b84fa6c Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4504a58 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..c031c2b Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..4ab9997 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..7c8b035 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ