From 80bddf8c0a2c698c26103f8f04326bbbb4c03a6f Mon Sep 17 00:00:00 2001 From: chyngyz Date: Fri, 31 May 2024 14:39:33 +0600 Subject: [PATCH 1/4] Add price change interval options to Appearance settings --- .../bankwallet/core/Interfaces.kt | 4 ++ .../core/managers/LocalStorageManager.kt | 14 +++++++ .../settings/appearance/AppearanceFragment.kt | 42 ++++++++++++------- .../settings/appearance/AppearanceModule.kt | 11 +++++ .../appearance/AppearanceViewModel.kt | 21 +++++++++- app/src/main/res/values/strings.xml | 3 ++ 6 files changed, 77 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt index d7aa010c81..ada6f2c33c 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/Interfaces.kt @@ -31,6 +31,7 @@ import io.horizontalsystems.bankwallet.modules.market.TimeDuration import io.horizontalsystems.bankwallet.modules.market.Value import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon +import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval import io.horizontalsystems.bankwallet.modules.settings.security.tor.TorStatus import io.horizontalsystems.bankwallet.modules.settings.terms.TermsModule @@ -127,6 +128,9 @@ interface ILocalStorage { val utxoExpertModeEnabledFlow: StateFlow + var priceChangeInterval: PriceChangeInterval + val priceChangeIntervalFlow: StateFlow + fun clear() } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt index 5be868063d..a351bf3a4a 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/LocalStorageManager.kt @@ -18,6 +18,7 @@ import io.horizontalsystems.bankwallet.modules.market.MarketModule import io.horizontalsystems.bankwallet.modules.market.TimeDuration import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon +import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval import io.horizontalsystems.bankwallet.modules.theme.ThemeType import io.horizontalsystems.core.ILockoutStorage @@ -83,6 +84,7 @@ class LocalStorageManager( private val UTXO_EXPERT_MODE = "utxo_expert_mode" private val RBF_ENABLED = "rbf_enabled" private val STATS_SYNC_TIME = "stats_sync_time" + private val PRICE_CHANGE_INTERVAL = "price_change_interval" private val _utxoExpertModeEnabledFlow = MutableStateFlow(false) override val utxoExpertModeEnabledFlow = _utxoExpertModeEnabledFlow @@ -531,4 +533,16 @@ class LocalStorageManager( set(value) { preferences.edit().putLong(STATS_SYNC_TIME, value).apply() } + + override var priceChangeInterval: PriceChangeInterval + get() = preferences.getString(PRICE_CHANGE_INTERVAL, null)?.let { + PriceChangeInterval.fromRaw(it) + } ?: PriceChangeInterval.LAST_24H + set(value) { + preferences.edit().putString(PRICE_CHANGE_INTERVAL, value.raw).apply() + + priceChangeIntervalFlow.update { value } + } + + override val priceChangeIntervalFlow = MutableStateFlow(priceChangeInterval) } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt index 4623bf4d27..5e5edd7771 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt @@ -90,6 +90,7 @@ fun AppearanceScreen(navController: NavController) { var openThemeSelector by rememberSaveable { mutableStateOf(false) } var openLaunchPageSelector by rememberSaveable { mutableStateOf(false) } var openBalanceValueSelector by rememberSaveable { mutableStateOf(false) } + var openPriceChangeIntervalSelector by rememberSaveable { mutableStateOf(false) } Surface(color = ComposeAppTheme.colors.tyler) { ModalBottomSheetLayout( @@ -134,24 +135,33 @@ fun AppearanceScreen(navController: NavController) { HeaderText(text = stringResource(id = R.string.Appearance_MarketsTab)) CellUniversalLawrenceSection( - listOf { - RowUniversal( - modifier = Modifier.padding(horizontal = 16.dp), - ) { - body_leah( - text = stringResource(id = R.string.Appearance_HideMarketsTab), - modifier = Modifier - .weight(1f) - .padding(end = 16.dp) - ) - HsSwitch( - checked = uiState.marketsTabHidden, - onCheckedChange = { - viewModel.onSetMarketTabsHidden(it) - } + listOf ( + { + RowUniversal( + modifier = Modifier.padding(horizontal = 16.dp), + ) { + body_leah( + text = stringResource(id = R.string.Appearance_HideMarketsTab), + modifier = Modifier + .weight(1f) + .padding(end = 16.dp) + ) + HsSwitch( + checked = uiState.marketsTabHidden, + onCheckedChange = { + viewModel.onSetMarketTabsHidden(it) + } + ) + } + }, + { + MenuItemWithDialog( + R.string.Appearance_PriceChangeInterval, + value = uiState.priceChangeInterval.title.getString(), + onClick = { openPriceChangeIntervalSelector = true } ) } - } + ) ) AnimatedVisibility(visible = !uiState.marketsTabHidden) { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceModule.kt index f03a31fcf9..caea07d538 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceModule.kt @@ -53,4 +53,15 @@ enum class AppIcon(val icon: Int, val titleText: String) : WithTranslatableTitle fun fromString(type: String?): AppIcon? = map[type] fun fromTitle(title: String?): AppIcon? = titleMap[title] } +} + +enum class PriceChangeInterval(val raw: String, override val title: TranslatableString): WithTranslatableTitle { + LAST_24H("24h", TranslatableString.ResString(R.string.Market_PriceChange_24H)), + FROM_UTC_MIDNIGHT("utc", TranslatableString.ResString(R.string.Market_PriceChange_Utc)); + + companion object { + fun fromRaw(raw: String): PriceChangeInterval? { + return entries.find { it.raw == raw } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceViewModel.kt index c9fd20df12..4e0cb204d1 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceViewModel.kt @@ -23,8 +23,9 @@ class AppearanceViewModel( private var themeOptions = themeService.optionsFlow.value private var marketsTabHidden = !localStorage.marketsTabEnabled private var balanceTabButtonsHidden = !localStorage.balanceTabButtonsEnabled - private var balanceViewTypeOptions = - buildBalanceViewTypeSelect(balanceViewTypeManager.balanceViewTypeFlow.value) + private var balanceViewTypeOptions = buildBalanceViewTypeSelect(balanceViewTypeManager.balanceViewTypeFlow.value) + private var priceChangeInterval = localStorage.priceChangeInterval + private var priceChangeIntervalOptions = buildPriceChangeIntervalSelect(priceChangeInterval) init { viewModelScope.launch { @@ -63,12 +64,18 @@ class AppearanceViewModel( selectedTheme = themeService.selectedTheme, selectedLaunchScreen = launchScreenService.selectedLaunchScreen, selectedBalanceViewType = balanceViewTypeManager.balanceViewType, + priceChangeInterval = priceChangeInterval, + priceChangeIntervalOptions = priceChangeIntervalOptions ) private fun buildBalanceViewTypeSelect(value: BalanceViewType): Select { return Select(value, balanceViewTypeManager.viewTypes) } + private fun buildPriceChangeIntervalSelect(value: PriceChangeInterval): Select { + return Select(value, PriceChangeInterval.entries) + } + private fun handleUpdatedLaunchScreenOptions(launchScreenOptions: Select) { this.launchScreenOptions = launchScreenOptions emitState() @@ -122,6 +129,14 @@ class AppearanceViewModel( emitState() } + fun onSetPriceChangeInterval(priceChangeInterval: PriceChangeInterval) { + localStorage.priceChangeInterval = priceChangeInterval + + this.priceChangeInterval = priceChangeInterval + this.priceChangeIntervalOptions = buildPriceChangeIntervalSelect(priceChangeInterval) + emitState() + } + } data class AppearanceUIState( @@ -134,4 +149,6 @@ data class AppearanceUIState( val selectedTheme: ThemeType, val selectedLaunchScreen: LaunchPage, val selectedBalanceViewType: BalanceViewType, + val priceChangeInterval: PriceChangeInterval, + val priceChangeIntervalOptions: Select ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e99a62269..24baec48bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -305,6 +305,8 @@ Price Period Trading Signals Price Change + 24 Hours + Midnight UTC Blockchains Outperformed BTC Outperformed ETH @@ -1016,6 +1018,7 @@ This configuration hides the Send, Receive, and Swap buttons on Balance tab. Balance Auto Hide Automatically hides balance each time the app is opened, regardless of previous preferences. + Price Change Coin Value Fiat Value From 22c61e995f333035c94186c83263e0d65bfec6f5 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Tue, 4 Jun 2024 12:05:27 +0600 Subject: [PATCH 2/4] Use 1-day price change wrt selected price change option --- app/build.gradle | 2 +- .../horizontalsystems/bankwallet/core/App.kt | 4 +++ .../bankwallet/core/MarketKitExtensions.kt | 11 ++++++- .../bankwallet/core/managers/PriceManager.kt | 29 +++++++++++++++++++ .../modules/balance/BalanceModule.kt | 1 + .../modules/balance/BalanceSorter.kt | 1 + .../modules/balance/BalanceViewItemFactory.kt | 3 +- .../modules/balance/BalanceViewModel.kt | 8 +++++ .../balance/cex/asset/CexAssetViewModel.kt | 13 ++++++--- .../coin/overview/CoinOverviewChartService.kt | 1 + .../bankwallet/modules/market/MarketModule.kt | 8 ++++- .../market/favorites/MarketFavoritesModule.kt | 3 +- .../favorites/MarketFavoritesService.kt | 10 ++++++- .../market/topcoins/MarketTopCoinsModule.kt | 1 + .../market/topcoins/MarketTopCoinsService.kt | 8 +++++ 15 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/io/horizontalsystems/bankwallet/core/managers/PriceManager.kt diff --git a/app/build.gradle b/app/build.gradle index 895709ca2a..55a65fdd84 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -274,7 +274,7 @@ dependencies { implementation 'com.github.horizontalsystems:ethereum-kit-android:3d83900' implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49' implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2' - implementation 'com.github.horizontalsystems:market-kit-android:872cb04' + implementation 'com.github.horizontalsystems:market-kit-android:de765ab' implementation 'com.github.horizontalsystems:solana-kit-android:ec238b4' implementation 'com.github.horizontalsystems:tron-kit-android:dc3dca7' // Zcash SDK diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt index 1c3c03e162..a35d27ebc2 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/App.kt @@ -48,6 +48,7 @@ import io.horizontalsystems.bankwallet.core.managers.NftAdapterManager import io.horizontalsystems.bankwallet.core.managers.NftMetadataManager import io.horizontalsystems.bankwallet.core.managers.NftMetadataSyncer import io.horizontalsystems.bankwallet.core.managers.NumberFormatter +import io.horizontalsystems.bankwallet.core.managers.PriceManager import io.horizontalsystems.bankwallet.core.managers.RateAppManager import io.horizontalsystems.bankwallet.core.managers.ReleaseNotesManager import io.horizontalsystems.bankwallet.core.managers.RestoreSettingsManager @@ -171,6 +172,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory { lateinit var termsManager: ITermsManager lateinit var marketFavoritesManager: MarketFavoritesManager lateinit var marketKit: MarketKitWrapper + lateinit var priceManager: PriceManager lateinit var releaseNotesManager: ReleaseNotesManager lateinit var restoreSettingsManager: RestoreSettingsManager lateinit var evmSyncSourceManager: EvmSyncSourceManager @@ -233,6 +235,8 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory { subscriptionManager = subscriptionManager ) + priceManager = PriceManager(localStorage) + feeRateProvider = FeeRateProvider(appConfigProvider) backgroundManager = BackgroundManager(this) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt index 35f7023d9e..b5301d2f99 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/MarketKitExtensions.kt @@ -7,12 +7,14 @@ import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.entities.AccountType import io.horizontalsystems.bankwallet.entities.BitcoinCashCoinType import io.horizontalsystems.bankwallet.entities.FeePriceScale +import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval import io.horizontalsystems.bitcoincash.MainNetBitcoinCash import io.horizontalsystems.hdwalletkit.ExtendedKeyCoinType import io.horizontalsystems.hdwalletkit.HDWallet import io.horizontalsystems.marketkit.models.Blockchain import io.horizontalsystems.marketkit.models.BlockchainType import io.horizontalsystems.marketkit.models.Coin +import io.horizontalsystems.marketkit.models.CoinPrice import io.horizontalsystems.marketkit.models.FullCoin import io.horizontalsystems.marketkit.models.HsPointTimePeriod import io.horizontalsystems.marketkit.models.Token @@ -20,6 +22,7 @@ import io.horizontalsystems.marketkit.models.TokenQuery import io.horizontalsystems.marketkit.models.TokenType import io.horizontalsystems.marketkit.models.TopPlatform import io.horizontalsystems.nftkit.models.NftType +import java.math.BigDecimal val Token.protocolType: String? get() = tokenQuery.protocolType @@ -574,4 +577,10 @@ val BlockchainType.Companion.supported: List BlockchainType.ECash, BlockchainType.Tron, BlockchainType.Ton, - ) \ No newline at end of file + ) + +val CoinPrice.diff: BigDecimal? + get() = when (App.priceManager.priceChangeInterval) { + PriceChangeInterval.LAST_24H -> diff24h + PriceChangeInterval.FROM_UTC_MIDNIGHT -> diff1d + } \ No newline at end of file diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/PriceManager.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/PriceManager.kt new file mode 100644 index 0000000000..cbefa860e6 --- /dev/null +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/PriceManager.kt @@ -0,0 +1,29 @@ +package io.horizontalsystems.bankwallet.core.managers + +import io.horizontalsystems.bankwallet.core.ILocalStorage +import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch + +class PriceManager( + private val storage: ILocalStorage +) { + private val coroutineScope = CoroutineScope(Dispatchers.Default) + + var priceChangeInterval: PriceChangeInterval = storage.priceChangeInterval + private set + + val priceChangeIntervalFlow: StateFlow + get() = storage.priceChangeIntervalFlow + + init { + coroutineScope.launch { + storage.priceChangeIntervalFlow.collect { + priceChangeInterval = it + } + } + } + +} diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceModule.kt index e1c83c30fd..fe2f873089 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceModule.kt @@ -40,6 +40,7 @@ object BalanceModule { App.localStorage, App.wcManager, AddressHandlerFactory(App.appConfigProvider.udnApiKey), + App.priceManager ) as T } } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceSorter.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceSorter.kt index 36dd102de5..81c476c516 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceSorter.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceSorter.kt @@ -1,5 +1,6 @@ package io.horizontalsystems.bankwallet.modules.balance +import io.horizontalsystems.bankwallet.core.diff import io.horizontalsystems.bankwallet.core.order import java.math.BigDecimal diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewItemFactory.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewItemFactory.kt index 137623eef6..f6bab68012 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewItemFactory.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewItemFactory.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable import io.horizontalsystems.bankwallet.R import io.horizontalsystems.bankwallet.core.AdapterState import io.horizontalsystems.bankwallet.core.App +import io.horizontalsystems.bankwallet.core.diff import io.horizontalsystems.bankwallet.core.providers.CexAsset import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.core.swappable @@ -178,7 +179,6 @@ class BalanceViewItemFactory { balanceViewType: BalanceViewType ): BalanceViewItem { val wallet = item.wallet - val coin = wallet.coin val state = item.state val latestRate = item.coinPrice @@ -261,7 +261,6 @@ class BalanceViewItemFactory { networkAvailable: Boolean ): BalanceViewItem2 { val wallet = item.wallet - val coin = wallet.coin val state = item.state val latestRate = item.coinPrice diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewModel.kt index 446a0110e2..94b0da1b2e 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/BalanceViewModel.kt @@ -11,6 +11,7 @@ import io.horizontalsystems.bankwallet.core.AdapterState import io.horizontalsystems.bankwallet.core.ILocalStorage import io.horizontalsystems.bankwallet.core.ViewModelUiState import io.horizontalsystems.bankwallet.core.factories.uriScheme +import io.horizontalsystems.bankwallet.core.managers.PriceManager import io.horizontalsystems.bankwallet.core.providers.Translator import io.horizontalsystems.bankwallet.core.stats.StatEvent import io.horizontalsystems.bankwallet.core.stats.StatPage @@ -44,6 +45,7 @@ class BalanceViewModel( private val localStorage: ILocalStorage, private val wCManager: WCManager, private val addressHandlerFactory: AddressHandlerFactory, + private val priceManager: PriceManager ) : ViewModelUiState(), ITotalBalance by totalBalance { private var balanceViewType = balanceViewTypeManager.balanceViewTypeFlow.value @@ -98,6 +100,12 @@ class BalanceViewModel( } } + viewModelScope.launch(Dispatchers.Default) { + priceManager.priceChangeIntervalFlow.collect { + refreshViewItems(service.balanceItemsFlow.value) + } + } + service.start() totalBalance.start(viewModelScope) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/cex/asset/CexAssetViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/cex/asset/CexAssetViewModel.kt index 7319c09063..dff6a883cf 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/cex/asset/CexAssetViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/balance/cex/asset/CexAssetViewModel.kt @@ -9,7 +9,7 @@ import androidx.lifecycle.viewModelScope import io.horizontalsystems.bankwallet.core.AdapterState import io.horizontalsystems.bankwallet.core.App import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager -import io.horizontalsystems.bankwallet.core.managers.ConnectivityManager +import io.horizontalsystems.bankwallet.core.managers.PriceManager import io.horizontalsystems.bankwallet.core.providers.CexAsset import io.horizontalsystems.bankwallet.modules.balance.BalanceViewItemFactory import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType @@ -25,7 +25,7 @@ class CexAssetViewModel( private val balanceHiddenManager: BalanceHiddenManager, private val xRateRepository: BalanceXRateRepository, private val balanceViewItemFactory: BalanceViewItemFactory, - private val connectivityManager: ConnectivityManager, + private val priceManager: PriceManager ) : ViewModel() { private val title = cexAsset.id @@ -53,6 +53,12 @@ class CexAssetViewModel( updateBalanceViewItem() } } + + viewModelScope.launch(Dispatchers.Default) { + priceManager.priceChangeIntervalFlow.collect { + updateBalanceViewItem() + } + } } fun toggleBalanceVisibility() { @@ -102,8 +108,7 @@ class CexAssetViewModel( App.balanceHiddenManager, BalanceXRateRepository("cex-asset", App.currencyManager, App.marketKit), BalanceViewItemFactory(), - App.connectivityManager, - + App.priceManager ) as T } } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/coin/overview/CoinOverviewChartService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/coin/overview/CoinOverviewChartService.kt index 4d850f788d..422da81570 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/coin/overview/CoinOverviewChartService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/coin/overview/CoinOverviewChartService.kt @@ -1,6 +1,7 @@ package io.horizontalsystems.bankwallet.modules.coin.overview import android.util.Log +import io.horizontalsystems.bankwallet.core.diff import io.horizontalsystems.bankwallet.core.managers.CurrencyManager import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper import io.horizontalsystems.bankwallet.core.stats.StatEvent diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt index 15025874f9..8b184fde65 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt @@ -15,6 +15,7 @@ import io.horizontalsystems.bankwallet.entities.Currency import io.horizontalsystems.bankwallet.entities.CurrencyValue import io.horizontalsystems.bankwallet.modules.market.filters.TimePeriod import io.horizontalsystems.bankwallet.modules.metricchart.MetricsType +import io.horizontalsystems.bankwallet.modules.settings.appearance.PriceChangeInterval import io.horizontalsystems.bankwallet.ui.compose.TranslatableString import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle import io.horizontalsystems.marketkit.models.FullCoin @@ -209,7 +210,12 @@ inline fun > Iterable.sortedByNullLast(crossinline selec } fun MarketInfo.priceChangeValue(period: TimePeriod) = when (period) { - TimePeriod.TimePeriod_1D -> priceChange24h + TimePeriod.TimePeriod_1D -> { + when(App.priceManager.priceChangeInterval) { + PriceChangeInterval.LAST_24H -> priceChange24h + PriceChangeInterval.FROM_UTC_MIDNIGHT -> priceChange1d + } + } TimePeriod.TimePeriod_1W -> priceChange7d TimePeriod.TimePeriod_2W -> priceChange14d TimePeriod.TimePeriod_1M -> priceChange30d diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesModule.kt index 3916391b72..60015e3082 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesModule.kt @@ -22,7 +22,8 @@ object MarketFavoritesModule { repository, menuService, App.currencyManager, - App.backgroundManager + App.backgroundManager, + App.priceManager ) return MarketFavoritesViewModel(service) as T } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesService.kt index c6aaadc4ef..83989a5dc7 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/favorites/MarketFavoritesService.kt @@ -1,6 +1,7 @@ package io.horizontalsystems.bankwallet.modules.market.favorites import io.horizontalsystems.bankwallet.core.managers.CurrencyManager +import io.horizontalsystems.bankwallet.core.managers.PriceManager import io.horizontalsystems.bankwallet.entities.DataState import io.horizontalsystems.bankwallet.modules.market.MarketItem import io.horizontalsystems.bankwallet.modules.market.SortingField @@ -34,7 +35,8 @@ class MarketFavoritesService( private val repository: MarketFavoritesRepository, private val menuService: MarketFavoritesMenuService, private val currencyManager: CurrencyManager, - private val backgroundManager: BackgroundManager + private val backgroundManager: BackgroundManager, + private val priceManager: PriceManager ) : BackgroundManager.Listener { private val coroutineScope = CoroutineScope(Dispatchers.Default) private var favoritesJob: Job? = null @@ -152,6 +154,12 @@ class MarketFavoritesService( } } + coroutineScope.launch { + priceManager.priceChangeIntervalFlow.collect { + fetch() + } + } + fetch() } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt index e3178e0338..ae6c8ef6e4 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsModule.kt @@ -25,6 +25,7 @@ object MarketTopCoinsModule { topMarketsRepository, App.currencyManager, App.marketFavoritesManager, + App.priceManager, topMarket ?: defaultTopMarket, sortingField ?: defaultSortingField, ) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsService.kt index 891af988d0..4062c0c45c 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsService.kt @@ -2,6 +2,7 @@ package io.horizontalsystems.bankwallet.modules.market.topcoins import io.horizontalsystems.bankwallet.core.managers.CurrencyManager import io.horizontalsystems.bankwallet.core.managers.MarketFavoritesManager +import io.horizontalsystems.bankwallet.core.managers.PriceManager import io.horizontalsystems.bankwallet.entities.DataState import io.horizontalsystems.bankwallet.modules.market.MarketItem import io.horizontalsystems.bankwallet.modules.market.SortingField @@ -21,6 +22,7 @@ class MarketTopCoinsService( private val marketTopMoversRepository: MarketTopMoversRepository, private val currencyManager: CurrencyManager, private val favoritesManager: MarketFavoritesManager, + private val priceManager: PriceManager, topMarket: TopMarket = TopMarket.Top100, sortingField: SortingField = SortingField.HighestCap, ) { @@ -108,6 +110,12 @@ class MarketTopCoinsService( } } + coroutineScope.launch { + priceManager.priceChangeIntervalFlow.collect { + sync() + } + } + sync() } From 208775c56568aa2d796a89e412463730d4fc3782 Mon Sep 17 00:00:00 2001 From: chyngyz Date: Tue, 4 Jun 2024 12:25:02 +0600 Subject: [PATCH 3/4] Use label `1D` instead of `24H` in filters and charts --- .../bankwallet/modules/market/MarketModule.kt | 2 +- app/src/main/res/values/strings.xml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt index 8b184fde65..7f45247670 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/MarketModule.kt @@ -226,7 +226,7 @@ fun MarketInfo.priceChangeValue(period: TimePeriod) = when (period) { @Parcelize enum class TimeDuration(val titleResId: Int) : WithTranslatableTitle, Parcelable { - OneDay(R.string.Market_Filter_TimePeriod_24H), + OneDay(R.string.Market_Filter_TimePeriod_1D), SevenDay(R.string.Market_Filter_TimePeriod_1W), ThirtyDay(R.string.Market_Filter_TimePeriod_1M), ThreeMonths(R.string.Market_Filter_TimePeriod_3M); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 24baec48bf..6db083a4d7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -363,7 +363,6 @@ 100B - 500B > 500B - 24 Hours 1 Day 1 Week 2 Weeks @@ -380,7 +379,6 @@ < -25% < -50% < -75% - 24h Manual Gainers @@ -1524,7 +1522,7 @@ Tweets TDY - 24H + 1D 7D 1M 2W From 5d10ee32a6c746e5c24b44c306ecf3f0bb8d144c Mon Sep 17 00:00:00 2001 From: chyngyz Date: Tue, 4 Jun 2024 12:34:56 +0600 Subject: [PATCH 4/4] Return deleted code after rebase --- .../modules/settings/appearance/AppearanceFragment.kt | 11 +++++++++++ app/src/main/res/values/strings.xml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt index 5e5edd7771..daad2da520 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/settings/appearance/AppearanceFragment.kt @@ -257,6 +257,17 @@ fun AppearanceScreen(navController: NavController) { { openBalanceValueSelector = false } ) } + if (openPriceChangeIntervalSelector) { + AlertGroup( + R.string.Appearance_PriceChangeInterval, + uiState.priceChangeIntervalOptions, + { selected -> + viewModel.onSetPriceChangeInterval(selected) + openPriceChangeIntervalSelector = false + }, + { openPriceChangeIntervalSelector = false } + ) + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6db083a4d7..b59f78bbc4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1016,7 +1016,7 @@ This configuration hides the Send, Receive, and Swap buttons on Balance tab. Balance Auto Hide Automatically hides balance each time the app is opened, regardless of previous preferences. - Price Change + Price Change % Coin Value Fiat Value