Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -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
Loading