Prefill setting
This commit is contained in:
@@ -12,6 +12,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -151,12 +152,25 @@ class EditBillActivity : AppCompatActivity() {
|
|||||||
val billIdToDuplicate = intent.getLongExtra(PARAM_BILL_ID_TO_DUPLICATE, 0)
|
val billIdToDuplicate = intent.getLongExtra(PARAM_BILL_ID_TO_DUPLICATE, 0)
|
||||||
val timeNowSeconds = System.currentTimeMillis() / 1000
|
val timeNowSeconds = System.currentTimeMillis() / 1000
|
||||||
if (billIdToDuplicate == 0L) {
|
if (billIdToDuplicate == 0L) {
|
||||||
|
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||||
|
val fillFromLast = preferences.getBoolean(getString(R.string.pref_key_fill_new_bill_from_last), false)
|
||||||
|
val lastBill = if (fillFromLast) db.getLastBillOfProject(projectId) else null
|
||||||
|
|
||||||
|
if (lastBill != null) {
|
||||||
|
bill = DBBill(
|
||||||
|
0, 0, projectId, lastBill.payerId, 0.0, timeNowSeconds,
|
||||||
|
"", DBBill.STATE_ADDED, lastBill.repeat ?: DBBill.NON_REPEATED,
|
||||||
|
lastBill.paymentMode, lastBill.categoryId, "", lastBill.paymentModeId
|
||||||
|
)
|
||||||
|
bill.billOwers = lastBill.billOwers.map { DBBillOwer(0, 0, it.memberId) }
|
||||||
|
} else {
|
||||||
val project = db.getProject(projectId)
|
val project = db.getProject(projectId)
|
||||||
bill = DBBill(
|
bill = DBBill(
|
||||||
0, 0, projectId, project?.lastPayerId ?: 0, 0.0, timeNowSeconds,
|
0, 0, projectId, project?.lastPayerId ?: 0, 0.0, timeNowSeconds,
|
||||||
"", DBBill.STATE_ADDED, DBBill.NON_REPEATED,
|
"", DBBill.STATE_ADDED, DBBill.NON_REPEATED,
|
||||||
DBBill.PAYMODE_NONE, DBBill.CATEGORY_NONE, "", DBBill.PAYMODE_ID_NONE
|
DBBill.PAYMODE_NONE, DBBill.CATEGORY_NONE, "", DBBill.PAYMODE_ID_NONE
|
||||||
)
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val btd = db.getBill(billIdToDuplicate)!!
|
val btd = db.getBill(billIdToDuplicate)!!
|
||||||
bill = DBBill(
|
bill = DBBill(
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ fun SettingsScreen(
|
|||||||
val keyOfflineMode = stringResource(R.string.pref_key_offline_mode)
|
val keyOfflineMode = stringResource(R.string.pref_key_offline_mode)
|
||||||
val keyShowArchived = stringResource(R.string.pref_key_show_archived)
|
val keyShowArchived = stringResource(R.string.pref_key_show_archived)
|
||||||
val keyBetaFeatures = stringResource(R.string.pref_key_beta_features)
|
val keyBetaFeatures = stringResource(R.string.pref_key_beta_features)
|
||||||
|
val keyFillNewBillFromLast = stringResource(R.string.pref_key_fill_new_bill_from_last)
|
||||||
|
|
||||||
val isNextcloudConfigured = CowspentServerSyncHelper.isNextcloudAccountConfigured(context)
|
val isNextcloudConfigured = CowspentServerSyncHelper.isNextcloudAccountConfigured(context)
|
||||||
|
|
||||||
@@ -123,6 +124,9 @@ fun SettingsScreen(
|
|||||||
var betaFeatures by remember(keyBetaFeatures) {
|
var betaFeatures by remember(keyBetaFeatures) {
|
||||||
mutableStateOf(sharedPreferences.getBoolean(keyBetaFeatures, false))
|
mutableStateOf(sharedPreferences.getBoolean(keyBetaFeatures, false))
|
||||||
}
|
}
|
||||||
|
var fillNewBillFromLast by remember(keyFillNewBillFromLast) {
|
||||||
|
mutableStateOf(sharedPreferences.getBoolean(keyFillNewBillFromLast, false))
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -269,6 +273,21 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (betaFeatures) {
|
||||||
|
SettingsSwitchPreference(
|
||||||
|
title = stringResource(R.string.settings_fill_new_bill_from_last),
|
||||||
|
summary = stringResource(R.string.settings_fill_new_bill_from_last_summary),
|
||||||
|
icon = Icons.Default.Info,
|
||||||
|
checked = fillNewBillFromLast,
|
||||||
|
onCheckedChange = {
|
||||||
|
fillNewBillFromLast = it
|
||||||
|
sharedPreferences.edit {
|
||||||
|
putBoolean(keyFillNewBillFromLast, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
SettingsPreference(
|
SettingsPreference(
|
||||||
title = stringResource(R.string.title_about),
|
title = stringResource(R.string.title_about),
|
||||||
icon = Icons.Default.Info,
|
icon = Icons.Default.Info,
|
||||||
|
|||||||
@@ -557,6 +557,15 @@ class CowspentSQLiteOpenHelper private constructor(val context: Context) :
|
|||||||
return if (bills.isEmpty()) null else bills[0]
|
return if (bills.isEmpty()) null else bills[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getLastBillOfProject(projectId: Long): DBBill? {
|
||||||
|
val list = getBillsCustom(
|
||||||
|
"$key_projectid = ? AND $key_state != ?",
|
||||||
|
arrayOf(projectId.toString(), DBBill.STATE_DELETED.toString()),
|
||||||
|
"$key_id DESC LIMIT 1"
|
||||||
|
)
|
||||||
|
return if (list.isEmpty()) null else list[0]
|
||||||
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun searchBills(query: CharSequence?, projectId: Long): List<DBBill> {
|
fun searchBills(query: CharSequence?, projectId: Long): List<DBBill> {
|
||||||
val andWhere: MutableList<String> = ArrayList()
|
val andWhere: MutableList<String> = ArrayList()
|
||||||
|
|||||||
@@ -137,6 +137,8 @@
|
|||||||
<string name="settings_show_archived">Show archived projects</string>
|
<string name="settings_show_archived">Show archived projects</string>
|
||||||
<string name="settings_beta_features">Beta Features</string>
|
<string name="settings_beta_features">Beta Features</string>
|
||||||
<string name="settings_beta_features_summary">Enable experimental features. Use at your own risk.</string>
|
<string name="settings_beta_features_summary">Enable experimental features. Use at your own risk.</string>
|
||||||
|
<string name="settings_fill_new_bill_from_last">Auto-fill from last bill</string>
|
||||||
|
<string name="settings_fill_new_bill_from_last_summary">Pre-fill payer, category, mode and owers from the last bill created in the project.</string>
|
||||||
<string name="settings_url_warn_http">WARNING: "http" is unsafe. Use "https".</string>
|
<string name="settings_url_warn_http">WARNING: "http" is unsafe. Use "https".</string>
|
||||||
<string name="settings_colorpicker_title">Choose Color</string>
|
<string name="settings_colorpicker_title">Choose Color</string>
|
||||||
|
|
||||||
@@ -158,6 +160,7 @@
|
|||||||
<string name="pref_key_offline_mode" translatable="false">offlineMode</string>
|
<string name="pref_key_offline_mode" translatable="false">offlineMode</string>
|
||||||
<string name="pref_key_show_archived" translatable="false">showArchived</string>
|
<string name="pref_key_show_archived" translatable="false">showArchived</string>
|
||||||
<string name="pref_key_beta_features" translatable="false">betaFeatures</string>
|
<string name="pref_key_beta_features" translatable="false">betaFeatures</string>
|
||||||
|
<string name="pref_key_fill_new_bill_from_last" translatable="false">fillNewBillFromLast</string>
|
||||||
<string name="pref_value_night_mode_no" translatable="false">1</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_yes" translatable="false">2</string>
|
||||||
<string name="pref_value_night_mode_system" translatable="false">-1</string>
|
<string name="pref_value_night_mode_system" translatable="false">-1</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user