Skip to content

Commit

Permalink
Support older Android API versions (#96)
Browse files Browse the repository at this point in the history
* Add binary icon versions for old android versions and use Java 7 date APIs

* Stop using some more modern Java constructs
  • Loading branch information
chvp authored Mar 4, 2024
1 parent 1806c0e commit f9d132e
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {

defaultConfig {
applicationId = "be.chvp.nanoledger"
minSdk = 26
minSdk = 21
targetSdk = 34
versionCode = 10700
versionName = "0.1.6"
Expand Down Expand Up @@ -47,9 +47,10 @@ android {
quiet = true
disable.addAll(
arrayOf(
"NewerVersionAvailable",
"GradleDependency",
"NewerVersionAvailable",
"ObsoleteLintCustomCheck",
"SimpleDateFormat",
),
)
checkAllWarnings = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions app/src/main/java/be/chvp/nanoledger/ui/add/AddActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = {},
Expand All @@ -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 = {
Expand Down
37 changes: 23 additions & 14 deletions app/src/main/java/be/chvp/nanoledger/ui/add/AddViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,8 +30,9 @@ class AddViewModel
private val _saving = MutableLiveData<Boolean>(false)
val saving: LiveData<Boolean> = _saving

private val _date = MutableLiveData<LocalDate>(LocalDate.now())
val date: LiveData<LocalDate> = _date
private val _date = MutableLiveData<Date>(Date())
val date: LiveData<Date> = _date
val formattedDate: LiveData<String> = _date.map { SimpleDateFormat("yyyy-MM-dd").format(it) }

private val _status = MutableLiveData<String>(preferencesDataSource.getDefaultStatus())
val status: LiveData<String> = _status
Expand Down Expand Up @@ -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}")
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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<Triple<String, String, String>>()
for (triple in result) {
if (triple.first != "" || triple.third != "") {
filteredResult.add(triple)
}
}
filteredResult.add(emptyPosting())
_postings.value = filteredResult
}

fun setCurrency(
Expand All @@ -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<Triple<String, String, String>>()
for (triple in result) {
if (triple.first != "" || triple.third != "") {
filteredResult.add(triple)
}
}
filteredResult.add(emptyPosting())
_postings.value = filteredResult
}

fun emptyPosting(): Triple<String, String, String> {
Expand Down
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.webp
Binary file not shown.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.webp
Binary file not shown.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Binary file not shown.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Binary file not shown.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Binary file not shown.

0 comments on commit f9d132e

Please sign in to comment.