Skip to content

Commit

Permalink
Implement changes in Watchlist
Browse files Browse the repository at this point in the history
- Add signals
- Add manual sorting
  • Loading branch information
rafaelekol committed May 22, 2024
1 parent 88e1cc6 commit d2840b5
Show file tree
Hide file tree
Showing 32 changed files with 716 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
termsManager = TermsManager(localStorage)

marketWidgetManager = MarketWidgetManager()
marketFavoritesManager = MarketFavoritesManager(appDatabase, marketWidgetManager)
marketFavoritesManager = MarketFavoritesManager(appDatabase, localStorage, marketWidgetManager)

marketWidgetRepository = MarketWidgetRepository(
marketKit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import io.horizontalsystems.bankwallet.modules.balance.BalanceSortType
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType
import io.horizontalsystems.bankwallet.modules.main.MainModule
import io.horizontalsystems.bankwallet.modules.market.MarketModule
import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.modules.market.Value
import io.horizontalsystems.bankwallet.modules.market.favorites.MarketFavoritesModule.Period
import io.horizontalsystems.bankwallet.modules.market.favorites.WatchlistSorting
import io.horizontalsystems.bankwallet.modules.settings.appearance.AppIcon
import io.horizontalsystems.bankwallet.modules.settings.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.settings.security.tor.TorStatus
Expand Down Expand Up @@ -107,8 +108,10 @@ interface ILocalStorage {
var launchPage: LaunchPage?
var appIcon: AppIcon?
var mainTab: MainModule.MainNavigation?
var marketFavoritesSortDescending: Boolean
var marketFavoritesPeriod: Period?
var marketFavoritesSorting: WatchlistSorting?
var marketFavoritesShowSignals: Boolean
var marketFavoritesManualSortingOrder: List<String>
var marketFavoritesPeriod: TimeDuration?
var relaunchBySettingChange: Boolean
var marketsTabEnabled: Boolean
val marketsTabEnabledFlow: StateFlow<Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import io.horizontalsystems.bankwallet.modules.balance.BalanceSortType
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType
import io.horizontalsystems.bankwallet.modules.main.MainModule
import io.horizontalsystems.bankwallet.modules.market.MarketModule
import io.horizontalsystems.bankwallet.modules.market.favorites.MarketFavoritesModule.Period
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.security.autolock.AutoLockInterval
import io.horizontalsystems.bankwallet.modules.theme.ThemeType
Expand Down Expand Up @@ -66,8 +67,10 @@ class LocalStorageManager(
private val LAUNCH_PAGE = "launch_page"
private val APP_ICON = "app_icon"
private val MAIN_TAB = "main_tab"
private val MARKET_FAVORITES_SORT_DESCENDING = "market_favorites_sort_descending"
private val MARKET_FAVORITES_SORTING = "market_favorites_sorting"
private val MARKET_FAVORITES_SHOW_SIGNALS = "market_favorites_show_signals"
private val MARKET_FAVORITES_TIME_DURATION = "market_favorites_time_duration"
private val MARKET_FAVORITES_MANUAL_SORTING_ORDER = "market_favorites_manual_sorting_order"
private val RELAUNCH_BY_SETTING_CHANGE = "relaunch_by_setting_change"
private val MARKETS_TAB_ENABLED = "markets_tab_enabled"
private val BALANCE_AUTO_HIDE_ENABLED = "balance_auto_hide_enabled"
Expand Down Expand Up @@ -421,15 +424,29 @@ class LocalStorageManager(
preferences.edit().putString(MAIN_TAB, value?.name).apply()
}

override var marketFavoritesSortDescending: Boolean
get() = preferences.getBoolean(MARKET_FAVORITES_SORT_DESCENDING, true)
override var marketFavoritesSorting: WatchlistSorting?
get() = preferences.getString(MARKET_FAVORITES_SORTING, null)?.let {
WatchlistSorting.valueOf(it)
}
set(value) {
preferences.edit().putString(MARKET_FAVORITES_SORTING, value?.name).apply()
}

override var marketFavoritesShowSignals: Boolean
get() = preferences.getBoolean(MARKET_FAVORITES_SHOW_SIGNALS, false)
set(value) {
preferences.edit().putBoolean(MARKET_FAVORITES_SHOW_SIGNALS, value).apply()
}

override var marketFavoritesManualSortingOrder: List<String>
get() = preferences.getString(MARKET_FAVORITES_MANUAL_SORTING_ORDER, null)?.split(",") ?: listOf()
set(value) {
preferences.edit().putBoolean(MARKET_FAVORITES_SORT_DESCENDING, value).apply()
preferences.edit().putString(MARKET_FAVORITES_MANUAL_SORTING_ORDER, value.joinToString(",")).apply()
}

override var marketFavoritesPeriod: Period?
override var marketFavoritesPeriod: TimeDuration?
get() = preferences.getString(MARKET_FAVORITES_TIME_DURATION, null)?.let {
Period.valueOf(it)
TimeDuration.entries.find { period -> period.name == it }
}
set(value) {
preferences.edit().putString(MARKET_FAVORITES_TIME_DURATION, value?.name).apply()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.horizontalsystems.bankwallet.core.managers

import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.core.storage.AppDatabase
import io.horizontalsystems.bankwallet.core.storage.FavoriteCoin
import io.horizontalsystems.bankwallet.core.storage.MarketFavoritesDao
Expand All @@ -9,6 +10,7 @@ import io.reactivex.subjects.PublishSubject

class MarketFavoritesManager(
appDatabase: AppDatabase,
private val localStorage: ILocalStorage,
private val marketWidgetManager: MarketWidgetManager
) {
val dataUpdatedAsync: Observable<Unit>
Expand All @@ -21,6 +23,10 @@ class MarketFavoritesManager(
}

fun add(coinUid: String) {
localStorage.marketFavoritesManualSortingOrder =
localStorage.marketFavoritesManualSortingOrder.toMutableList().apply {
add(coinUid)
}
dao.insert(FavoriteCoin(coinUid))
dataUpdatedSubject.onNext(Unit)
marketWidgetManager.updateWatchListWidgets()
Expand All @@ -33,6 +39,10 @@ class MarketFavoritesManager(
}

fun remove(coinUid: String) {
localStorage.marketFavoritesManualSortingOrder =
localStorage.marketFavoritesManualSortingOrder.toMutableList().apply {
remove(coinUid)
}
dao.delete(coinUid)
dataUpdatedSubject.onNext(Unit)
marketWidgetManager.updateWatchListWidgets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ class MarketKitWrapper(
fun topPlatformCoinListSingle(chain: String, currencyCode: String) =
marketKit.topPlatformMarketInfosSingle(chain, currencyCode)

fun getCoinSignalsSingle(coinUids: List<String>) = marketKit.coinsSignalsSingle(coinUids)

// NFT

suspend fun nftCollections(): List<NftTopCollection> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.horizontalsystems.bankwallet.modules.market.MarketModule
import io.horizontalsystems.bankwallet.modules.market.SortingField
import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.modules.market.TopMarket
import io.horizontalsystems.bankwallet.modules.market.favorites.MarketFavoritesModule
import io.horizontalsystems.bankwallet.modules.market.filters.TimePeriod
import io.horizontalsystems.bankwallet.modules.market.search.MarketSearchSection
import io.horizontalsystems.bankwallet.modules.metricchart.MetricsType
import io.horizontalsystems.bankwallet.modules.metricchart.ProChartModule
Expand Down Expand Up @@ -261,11 +261,15 @@ val MarketSearchSection.statSection: StatSection
MarketSearchSection.SearchResults -> StatSection.SearchResults
}

val MarketFavoritesModule.Period.statPeriod: StatPeriod
val TimePeriod.statPeriod: StatPeriod
get() = when (this) {
MarketFavoritesModule.Period.OneDay -> StatPeriod.Day1
MarketFavoritesModule.Period.SevenDay -> StatPeriod.Week1
MarketFavoritesModule.Period.ThirtyDay -> StatPeriod.Month1
TimePeriod.TimePeriod_1D -> StatPeriod.Day1
TimePeriod.TimePeriod_1W -> StatPeriod.Week1
TimePeriod.TimePeriod_1M -> StatPeriod.Month1
TimePeriod.TimePeriod_2W -> TODO()
TimePeriod.TimePeriod_3M -> TODO()
TimePeriod.TimePeriod_6M -> TODO()
TimePeriod.TimePeriod_1Y -> TODO()
}

val FilterTransactionType.statTab: StatTab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fun CoinMarketCell(
Column(
modifier = Modifier.fillMaxWidth()
) {
MarketCoinFirstRow(name, volumeToken, badge?.getString())
MarketCoinFirstRow(name, volumeToken, badge = badge?.getString())
Spacer(modifier = Modifier.height(3.dp))
MarketCoinSecondRow(subtitle, marketDataValue, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.entities.Currency
import io.horizontalsystems.bankwallet.entities.CurrencyValue
import io.horizontalsystems.bankwallet.modules.market.favorites.MarketFavoritesModule.Period
import io.horizontalsystems.bankwallet.modules.market.filters.TimePeriod
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle
Expand Down Expand Up @@ -74,7 +73,7 @@ data class MarketItem(
fun createFromCoinMarket(
marketInfo: MarketInfo,
currency: Currency,
period: Period,
period: TimePeriod = TimePeriod.TimePeriod_1D
): MarketItem {
return MarketItem(
fullCoin = marketInfo.fullCoin,
Expand All @@ -85,21 +84,6 @@ data class MarketItem(
rank = marketInfo.marketCapRank
)
}

fun createFromCoinMarket(
marketInfo: MarketInfo,
currency: Currency,
pricePeriod: TimePeriod = TimePeriod.TimePeriod_1D
): MarketItem {
return MarketItem(
fullCoin = marketInfo.fullCoin,
volume = CurrencyValue(currency, marketInfo.totalVolume ?: BigDecimal.ZERO),
rate = CurrencyValue(currency, marketInfo.price ?: BigDecimal.ZERO),
diff = marketInfo.priceChangeValue(pricePeriod),
marketCap = CurrencyValue(currency, marketInfo.marketCap ?: BigDecimal.ZERO),
rank = marketInfo.marketCapRank
)
}
}
}

Expand Down Expand Up @@ -205,12 +189,6 @@ fun MarketInfo.priceChangeValue(period: TimePeriod) = when (period) {
TimePeriod.TimePeriod_1Y -> priceChange1y
}

fun MarketInfo.priceChangeValue(period: Period) = when (period) {
Period.OneDay -> priceChange24h
Period.SevenDay -> priceChange7d
Period.ThirtyDay -> priceChange30d
}

@Parcelize
enum class TimeDuration(val titleResId: Int) : WithTranslatableTitle, Parcelable {
OneDay(R.string.CoinPage_TimeDuration_Day),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.iconPlaceholder
import io.horizontalsystems.bankwallet.core.imageUrl
import io.horizontalsystems.marketkit.models.Analytics.TechnicalAdvice.Advice
import io.horizontalsystems.marketkit.models.FullCoin

@Immutable
Expand All @@ -13,6 +14,7 @@ data class MarketViewItem(
val marketDataValue: MarketDataValue,
val rank: String?,
val favorited: Boolean,
val signal: Advice? = null
) {

val coinUid: String
Expand Down Expand Up @@ -41,7 +43,8 @@ data class MarketViewItem(
companion object {
fun create(
marketItem: MarketItem,
favorited: Boolean = false
favorited: Boolean = false,
advice: Advice? = null
): MarketViewItem {
return MarketViewItem(
marketItem.fullCoin,
Expand All @@ -51,14 +54,15 @@ data class MarketViewItem(
),
MarketDataValue.Diff(marketItem.diff),
marketItem.rank?.toString(),
favorited
favorited,
advice
)
}

fun create(
marketItem: MarketItem,
marketField: MarketField,
favorited: Boolean = false
favorited: Boolean = false,
): MarketViewItem {
val marketDataValue = when (marketField) {
MarketField.MarketCap -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.horizontalsystems.bankwallet.modules.market.MarketItem
import io.horizontalsystems.bankwallet.modules.market.SortingField
import io.horizontalsystems.bankwallet.modules.market.TopMarket
import io.horizontalsystems.bankwallet.ui.compose.Select
import io.horizontalsystems.marketkit.models.Analytics
import io.horizontalsystems.marketkit.models.CoinCategory

object MarketCategoryModule {
Expand Down Expand Up @@ -64,4 +65,5 @@ object MarketCategoryModule {
data class MarketItemWrapper(
val marketItem: MarketItem,
val favorited: Boolean,
val signal: Analytics.TechnicalAdvice.Advice? = null
)
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
package io.horizontalsystems.bankwallet.modules.market.favorites

import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.modules.market.favorites.MarketFavoritesModule.Period
import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.widgets.MarketWidgetManager

class MarketFavoritesMenuService(
private val localStorage: ILocalStorage,
private val marketWidgetManager: MarketWidgetManager
) {

var sortDescending: Boolean
get() = localStorage.marketFavoritesSortDescending
var listSorting: WatchlistSorting
get() = localStorage.marketFavoritesSorting ?: WatchlistSorting.Manual
set(value) {
localStorage.marketFavoritesSortDescending = value
localStorage.marketFavoritesSorting = value
marketWidgetManager.updateWatchListWidgets()
}

var period: Period
get() = localStorage.marketFavoritesPeriod ?: Period.OneDay
var timeDuration: TimeDuration
get() = localStorage.marketFavoritesPeriod ?: TimeDuration.OneDay
set(value) {
localStorage.marketFavoritesPeriod = value
marketWidgetManager.updateWatchListWidgets()
}

var showSignals: Boolean
get() = localStorage.marketFavoritesShowSignals
set(value) {
localStorage.marketFavoritesShowSignals = value
marketWidgetManager.updateWatchListWidgets()
}

var manualSortOrder: List<String>
get() = localStorage.marketFavoritesManualSortingOrder
set(value) {
localStorage.marketFavoritesManualSortingOrder = value
marketWidgetManager.updateWatchListWidgets()
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package io.horizontalsystems.bankwallet.modules.market.favorites

import android.os.Parcelable
import androidx.annotation.StringRes
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.MarketViewItem
import io.horizontalsystems.bankwallet.ui.compose.Select
import io.horizontalsystems.bankwallet.modules.market.TimeDuration
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import javax.annotation.concurrent.Immutable

object MarketFavoritesModule {

Expand All @@ -20,25 +18,33 @@ object MarketFavoritesModule {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val repository = MarketFavoritesRepository(App.marketKit, App.marketFavoritesManager)
val menuService = MarketFavoritesMenuService(App.localStorage, App.marketWidgetManager)
val service = MarketFavoritesService(repository, menuService, App.currencyManager, App.backgroundManager)
val service = MarketFavoritesService(
repository,
menuService,
App.currencyManager,
App.backgroundManager
)
return MarketFavoritesViewModel(service) as T
}
}

@Immutable
data class ViewItem(
val sortingDescending: Boolean,
val periodSelect: Select<Period>,
val marketItems: List<MarketViewItem>
data class UiState(
val viewItems: List<MarketViewItem>,
val viewState: ViewState,
val isRefreshing: Boolean,
val sortingField: WatchlistSorting,
val period: TimeDuration,
val showSignal: Boolean,
)

@Parcelize
enum class Period(val titleResId: Int) : WithTranslatableTitle, Parcelable {
OneDay(R.string.CoinPage_TimeDuration_Day),
SevenDay(R.string.CoinPage_TimeDuration_Week),
ThirtyDay(R.string.CoinPage_TimeDuration_Month);
}

@IgnoredOnParcel
override val title = TranslatableString.ResString(titleResId)
}
enum class WatchlistSorting(@StringRes val titleResId: Int): WithTranslatableTitle {
Manual(R.string.Market_Sorting_Manual),
HighestCap(R.string.Market_Sorting_HighestCap),
LowestCap(R.string.Market_Sorting_LowestCap),
Gainers(R.string.Market_Sorting_Gainers),
Losers(R.string.Market_Sorting_Losers);

override val title = TranslatableString.ResString(titleResId)
}
Loading

0 comments on commit d2840b5

Please sign in to comment.