Compare commits

...
28 Commits
Author SHA1 Message Date
sora 95a65fe7d1 Fix tests failing 2026-12-02 00:33:27 +01:00
sora 5846a98870 reworked percent split to fraction split 2026-12-02 00:26:42 +01:00
sora a1a7092318 count 404/deleted as archived 2026-12-02 00:00:47 +01:00
sora 28c4487747 Field order setting 2026-12-01 23:20:44 +01:00
sora 39e21dce11 Fix local network 2026-12-01 22:14:33 +01:00
sora 0bb1ca9682 Fix build issues 2026-11-14 14:13:45 +01:00
sora c21f0c2d7a Undo java bump breaking build 2026-11-14 13:47:24 +01:00
sora d8fd4aaded build with version file 2026-11-14 13:39:31 +01:00
sora a5c825c8e0 better prefill, autocategorize 2026-11-14 13:34:43 +01:00
sora 206223bff5 Merge pull request 'Update plugin com.android.application to v9.5.1' (#7) from renovate/com.android.application-9.x into main
Reviewed-on: #7
2026-11-14 12:24:53 +01:00
sora 3deaff97fb Merge pull request 'Update dependency androidx.datastore:datastore-preferences to v1.3.0' (#25) from renovate/androidx.datastore-datastore-preferences-1.x into main
Reviewed-on: #25
2026-11-14 12:24:14 +01:00
sora 9e6ba6e1b7 Merge pull request 'Update dependency java-jdk to v27' (#26) from renovate/java-jdk-27.x into main
Reviewed-on: #26
2026-11-14 12:23:59 +01:00
sora af72449037 Merge pull request 'Update dependency com.github.nextcloud:Android-SingleSignOn to v1.3.5' (#27) from renovate/com.github.nextcloud-android-singlesignon-1.x into main
Reviewed-on: #27
2026-11-14 12:23:47 +01:00
Renovate Bot 211f751c0e Update plugin com.android.application to v9.5.1 2026-11-06 02:01:21 +00:00
Renovate Bot bad6d59c5c Update dependency com.github.nextcloud:Android-SingleSignOn to v1.3.5 2026-10-29 02:01:11 +00:00
Renovate Bot 7ecd10abf0 Update dependency java-jdk to v27 2026-10-23 02:02:12 +00:00
Renovate Bot 04c7deb066 Update dependency androidx.datastore:datastore-preferences to v1.3.0 2026-10-22 02:01:42 +00:00
sora c2da40ba4d Update .github/workflows/build.yml 2026-10-03 19:38:47 +02:00
sora 6e45507b22 Merge pull request 'Update plugin org.jetbrains.kotlin.plugin.serialization to v2.4.20' (#15) from renovate/org.jetbrains.kotlin.plugin.serialization-2.x into main
Reviewed-on: #15
2026-10-03 19:33:49 +02:00
sora 99d05680c5 Merge pull request 'Update dependency androidx.compose.runtime:runtime to v1.12.1' (#17) from renovate/androidx.compose.runtime-runtime-1.x into main
Reviewed-on: #17
2026-10-03 19:33:35 +02:00
Renovate Bot d89d99ceff Update plugin org.jetbrains.kotlin.plugin.serialization to v2.4.20 2026-10-01 02:01:46 +00:00
Renovate Bot 40be1b79f2 Update dependency androidx.compose.runtime:runtime to v1.12.1 2026-10-01 02:01:44 +00:00
sora e807d6fa66 Merge pull request 'Update dependency androidx.work:work-runtime-ktx to v2.12.0' (#20) from renovate/androidx.work-work-runtime-ktx-2.x into main
Reviewed-on: #20
2026-09-30 23:03:02 +02:00
sora 8ae8df6ef8 Merge pull request 'Update dependency org.robolectric:robolectric to v4.17' (#19) from renovate/org.robolectric-robolectric-4.x into main
Reviewed-on: #19
2026-09-30 23:02:53 +02:00
sora 791f3572b6 Merge pull request 'Update dependency androidx.compose:compose-bom to v2026.09.00' (#18) from renovate/androidx.compose-compose-bom-2026.x into main
Reviewed-on: #18
2026-09-30 23:02:34 +02:00
Renovate Bot 1f56757d30 Update dependency androidx.work:work-runtime-ktx to v2.12.0 2026-09-24 02:02:58 +00:00
Renovate Bot 73dc64a688 Update dependency org.robolectric:robolectric to v4.17 2026-09-11 02:01:48 +00:00
Renovate Bot 3b22037496 Update dependency androidx.compose:compose-bom to v2026.09.00 2026-09-11 02:01:46 +00:00
47 changed files with 862 additions and 211 deletions

No files matched your search

+19 -13
View File
@@ -8,11 +8,11 @@ env:
on: on:
push: push:
branches: [ main ] branches: [main]
tags: tags:
- '**' - "**"
pull_request: pull_request:
branches: [ main ] branches: [main]
workflow_dispatch: workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel # A workflow run is made up of one or more jobs that can run sequentially or in parallel
@@ -67,9 +67,8 @@ jobs:
else else
VERSION_NAME="${VERSION_BASE}" VERSION_NAME="${VERSION_BASE}"
fi fi
printf '%s\n%s\n' "$VERSION_CODE" "$VERSION_NAME" > version.txt
./gradlew bundleSignedRelease assembleSignedRelease -PVERSION_CODE=$VERSION_CODE -PVERSION_NAME=$VERSION_NAME ./gradlew bundleSignedRelease assembleSignedRelease -PVERSION_CODE=$VERSION_CODE -PVERSION_NAME=$VERSION_NAME
# ./gradlew assembleSignedRelease -PVERSION_CODE=$VERSION_CODE -PVERSION_NAME=$VERSION_NAME
# ./gradlew bundleSignedRelease -PVERSION_CODE=$VERSION_CODE -PVERSION_NAME=$VERSION_NAME
- name: Upload APK - name: Upload APK
uses: actions/upload-artifact@v7 uses: actions/upload-artifact@v7
@@ -78,26 +77,33 @@ jobs:
compression-level: 0 compression-level: 0
archive: false archive: false
- name: Determine prerelease
id: prerelease
if: startsWith(github.ref, 'refs/tags/')
run: |
if [[ "$GITHUB_REF_NAME" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
echo "value=false" >> "$GITHUB_OUTPUT"
else
echo "value=true" >> "$GITHUB_OUTPUT"
fi
- name: Release - name: Release
uses: softprops/action-gh-release@v3 uses: softprops/action-gh-release@v3
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
with: with:
files: | files: |
app/build/outputs/apk/signedRelease/app-signedRelease.apk app/build/outputs/apk/signedRelease/app-signedRelease.apk
prerelease: | version.txt
if [[ ${{ github.ref }} =~ ^refs/tags/[0-9]+\.[0-9]+[a-z]+$ ]]; then prerelease: ${{ steps.prerelease.outputs.value }}
echo "false"
else
echo "true"
fi
- name: Upload to Google Play - name: Upload to Google Play
uses: r0adkll/upload-google-play@v1 uses: r0adkll/upload-google-play@v1
if: startsWith(github.ref, 'refs/tags/') if: github.event_name == 'push'
continue-on-error: true
with: with:
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }} serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
packageName: net.helcel.cowspent packageName: net.helcel.cowspent
releaseFiles: app/build/outputs/bundle/signedRelease/app-signedRelease.aab releaseFiles: app/build/outputs/bundle/signedRelease/app-signedRelease.aab
tracks: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'alpha' }} tracks: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'internal' }}
status: completed status: completed
whatsNewDirectory: tmp/whatsnew whatsNewDirectory: tmp/whatsnew
+9 -9
View File
@@ -1,6 +1,6 @@
plugins { plugins {
id 'com.android.application' version '9.3.2' id 'com.android.application' version '9.5.1'
id 'org.jetbrains.kotlin.plugin.serialization' version '2.4.10' id 'org.jetbrains.kotlin.plugin.serialization' version '2.4.20'
id 'org.jetbrains.kotlin.plugin.compose' version '2.4.20' id 'org.jetbrains.kotlin.plugin.compose' version '2.4.20'
id 'jacoco' id 'jacoco'
} }
@@ -119,20 +119,20 @@ android {
dependencies { dependencies {
implementation 'androidx.compose.foundation:foundation:1.12.1' implementation 'androidx.compose.foundation:foundation:1.12.1'
implementation 'androidx.compose.runtime:runtime:1.12.0' implementation 'androidx.compose.runtime:runtime:1.12.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
implementation 'androidx.preference:preference-ktx:1.2.1' implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.work:work-runtime-ktx:2.11.2' implementation 'androidx.work:work-runtime-ktx:2.12.0'
implementation 'com.google.zxing:core:3.5.4' implementation 'com.google.zxing:core:3.5.4'
implementation 'androidx.camera:camera-camera2:1.6.2' implementation 'androidx.camera:camera-camera2:1.6.2'
implementation 'androidx.camera:camera-lifecycle:1.6.2' implementation 'androidx.camera:camera-lifecycle:1.6.2'
implementation 'androidx.camera:camera-view:1.6.2' implementation 'androidx.camera:camera-view:1.6.2'
implementation 'com.github.nextcloud:Android-SingleSignOn:1.3.4' implementation 'com.github.nextcloud:Android-SingleSignOn:1.3.5'
implementation 'com.opencsv:opencsv:5.12.0' implementation 'com.opencsv:opencsv:5.12.0'
implementation platform('androidx.compose:compose-bom:2026.08.00') implementation platform('androidx.compose:compose-bom:2026.09.00')
implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.material:material' implementation 'androidx.compose.material:material'
implementation 'androidx.compose.material:material-icons-extended' implementation 'androidx.compose.material:material-icons-extended'
@@ -142,17 +142,17 @@ dependencies {
implementation 'androidx.activity:activity-ktx:1.13.0' implementation 'androidx.activity:activity-ktx:1.13.0'
implementation 'androidx.security:security-crypto:1.1.0' implementation 'androidx.security:security-crypto:1.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.11.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.11.0'
implementation "androidx.datastore:datastore-preferences:1.2.1" implementation "androidx.datastore:datastore-preferences:1.3.0"
implementation "com.google.crypto.tink:tink-android:1.23.0" implementation "com.google.crypto.tink:tink-android:1.23.0"
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
testImplementation 'io.mockk:mockk:1.14.11' testImplementation 'io.mockk:mockk:1.14.11'
testImplementation 'org.robolectric:robolectric:4.16.1' testImplementation 'org.robolectric:robolectric:4.17'
testImplementation 'androidx.test:core:1.7.0' testImplementation 'androidx.test:core:1.7.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0' testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.11.0'
testImplementation 'androidx.compose.ui:ui-test-junit4' testImplementation 'androidx.compose.ui:ui-test-junit4'
androidTestImplementation platform('androidx.compose:compose-bom:2026.08.00') androidTestImplementation platform('androidx.compose:compose-bom:2026.09.00')
androidTestImplementation 'androidx.test.ext:junit:1.3.0' androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
androidTestImplementation 'androidx.compose.ui:ui-test-junit4' androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
+1
View File
@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-feature <uses-feature
android:name="android.hardware.camera" android:name="android.hardware.camera"
@@ -42,6 +42,7 @@ import net.helcel.cowspent.persistence.CowspentServerSyncHelper
import net.helcel.cowspent.theme.ThemeUtils import net.helcel.cowspent.theme.ThemeUtils
import net.helcel.cowspent.util.CospendClientUtil import net.helcel.cowspent.util.CospendClientUtil
import net.helcel.cowspent.util.CospendClientUtil.LoginStatus import net.helcel.cowspent.util.CospendClientUtil.LoginStatus
import net.helcel.cowspent.util.LocalNetworkPermissionHelper
import net.helcel.cowspent.util.SecureStorage import net.helcel.cowspent.util.SecureStorage
import java.net.URLDecoder import java.net.URLDecoder
import java.util.Locale import java.util.Locale
@@ -72,6 +73,7 @@ class AccountActivity : AppCompatActivity() {
private lateinit var preferences: SharedPreferences private lateinit var preferences: SharedPreferences
private var useWebLogin = true private var useWebLogin = true
private var showLoginDialog by mutableStateOf(false) private var showLoginDialog by mutableStateOf(false)
private val localNetworkPermissionHelper = LocalNetworkPermissionHelper(this)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() enableEdgeToEdge()
@@ -101,7 +103,9 @@ class AccountActivity : AppCompatActivity() {
AccountScreen( AccountScreen(
viewModel = viewModel, viewModel = viewModel,
onBack = { finish() }, onBack = { finish() },
onConnect = { login() }, onConnect = {
withLocalNetworkPermission(CospendClientUtil.formatURL(viewModel.serverUrl)) { login() }
},
onSsoClick = { isChecked -> onSsoClick = { isChecked ->
if (isChecked) { if (isChecked) {
showLoginDialog = true showLoginDialog = true
@@ -194,6 +198,13 @@ class AccountActivity : AppCompatActivity() {
.cowspentServerSyncHelper.runAccountProjectsSync() .cowspentServerSyncHelper.runAccountProjectsSync()
} }
private fun withLocalNetworkPermission(serverUrl: String, action: () -> Unit) {
localNetworkPermissionHelper.runWithAccess(
listOf(serverUrl),
action = action
)
}
@Deprecated("Deprecated in Java") @Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
@@ -213,6 +224,7 @@ class AccountActivity : AppCompatActivity() {
viewModel.serverUrl = ssoAccount.url viewModel.serverUrl = ssoAccount.url
viewModel.username = ssoAccount.userId viewModel.username = ssoAccount.userId
withLocalNetworkPermission(ssoAccount.url) {
startInitialAccountSync() startInitialAccountSync()
val resultData = Intent() val resultData = Intent()
@@ -221,6 +233,7 @@ class AccountActivity : AppCompatActivity() {
finish() finish()
} }
} }
}
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "SSO account selection failed", e) Log.e(TAG, "SSO account selection failed", e)
} }
@@ -9,6 +9,7 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.annotation.WorkerThread
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
@@ -27,6 +28,10 @@ import net.helcel.cowspent.model.ProjectType
import net.helcel.cowspent.persistence.CowspentSQLiteOpenHelper import net.helcel.cowspent.persistence.CowspentSQLiteOpenHelper
import net.helcel.cowspent.theme.ThemeUtils import net.helcel.cowspent.theme.ThemeUtils
import net.helcel.cowspent.util.BillParser import net.helcel.cowspent.util.BillParser
import net.helcel.cowspent.util.BillPrefill
import net.helcel.cowspent.util.BillTemplate
import net.helcel.cowspent.util.CategorySuggester
import net.helcel.cowspent.util.PrefillMode
import net.helcel.cowspent.util.SupportUtil import net.helcel.cowspent.util.SupportUtil
import java.text.ParseException import java.text.ParseException
import java.time.ZoneId import java.time.ZoneId
@@ -40,6 +45,9 @@ class EditBillActivity : AppCompatActivity() {
private var projectType: ProjectType = ProjectType.LOCAL private var projectType: ProjectType = ProjectType.LOCAL
private val calendar = Calendar.getInstance() private val calendar = Calendar.getInstance()
// The pre-fill mode the form was opened with; null when the bill is not a fresh one.
private var prefillMode: PrefillMode? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() enableEdgeToEdge()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@@ -95,8 +103,14 @@ class EditBillActivity : AppCompatActivity() {
val createIntent = Intent(this@EditBillActivity, QrCodeScannerActivity::class.java) val createIntent = Intent(this@EditBillActivity, QrCodeScannerActivity::class.java)
scanQRCodeLauncher.launch(createIntent) scanQRCodeLauncher.launch(createIntent)
}, },
onDuplicate = if (!viewModel.isNewBill) { { duplicateCurrentBill() } } else null, onDuplicate = if (!viewModel.isNewBill) {
onDelete = if (!viewModel.isNewBill) { { deleteBillAsked() } } else null, { duplicateCurrentBill() }
} else null,
onDelete = if (!viewModel.isNewBill) {
{ deleteBillAsked() }
} else null,
onPrefillModeSelected = { onPrefillModeSelected(it) },
onSavePrefillPreset = { onSavePrefillPreset() },
accessLevel = db.getProject(bill.projectId)?.myAccessLevel ?: DBProject.ACCESS_LEVEL_ADMIN accessLevel = db.getProject(bill.projectId)?.myAccessLevel ?: DBProject.ACCESS_LEVEL_ADMIN
) )
} }
@@ -152,25 +166,13 @@ 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 mode = BillPrefill.mode(applicationContext, projectId)
val fillFromLast = preferences.getBoolean(getString(R.string.pref_key_fill_new_bill_from_last), false) bill = newBill(
val lastBill = if (fillFromLast) db.getLastBillOfProject(projectId) else null projectId,
timeNowSeconds,
if (lastBill != null) { BillPrefill.templateFor(applicationContext, db, projectId, mode)
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) } prefillMode = mode
} else {
val project = db.getProject(projectId)
bill = DBBill(
0, 0, projectId, project?.lastPayerId ?: 0, 0.0, timeNowSeconds,
"", DBBill.STATE_ADDED, DBBill.NON_REPEATED,
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(
@@ -201,15 +203,99 @@ class EditBillActivity : AppCompatActivity() {
db.ensureDefaultLabels(bill.projectId, project.type) db.ensureDefaultLabels(bill.projectId, project.type)
} }
val hasPreset = BillPrefill.preset(applicationContext, bill.projectId) != null
val categoryMatcher = if (bill.id == 0L) autoCategoryMatcher(bill.projectId) else null
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
viewModel.currencies = currencies viewModel.currencies = currencies
viewModel.mainCurrencyName = project?.currencyName ?: "" viewModel.mainCurrencyName = project?.currencyName ?: ""
viewModel.isNewBill = (bill.id == 0L) viewModel.isNewBill = (bill.id == 0L)
viewModel.prefillMode = prefillMode
viewModel.hasPrefillPreset = hasPreset
viewModel.initFromBill(bill, members, customSplits) viewModel.initFromBill(bill, members, customSplits)
categoryMatcher?.let { viewModel.enableAutoCategorize(it) }
} }
} }
} }
@WorkerThread
private fun autoCategoryMatcher(projectId: Long): ((String) -> Long?)? {
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
// The switch lives under Extra Features; with those off it is hidden, so it must not act.
if (!preferences.getBoolean(getString(R.string.pref_key_extra_features), false)) return null
if (!preferences.getBoolean(getString(R.string.pref_key_auto_categorize), false)) return null
val categorized = db.getBillsOfProject(projectId)
.filter { it.categoryId != DBBill.CATEGORY_NONE && it.state != DBBill.STATE_DELETED }
// Only categories the picker offers: the project's own, plus the built-in reimbursement.
val allowed = db.getCategories(projectId).map { it.id }.toSet() + DBBill.CATEGORY_REIMBURSEMENT
return { what -> CategorySuggester.confidentMatch(what, categorized, allowed) }
}
@WorkerThread
private fun newBill(projectId: Long, timestamp: Long, template: BillTemplate?): DBBill {
val project = db.getProject(projectId)
val lastPayerId = project?.lastPayerId ?: 0
if (template == null) {
return DBBill(
0, 0, projectId, lastPayerId, 0.0, timestamp,
"", DBBill.STATE_ADDED, DBBill.NON_REPEATED,
DBBill.PAYMODE_NONE, DBBill.CATEGORY_NONE, "", DBBill.PAYMODE_ID_NONE
)
}
val activeIds = db.getMembersOfProject(projectId, null).filter { it.isActivated }.map { it.id }.toSet()
return DBBill(
0, 0, projectId, if (template.payerId in activeIds) template.payerId else lastPayerId,
0.0, timestamp, "", DBBill.STATE_ADDED, template.repeat,
template.paymentMode, template.categoryId, "", template.paymentModeId
).apply {
billOwers = template.owerIds.filter { it in activeIds }.map { DBBillOwer(0, 0, it) }
}
}
private fun onPrefillModeSelected(mode: PrefillMode) {
val projectId = bill.projectId
lifecycleScope.launch {
val template = withContext(Dispatchers.IO) {
BillPrefill.setMode(applicationContext, projectId, mode)
newBill(projectId, bill.timestamp, BillPrefill.templateFor(applicationContext, db, projectId, mode))
}
// Keep the reference bill in step, so the unsaved-changes check compares against
// what pre-filling put there rather than flagging it as the user's edit.
bill.payerId = template.payerId
bill.billOwers = template.billOwers
bill.categoryId = template.categoryId
bill.paymentMode = template.paymentMode
bill.paymentModeId = template.paymentModeId
bill.repeat = template.repeat
viewModel.prefillMode = mode
viewModel.applyPrefill(template)
}
}
private fun currentTemplate() = BillTemplate(
payerId = viewModel.payerId,
owerIds = viewModel.getOwersIds(),
categoryId = viewModel.categoryId,
paymentModeId = viewModel.paymentModeId,
paymentMode = bill.paymentMode,
repeat = viewModel.repeat
)
/** Saves the form's current values as the project's preset and switches to using it. */
private fun onSavePrefillPreset() {
val projectId = bill.projectId
val template = currentTemplate()
lifecycleScope.launch {
withContext(Dispatchers.IO) {
BillPrefill.savePreset(applicationContext, projectId, template)
BillPrefill.setMode(applicationContext, projectId, PrefillMode.PRESET)
}
viewModel.hasPrefillPreset = true
viewModel.prefillMode = PrefillMode.PRESET
showToast(this@EditBillActivity, getString(R.string.prefill_preset_saved))
}
}
private val scanQRCodeLauncher = private val scanQRCodeLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == RESULT_OK && result.data != null) { if (result.resultCode == RESULT_OK && result.data != null) {
@@ -282,8 +368,18 @@ class EditBillActivity : AppCompatActivity() {
if (validationError != null) { if (validationError != null) {
showToast(this, validationError) showToast(this, validationError)
} else { } else {
// Taken before saving: saving can split the bill into one per ower, and the template
// should hold the whole selection rather than whichever split was written last.
val createdHere = bill.id == 0L
val template = currentTemplate()
lifecycleScope.launch { lifecycleScope.launch {
val savedBillId = withContext(Dispatchers.IO) { saveBill() } val savedBillId = withContext(Dispatchers.IO) {
saveBill().also { id ->
if (createdHere && id != 0L) {
BillPrefill.recordCreatedOnDevice(applicationContext, bill.projectId, template)
}
}
}
val data = Intent() val data = Intent()
data.putExtra(MainConstants.SAVED_BILL_ID, savedBillId) data.putExtra(MainConstants.SAVED_BILL_ID, savedBillId)
setResult(RESULT_OK, data) setResult(RESULT_OK, data)
@@ -349,13 +445,14 @@ class EditBillActivity : AppCompatActivity() {
val uiAmount = viewModel.parseAmountFromUi(it.value) val uiAmount = viewModel.parseAmountFromUi(it.value)
SupportUtil.round2(uiAmount * viewModel.selectedCurrencyRate) SupportUtil.round2(uiAmount * viewModel.selectedCurrencyRate)
} }
} else { // PERCENT } else { // FRACTION
val totalAmount = viewModel.amountAsDouble val totalAmount = viewModel.amountAsDouble
viewModel.owersPercentSplit.filter { (id, percentStr) -> val fractionTotal = viewModel.getFractionTotal()
viewModel.owersSelection[id] == true && viewModel.parseAmountFromUi(percentStr) > 0 viewModel.owersFractionSplit.filter { (id, fraction) ->
viewModel.owersSelection[id] == true && (fraction.toIntOrNull() ?: 0) > 0
}.mapValues { }.mapValues {
val percent = viewModel.parseAmountFromUi(it.value) val fraction = it.value.toInt()
val uiAmount = SupportUtil.round2(totalAmount * percent / 100.0) val uiAmount = SupportUtil.round2(totalAmount * fraction / fractionTotal)
SupportUtil.round2(uiAmount * viewModel.selectedCurrencyRate) SupportUtil.round2(uiAmount * viewModel.selectedCurrencyRate)
} }
} }
@@ -45,10 +45,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.preference.PreferenceManager
import net.helcel.cowspent.R import net.helcel.cowspent.R
import net.helcel.cowspent.android.helper.* import net.helcel.cowspent.android.helper.*
import net.helcel.cowspent.model.* import net.helcel.cowspent.model.*
import net.helcel.cowspent.util.CategoryUtils import net.helcel.cowspent.util.CategoryUtils
import net.helcel.cowspent.util.PrefillMode
import net.helcel.cowspent.util.SupportUtil import net.helcel.cowspent.util.SupportUtil
import java.util.Date import java.util.Date
import kotlin.math.abs import kotlin.math.abs
@@ -66,24 +68,35 @@ fun EditBillScreen(
onScan: () -> Unit, onScan: () -> Unit,
onDuplicate: (() -> Unit)? = null, onDuplicate: (() -> Unit)? = null,
onDelete: (() -> Unit)? = null, onDelete: (() -> Unit)? = null,
onPrefillModeSelected: (PrefillMode) -> Unit = {},
onSavePrefillPreset: () -> Unit = {},
accessLevel: Int = DBProject.ACCESS_LEVEL_ADMIN accessLevel: Int = DBProject.ACCESS_LEVEL_ADMIN
) { ) {
val canEdit = accessLevel == DBProject.ACCESS_LEVEL_UNKNOWN || accessLevel >= DBProject.ACCESS_LEVEL_PARTICIPANT val canEdit = accessLevel == DBProject.ACCESS_LEVEL_UNKNOWN || accessLevel >= DBProject.ACCESS_LEVEL_PARTICIPANT
val context = LocalContext.current val context = LocalContext.current
val focusRequester = remember { FocusRequester() } 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 amountFocused by remember { mutableStateOf(false) }
var amountSelection by remember { mutableStateOf(TextRange(viewModel.amount.length)) } 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 // 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 // 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. // is what makes the effect run at all.
LaunchedEffect(viewModel.isNewBill) { LaunchedEffect(viewModel.isNewBill, whatFirst) {
if (!viewModel.isNewBill) return@LaunchedEffect if (!viewModel.isNewBill) return@LaunchedEffect
// The field has to be laid out before it can take focus, which is not yet true on the // 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 // pass that composed it. Waiting for the next frame makes this hold whether the flag was
// already set or arrived later. // already set or arrived later.
withFrameNanos { } withFrameNanos { }
focusRequester.requestFocus() (if (whatFirst) whatFocusRequester else focusRequester).requestFocus()
} }
StatefulAlertDialog( StatefulAlertDialog(
@@ -102,6 +115,14 @@ fun EditBillScreen(
}, },
actions = { actions = {
if (canEdit) { if (canEdit) {
viewModel.prefillMode?.let { mode ->
PrefillMenu(
mode = mode,
hasPreset = viewModel.hasPrefillPreset,
onModeSelected = onPrefillModeSelected,
onSavePreset = onSavePrefillPreset
)
}
IconButton(onClick = onScan) { IconButton(onClick = onScan) {
Icon(Icons.Default.QrCodeScanner, contentDescription = null) Icon(Icons.Default.QrCodeScanner, contentDescription = null)
} }
@@ -171,6 +192,8 @@ fun EditBillScreen(
onDateClick = onDateClick, onDateClick = onDateClick,
onTimeClick = onTimeClick, onTimeClick = onTimeClick,
amountFocusRequester = focusRequester, amountFocusRequester = focusRequester,
whatFocusRequester = whatFocusRequester,
whatFirst = whatFirst,
amountSelection = amountSelection, amountSelection = amountSelection,
onAmountSelectionChange = { amountSelection = it }, onAmountSelectionChange = { amountSelection = it },
onAmountFocusChange = { amountFocused = it } onAmountFocusChange = { amountFocused = it }
@@ -218,6 +241,65 @@ fun EditBillScreen(
private val MathOperatorRowHeight = 54.dp private val MathOperatorRowHeight = 54.dp
/**
* Chooses where this project's new bills take their payer, owers, category and payment mode
* from, and saves the form's current values as the project's preset.
*/
@Composable
fun PrefillMenu(
mode: PrefillMode,
hasPreset: Boolean,
onModeSelected: (PrefillMode) -> Unit,
onSavePreset: () -> Unit
) {
var expanded by remember { mutableStateOf(false) }
Box {
IconButton(onClick = { expanded = true }) {
Icon(Icons.Default.AutoFixHigh, contentDescription = stringResource(R.string.prefill_button))
}
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
val options = listOf(
PrefillMode.OFF to R.string.prefill_mode_off,
PrefillMode.LATEST_IN_PROJECT to R.string.prefill_mode_latest_project,
PrefillMode.LATEST_ON_DEVICE to R.string.prefill_mode_latest_device,
PrefillMode.PRESET to R.string.prefill_mode_preset
)
for ((option, label) in options) {
// The preset has nothing to fill from until one is saved.
val enabled = option != PrefillMode.PRESET || hasPreset
DropdownMenuItem(
enabled = enabled,
onClick = {
expanded = false
onModeSelected(option)
}
) {
RadioButton(selected = option == mode, onClick = null, enabled = enabled)
Spacer(Modifier.width(12.dp))
Column {
Text(stringResource(label))
if (!enabled) {
Text(
text = stringResource(R.string.prefill_mode_preset_empty),
style = MaterialTheme.typography.caption
)
}
}
}
}
Divider(modifier = Modifier.padding(vertical = 4.dp))
DropdownMenuItem(onClick = {
expanded = false
onSavePreset()
}) {
Icon(Icons.Default.Save, contentDescription = null)
Spacer(Modifier.width(12.dp))
Text(stringResource(R.string.prefill_save_preset))
}
}
}
}
private data class KeyboardColors(val tray: Color, val edge: Color, val key: Color, val label: Color) private data class KeyboardColors(val tray: Color, val edge: Color, val key: Color, val label: Color)
@Composable @Composable
@@ -300,6 +382,8 @@ fun BillBasicInfoSection(
onDateClick: () -> Unit, onDateClick: () -> Unit,
onTimeClick: () -> Unit, onTimeClick: () -> Unit,
amountFocusRequester: FocusRequester, amountFocusRequester: FocusRequester,
whatFocusRequester: FocusRequester,
whatFirst: Boolean,
amountSelection: TextRange = TextRange(viewModel.amount.length), amountSelection: TextRange = TextRange(viewModel.amount.length),
onAmountSelectionChange: (TextRange) -> Unit = {}, onAmountSelectionChange: (TextRange) -> Unit = {},
onAmountFocusChange: (Boolean) -> Unit = {} onAmountFocusChange: (Boolean) -> Unit = {}
@@ -317,6 +401,7 @@ fun BillBasicInfoSection(
val currencyDialogTitle = val currencyDialogTitle =
stringResource(R.string.currency_dialog_title, viewModel.mainCurrencyName) stringResource(R.string.currency_dialog_title, viewModel.mainCurrencyName)
val amountField: @Composable () -> Unit = {
OutlinedTextField( OutlinedTextField(
value = TextFieldValue( value = TextFieldValue(
text = viewModel.amount, text = viewModel.amount,
@@ -374,22 +459,42 @@ fun BillBasicInfoSection(
Icon(Icons.Default.SwapHoriz, contentDescription = "Change Currency") Icon(Icons.Default.SwapHoriz, contentDescription = "Change Currency")
} }
}, },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal, imeAction = ImeAction.Next), keyboardOptions = KeyboardOptions(
keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }) 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( OutlinedTextField(
value = viewModel.what, value = viewModel.what,
onValueChange = { viewModel.what = it }, onValueChange = { viewModel.updateWhat(it) },
enabled = canEdit, enabled = canEdit,
placeholder = { Text(stringResource(R.string.label_what)) }, placeholder = { Text(stringResource(R.string.label_what)) },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().focusRequester(whatFocusRequester),
leadingIcon = { Icon(Icons.Default.Title, contentDescription = null) }, leadingIcon = { Icon(Icons.Default.Title, contentDescription = null) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), keyboardOptions = KeyboardOptions(imeAction = if (whatFirst) ImeAction.Next else ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }) 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)) Spacer(modifier = Modifier.height(8.dp))
@@ -514,14 +619,13 @@ fun OwerSelectionSection(
) )
Spacer(Modifier.weight(1f)) Spacer(Modifier.weight(1f))
if (viewModel.splitMode != SplitMode.EVEN) { if (viewModel.splitMode != SplitMode.EVEN && viewModel.splitMode != SplitMode.FRACTION) {
val diff = viewModel.getDiffSplit() val diff = viewModel.getDiffSplit()
if (abs(diff) > 0.01) { if (abs(diff) > 0.01) {
val unit = if (viewModel.splitMode == SplitMode.PERCENT) "%" else ""
val diffText = val diffText =
if (diff > 0) "Missing: ${SupportUtil.normalNumberFormat.format(diff)}$unit" else "Excess: ${ if (diff > 0) "Missing: ${SupportUtil.normalNumberFormat.format(diff)}" else "Excess: ${
SupportUtil.normalNumberFormat.format(-diff) SupportUtil.normalNumberFormat.format(-diff)
}$unit" }"
Text( Text(
diffText, diffText,
color = MaterialTheme.colors.error, color = MaterialTheme.colors.error,
@@ -531,7 +635,7 @@ fun OwerSelectionSection(
} }
} }
val splitOptions = listOf(SplitMode.EVEN, SplitMode.CUSTOM, SplitMode.PERCENT) val splitOptions = listOf(SplitMode.EVEN, SplitMode.CUSTOM, SplitMode.FRACTION)
Row( Row(
modifier = Modifier modifier = Modifier
.padding(start = 8.dp) .padding(start = 8.dp)
@@ -553,7 +657,7 @@ fun OwerSelectionSection(
text = when (mode) { text = when (mode) {
SplitMode.EVEN -> "=" SplitMode.EVEN -> "="
SplitMode.CUSTOM -> "#" SplitMode.CUSTOM -> "#"
SplitMode.PERCENT -> "%" SplitMode.FRACTION -> "÷"
}, },
color = if (isSelected) MaterialTheme.colors.onPrimary else MaterialTheme.colors.onSurface, color = if (isSelected) MaterialTheme.colors.onPrimary else MaterialTheme.colors.onSurface,
fontSize = 14.sp, fontSize = 14.sp,
@@ -593,18 +697,23 @@ fun OwerSelectionSection(
if (isSelected || viewModel.splitMode != SplitMode.EVEN) { if (isSelected || viewModel.splitMode != SplitMode.EVEN) {
val focusManager = LocalFocusManager.current val focusManager = LocalFocusManager.current
val interactionSource = remember { MutableInteractionSource() } val interactionSource = remember { MutableInteractionSource() }
val value = if (viewModel.splitMode == SplitMode.PERCENT) { val value = if (viewModel.splitMode == SplitMode.FRACTION) {
viewModel.owersPercentSplit[member.id] ?: "" viewModel.owersFractionSplit[member.id] ?: ""
} else { } else {
viewModel.owersCustomSplit[member.id] ?: "" viewModel.owersCustomSplit[member.id] ?: ""
} }
val fractionTotal = viewModel.getFractionTotal()
BasicTextField( BasicTextField(
value = value, value = value,
onValueChange = { nv -> onValueChange = { nv ->
val filteredValue = nv.filter { it in "0123456789,.+-*/" } val filteredValue = if (viewModel.splitMode == SplitMode.FRACTION) {
if (viewModel.splitMode == SplitMode.PERCENT) { nv.filter { it.isDigit() }
viewModel.owersPercentSplit[member.id] = filteredValue } else {
nv.filter { it in "0123456789,.+-*/" }
}
if (viewModel.splitMode == SplitMode.FRACTION) {
viewModel.owersFractionSplit[member.id] = filteredValue
} else { } else {
viewModel.owersCustomSplit[member.id] = filteredValue viewModel.owersCustomSplit[member.id] = filteredValue
} }
@@ -612,7 +721,7 @@ fun OwerSelectionSection(
}, },
modifier = Modifier modifier = Modifier
.width(80.dp) .width(80.dp)
.height(46.dp), .height(40.dp),
interactionSource = interactionSource, interactionSource = interactionSource,
singleLine = true, singleLine = true,
enabled = viewModel.splitMode != SplitMode.EVEN && canEdit, enabled = viewModel.splitMode != SplitMode.EVEN && canEdit,
@@ -632,12 +741,16 @@ fun OwerSelectionSection(
enabled = viewModel.splitMode != SplitMode.EVEN && canEdit, enabled = viewModel.splitMode != SplitMode.EVEN && canEdit,
interactionSource = interactionSource, interactionSource = interactionSource,
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp), contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp),
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.outlinedTextFieldColors(
cursorColor = MaterialTheme.colors.onSurface, cursorColor = MaterialTheme.colors.onSurface,
backgroundColor = Color.Transparent, backgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.02f),
unfocusedIndicatorColor = Color.Transparent, unfocusedBorderColor = MaterialTheme.colors.onSurface.copy(alpha = 0.2f),
disabledIndicatorColor = Color.Transparent focusedBorderColor = MaterialTheme.colors.primary.copy(alpha = 0.7f),
) disabledBorderColor = MaterialTheme.colors.onSurface.copy(alpha = 0.14f)
),
trailingIcon = if (viewModel.splitMode == SplitMode.FRACTION && isSelected && fractionTotal > 0) {
{ Text("/$fractionTotal", color = MaterialTheme.colors.onSurface.copy(alpha = 0.65f)) }
} else null
) )
} }
} }
@@ -686,7 +799,7 @@ fun BillAdditionalDetailsSection(
}, },
content = { content = {
DropdownMenuItem(onClick = { DropdownMenuItem(onClick = {
viewModel.categoryId = 0 viewModel.selectCategory(DBBill.CATEGORY_NONE)
categoryExpanded = false categoryExpanded = false
}) { }) {
Icon(Icons.Default.Close, tint = Color.Red, contentDescription = null) Icon(Icons.Default.Close, tint = Color.Red, contentDescription = null)
@@ -695,7 +808,7 @@ fun BillAdditionalDetailsSection(
} }
DropdownMenuItem(onClick = { DropdownMenuItem(onClick = {
viewModel.categoryId = DBBill.CATEGORY_REIMBURSEMENT viewModel.selectCategory(DBBill.CATEGORY_REIMBURSEMENT)
categoryExpanded = false categoryExpanded = false
}) { }) {
Text(text = "\uD83D\uDCB0", fontSize = 20.sp) Text(text = "\uD83D\uDCB0", fontSize = 20.sp)
@@ -705,7 +818,7 @@ fun BillAdditionalDetailsSection(
categories.filter { it.remoteId != DBBill.CATEGORY_REIMBURSEMENT }.forEach { category -> categories.filter { it.remoteId != DBBill.CATEGORY_REIMBURSEMENT }.forEach { category ->
DropdownMenuItem(onClick = { DropdownMenuItem(onClick = {
viewModel.categoryId = category.id viewModel.selectCategory(category.id)
categoryExpanded = false categoryExpanded = false
}) { }) {
Text(text = category.icon, fontSize = 20.sp) Text(text = category.icon, fontSize = 20.sp)
@@ -906,24 +1019,24 @@ fun EditBillScreenCustomPreview() {
} }
@SuppressLint("ViewModelConstructorInComposable") @SuppressLint("ViewModelConstructorInComposable")
@Preview(showBackground = true, name = "Percent Split (%)") @Preview(showBackground = true, name = "Fraction Split")
@Composable @Composable
fun EditBillScreenPercentPreview() { fun EditBillScreenFractionPreview() {
MaterialTheme { MaterialTheme {
EditBillScreen( EditBillScreen(
viewModel = EditBillViewModel().apply { viewModel = EditBillViewModel().apply {
what = "Percent Split Pizza" what = "Fraction Split Pizza"
amount = "100.00" amount = "100.00"
mainCurrencyName = "EUR" mainCurrencyName = "EUR"
members = listOf( members = listOf(
DBMember(1, 0, 0, "Alice", true, 1.0, 0, null, null, null, null, null), DBMember(1, 0, 0, "Alice", true, 1.0, 0, null, null, null, null, null),
DBMember(2, 0, 0, "Bob", true, 1.0, 0, null, null, null, null, null) DBMember(2, 0, 0, "Bob", true, 1.0, 0, null, null, null, null, null)
) )
splitMode = SplitMode.PERCENT splitMode = SplitMode.FRACTION
owersSelection[1] = true owersSelection[1] = true
owersSelection[2] = true owersSelection[2] = true
owersPercentSplit[1] = "70" owersFractionSplit[1] = "1"
owersPercentSplit[2] = "30" owersFractionSplit[2] = "3"
}, },
categories = emptyList(), categories = emptyList(),
paymentModes = emptyList(), paymentModes = emptyList(),
@@ -13,11 +13,12 @@ import net.helcel.cowspent.android.helper.parseAmount
import net.helcel.cowspent.model.DBBill import net.helcel.cowspent.model.DBBill
import net.helcel.cowspent.model.DBCurrency import net.helcel.cowspent.model.DBCurrency
import net.helcel.cowspent.model.DBMember import net.helcel.cowspent.model.DBMember
import net.helcel.cowspent.util.PrefillMode
import net.helcel.cowspent.util.SupportUtil import net.helcel.cowspent.util.SupportUtil
import net.helcel.cowspent.util.evalMath import net.helcel.cowspent.util.evalMath
enum class SplitMode { enum class SplitMode {
EVEN, CUSTOM, PERCENT EVEN, CUSTOM, FRACTION
} }
class EditBillViewModel : ViewModel() { class EditBillViewModel : ViewModel() {
@@ -31,6 +32,20 @@ class EditBillViewModel : ViewModel() {
var categoryId by mutableLongStateOf(0L) var categoryId by mutableLongStateOf(0L)
var isNewBill by mutableStateOf(false) var isNewBill by mutableStateOf(false)
// Null hides the pre-fill menu: it only applies to a bill started from scratch.
var prefillMode by mutableStateOf<PrefillMode?>(null)
var hasPrefillPreset by mutableStateOf(false)
// Auto-categorization: null while it is off, or for a bill that is not new.
private var autoCategorizer: ((String) -> Long?)? = null
// Once the user picks a category themselves, the name no longer gets a say.
private var categoryChosenByUser = false
// The category in place before an automatic one replaced it, to restore when the name stops
// matching; null while no automatic category is applied.
private var categoryBeforeAuto: Long? = null
var currencies by mutableStateOf<List<DBCurrency>>(emptyList()) var currencies by mutableStateOf<List<DBCurrency>>(emptyList())
var mainCurrencyName by mutableStateOf("") var mainCurrencyName by mutableStateOf("")
var selectedCurrencyName by mutableStateOf("") var selectedCurrencyName by mutableStateOf("")
@@ -40,7 +55,7 @@ class EditBillViewModel : ViewModel() {
var owersSelection = mutableStateMapOf<Long, Boolean>() var owersSelection = mutableStateMapOf<Long, Boolean>()
var splitMode by mutableStateOf(SplitMode.EVEN) var splitMode by mutableStateOf(SplitMode.EVEN)
var owersCustomSplit = mutableStateMapOf<Long, String>() var owersCustomSplit = mutableStateMapOf<Long, String>()
var owersPercentSplit = mutableStateMapOf<Long, String>() var owersFractionSplit = mutableStateMapOf<Long, String>()
var dialogState by mutableStateOf<DialogState?>(null) var dialogState by mutableStateOf<DialogState?>(null)
@@ -52,7 +67,8 @@ class EditBillViewModel : ViewModel() {
try { try {
val result = evalMath(sanitized) val result = evalMath(sanitized)
if (result != 0.0) return SupportUtil.round2(result) if (result != 0.0) return SupportUtil.round2(result)
} catch (_: Exception) {} } catch (_: Exception) {
}
} }
val parsed = parseAmount(input) ?: 0.0 val parsed = parseAmount(input) ?: 0.0
return SupportUtil.round2(parsed) return SupportUtil.round2(parsed)
@@ -77,18 +93,16 @@ class EditBillViewModel : ViewModel() {
owersCustomSplit.remove(m.id) owersCustomSplit.remove(m.id)
} }
} }
} else if (splitMode == SplitMode.PERCENT) { } else if (splitMode == SplitMode.FRACTION) {
val selectedCount = owersSelection.count { it.value } val selectedCount = owersSelection.count { it.value }
if (selectedCount > 0) { if (selectedCount > 0) {
val evenPercent = 100.0 / selectedCount
val evenPercentStr = SupportUtil.round2(evenPercent).toString()
members.forEach { m -> members.forEach { m ->
if (owersSelection[m.id] == true) { if (owersSelection[m.id] == true) {
if (owersPercentSplit[m.id].isNullOrEmpty()) { if (owersFractionSplit[m.id].isNullOrEmpty()) {
owersPercentSplit[m.id] = evenPercentStr owersFractionSplit[m.id] = "1"
} }
} else { } else {
owersPercentSplit.remove(m.id) owersFractionSplit.remove(m.id)
} }
} }
} }
@@ -101,12 +115,12 @@ class EditBillViewModel : ViewModel() {
if (selected) { if (selected) {
if (splitMode == SplitMode.CUSTOM && owersCustomSplit[id].isNullOrEmpty()) { if (splitMode == SplitMode.CUSTOM && owersCustomSplit[id].isNullOrEmpty()) {
owersCustomSplit[id] = "0" owersCustomSplit[id] = "0"
} else if (splitMode == SplitMode.PERCENT && owersPercentSplit[id].isNullOrEmpty()) { } else if (splitMode == SplitMode.FRACTION && owersFractionSplit[id].isNullOrEmpty()) {
owersPercentSplit[id] = "0" owersFractionSplit[id] = "1"
} }
} else { } else {
owersCustomSplit.remove(id) owersCustomSplit.remove(id)
owersPercentSplit.remove(id) owersFractionSplit.remove(id)
} }
} else { } else {
updateSplits() updateSplits()
@@ -114,11 +128,8 @@ class EditBillViewModel : ViewModel() {
} }
fun getDiffSplit(): Double { fun getDiffSplit(): Double {
return if (splitMode == SplitMode.PERCENT) { return if (splitMode == SplitMode.FRACTION) {
val customTotal = owersPercentSplit.entries 0.0
.filter { owersSelection[it.key] == true }
.sumOf { parseAmountFromUi(it.value) }
SupportUtil.round2(100.0 - customTotal)
} else { } else {
val customTotal = owersCustomSplit.entries val customTotal = owersCustomSplit.entries
.filter { owersSelection[it.key] == true } .filter { owersSelection[it.key] == true }
@@ -127,6 +138,10 @@ class EditBillViewModel : ViewModel() {
} }
} }
fun getFractionTotal(): Int = owersFractionSplit.entries
.filter { owersSelection[it.key] == true }
.sumOf { it.value.toIntOrNull()?.coerceAtLeast(0) ?: 0 }
fun getOwersIds(): List<Long> { fun getOwersIds(): List<Long> {
return owersSelection.filter { it.value }.keys.toList() return owersSelection.filter { it.value }.keys.toList()
} }
@@ -242,7 +257,7 @@ class EditBillViewModel : ViewModel() {
owersSelection.clear() owersSelection.clear()
owersCustomSplit.clear() owersCustomSplit.clear()
owersPercentSplit.clear() owersFractionSplit.clear()
if (customSplits != null) { if (customSplits != null) {
splitMode = SplitMode.CUSTOM splitMode = SplitMode.CUSTOM
@@ -279,6 +294,48 @@ class EditBillViewModel : ViewModel() {
} }
} }
fun applyPrefill(bill: DBBill) {
payerId = bill.payerId
categoryId = bill.categoryId
paymentModeId = bill.paymentModeId
repeat = bill.repeat ?: DBBill.NON_REPEATED
val owerIds = bill.billOwersIds.toSet()
for (member in members) {
toggleMember(member.id, member.id in owerIds)
}
// The pre-filled category is the new fallback; a name match still wins over it.
categoryBeforeAuto = null
autoCategorize()
}
fun enableAutoCategorize(match: (String) -> Long?) {
autoCategorizer = match
}
fun updateWhat(value: String) {
what = value
autoCategorize()
}
fun selectCategory(id: Long) {
categoryId = id
categoryChosenByUser = true
categoryBeforeAuto = null
}
private fun autoCategorize() {
val match = autoCategorizer ?: return
if (!isNewBill || categoryChosenByUser) return
val categoryForName = match(what)
if (categoryForName != null) {
if (categoryBeforeAuto == null) categoryBeforeAuto = categoryId
categoryId = categoryForName
} else {
categoryBeforeAuto?.let { categoryId = it }
categoryBeforeAuto = null
}
}
fun isFormValid(): Boolean { fun isFormValid(): Boolean {
return what.isNotEmpty() && return what.isNotEmpty() &&
timestamp != 0L && timestamp != 0L &&
@@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModel
import net.helcel.cowspent.model.DBBill import net.helcel.cowspent.model.DBBill
import net.helcel.cowspent.model.DBCategory import net.helcel.cowspent.model.DBCategory
import net.helcel.cowspent.persistence.CowspentSQLiteOpenHelper import net.helcel.cowspent.persistence.CowspentSQLiteOpenHelper
import net.helcel.cowspent.util.CategorySuggester
class LabelBillsViewModel : ViewModel() { class LabelBillsViewModel : ViewModel() {
var billsToLabel by mutableStateOf<List<DBBill>>(emptyList()) var billsToLabel by mutableStateOf<List<DBBill>>(emptyList())
@@ -32,26 +33,9 @@ class LabelBillsViewModel : ViewModel() {
suggestedCategories = emptyList() suggestedCategories = emptyList()
return return
} }
val name = bill.what.lowercase().trim() suggestedCategories = CategorySuggester.rank(bill.what, allCategorizedBills)
if (name.isEmpty()) {
suggestedCategories = emptyList()
return
}
val matches = allCategorizedBills.filter {
val otherName = it.what.lowercase().trim()
otherName == name || (name.length > 3 && otherName.contains(name)) || (otherName.length > 3 && name.contains(otherName))
}
val counts = matches.groupBy { it.categoryId }
.mapValues { it.value.size }
.toList()
.sortedByDescending { it.second }
.take(2) .take(2)
.mapNotNull { (catId, _) -> categoriesMap[catId] }
suggestedCategories = counts.mapNotNull { (catId, _) ->
categoriesMap[catId]
}
} }
fun labelCurrentBill(db: CowspentSQLiteOpenHelper, categoryId: Long) { fun labelCurrentBill(db: CowspentSQLiteOpenHelper, categoryId: Long) {
@@ -55,6 +55,7 @@ import net.helcel.cowspent.util.CospendClientUtil
import net.helcel.cowspent.util.ExportUtil import net.helcel.cowspent.util.ExportUtil
import net.helcel.cowspent.util.ICallback import net.helcel.cowspent.util.ICallback
import net.helcel.cowspent.util.IRefreshBillsListCallback import net.helcel.cowspent.util.IRefreshBillsListCallback
import net.helcel.cowspent.util.LocalNetworkPermissionHelper
import net.helcel.cowspent.util.SyncSettings import net.helcel.cowspent.util.SyncSettings
import net.helcel.cowspent.util.SupportUtil import net.helcel.cowspent.util.SupportUtil
import net.helcel.cowspent.util.VersatileProjectSyncClient import net.helcel.cowspent.util.VersatileProjectSyncClient
@@ -90,6 +91,7 @@ class BillsListViewActivity :
private var mActionMode: ActionMode? = null private var mActionMode: ActionMode? = null
private lateinit var db: CowspentSQLiteOpenHelper private lateinit var db: CowspentSQLiteOpenHelper
private val localNetworkPermissionHelper = LocalNetworkPermissionHelper(this)
private val syncCallBack = object : ICallback { private val syncCallBack = object : ICallback {
override fun onFinish() { override fun onFinish() {
@@ -341,15 +343,23 @@ class BillsListViewActivity :
} }
viewModel.isRefreshing = false viewModel.isRefreshing = false
synchronize(SyncTrigger.APP_OPEN) registerBroadcastReceiver()
isActivityVisible = true
lifecycleScope.launch { synchronize(SyncTrigger.APP_OPEN)
syncNewlyDiscoveredProjects(withContext(Dispatchers.IO) { db.projects })
} }
registerBroadcastReceiver() private fun configuredServerUrls(projects: List<DBProject>): List<String> = buildList {
updateAvatarInDrawer(CowspentServerSyncHelper.isNextcloudAccountConfigured(this)) addAll(projects.filterNot { it.isLocal }.mapNotNull { it.serverUrl })
isActivityVisible = true if (CowspentServerSyncHelper.isNextcloudAccountConfigured(applicationContext)) {
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
val accountUrl = if (preferences.getBoolean(AccountActivity.SETTINGS_USE_SSO, false)) {
preferences.getString(AccountActivity.SETTINGS_SSO_URL, null)
} else {
preferences.getString(AccountActivity.SETTINGS_URL, null)
}
accountUrl?.let(::add)
}
} }
override fun onPause() { override fun onPause() {
@@ -802,6 +812,26 @@ class BillsListViewActivity :
@VisibleForTesting @VisibleForTesting
internal fun synchronize(trigger: SyncTrigger) { internal fun synchronize(trigger: SyncTrigger) {
lifecycleScope.launch {
val projects = withContext(Dispatchers.IO) { db.projects }
localNetworkPermissionHelper.runWithAccess(
configuredServerUrls(projects),
action = {
synchronizeAfterPermission(trigger)
if (trigger == SyncTrigger.APP_OPEN) {
lifecycleScope.launch {
syncNewlyDiscoveredProjects(withContext(Dispatchers.IO) { db.projects })
}
updateAvatarInDrawer(
CowspentServerSyncHelper.isNextcloudAccountConfigured(this@BillsListViewActivity)
)
}
}
)
}
}
private fun synchronizeAfterPermission(trigger: SyncTrigger) {
val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext) val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
// isSyncPossible is networkConnected && !offlineMode, so offline mode is already covered // isSyncPossible is networkConnected && !offlineMode, so offline mode is already covered
// here - including for a manual refresh, which cannot currently override it. // here - including for a manual refresh, which cannot currently override it.
@@ -31,6 +31,7 @@ class NewProjectActivity : AppCompatActivity() {
internal val viewModel: NewProjectViewModel by viewModels() internal val viewModel: NewProjectViewModel by viewModels()
private lateinit var db: CowspentSQLiteOpenHelper private lateinit var db: CowspentSQLiteOpenHelper
private val localNetworkPermissionHelper = LocalNetworkPermissionHelper(this)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() enableEdgeToEdge()
@@ -136,7 +137,16 @@ class NewProjectActivity : AppCompatActivity() {
viewModel.isAuthenticatedAccount = db.cowspentServerSyncHelper.canCreateAuthenticatedProject(fakeProj) viewModel.isAuthenticatedAccount = db.cowspentServerSyncHelper.canCreateAuthenticatedProject(fakeProj)
} }
private fun onPressOk() = createProject() private fun onPressOk() {
if (viewModel.projectType == ProjectType.LOCAL) {
createProject()
} else {
localNetworkPermissionHelper.runWithAccess(
listOf(getFormattedUrl()),
action = { createProject() }
)
}
}
private fun getFormattedUrl(): String { private fun getFormattedUrl(): String {
var url = viewModel.projectUrl.trim() var url = viewModel.projectUrl.trim()
@@ -32,11 +32,13 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.AccountCircle import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Archive import androidx.compose.material.icons.filled.Archive
import androidx.compose.material.icons.filled.Brightness2 import androidx.compose.material.icons.filled.Brightness2
import androidx.compose.material.icons.filled.Category
import androidx.compose.material.icons.filled.Group import androidx.compose.material.icons.filled.Group
import androidx.compose.material.icons.filled.Info import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Palette import androidx.compose.material.icons.filled.Palette
import androidx.compose.material.icons.filled.Restore import androidx.compose.material.icons.filled.Restore
import androidx.compose.material.icons.filled.Sync import androidx.compose.material.icons.filled.Sync
import androidx.compose.material.icons.filled.SwapVert
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
@@ -95,9 +97,12 @@ fun SettingsScreen(
val keyShowArchived = stringResource(R.string.pref_key_show_archived) val keyShowArchived = stringResource(R.string.pref_key_show_archived)
val keyExtraFeatures = stringResource(R.string.pref_key_extra_features) val keyExtraFeatures = stringResource(R.string.pref_key_extra_features)
val keyStatsIncludeDeactivated = stringResource(R.string.pref_key_stats_include_deactivated) val keyStatsIncludeDeactivated = stringResource(R.string.pref_key_stats_include_deactivated)
val keyAutoCategorize = stringResource(R.string.pref_key_auto_categorize)
val keyFullSyncDelay = stringResource(R.string.pref_key_full_sync_delay) val keyFullSyncDelay = stringResource(R.string.pref_key_full_sync_delay)
val keyFillNewBillFromLast = stringResource(R.string.pref_key_fill_new_bill_from_last)
val keyLastAccountSync = stringResource(R.string.pref_key_last_account_sync_timestamp) 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) val isNextcloudConfigured = CowspentServerSyncHelper.isNextcloudAccountConfigured(context)
@@ -150,12 +155,15 @@ fun SettingsScreen(
var extraFeatures by remember(keyExtraFeatures) { var extraFeatures by remember(keyExtraFeatures) {
mutableStateOf(sharedPreferences.getBoolean(keyExtraFeatures, false)) mutableStateOf(sharedPreferences.getBoolean(keyExtraFeatures, false))
} }
var fillNewBillFromLast by remember(keyFillNewBillFromLast) {
mutableStateOf(sharedPreferences.getBoolean(keyFillNewBillFromLast, false))
}
var statsIncludeDeactivated by remember(keyStatsIncludeDeactivated) { var statsIncludeDeactivated by remember(keyStatsIncludeDeactivated) {
mutableStateOf(sharedPreferences.getBoolean(keyStatsIncludeDeactivated, false)) mutableStateOf(sharedPreferences.getBoolean(keyStatsIncludeDeactivated, false))
} }
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 fullSyncDelays = SyncSettings.FULL_SYNC_DELAY_CHOICES_MINUTES
val fullSyncDelayLabels = listOf( val fullSyncDelayLabels = listOf(
@@ -319,6 +327,20 @@ fun SettingsScreen(
) )
if (extraFeatures) { 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( SettingsSwitchPreference(
title = stringResource(R.string.settings_show_archived), title = stringResource(R.string.settings_show_archived),
icon = Icons.Default.Archive, icon = Icons.Default.Archive,
@@ -341,19 +363,6 @@ fun SettingsScreen(
} }
) )
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)
}
}
)
SettingsSwitchPreference( SettingsSwitchPreference(
title = stringResource(R.string.settings_stats_include_deactivated), title = stringResource(R.string.settings_stats_include_deactivated),
icon = Icons.Default.Group, icon = Icons.Default.Group,
@@ -366,6 +375,19 @@ fun SettingsScreen(
} }
) )
SettingsSwitchPreference(
title = stringResource(R.string.settings_auto_categorize),
summary = stringResource(R.string.settings_auto_categorize_summary),
icon = Icons.Default.Category,
checked = autoCategorize,
onCheckedChange = {
autoCategorize = it
sharedPreferences.edit {
putBoolean(keyAutoCategorize, it)
}
}
)
SettingsSliderPreference( SettingsSliderPreference(
title = stringResource(R.string.settings_full_sync_delay), title = stringResource(R.string.settings_full_sync_delay),
summary = stringResource(R.string.settings_full_sync_delay_summary), summary = stringResource(R.string.settings_full_sync_delay_summary),
@@ -21,6 +21,7 @@ import net.helcel.cowspent.model.DBMember
import net.helcel.cowspent.model.DBPaymentMode import net.helcel.cowspent.model.DBPaymentMode
import net.helcel.cowspent.model.DBProject import net.helcel.cowspent.model.DBProject
import net.helcel.cowspent.model.ProjectType import net.helcel.cowspent.model.ProjectType
import net.helcel.cowspent.util.BillPrefill
import net.helcel.cowspent.util.CategoryUtils import net.helcel.cowspent.util.CategoryUtils
import net.helcel.cowspent.util.SecureStorage import net.helcel.cowspent.util.SecureStorage
import net.helcel.cowspent.util.SupportUtil import net.helcel.cowspent.util.SupportUtil
@@ -312,6 +313,7 @@ class CowspentSQLiteOpenHelper private constructor(val context: Context) :
db.delete(table_projects, "$key_id = ?", projectId) db.delete(table_projects, "$key_id = ?", projectId)
} }
SecureStorage.removePasswordSync(context, "ProjectPassword_$id") SecureStorage.removePasswordSync(context, "ProjectPassword_$id")
BillPrefill.clear(context, id)
} }
// --- Members logic --- // --- Members logic ---
@@ -67,6 +67,12 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
return networkConnected && !offlineMode return networkConnected && !offlineMode
} }
private fun removeDeletedRemoteProject(project: DBProject) {
dbHelper.deleteProject(project.id)
projectIdsToSync.removeAll { it == project.id }
appContext.sendBroadcast(Intent(MainConstants.BROADCAST_PROJECT_SYNCED))
}
fun addCallbackPull(callback: ICallback) { fun addCallbackPull(callback: ICallback) {
// Callers register on every resume but the list is only drained when a task actually // Callers register on every resume but the list is only drained when a task actually
// starts, so refuse duplicates rather than letting the same callback pile up. // starts, so refuse duplicates rather than letting the same callback pile up.
@@ -167,8 +173,8 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
private var newBillsDialogText = "" private var newBillsDialogText = ""
private var updatedBillsDialogText = "" private var updatedBillsDialogText = ""
private var deletedBillsDialogText = "" private var deletedBillsDialogText = ""
private var deferred: Deferred<LoginStatus>? = null private var deferred: Deferred<LoginStatus>? = null
private var archivedAfterNotFound = false
init { init {
Log.i(TAG, "SYNC TASK project : ${project.remoteId}") Log.i(TAG, "SYNC TASK project : ${project.remoteId}")
@@ -230,9 +236,11 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
} }
Log.i(TAG, "STARTING SYNCHRONIZATION with Cospend version($version)") Log.i(TAG, "STARTING SYNCHRONIZATION with Cospend version($version)")
var status = pushLocalChanges() var status = pushLocalChanges()
if (archivedAfterNotFound) return LoginStatus.OK
if (status == LoginStatus.OK) { if (status == LoginStatus.OK) {
status = pullRemoteChanges() status = pullRemoteChanges()
} }
if (archivedAfterNotFound) return LoginStatus.OK
Log.i(TAG, "SYNCHRONIZATION FINISHED") Log.i(TAG, "SYNCHRONIZATION FINISHED")
return status return status
} }
@@ -254,6 +262,15 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
preferences.edit { putString(versionKey(), version) } preferences.edit { putString(versionKey(), version) }
} }
private fun archiveOnRemoteNotFound(e: NextcloudHttpRequestFailedException): Boolean {
if (project.type != ProjectType.COSPEND || e.statusCode != 404) return false
val archivedTs = System.currentTimeMillis() / 1000
project.archivedTs = archivedTs
dbHelper.updateProject(projId = project.id, newArchivedTs = archivedTs)
archivedAfterNotFound = true
return true
}
private fun pushLocalChanges(): LoginStatus { private fun pushLocalChanges(): LoginStatus {
Log.d(TAG, "PUSH LOCAL CHANGES") Log.d(TAG, "PUSH LOCAL CHANGES")
@@ -570,11 +587,15 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
LoginStatus.SSO_TOKEN_MISMATCH LoginStatus.SSO_TOKEN_MISMATCH
} catch (e: NextcloudHttpRequestFailedException) { } catch (e: NextcloudHttpRequestFailedException) {
Log.e(TAG, "Catch SSO HTTP req FAILED", e) Log.e(TAG, "Catch SSO HTTP req FAILED", e)
if (archiveOnRemoteNotFound(e)) {
LoginStatus.OK
} else {
errorMessages.add(getErrorMessageFromException(e)) errorMessages.add(getErrorMessageFromException(e))
e.cause?.let { exceptions.add(it) } e.cause?.let { exceptions.add(it) }
LoginStatus.REQ_FAILED LoginStatus.REQ_FAILED
} }
} }
}
/** /**
* Reads the project's own row and each of its collections. One request, and everything it * Reads the project's own row and each of its collections. One request, and everything it
@@ -646,11 +667,15 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
LoginStatus.SSO_TOKEN_MISMATCH LoginStatus.SSO_TOKEN_MISMATCH
} catch (e: NextcloudHttpRequestFailedException) { } catch (e: NextcloudHttpRequestFailedException) {
Log.e(TAG, "Catch NC REQ failed", e) Log.e(TAG, "Catch NC REQ failed", e)
if (archiveOnRemoteNotFound(e)) {
LoginStatus.OK
} else {
errorMessages.add(getErrorMessageFromException(e)) errorMessages.add(getErrorMessageFromException(e))
e.cause?.let { exceptions.add(it) } e.cause?.let { exceptions.add(it) }
LoginStatus.REQ_FAILED LoginStatus.REQ_FAILED
} }
} }
}
private fun updateLocalProject(projResponse: ServerResponse.ProjectResponse) { private fun updateLocalProject(projResponse: ServerResponse.ProjectResponse) {
val name = projResponse.name val name = projResponse.name
val email = projResponse.email val email = projResponse.email
@@ -1356,7 +1381,7 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
appContext.sendBroadcast(Intent(MainConstants.BROADCAST_SSO_TOKEN_MISMATCH)) appContext.sendBroadcast(Intent(MainConstants.BROADCAST_SSO_TOKEN_MISMATCH))
} }
} else { } else {
dbHelper.deleteProject(project!!.id) removeDeletedRemoteProject(project!!)
} }
callback.onFinish(project?.id?.toString() ?: "", errorString) callback.onFinish(project?.id?.toString() ?: "", errorString)
} }
@@ -0,0 +1,163 @@
package net.helcel.cowspent.util
import android.content.Context
import androidx.annotation.WorkerThread
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import net.helcel.cowspent.R
import net.helcel.cowspent.model.DBBill
import net.helcel.cowspent.persistence.CowspentSQLiteOpenHelper
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
/** Where a new bill takes its payer, owers, category, payment mode and repeat from. */
enum class PrefillMode(val id: String) {
/** Start from an empty form (the project's last payer is still suggested). */
OFF("off"),
/** The most recent bill of the project, whoever created it and on whichever device. */
LATEST_IN_PROJECT("project"),
/**
* The last bill created on this device. When entering a batch of older bills, the project's
* newest bill keeps changing under you as other members sync theirs, while this one only
* follows what you typed.
*/
LATEST_ON_DEVICE("device"),
/** Values the user saved once for the project and wants every time. */
PRESET("preset");
companion object {
fun fromId(id: String?): PrefillMode? = entries.firstOrNull { it.id == id }
}
}
/**
* The part of a bill that pre-filling carries over. Amount, description, date and comment are
* deliberately absent: those describe the one expense, not the habit.
*/
data class BillTemplate(
val payerId: Long,
val owerIds: List<Long>,
val categoryId: Long,
val paymentModeId: Long,
val paymentMode: String?,
val repeat: String
) {
fun toJson(): String = JSONObject()
.put(KEY_PAYER, payerId)
.put(KEY_OWERS, JSONArray(owerIds))
.put(KEY_CATEGORY, categoryId)
.put(KEY_PAYMENT_MODE_ID, paymentModeId)
.put(KEY_PAYMENT_MODE, paymentMode ?: JSONObject.NULL)
.put(KEY_REPEAT, repeat)
.toString()
companion object {
private const val KEY_PAYER = "payer"
private const val KEY_OWERS = "owers"
private const val KEY_CATEGORY = "category"
private const val KEY_PAYMENT_MODE_ID = "paymentModeId"
private const val KEY_PAYMENT_MODE = "paymentMode"
private const val KEY_REPEAT = "repeat"
fun of(bill: DBBill) = BillTemplate(
payerId = bill.payerId,
owerIds = bill.billOwersIds,
categoryId = bill.categoryId,
paymentModeId = bill.paymentModeId,
paymentMode = bill.paymentMode,
repeat = bill.repeat ?: DBBill.NON_REPEATED
)
/** Null for a missing or unreadable value, so a corrupt entry acts as "nothing saved". */
fun fromJson(json: String?): BillTemplate? {
if (json.isNullOrEmpty()) return null
return try {
val o = JSONObject(json)
val owers = o.getJSONArray(KEY_OWERS)
BillTemplate(
payerId = o.getLong(KEY_PAYER),
owerIds = List(owers.length()) { owers.getLong(it) },
categoryId = o.optLong(KEY_CATEGORY, DBBill.CATEGORY_NONE),
paymentModeId = o.optLong(KEY_PAYMENT_MODE_ID, DBBill.PAYMODE_ID_NONE),
paymentMode = if (o.isNull(KEY_PAYMENT_MODE)) null else o.getString(KEY_PAYMENT_MODE),
repeat = o.optString(KEY_REPEAT, DBBill.NON_REPEATED)
)
} catch (_: JSONException) {
null
}
}
}
}
/**
* Per-project pre-fill choice and the templates behind it. Everything lives in this device's
* preferences: "latest on this device" is device-local by definition, and the mode and preset
* describe how this user enters bills, not something the other members should get.
*/
object BillPrefill {
private fun modeKey(projectId: Long) = "prefill_mode_$projectId"
private fun deviceKey(projectId: Long) = "prefill_device_$projectId"
private fun presetKey(projectId: Long) = "prefill_preset_$projectId"
private fun prefs(context: Context) = PreferenceManager.getDefaultSharedPreferences(context)
fun mode(context: Context, projectId: Long): PrefillMode {
val prefs = prefs(context)
PrefillMode.fromId(prefs.getString(modeKey(projectId), null))?.let { return it }
// This used to be one global on/off switch. Projects that never picked a mode keep
// behaving the way that switch said.
val legacyOn = prefs.getBoolean(context.getString(R.string.pref_key_fill_new_bill_from_last), false)
return if (legacyOn) PrefillMode.LATEST_IN_PROJECT else PrefillMode.OFF
}
fun setMode(context: Context, projectId: Long, mode: PrefillMode) {
prefs(context).edit { putString(modeKey(projectId), mode.id) }
}
fun deviceTemplate(context: Context, projectId: Long): BillTemplate? =
BillTemplate.fromJson(prefs(context).getString(deviceKey(projectId), null))
/** Called for every bill created here, whatever the mode, so switching to it later works. */
fun recordCreatedOnDevice(context: Context, projectId: Long, template: BillTemplate) {
prefs(context).edit { putString(deviceKey(projectId), template.toJson()) }
}
fun preset(context: Context, projectId: Long): BillTemplate? =
BillTemplate.fromJson(prefs(context).getString(presetKey(projectId), null))
fun savePreset(context: Context, projectId: Long, template: BillTemplate) {
prefs(context).edit { putString(presetKey(projectId), template.toJson()) }
}
/** Forget everything stored for a project, e.g. once it is removed from the device. */
fun clear(context: Context, projectId: Long) {
prefs(context).edit {
remove(modeKey(projectId))
remove(deviceKey(projectId))
remove(presetKey(projectId))
}
}
/**
* The template [mode] points at, or null when there is nothing to fill from: the mode is
* off, the project has no bill yet, nothing was created on this device, or no preset was
* saved. Callers then fall back to an empty form.
*/
@WorkerThread
fun templateFor(
context: Context,
db: CowspentSQLiteOpenHelper,
projectId: Long,
mode: PrefillMode = mode(context, projectId)
): BillTemplate? = when (mode) {
PrefillMode.OFF -> null
PrefillMode.LATEST_IN_PROJECT -> db.getLastBillOfProject(projectId)?.let(BillTemplate::of)
PrefillMode.LATEST_ON_DEVICE -> deviceTemplate(context, projectId)
PrefillMode.PRESET -> preset(context, projectId)
}
}
@@ -0,0 +1,64 @@
package net.helcel.cowspent.util
import net.helcel.cowspent.model.DBBill
/**
* Guesses a bill's category from the names of bills that already have one.
*
* The bill-labelling screen shows the top guesses and lets the user pick; the bill editor can
* apply one by itself, so it asks [confidentMatch] instead, which only answers when the history
* clearly agrees.
*/
object CategorySuggester {
/** Below this length a name matches too many others by containment ("a", "bus", ...). */
private const val MIN_CONTAINMENT_LENGTH = 4
/** Share of the matching bills the leading category needs before it is applied unasked. */
private const val CONFIDENT_SHARE = 0.75
/** Matches by containment are looser, so one of them alone is not enough. */
private const val MIN_LOOSE_MATCHES = 2
private fun normalize(name: String) = name.lowercase().trim()
private fun isExactMatch(name: String, other: String) = other == name
private fun isLooseMatch(name: String, other: String) =
(name.length >= MIN_CONTAINMENT_LENGTH && other.contains(name)) ||
(other.length >= MIN_CONTAINMENT_LENGTH && name.contains(other))
fun rank(what: String, categorizedBills: List<DBBill>): List<Pair<Long, Int>> {
val name = normalize(what)
if (name.isEmpty()) return emptyList()
return categorizedBills
.filter { val other = normalize(it.what); isExactMatch(name, other) || isLooseMatch(name, other) }
.groupingBy { it.categoryId }
.eachCount()
.toList()
.sortedByDescending { it.second }
}
fun confidentMatch(
what: String,
categorizedBills: List<DBBill>,
allowedCategoryIds: Set<Long>
): Long? {
val name = normalize(what)
if (name.isEmpty()) return null
val candidates = categorizedBills.filter { it.categoryId in allowedCategoryIds }
val exact = candidates.filter { isExactMatch(name, normalize(it.what)) }
if (exact.isNotEmpty()) return dominant(exact, minCount = 1)
val loose = candidates.filter { isLooseMatch(name, normalize(it.what)) }
return dominant(loose, minCount = MIN_LOOSE_MATCHES)
}
private fun dominant(bills: List<DBBill>, minCount: Int): Long? {
if (bills.size < minCount) return null
val (categoryId, count) = bills.groupingBy { it.categoryId }.eachCount().maxByOrNull { it.value }
?: return null
return if (count >= minCount && count >= bills.size * CONFIDENT_SHARE) categoryId else null
}
}
@@ -0,0 +1,102 @@
package net.helcel.cowspent.util
import android.Manifest
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.helcel.cowspent.R
import java.net.Inet6Address
import java.net.InetAddress
/** Handles the Android 17 permission for servers that resolve to the local network. */
class LocalNetworkPermissionHelper(private val activity: AppCompatActivity) {
private var onAllowed: (() -> Unit)? = null
private var requestInProgress = false
private val permissionLauncher = activity.registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
requestInProgress = false
onAllowed?.takeIf { granted }?.invoke()
onAllowed = null
if (!granted) showDeniedMessage()
}
fun runWithAccess(serverUrls: Collection<String>, action: () -> Unit) {
if (Build.VERSION.SDK_INT < ANDROID_17 || hasPermission()) {
action()
return
}
activity.lifecycleScope.launch {
val isLocalServer = withContext(Dispatchers.IO) {
serverUrls.any(::resolvesToLocalNetwork)
}
if (!isLocalServer || hasPermission()) {
action()
} else if (!requestInProgress) {
onAllowed = action
requestInProgress = true
if (activity.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_LOCAL_NETWORK)) {
AlertDialog.Builder(activity)
.setTitle(R.string.local_network_permission_title)
.setMessage(R.string.local_network_permission_rationale)
.setPositiveButton(R.string.local_network_permission_continue) { _, _ ->
permissionLauncher.launch(Manifest.permission.ACCESS_LOCAL_NETWORK)
}
.setNegativeButton(android.R.string.cancel) { _, _ -> cancelRequest() }
.setOnCancelListener { cancelRequest() }
.show()
} else {
permissionLauncher.launch(Manifest.permission.ACCESS_LOCAL_NETWORK)
}
}
}
}
private fun cancelRequest() {
requestInProgress = false
onAllowed = null
showDeniedMessage()
}
private fun hasPermission() = ContextCompat.checkSelfPermission(
activity,
Manifest.permission.ACCESS_LOCAL_NETWORK
) == PackageManager.PERMISSION_GRANTED
private fun resolvesToLocalNetwork(url: String): Boolean {
val host = Uri.parse(url).host?.trim('[', ']')?.lowercase() ?: return false
if (host == "localhost" || host.endsWith(".localhost") || host.endsWith(".local") ||
host.endsWith(".lan") || host.endsWith(".home") || host.endsWith(".internal")
) return true
return try {
InetAddress.getAllByName(host).any { address ->
address.isAnyLocalAddress || address.isLoopbackAddress || address.isLinkLocalAddress ||
address.isSiteLocalAddress || (address is Inet6Address && (address.address[0].toInt() and 0xfe) == 0xfc)
}
} catch (_: Exception) {
false
}
}
private fun showDeniedMessage() = Toast.makeText(
activity,
R.string.local_network_permission_denied,
Toast.LENGTH_LONG
).show()
private companion object {
const val ANDROID_17 = 37
}
}
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -138,8 +138,6 @@
<string name="settings_color_custom">Eigene Farbe</string> <string name="settings_color_custom">Eigene Farbe</string>
<string name="settings_color_mode">Farbauswahl</string> <string name="settings_color_mode">Farbauswahl</string>
<string name="settings_show_archived">Archivierte Projekte anzeigen</string> <string name="settings_show_archived">Archivierte Projekte anzeigen</string>
<string name="settings_fill_new_bill_from_last">Aus letzter Rechnung vorausfüllen</string>
<string name="settings_fill_new_bill_from_last_summary">Zahler, Kategorie, Zahlungsart und Beteiligte aus der zuletzt erstellten Rechnung des Projekts übernehmen.</string>
<string name="pref_value_sync_1h">1 Stunde</string> <string name="pref_value_sync_1h">1 Stunde</string>
<string name="pref_value_sync_1d">1 Tag</string> <string name="pref_value_sync_1d">1 Tag</string>
<string name="settings_url_warn_http">WARNUNG: \"http\" ist unsicher. Verwende \"https\".</string> <string name="settings_url_warn_http">WARNUNG: \"http\" ist unsicher. Verwende \"https\".</string>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -137,8 +137,6 @@
<string name="settings_color_custom">Color personalizado</string> <string name="settings_color_custom">Color personalizado</string>
<string name="settings_color_mode">Selección de color</string> <string name="settings_color_mode">Selección de color</string>
<string name="settings_show_archived">Mostrar los proyectos archivados</string> <string name="settings_show_archived">Mostrar los proyectos archivados</string>
<string name="settings_fill_new_bill_from_last">Rellenar desde la última factura</string>
<string name="settings_fill_new_bill_from_last_summary">Reutilizar el pagador, la categoría, el modo y los participantes de la última factura creada en el proyecto.</string>
<string name="pref_value_sync_1h">1 hora</string> <string name="pref_value_sync_1h">1 hora</string>
<string name="pref_value_sync_1d">1 día</string> <string name="pref_value_sync_1d">1 día</string>
<string name="settings_url_warn_http">ADVERTENCIA: \"http\" no es seguro. Usa \"https\".</string> <string name="settings_url_warn_http">ADVERTENCIA: \"http\" no es seguro. Usa \"https\".</string>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -138,8 +138,6 @@
<string name="settings_color_custom">Couleur personnalisée</string> <string name="settings_color_custom">Couleur personnalisée</string>
<string name="settings_color_mode">Sélection de la couleur</string> <string name="settings_color_mode">Sélection de la couleur</string>
<string name="settings_show_archived">Afficher les projets archivés</string> <string name="settings_show_archived">Afficher les projets archivés</string>
<string name="settings_fill_new_bill_from_last">Pré-remplir depuis la dernière facture</string>
<string name="settings_fill_new_bill_from_last_summary">Reprendre le payeur, la catégorie, le mode et les participants de la dernière facture créée dans le projet.</string>
<string name="pref_value_sync_1h">1 heure</string> <string name="pref_value_sync_1h">1 heure</string>
<string name="pref_value_sync_1d">1 jour</string> <string name="pref_value_sync_1d">1 jour</string>
<string name="settings_url_warn_http">AVERTISSEMENT : \"http\" n\'est pas sûr. Utilisez \"https\".</string> <string name="settings_url_warn_http">AVERTISSEMENT : \"http\" n\'est pas sûr. Utilisez \"https\".</string>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -137,8 +137,6 @@
<string name="settings_color_custom">Пользовательский цвет</string> <string name="settings_color_custom">Пользовательский цвет</string>
<string name="settings_color_mode">Выбор цвета</string> <string name="settings_color_mode">Выбор цвета</string>
<string name="settings_show_archived">Показывать заархивированные проекты</string> <string name="settings_show_archived">Показывать заархивированные проекты</string>
<string name="settings_fill_new_bill_from_last">Автозаполнение на основе последнего расхода</string>
<string name="settings_fill_new_bill_from_last_summary">Предварительное заполнение полей "Плательщик", "Категория", "Способ оплаты" и "Для кого" на основе последнего расхода, созданного в проекте.</string>
<string name="pref_value_sync_1h">1 час</string> <string name="pref_value_sync_1h">1 час</string>
<string name="pref_value_sync_1d">1 день</string> <string name="pref_value_sync_1d">1 день</string>
<string name="settings_url_warn_http">ПРЕДУПРЕЖДЕНИЕ: "http" небезопасен. Используйте "https".</string> <string name="settings_url_warn_http">ПРЕДУПРЕЖДЕНИЕ: "http" небезопасен. Используйте "https".</string>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
@@ -144,8 +144,6 @@
<string name="settings_color_custom">Custom color</string> <string name="settings_color_custom">Custom color</string>
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</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="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</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>
+24 -4
View File
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<string name="local_network_permission_title">Allow local network access?</string>
<string name="local_network_permission_rationale">Cowspent needs local network access to sync Cospend and Nextcloud servers hosted on your network.</string>
<string name="local_network_permission_continue">Continue</string>
<string name="local_network_permission_denied">Local network access was denied. Remote server sync is paused.</string>
<string name="app_name" translatable="false">Cowspent</string> <string name="app_name" translatable="false">Cowspent</string>
<!-- Actions --> <!-- Actions -->
@@ -146,12 +151,23 @@
<string name="settings_color_mode">Color Selection</string> <string name="settings_color_mode">Color Selection</string>
<string name="settings_show_archived">Show archived projects</string> <string name="settings_show_archived">Show archived projects</string>
<string name="settings_extra_features">Extra Features</string> <string name="settings_extra_features">Extra Features</string>
<string name="settings_extra_features_summary">Experimental and advanced settings. Use at your own risk.</string> <string name="settings_extra_features_summary">Experimental and advanced options.</string>
<string name="settings_fill_new_bill_from_last">Auto-fill from last bill</string> <string name="settings_bill_field_order">Bill field order</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_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>
<string name="prefill_mode_latest_device">Last from device</string>
<string name="prefill_mode_preset">Saved preset</string>
<string name="prefill_mode_preset_empty">None saved yet</string>
<string name="prefill_save_preset">Save current as preset</string>
<string name="prefill_preset_saved">Preset saved for this project</string>
<string name="settings_stats_include_deactivated">Include deactivated members in stats</string> <string name="settings_stats_include_deactivated">Include deactivated members in stats</string>
<string name="settings_auto_categorize">Auto-categorize new bills</string>
<string name="settings_auto_categorize_summary">Pick the category from similar past bills.</string>
<string name="settings_full_sync_delay">Full sync delay</string> <string name="settings_full_sync_delay">Full sync delay</string>
<string name="settings_full_sync_delay_summary">How long a pull-to-refresh waits between two full syncs. In between, it only fetches what changed, which is much faster.</string> <string name="settings_full_sync_delay_summary">Time between full syncs. Other refreshes only fetch changes.</string>
<string name="pref_value_sync_always">Always</string> <string name="pref_value_sync_always">Always</string>
<string name="pref_value_sync_1h">1 hour</string> <string name="pref_value_sync_1h">1 hour</string>
<string name="pref_value_sync_1d">1 day</string> <string name="pref_value_sync_1d">1 day</string>
@@ -177,10 +193,14 @@
<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_extra_features" translatable="false">betaFeatures</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_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_full_sync_delay" translatable="false">fullSyncDelayMinutes</string>
<string name="pref_key_last_account_sync_timestamp" translatable="false">lastAccountSyncTimestamp</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_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_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>
@@ -43,7 +43,7 @@ class PreviewsTest {
@Test fun testEditBillScreen() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenPreview() } @Test fun testEditBillScreen() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenPreview() }
@Test fun testEditBillScreenWeighted() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenWeightedPreview() } @Test fun testEditBillScreenWeighted() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenWeightedPreview() }
@Test fun testEditBillScreenCustom() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenCustomPreview() } @Test fun testEditBillScreenCustom() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenCustomPreview() }
@Test fun testEditBillScreenPercent() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenPercentPreview() } @Test fun testEditBillScreenFraction() = renders { net.helcel.cowspent.android.bill_edit.EditBillScreenFractionPreview() }
@Test fun testUserAvatar() = renders { net.helcel.cowspent.android.helper.UserAvatarPreview() } @Test fun testUserAvatar() = renders { net.helcel.cowspent.android.helper.UserAvatarPreview() }
@Test fun testUserAvatarCustomColor() = renders { net.helcel.cowspent.android.helper.UserAvatarCustomColorPreview() } @Test fun testUserAvatarCustomColor() = renders { net.helcel.cowspent.android.helper.UserAvatarCustomColorPreview() }