Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.github.ai.simplesplit.android.data.repository.GroupRepository
import com.github.ai.simplesplit.android.data.repository.MemberRepository
import com.github.ai.simplesplit.android.data.settings.Settings
import com.github.ai.simplesplit.android.data.settings.SettingsImpl
import com.github.ai.simplesplit.android.domain.TimestampFormatter
import com.github.ai.simplesplit.android.domain.usecase.CreateExportUrlUseCase
import com.github.ai.simplesplit.android.domain.usecase.CreateGroupUrlUseCase
import com.github.ai.simplesplit.android.domain.usecase.ParseGroupUrlUseCase
Expand Down Expand Up @@ -60,6 +61,7 @@ object AndroidAppModule {
singleOf(::ThemeProviderImpl).bind(ThemeProvider::class)
singleOf(::ResourceProviderImpl).bind(ResourceProvider::class)
singleOf(::SettingsImpl).bind(Settings::class)
singleOf(::TimestampFormatter)

// Database
single { AppDatabase.buildDatabase(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.ai.simplesplit.android.domain

import android.content.Context
import java.text.DateFormat
import java.util.Date
import java.util.Locale

class TimestampFormatter(
private val context: Context
) {

fun formatShortDate(timestampMillis: Long): String {
val formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, getSystemLocale(context))
return formatter.format(Date(timestampMillis))
}

fun formatDateAndTime(timestampMillis: Long): String {
val dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, getSystemLocale(context))
val timeFormatter = DateFormat.getTimeInstance()
val date = Date(timestampMillis)
return dateFormatter.format(date) + " " + timeFormatter.format(date)
}

private fun getSystemLocale(context: Context): Locale {
return context.resources.configuration.locales[0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun EmptyMessageCell(viewModel: EmptyMessageCellViewModel) {
Text(
text = model.message,
textAlign = TextAlign.Center,
style = TextSize.BODY_MEDIUM.toTextStyle(),
style = TextSize.TITLE_MEDIUM.toTextStyle(),
color = AppTheme.theme.colors.secondaryText
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.ai.simplesplit.android.presentation.dialogs.expenseDetails
import androidx.compose.ui.unit.dp
import com.github.ai.simplesplit.android.R
import com.github.ai.simplesplit.android.data.api.coverters.toCurrency
import com.github.ai.simplesplit.android.domain.TimestampFormatter
import com.github.ai.simplesplit.android.presentation.core.ResourceProvider
import com.github.ai.simplesplit.android.presentation.core.compose.TextColor
import com.github.ai.simplesplit.android.presentation.core.compose.TextSize
Expand Down Expand Up @@ -30,7 +31,8 @@ import com.github.ai.split.api.ExpenseDto

class ExpenseDetailsDialogCellFactory(
private val themeProvider: ThemeProvider,
private val resourceProvider: ResourceProvider
private val resources: ResourceProvider,
private val timestampFormatter: TimestampFormatter
) {

fun createCells(
Expand Down Expand Up @@ -89,11 +91,31 @@ class ExpenseDetailsDialogCellFactory(
)
)

val created = expense.created.timestampSeconds * 1000L
val modified = expense.modified.timestampSeconds * 1000L

cells.add(
TextCellViewModel(
TextCellModel(
id = "created_date",
text = resources.getString(
R.string.create_on_with_str,
timestampFormatter.formatDateAndTime(created)
),
textSize = TextSize.BODY_LARGE,
textColor = TextColor.SECONDARY
)
)
)

cells.add(
TextCellViewModel(
TextCellModel(
id = "added_date",
text = "added on 01 Jan 2025", // TODO: handle date
id = "modified_date",
text = resources.getString(
R.string.modified_on_with_str,
timestampFormatter.formatDateAndTime(modified)
),
textSize = TextSize.BODY_LARGE,
textColor = TextColor.SECONDARY
)
Expand Down Expand Up @@ -222,7 +244,7 @@ class ExpenseDetailsDialogCellFactory(
MenuCellModel(
id = CellId.EDIT_MENU.name,
icon = AppIcon.EDIT.vector,
title = resourceProvider.getString(R.string.edit),
title = resources.getString(R.string.edit),
height = OneLineSmallItemHeight
),
eventProvider
Expand All @@ -231,7 +253,7 @@ class ExpenseDetailsDialogCellFactory(
MenuCellModel(
id = CellId.REMOVE_MENU.name,
icon = AppIcon.REMOVE.vector,
title = resourceProvider.getString(R.string.remove),
title = resources.getString(R.string.remove),
height = OneLineSmallItemHeight
),
eventProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.github.ai.simplesplit.android.R
import com.github.ai.simplesplit.android.presentation.core.compose.CenteredBox
import com.github.ai.simplesplit.android.presentation.core.compose.CornersShape
import com.github.ai.simplesplit.android.presentation.core.compose.ErrorMessageCard
import com.github.ai.simplesplit.android.presentation.core.compose.ErrorState
import com.github.ai.simplesplit.android.presentation.core.compose.TextSize
import com.github.ai.simplesplit.android.presentation.core.compose.TopBar
import com.github.ai.simplesplit.android.presentation.core.compose.TopBarMenuItem
import com.github.ai.simplesplit.android.presentation.core.compose.cells.CellViewModel
Expand All @@ -29,6 +33,9 @@ import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.Head
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.ShapedSpaceCell
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.ShapedTextCell
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.SpaceCell
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.newShapedSpaceCellViewModel
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.newShapedTextCell
import com.github.ai.simplesplit.android.presentation.core.compose.cells.ui.newSpaceCell
import com.github.ai.simplesplit.android.presentation.core.compose.cells.viewModel.DividerCellViewModel
import com.github.ai.simplesplit.android.presentation.core.compose.cells.viewModel.EmptyMessageCellViewModel
import com.github.ai.simplesplit.android.presentation.core.compose.cells.viewModel.HeaderCellViewModel
Expand All @@ -39,6 +46,9 @@ import com.github.ai.simplesplit.android.presentation.core.compose.preview.Theme
import com.github.ai.simplesplit.android.presentation.core.compose.rememberCallback
import com.github.ai.simplesplit.android.presentation.core.compose.rememberOnClickedCallback
import com.github.ai.simplesplit.android.presentation.core.compose.theme.AppTheme
import com.github.ai.simplesplit.android.presentation.core.compose.theme.ElementMargin
import com.github.ai.simplesplit.android.presentation.core.compose.theme.GroupMargin
import com.github.ai.simplesplit.android.presentation.core.compose.theme.HalfMargin
import com.github.ai.simplesplit.android.presentation.core.compose.theme.LightTheme
import com.github.ai.simplesplit.android.presentation.screens.groupDetails.cells.ui.ExpenseCell
import com.github.ai.simplesplit.android.presentation.screens.groupDetails.cells.ui.SettlementCell
Expand Down Expand Up @@ -167,7 +177,58 @@ fun GroupDetailsDataPreview() {
}
}

@Composable
private fun newDataState() =
GroupDetailsState.Data(
cellViewModels = listOf()
cellViewModels = listOf(
newSpaceCell(
height = HalfMargin
),
newShapedSpaceCellViewModel(
height = GroupMargin,
shape = CornersShape.TOP
),
newShapedTextCell(
text = "Trip to Disney Land",
textColor = AppTheme.theme.colors.primaryText,
textSize = TextSize.TITLE_LARGE,
shape = CornersShape.NONE
),
newShapedSpaceCellViewModel(
height = ElementMargin,
shape = CornersShape.NONE
),
newShapedTextCell(
text = stringResource(R.string.members_with_str, 5),
textColor = AppTheme.theme.colors.primaryText,
textSize = TextSize.TITLE_MEDIUM,
shape = CornersShape.NONE
),
newShapedTextCell(
text = "Mickey Mouse - Donald Duck - Goofy - Minnie Mouse - Shlof",
textColor = AppTheme.theme.colors.secondaryText,
textSize = TextSize.BODY_LARGE,
shape = CornersShape.NONE
),
newShapedSpaceCellViewModel(
height = ElementMargin,
shape = CornersShape.NONE
),
newShapedTextCell(
text = stringResource(R.string.total_spending),
textColor = AppTheme.theme.colors.primaryText,
textSize = TextSize.TITLE_MEDIUM,
shape = CornersShape.NONE
),
newShapedTextCell(
text = "$300",
textColor = AppTheme.theme.colors.secondaryText,
textSize = TextSize.BODY_LARGE,
shape = CornersShape.NONE
),
newShapedSpaceCellViewModel(
height = GroupMargin,
shape = CornersShape.BOTTOM
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.ai.simplesplit.android.presentation.screens.groupDetails.cell

import com.github.ai.simplesplit.android.R
import com.github.ai.simplesplit.android.data.api.coverters.toCurrency
import com.github.ai.simplesplit.android.domain.TimestampFormatter
import com.github.ai.simplesplit.android.presentation.core.ResourceProvider
import com.github.ai.simplesplit.android.presentation.core.compose.CornersShape
import com.github.ai.simplesplit.android.presentation.core.compose.TextSize
Expand Down Expand Up @@ -38,7 +39,8 @@ import com.github.ai.split.api.GroupDto

class GroupDetailsCellFactory(
private val themeProvider: ThemeProvider,
private val resourceProvider: ResourceProvider
private val resources: ResourceProvider,
private val timestampFormatter: TimestampFormatter
) {

fun createCells(
Expand Down Expand Up @@ -76,7 +78,9 @@ class GroupDetailsCellFactory(
val members = group.members.map { member -> member.name }
.joinToString(" - ")

return listOf(
val totalSpending = group.expenses.sumOf { expense -> expense.amount }

val models = mutableListOf(
SpaceCellModel(
id = "top_space",
height = HalfMargin
Expand All @@ -95,7 +99,14 @@ class GroupDetailsCellFactory(
),
ShapedSpaceCellModel(
id = "title_middle_space",
height = HalfMargin,
height = ElementMargin,
shape = CornersShape.NONE
),
ShapedTextCellModel(
id = "members_title",
text = resources.getString(R.string.members_with_str, group.members.size),
textColor = themeProvider.theme.colors.primaryText,
textSize = TextSize.TITLE_MEDIUM,
shape = CornersShape.NONE
),
ShapedTextCellModel(
Expand All @@ -104,13 +115,44 @@ class GroupDetailsCellFactory(
textColor = themeProvider.theme.colors.secondaryText,
textSize = TextSize.BODY_LARGE,
shape = CornersShape.NONE
),
)
)

if (group.expenses.isNotEmpty()) {
models.addAll(
listOf(
ShapedSpaceCellModel(
id = "total_spending_space",
height = ElementMargin,
shape = CornersShape.NONE
),
ShapedTextCellModel(
id = "total_spending_title",
text = resources.getString(R.string.total_spending),
textColor = themeProvider.theme.colors.primaryText,
textSize = TextSize.TITLE_MEDIUM,
shape = CornersShape.NONE
),
ShapedTextCellModel(
id = "total_spending",
text = totalSpending.formatAsMoney(group.currency.toCurrency()),
textColor = themeProvider.theme.colors.secondaryText,
textSize = TextSize.BODY_LARGE,
shape = CornersShape.NONE
)
)
)
}

models.add(
ShapedSpaceCellModel(
id = "title_bottom_space",
height = GroupMargin,
shape = CornersShape.BOTTOM
)
)

return models
}

private fun createExpenseHeaderModels(): List<CellModel> {
Expand All @@ -121,7 +163,7 @@ class GroupDetailsCellFactory(
),
HeaderCellModel(
id = "expense_header",
text = resourceProvider.getString(R.string.expenses),
text = resources.getString(R.string.expenses),
textSize = TextSize.TITLE_MEDIUM,
textColor = themeProvider.theme.colors.primaryText
)
Expand All @@ -132,7 +174,7 @@ class GroupDetailsCellFactory(
return listOf(
EmptyMessageCellModel(
id = "empty_message",
message = resourceProvider.getString(R.string.no_expenses_message),
message = resources.getString(R.string.no_expenses_message),
height = EmptyMessageItemHeight
)
)
Expand Down Expand Up @@ -167,15 +209,18 @@ class GroupDetailsCellFactory(
)
}

val date = timestampFormatter.formatShortDate(
expense.modified.timestampSeconds * 1000L
)

models.add(
ExpenseCellModel(
id = CellId("expense", StringPayload(expense.uid)).format(),
title = expense.title,
description = "Paid by $payerName", // TODO: string
description = resources.getString(R.string.paid_by_with_str, payerName),
members = members,
amount = expense.amount.formatAsMoney(expense.currency.toCurrency()),
// TODO: date should be implemented on server side
date = "01 Jan",
date = date,
shape = shape
)
)
Expand All @@ -192,7 +237,7 @@ class GroupDetailsCellFactory(
),
HeaderCellModel(
id = "settlement_header",
text = "How to Settle Debts", // TODO: string
text = resources.getString(R.string.how_to_settle_debts),
textSize = TextSize.TITLE_MEDIUM,
textColor = themeProvider.theme.colors.primaryText
)
Expand Down Expand Up @@ -238,7 +283,7 @@ class GroupDetailsCellFactory(
models.add(
SettlementCellModel(
id = "settlement_$idx",
title = "${debtor.name} ${creditor.name}",
title = "${debtor.name} > ${creditor.name}",
amount = transaction.amount.formatAsMoney(currency),
shape = shape
)
Expand All @@ -249,7 +294,7 @@ class GroupDetailsCellFactory(
models.add(
EmptyMessageCellModel(
id = "settlement_empty_message",
message = resourceProvider.getString(R.string.no_debts_yet),
message = resources.getString(R.string.no_debts_yet),
height = HugeMargin
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fun SettlementCellPreview() {
DividerCell(newDividerCell())
SettlementCell(
newSettlementCell(
text = "JohnJohnJohnJohn → JaneJaneJaneJaneJaneJane",
shape = CornersShape.BOTTOM
)
)
Expand Down
Loading