Skip to content

Commit

Permalink
Merge pull request #130 from YAPP-Github/feature/MZ-143-sent-filter
Browse files Browse the repository at this point in the history
Feature/mz 143 sent filter
  • Loading branch information
jinukeu authored Feb 7, 2024
2 parents 2c565ed + c4523bb commit 67cddf8
Show file tree
Hide file tree
Showing 16 changed files with 356 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.susu.core.model

import androidx.compose.runtime.Stable

@Stable
data class EnvelopeSearch(
val envelope: Envelope,
val category: Category? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.susu.core.model

import androidx.compose.runtime.Stable

@Stable
data class FriendStatistics(
val friend: Friend = Friend(),
val receivedAmounts: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class EnvelopesRepositoryImpl @Inject constructor(
) : EnvelopesRepository {
override suspend fun getEnvelopesList(
friendIds: List<Long>?,
fromTotalAmounts: Int?,
toTotalAmounts: Int?,
fromTotalAmounts: Long?,
toTotalAmounts: Long?,
page: Int?,
size: Int?,
sort: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface EnvelopesService {
@GET("envelopes/friend-statistics")
suspend fun getEnvelopesList(
@Query("friendIds") friendIds: List<Long>?,
@Query("fromTotalAmounts") fromTotalAmounts: Int?,
@Query("toTotalAmounts") toTotalAmounts: Int?,
@Query("fromTotalAmounts") fromTotalAmounts: Long?,
@Query("toTotalAmounts") toTotalAmounts: Long?,
@Query("page") page: Int?,
@Query("size") size: Int?,
@Query("sort") sort: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import kotlinx.datetime.LocalDateTime
interface EnvelopesRepository {
suspend fun getEnvelopesList(
friendIds: List<Long>?,
fromTotalAmounts: Int?,
toTotalAmounts: Int?,
fromTotalAmounts: Long?,
toTotalAmounts: Long?,
page: Int?,
size: Int?,
sort: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class GetEnvelopesListUseCase @Inject constructor(

data class Param(
val friendIds: List<Long>? = emptyList(),
val fromTotalAmounts: Int? = null,
val toTotalAmounts: Int? = null,
val fromTotalAmounts: Long? = null,
val toTotalAmounts: Long? = null,
val page: Int? = null,
val size: Int? = null,
val sort: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ internal fun MainScreen(
navigator.popBackStackIfNotHome()
},
navigateSentEnvelopeSearch = navigator::navigateSentEnvelopeSearch,
navigateEnvelopeFilter = navigator::navigateEnvelopeFilter,
handleException = viewModel::handleException,
onShowSnackbar = viewModel::onShowSnackbar,
onShowDialog = viewModel::onShowDialog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class EnvelopeFilterState(
val toAmount: Long? = null,
val maxFromAmount: Long = 0,
val maxToAmount: Long = 0,
val isSent: Boolean = false,
) : UiState {
val sliderValue = fromAmount?.toFloat()?.rangeTo(toAmount?.toFloat()!!) ?: maxFromAmount.toFloat()..maxToAmount.toFloat()
val sliderValueRange = maxFromAmount.toFloat()..maxToAmount.toFloat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ fun EnvelopeFilterScreen(

if (uiState.maxFromAmount != uiState.maxToAmount) {
Text(
text = stringResource(R.string.envelope_filter_screen_money),
text = stringResource(
if (uiState.isSent) {
R.string.envelope_filter_total_money
} else {
R.string.envelope_filter_screen_money
},
),
style = SusuTheme.typography.title_xs,
)
Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_m))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class EnvelopeFilterViewModel @Inject constructor(
maxToAmount = maxToAmount,
fromAmount = filter.fromAmount,
toAmount = filter.toAmount,
isSent = filter.isSent,
)
}
}
Expand Down
35 changes: 34 additions & 1 deletion feature/sent/src/main/java/com/susu/feature/sent/SentContract.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.susu.feature.sent

import androidx.annotation.StringRes
import com.susu.core.model.EnvelopeSearch
import com.susu.core.model.Friend
import com.susu.core.model.FriendStatistics
import com.susu.core.ui.R
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState
import kotlinx.collections.immutable.PersistentList
Expand All @@ -12,7 +14,14 @@ data class SentState(
val isLoading: Boolean = false,
val envelopesList: PersistentList<FriendStatisticsState> = persistentListOf(),
val showEmptyEnvelopes: Boolean = false,
) : UiState
val selectedFriendList: PersistentList<Friend> = persistentListOf(),
val fromAmount: Long? = null,
val toAmount: Long? = null,
val selectedAlignPosition: Int = EnvelopeAlign.RECENT.ordinal,
val showAlignBottomSheet: Boolean = false,
) : UiState {
val isFiltered = fromAmount != null || toAmount != null || selectedFriendList.isNotEmpty()
}

data class FriendStatisticsState(
val friend: Friend = Friend(),
Expand All @@ -30,8 +39,32 @@ internal fun FriendStatistics.toState() = FriendStatisticsState(
totalAmounts = totalAmounts,
)

enum class EnvelopeAlign(
@StringRes val stringResId: Int,
val query: String,
) {
RECENT(
stringResId = R.string.word_align_recently,
query = "createdAt,desc",
),
OUTDATED(
stringResId = R.string.word_align_outdated,
query = "createdAt,asc",
),
HIGH_AMOUNT(
stringResId = R.string.word_align_high_amount,
query = "totalSentAmounts,desc",
),
LOW_AMOUNT(
stringResId = R.string.word_align_low_amount,
query = "totalSentAmounts,asc",
),
}

sealed interface SentEffect : SideEffect {
data class NavigateEnvelope(val id: Long) : SentEffect
data object NavigateEnvelopeAdd : SentEffect
data object NavigateEnvelopeSearch : SentEffect
data class NavigateEnvelopeFilter(val filter: String) : SentEffect
data object ScrollToTop : SentEffect
}
Loading

0 comments on commit 67cddf8

Please sign in to comment.