Field order setting
This commit is contained in:
4 files changed
+74
-10
No files matched your search
@@ -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))
|
||||
|
||||
|
||||
@@ -822,7 +822,9 @@ class BillsListViewActivity :
|
||||
lifecycleScope.launch {
|
||||
syncNewlyDiscoveredProjects(withContext(Dispatchers.IO) { db.projects })
|
||||
}
|
||||
updateAvatarInDrawer(CowspentServerSyncHelper.isNextcloudAccountConfigured(this))
|
||||
updateAvatarInDrawer(
|
||||
CowspentServerSyncHelper.isNextcloudAccountConfigured(this@BillsListViewActivity)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -152,6 +152,9 @@
|
||||
<string name="settings_show_archived">Show archived projects</string>
|
||||
<string name="settings_extra_features">Extra Features</string>
|
||||
<string name="settings_extra_features_summary">Experimental and advanced options.</string>
|
||||
<string name="settings_bill_field_order">Bill field order</string>
|
||||
<string name="settings_bill_amount_first">Amount first</string>
|
||||
<string name="settings_bill_what_first">What first</string>
|
||||
<string name="prefill_button">Pre-fill</string>
|
||||
<string name="prefill_mode_off">Nothing</string>
|
||||
<string name="prefill_mode_latest_project">Last from project</string>
|
||||
@@ -190,11 +193,14 @@
|
||||
<string name="pref_key_offline_mode" translatable="false">offlineMode</string>
|
||||
<string name="pref_key_show_archived" translatable="false">showArchived</string>
|
||||
<string name="pref_key_extra_features" translatable="false">betaFeatures</string>
|
||||
<string name="pref_key_bill_field_order" translatable="false">billFieldOrder</string>
|
||||
<string name="pref_key_stats_include_deactivated" translatable="false">statsIncludeDeactivated</string>
|
||||
<string name="pref_key_auto_categorize" translatable="false">autoCategorizeNewBills</string>
|
||||
<string name="pref_key_full_sync_delay" translatable="false">fullSyncDelayMinutes</string>
|
||||
<string name="pref_key_last_account_sync_timestamp" translatable="false">lastAccountSyncTimestamp</string>
|
||||
<string name="pref_key_fill_new_bill_from_last" translatable="false">fillNewBillFromLast</string>
|
||||
<string name="pref_value_bill_amount_first" translatable="false">amount_first</string>
|
||||
<string name="pref_value_bill_what_first" translatable="false">what_first</string>
|
||||
<string name="pref_value_night_mode_no" translatable="false">1</string>
|
||||
<string name="pref_value_night_mode_yes" translatable="false">2</string>
|
||||
<string name="pref_value_night_mode_system" translatable="false">-1</string>
|
||||
|
||||
Reference in new issue
Block a user