diff --git a/app/src/main/java/net/helcel/cowspent/android/bill_edit/EditBillScreen.kt b/app/src/main/java/net/helcel/cowspent/android/bill_edit/EditBillScreen.kt
index b284735..0b099f8 100644
--- a/app/src/main/java/net/helcel/cowspent/android/bill_edit/EditBillScreen.kt
+++ b/app/src/main/java/net/helcel/cowspent/android/bill_edit/EditBillScreen.kt
@@ -45,6 +45,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
+import androidx.preference.PreferenceManager
import net.helcel.cowspent.R
import net.helcel.cowspent.android.helper.*
import net.helcel.cowspent.model.*
@@ -74,19 +75,28 @@ fun EditBillScreen(
val canEdit = accessLevel == DBProject.ACCESS_LEVEL_UNKNOWN || accessLevel >= DBProject.ACCESS_LEVEL_PARTICIPANT
val context = LocalContext.current
val focusRequester = remember { FocusRequester() }
+ val whatFocusRequester = remember { FocusRequester() }
+ val whatFirst = remember(context) {
+ val preferences = PreferenceManager.getDefaultSharedPreferences(context)
+ preferences.getBoolean(context.getString(R.string.pref_key_extra_features), false) &&
+ preferences.getString(
+ context.getString(R.string.pref_key_bill_field_order),
+ context.getString(R.string.pref_value_bill_amount_first)
+ ) == context.getString(R.string.pref_value_bill_what_first)
+ }
var amountFocused by remember { mutableStateOf(false) }
var amountSelection by remember { mutableStateOf(TextRange(viewModel.amount.length)) }
// The activity reads the project off the main thread and only then reports whether this is a
// new bill, so the flag arrives after the first composition. Keying on it rather than on Unit
// is what makes the effect run at all.
- LaunchedEffect(viewModel.isNewBill) {
+ LaunchedEffect(viewModel.isNewBill, whatFirst) {
if (!viewModel.isNewBill) return@LaunchedEffect
// The field has to be laid out before it can take focus, which is not yet true on the
// pass that composed it. Waiting for the next frame makes this hold whether the flag was
// already set or arrived later.
withFrameNanos { }
- focusRequester.requestFocus()
+ (if (whatFirst) whatFocusRequester else focusRequester).requestFocus()
}
StatefulAlertDialog(
@@ -182,6 +192,8 @@ fun EditBillScreen(
onDateClick = onDateClick,
onTimeClick = onTimeClick,
amountFocusRequester = focusRequester,
+ whatFocusRequester = whatFocusRequester,
+ whatFirst = whatFirst,
amountSelection = amountSelection,
onAmountSelectionChange = { amountSelection = it },
onAmountFocusChange = { amountFocused = it }
@@ -370,6 +382,8 @@ fun BillBasicInfoSection(
onDateClick: () -> Unit,
onTimeClick: () -> Unit,
amountFocusRequester: FocusRequester,
+ whatFocusRequester: FocusRequester,
+ whatFirst: Boolean,
amountSelection: TextRange = TextRange(viewModel.amount.length),
onAmountSelectionChange: (TextRange) -> Unit = {},
onAmountFocusChange: (Boolean) -> Unit = {}
@@ -387,6 +401,7 @@ fun BillBasicInfoSection(
val currencyDialogTitle =
stringResource(R.string.currency_dialog_title, viewModel.mainCurrencyName)
+ val amountField: @Composable () -> Unit = {
OutlinedTextField(
value = TextFieldValue(
text = viewModel.amount,
@@ -444,22 +459,42 @@ fun BillBasicInfoSection(
Icon(Icons.Default.SwapHoriz, contentDescription = "Change Currency")
}
},
- keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal, imeAction = ImeAction.Next),
- keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) })
+ keyboardOptions = KeyboardOptions(
+ keyboardType = KeyboardType.Decimal,
+ imeAction = if (whatFirst) ImeAction.Done else ImeAction.Next
+ ),
+ keyboardActions = KeyboardActions(
+ onNext = { focusManager.moveFocus(FocusDirection.Next) },
+ onDone = { focusManager.clearFocus() }
+ )
)
+ }
- Spacer(modifier = Modifier.height(8.dp))
-
+ val whatField: @Composable () -> Unit = {
OutlinedTextField(
value = viewModel.what,
onValueChange = { viewModel.updateWhat(it) },
enabled = canEdit,
placeholder = { Text(stringResource(R.string.label_what)) },
- modifier = Modifier.fillMaxWidth(),
+ modifier = Modifier.fillMaxWidth().focusRequester(whatFocusRequester),
leadingIcon = { Icon(Icons.Default.Title, contentDescription = null) },
- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
- keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() })
+ keyboardOptions = KeyboardOptions(imeAction = if (whatFirst) ImeAction.Next else ImeAction.Done),
+ keyboardActions = KeyboardActions(
+ onNext = { focusManager.moveFocus(FocusDirection.Next) },
+ onDone = { focusManager.clearFocus() }
+ )
)
+ }
+
+ if (whatFirst) {
+ whatField()
+ Spacer(modifier = Modifier.height(8.dp))
+ amountField()
+ } else {
+ amountField()
+ Spacer(modifier = Modifier.height(8.dp))
+ whatField()
+ }
Spacer(modifier = Modifier.height(8.dp))
diff --git a/app/src/main/java/net/helcel/cowspent/android/main/BillsListViewActivity.kt b/app/src/main/java/net/helcel/cowspent/android/main/BillsListViewActivity.kt
index ded13a4..a7b761b 100644
--- a/app/src/main/java/net/helcel/cowspent/android/main/BillsListViewActivity.kt
+++ b/app/src/main/java/net/helcel/cowspent/android/main/BillsListViewActivity.kt
@@ -822,7 +822,9 @@ class BillsListViewActivity :
lifecycleScope.launch {
syncNewlyDiscoveredProjects(withContext(Dispatchers.IO) { db.projects })
}
- updateAvatarInDrawer(CowspentServerSyncHelper.isNextcloudAccountConfigured(this))
+ updateAvatarInDrawer(
+ CowspentServerSyncHelper.isNextcloudAccountConfigured(this@BillsListViewActivity)
+ )
}
}
)
diff --git a/app/src/main/java/net/helcel/cowspent/android/settings/SettingsScreen.kt b/app/src/main/java/net/helcel/cowspent/android/settings/SettingsScreen.kt
index 05945ad..eca115a 100644
--- a/app/src/main/java/net/helcel/cowspent/android/settings/SettingsScreen.kt
+++ b/app/src/main/java/net/helcel/cowspent/android/settings/SettingsScreen.kt
@@ -38,6 +38,7 @@ import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Palette
import androidx.compose.material.icons.filled.Restore
import androidx.compose.material.icons.filled.Sync
+import androidx.compose.material.icons.filled.SwapVert
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
@@ -99,6 +100,9 @@ fun SettingsScreen(
val keyAutoCategorize = stringResource(R.string.pref_key_auto_categorize)
val keyFullSyncDelay = stringResource(R.string.pref_key_full_sync_delay)
val keyLastAccountSync = stringResource(R.string.pref_key_last_account_sync_timestamp)
+ val keyBillFieldOrder = stringResource(R.string.pref_key_bill_field_order)
+ val billAmountFirstValue = stringResource(R.string.pref_value_bill_amount_first)
+ val billWhatFirstValue = stringResource(R.string.pref_value_bill_what_first)
val isNextcloudConfigured = CowspentServerSyncHelper.isNextcloudAccountConfigured(context)
@@ -157,6 +161,9 @@ fun SettingsScreen(
var autoCategorize by remember(keyAutoCategorize) {
mutableStateOf(sharedPreferences.getBoolean(keyAutoCategorize, false))
}
+ var billFieldOrder by remember(keyBillFieldOrder) {
+ mutableStateOf(sharedPreferences.getString(keyBillFieldOrder, billAmountFirstValue) ?: billAmountFirstValue)
+ }
val fullSyncDelays = SyncSettings.FULL_SYNC_DELAY_CHOICES_MINUTES
val fullSyncDelayLabels = listOf(
@@ -320,6 +327,20 @@ fun SettingsScreen(
)
if (extraFeatures) {
+ SettingsListPreference(
+ title = stringResource(R.string.settings_bill_field_order),
+ icon = Icons.Default.SwapVert,
+ value = billFieldOrder,
+ entries = mapOf(
+ billAmountFirstValue to stringResource(R.string.settings_bill_amount_first),
+ billWhatFirstValue to stringResource(R.string.settings_bill_what_first)
+ ),
+ onValueChange = { value ->
+ billFieldOrder = value
+ sharedPreferences.edit { putString(keyBillFieldOrder, value) }
+ }
+ )
+
SettingsSwitchPreference(
title = stringResource(R.string.settings_show_archived),
icon = Icons.Default.Archive,
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 24f995f..7172b9a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -152,6 +152,9 @@
Show archived projects
Extra Features
Experimental and advanced options.
+ Bill field order
+ Amount first
+ What first
Pre-fill
Nothing
Last from project
@@ -190,11 +193,14 @@
offlineMode
showArchived
betaFeatures
+ billFieldOrder
statsIncludeDeactivated
autoCategorizeNewBills
fullSyncDelayMinutes
lastAccountSyncTimestamp
fillNewBillFromLast
+ amount_first
+ what_first
1
2
-1