Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ jobs:
- name: Test
run: ./gradlew :app:testDebugUnitTest


debug-apk:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { distribution: temurin, java-version: '17', cache: gradle }
- uses: android-actions/setup-android@v4
- name: Build debug APK
run: ./gradlew :app:assembleDebug
- name: Upload debug APK
uses: actions/upload-artifact@v4
with:
name: SplitSmart-PR-${{ github.event.pull_request.number }}-debug
path: app/build/outputs/apk/debug/*.apk
if-no-files-found: error
retention-days: 14

release:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/splitsmart/ui/screens/ExpenseEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.listSaver
Expand Down Expand Up @@ -418,7 +419,7 @@ fun ExpenseEditorScreen(
actions = { TextButton(onClick = doSave, enabled = canSave && !saving) { Text("Save") } },
) { p ->
Column(
Modifier.fillMaxSize().padding(p).padding(16.dp),
Modifier.fillMaxSize().padding(p).imePadding().verticalScroll(rememberScrollState()).padding(16.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (itemized) {
Expand Down Expand Up @@ -595,8 +596,8 @@ fun ExpenseEditorScreen(
}
}
ExpenseMembersPicker(rows, itemized, type, preview, cur) { touch("rows") }
LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
items(rows, key = { it.id }) { r ->
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(4.dp)) {
rows.forEach { r ->
ExpenseMemberRow(
r, itemized, type, preview?.get(r.id)?.let { money(it, cur) } ?: "") {
touch("rows")
Expand Down Expand Up @@ -690,7 +691,8 @@ fun ExpenseEditorScreen(
touch("note")
},
label = { Text("Note (optional)") },
singleLine = true,
minLines = 2,
maxLines = 4,
modifier = Modifier.fillMaxWidth())
}
}
Expand Down
111 changes: 111 additions & 0 deletions app/src/main/java/com/splitsmart/ui/screens/FriendDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
Expand All @@ -20,6 +21,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.splitsmart.core.settle.Transfer
import com.splitsmart.data.ExpenseBundle
import com.splitsmart.data.FxRate
import com.splitsmart.data.parseRate
import com.splitsmart.data.rateLine
import com.splitsmart.data.unpricedNote
import com.splitsmart.ui.shell.ChildShell
import com.splitsmart.ui.vm.GroupDetailVm
Expand Down Expand Up @@ -54,6 +58,7 @@ fun FriendDetailScreen(
var settleErr by remember { mutableStateOf<String?>(null) }
var settling by remember { mutableStateOf(false) }
var share by remember { mutableStateOf(false) }
var rateOpen by rememberSaveable { mutableStateOf(false) }
var detailOf by remember { mutableStateOf<ExpenseBundle?>(null) }
val cur = g?.currencyCode ?: ""
val self = g?.selfMemberId
Expand Down Expand Up @@ -140,6 +145,39 @@ fun FriendDetailScreen(
}
}
}
item {
ElevatedCard(Modifier.fillMaxWidth()) {
Column(
Modifier.padding(12.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
"Currency rates (manual)",
modifier = Modifier.weight(1f),
style = MaterialTheme.typography.titleSmall)
TextButton(onClick = { rateOpen = true }) { Text("+ Add") }
}
if (rates.isEmpty())
Text(
"Add a rate to convert expenses in other currencies into $cur.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant)
rates.forEach { r ->
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically) {
Text(
rateLine(r),
modifier = Modifier.weight(1f),
style = MaterialTheme.typography.bodyMedium)
IconButton(onClick = { vm.deleteRate(r.id) }) {
Icon(Icons.Default.Delete, "Delete rate")
}
}
}
}
}
}
if (friend != null)
item {
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Expand Down Expand Up @@ -169,6 +207,79 @@ fun FriendDetailScreen(
}
}
}
if (rateOpen) {
var from by remember { mutableStateOf("") }
var to by remember(cur) { mutableStateOf(cur) }
var rate by remember { mutableStateOf("") }
var rateErr by remember { mutableStateOf<String?>(null) }
var savingRate by remember { mutableStateOf(false) }
AlertDialog(
onDismissRequest = { if (!savingRate) rateOpen = false },
title = { Text("Add rate") },
text = {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(
"1 unit of currency A = ? units of currency B.",
style = MaterialTheme.typography.bodySmall)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedTextField(
from,
{ from = it.uppercase().take(3); rateErr = null },
label = { Text("From") },
singleLine = true,
modifier = Modifier.weight(1f))
OutlinedTextField(
to,
{ to = it.uppercase().take(3); rateErr = null },
label = { Text("To") },
singleLine = true,
modifier = Modifier.weight(1f))
}
OutlinedTextField(
rate,
{ rate = it; rateErr = null },
label = { Text("Rate") },
singleLine = true,
modifier = Modifier.fillMaxWidth())
rateErr?.let {
Text(it, color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall)
}
}
},
confirmButton = {
TextButton(
enabled = !savingRate,
onClick = {
val parsed = parseRate(rate)
rateErr =
when {
from.length != 3 || to.length != 3 -> "Enter two 3-letter codes."
from == to -> "Choose two different currencies."
parsed == null -> "Enter a positive rate."
else -> null
}
if (rateErr == null && parsed != null) {
savingRate = true
scope.launch {
val problem =
vm.saveRate(
FxRate(
groupId = gid,
fromCode = from,
toCode = to,
rate = parsed,
timeEpoch = System.currentTimeMillis()))
savingRate = false
if (problem == null) rateOpen = false else rateErr = problem
}
}
}) { Text("Save") }
},
dismissButton = {
TextButton(enabled = !savingRate, onClick = { rateOpen = false }) { Text("Cancel") }
})
}
settleOf?.let { (f, t, a) ->
SettleDialog(
names[f] ?: "?",
Expand Down
25 changes: 25 additions & 0 deletions app/src/test/java/com/splitsmart/ui/vm/FriendDetailTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.splitsmart.ui.vm
import com.google.common.truth.Truth.assertThat
import com.splitsmart.data.Category
import com.splitsmart.data.Expense
import com.splitsmart.data.FxRate
import org.junit.jupiter.api.Test

class FriendDetailTest {
Expand Down Expand Up @@ -39,4 +40,28 @@ class FriendDetailTest {
assertThat(settleTriple(-500, 7, 9)).isEqualTo(Triple(7L, 9L, 500L))
assertThat(settleTriple(0, 7, 9)).isNull()
}
@Test
fun `friend expenses use entered currency rates for totals`() {
val foreign =
ex(1, 7, 10000).copy(currencyCode = "EUR")
val rate =
FxRate(
groupId = 1,
fromCode = "EUR",
toCode = "USD",
rate = 1.2,
timeEpoch = 0)
val totals = friendTotalsIn(listOf(foreign), 7, "USD", listOf(rate))
assertThat(totals.paidBySelf).isEqualTo(12000L)
assertThat(totals.paidByFriend).isEqualTo(0L)
assertThat(totals.unpriced).isEmpty()
}

@Test
fun `friend expenses without rates remain flagged as unpriced`() {
val foreign = ex(1, 9, 10000).copy(currencyCode = "EUR")
val totals = friendTotalsIn(listOf(foreign), 7, "USD", emptyList())
assertThat(totals.unpriced).containsExactly("EUR")
}

}
Loading