-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab8ff3c
commit 551e355
Showing
19 changed files
with
466 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
app/src/main/java/io/horizontalsystems/bankwallet/modules/market/etf/EtfFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package io.horizontalsystems.bankwallet.modules.market.etf | ||
|
||
import androidx.compose.animation.Crossfade | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.NavController | ||
import io.horizontalsystems.bankwallet.R | ||
import io.horizontalsystems.bankwallet.core.BaseComposeFragment | ||
import io.horizontalsystems.bankwallet.entities.ViewState | ||
import io.horizontalsystems.bankwallet.modules.coin.overview.ui.Loading | ||
import io.horizontalsystems.bankwallet.modules.market.ImageSource | ||
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme | ||
import io.horizontalsystems.bankwallet.ui.compose.HSSwipeRefresh | ||
import io.horizontalsystems.bankwallet.ui.compose.Select | ||
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString | ||
import io.horizontalsystems.bankwallet.ui.compose.components.AlertGroup | ||
import io.horizontalsystems.bankwallet.ui.compose.components.AppBar | ||
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonSecondaryWithIcon | ||
import io.horizontalsystems.bankwallet.ui.compose.components.DescriptionCard | ||
import io.horizontalsystems.bankwallet.ui.compose.components.HSpacer | ||
import io.horizontalsystems.bankwallet.ui.compose.components.HeaderSorting | ||
import io.horizontalsystems.bankwallet.ui.compose.components.ListErrorView | ||
import io.horizontalsystems.bankwallet.ui.compose.components.MarketCoinClear | ||
import io.horizontalsystems.bankwallet.ui.compose.components.MenuItem | ||
|
||
class EtfFragment : BaseComposeFragment() { | ||
|
||
@Composable | ||
override fun GetContent(navController: NavController) { | ||
val factory = EtfModule.Factory() | ||
val viewModel by viewModels<EtfViewModel> { factory } | ||
EtfPage(viewModel, navController) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun EtfPage( | ||
viewModel: EtfViewModel, | ||
navController: NavController, | ||
) { | ||
val uiState = viewModel.uiState | ||
val title = stringResource(id = R.string.MarketEtf_Title) | ||
val description = stringResource(id = R.string.MarketEtf_Description) | ||
var openPeriodSelector by rememberSaveable { mutableStateOf(false) } | ||
var openSortingSelector by rememberSaveable { mutableStateOf(false) } | ||
|
||
Column(Modifier.background(color = ComposeAppTheme.colors.tyler)) { | ||
AppBar( | ||
menuItems = listOf( | ||
MenuItem( | ||
title = TranslatableString.ResString(R.string.Button_Close), | ||
icon = R.drawable.ic_close, | ||
onClick = { | ||
navController.popBackStack() | ||
} | ||
) | ||
) | ||
) | ||
|
||
HSSwipeRefresh( | ||
refreshing = uiState.isRefreshing, | ||
onRefresh = { | ||
viewModel.refresh() | ||
} | ||
) { | ||
Crossfade(uiState.viewState, label = "") { viewState -> | ||
when (viewState) { | ||
ViewState.Loading -> { | ||
Loading() | ||
} | ||
|
||
is ViewState.Error -> { | ||
ListErrorView( | ||
stringResource(R.string.SyncError), | ||
viewModel::onErrorClick | ||
) | ||
} | ||
|
||
ViewState.Success -> { | ||
val listState = rememberSaveable( | ||
uiState.sortBy, | ||
saver = LazyListState.Saver | ||
) { | ||
LazyListState() | ||
} | ||
|
||
LazyColumn( | ||
modifier = Modifier.fillMaxSize(), | ||
state = listState, | ||
contentPadding = PaddingValues(bottom = 32.dp), | ||
) { | ||
item { | ||
DescriptionCard( | ||
title, | ||
description, | ||
ImageSource.Remote("https://cdn.blocksdecoded.com/category-icons/[email protected]") | ||
) | ||
} | ||
//todo Add chart | ||
// item { | ||
// Chart(chartViewModel = chartViewModel) | ||
// } | ||
stickyHeader { | ||
HeaderSorting(borderBottom = true, borderTop = true) { | ||
HSpacer(width = 16.dp) | ||
ButtonSecondaryWithIcon( | ||
modifier = Modifier.height(28.dp), | ||
onClick = { | ||
openSortingSelector = true | ||
}, | ||
title = stringResource(uiState.sortBy.titleResId), | ||
iconRight = painterResource(R.drawable.ic_down_arrow_20), | ||
) | ||
HSpacer(width = 8.dp) | ||
ButtonSecondaryWithIcon( | ||
modifier = Modifier.height(28.dp), | ||
onClick = { | ||
openPeriodSelector = true | ||
}, | ||
title = stringResource(uiState.timeDuration.titleResId), | ||
iconRight = painterResource(R.drawable.ic_down_arrow_20), | ||
) | ||
HSpacer(width = 16.dp) | ||
} | ||
} | ||
items(uiState.viewItems) { viewItem -> | ||
MarketCoinClear( | ||
subtitle = viewItem.subtitle, | ||
title = viewItem.title, | ||
coinIconUrl = viewItem.iconUrl, | ||
coinIconPlaceholder = R.drawable.ic_platform_placeholder_24, | ||
value = viewItem.value, | ||
marketDataValue = viewItem.subvalue, | ||
label = viewItem.rank, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (openPeriodSelector) { | ||
AlertGroup( | ||
title = R.string.CoinPage_Period, | ||
select = Select(uiState.timeDuration, viewModel.timeDurations), | ||
onSelect = { selected -> | ||
viewModel.onSelectTimeDuration(selected) | ||
openPeriodSelector = false | ||
}, | ||
onDismiss = { | ||
openPeriodSelector = false | ||
} | ||
) | ||
} | ||
if (openSortingSelector) { | ||
AlertGroup( | ||
title = R.string.Market_Sort_PopupTitle, | ||
select = Select(uiState.sortBy, viewModel.sortByOptions), | ||
onSelect = { selected -> | ||
viewModel.onSelectSortBy(selected) | ||
openSortingSelector = false | ||
}, | ||
onDismiss = { | ||
openSortingSelector = false | ||
} | ||
) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/io/horizontalsystems/bankwallet/modules/market/etf/EtfModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.horizontalsystems.bankwallet.modules.market.etf | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.runtime.Immutable | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import io.horizontalsystems.bankwallet.R | ||
import io.horizontalsystems.bankwallet.core.App | ||
import io.horizontalsystems.bankwallet.entities.ViewState | ||
import io.horizontalsystems.bankwallet.modules.market.MarketDataValue | ||
import io.horizontalsystems.bankwallet.modules.market.TimeDuration | ||
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString | ||
import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle | ||
|
||
object EtfModule { | ||
|
||
class Factory : ViewModelProvider.Factory { | ||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return EtfViewModel(App.currencyManager, App.marketKit) as T | ||
} | ||
} | ||
|
||
@Immutable | ||
data class EtfViewItem( | ||
val title: String, | ||
val iconUrl: String, | ||
val subtitle: String, | ||
val value: String?, | ||
val subvalue: MarketDataValue?, | ||
val rank: String?, | ||
) | ||
|
||
@Immutable | ||
data class UiState( | ||
val viewItems: List<EtfViewItem>, | ||
val viewState: ViewState, | ||
val isRefreshing: Boolean, | ||
val timeDuration: TimeDuration, | ||
val sortBy: SortBy, | ||
) | ||
|
||
enum class SortBy(@StringRes val titleResId: Int): WithTranslatableTitle { | ||
HighestAssets(R.string.MarketEtf_HighestAssets), | ||
LowestAssets(R.string.MarketEtf_LowestAssets), | ||
Inflow(R.string.MarketEtf_Inflow), | ||
Outflow(R.string.MarketEtf_Outflow); | ||
|
||
override val title = TranslatableString.ResString(titleResId) | ||
} | ||
} | ||
|
Oops, something went wrong.