Skip to content

Commit

Permalink
Minor improvements (#138)
Browse files Browse the repository at this point in the history
* Back button should clear filter query before exiting screen

* Add horizontal padding to group tab text
  • Loading branch information
mdrlzy authored Jan 30, 2025
1 parent d60d770 commit 91a229e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.ScrollableTabRow
Expand Down Expand Up @@ -65,6 +66,7 @@ fun GroupViewPager(
selectedContentColor = Color.Transparent,
) {
Text(
modifier = Modifier.padding(horizontal = 6.dp),
text = group ?: stringResource(R.string.group_default_name),
color = if (selected) ArkColor.Teal700 else ArkColor.TextQuarterary,
fontWeight = FontWeight.SemiBold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package dev.arkbuilders.rate.feature.portfolio.presentation.main

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -80,6 +81,10 @@ fun PortfolioScreen(navigator: DestinationsNavigator) {
val viewModel: PortfolioViewModel =
viewModel(factory = component.assetsVMFactory())

BackHandler {
viewModel.onBackClick()
}

val state by viewModel.collectAsState()
val snackState = remember { SnackbarHostState() }

Expand All @@ -106,6 +111,8 @@ fun PortfolioScreen(navigator: DestinationsNavigator) {
)
snackState.showSnackbar(visuals)
}

PortfolioScreenEffect.NavigateBack -> navigator.popBackStack()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ sealed class PortfolioScreenEffect {
) : PortfolioScreenEffect()

data class ShowRemovedSnackbar(val asset: Asset) : PortfolioScreenEffect()

data object NavigateBack : PortfolioScreenEffect()
}

class PortfolioViewModel(
Expand Down Expand Up @@ -125,6 +127,17 @@ class PortfolioViewModel(
reduce { state.copy(filter = filter) }
}

fun onBackClick() =
intent {
if (state.filter.isNotEmpty()) {
reduce {
state.copy(filter = "")
}
} else {
postSideEffect(PortfolioScreenEffect.NavigateBack)
}
}

private fun initPages() =
intent {
val baseCode = prefs.get(PreferenceKey.BaseCurrencyCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.arkbuilders.rate.feature.quick.presentation.main

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -67,6 +68,7 @@ import dev.arkbuilders.rate.core.presentation.ui.NotifyRemovedSnackbarVisuals
import dev.arkbuilders.rate.core.presentation.ui.RateSnackbarHost
import dev.arkbuilders.rate.core.presentation.ui.SearchTextField
import dev.arkbuilders.rate.core.presentation.utils.DateFormatUtils
import dev.arkbuilders.rate.core.presentation.utils.findActivity
import dev.arkbuilders.rate.feature.quick.di.QuickComponentHolder
import dev.arkbuilders.rate.feature.quick.domain.model.PinnedQuickPair
import dev.arkbuilders.rate.feature.quick.domain.model.QuickPair
Expand All @@ -93,6 +95,10 @@ fun QuickScreen(navigator: DestinationsNavigator) {
factory = component.quickVMFactory().create(),
)

BackHandler {
viewModel.onBackClick()
}

val state by viewModel.collectAsState()
val snackState = remember { SnackbarHostState() }
viewModel.collectSideEffect { effect ->
Expand Down Expand Up @@ -121,6 +127,8 @@ fun QuickScreen(navigator: DestinationsNavigator) {
)
snackState.showSnackbar(visuals)
}

QuickScreenEffect.NavigateBack -> ctx.findActivity()?.finish()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ sealed class QuickScreenEffect {
) : QuickScreenEffect()

data class ShowRemovedSnackbar(val pair: QuickPair) : QuickScreenEffect()

data object NavigateBack : QuickScreenEffect()
}

class QuickViewModel(
Expand Down Expand Up @@ -181,6 +183,17 @@ class QuickViewModel(
quickRepo.insert(pair)
}

fun onBackClick() =
intent {
if (state.filter.isNotEmpty()) {
reduce {
state.copy(filter = "")
}
} else {
postSideEffect(QuickScreenEffect.NavigateBack)
}
}

private suspend fun mapPairsToPages(pairs: List<QuickPair>): List<QuickScreenPage> {
val refreshDate = timestampRepo.getTimestamp(TimestampType.FetchRates)
val pages =
Expand Down

0 comments on commit 91a229e

Please sign in to comment.