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

Implement settings page minor redesign #5767

Merged
merged 1 commit into from
Apr 26, 2024
Merged
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 @@ -8,6 +8,36 @@ struct AppearanceView: View {
var body: some View {
ScrollableThemeView {
VStack(spacing: .margin24) {
VStack(spacing: 0) {
ListSection {
NavigationRow(spacing: .margin8, destination: {
BaseCurrencySettingsModule.view()
}) {
HStack(spacing: .margin16) {
Image("usd_24").themeIcon()
Text("settings.base_currency".localized).textBody()
}
Spacer()
Text(viewModel.baseCurrency.code).textSubhead1()
Image.disclosureIcon
}

NavigationRow(spacing: .margin8, destination: {
LanguageSettingsModule.view()
}) {
HStack(spacing: .margin16) {
Image("globe_24").themeIcon()
Text("settings.language".localized).textBody()
}
Spacer()
if let language = viewModel.currentLanguageDisplayName {
Text(language).textSubhead1()
}
Image.disclosureIcon
}
}
}

VStack(spacing: 0) {
ListSectionHeader(text: "appearance.theme".localized)
ListSection {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import Combine
import MarketKit
import SwiftUI
import ThemeKit

class AppearanceViewModel: ObservableObject {
private var cancellables = Set<AnyCancellable>()

private let themeManager = App.shared.themeManager
private let launchScreenManager = App.shared.launchScreenManager
private let appIconManager = App.shared.appIconManager
private let balancePrimaryValueManager = App.shared.balancePrimaryValueManager
private let balanceConversionManager = App.shared.balanceConversionManager
private let currencyManager = App.shared.currencyManager
private let languageManager = LanguageManager.shared

let themeModes: [ThemeMode] = [.system, .dark, .light]
let conversionTokens: [Token]

var currentLanguageDisplayName: String? {
languageManager.currentLanguageDisplayName
}

@Published var baseCurrency: Currency

@Published var themMode: ThemeMode {
didSet {
themeManager.themeMode = themMode
Expand Down Expand Up @@ -57,5 +68,8 @@ class AppearanceViewModel: ObservableObject {
conversionToken = balanceConversionManager.conversionToken
balancePrimaryValue = balancePrimaryValueManager.balancePrimaryValue
appIcon = appIconManager.appIcon
baseCurrency = currencyManager.baseCurrency

currencyManager.$baseCurrency.sink { [weak self] in self?.baseCurrency = $0 }.store(in: &cancellables)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ enum MainSettingsModule {
passcodeManager: App.shared.passcodeManager,
termsManager: App.shared.termsManager,
systemInfoManager: App.shared.systemInfoManager,
currencyManager: App.shared.currencyManager,
walletConnectSessionManager: App.shared.walletConnectSessionManager,
subscriptionManager: App.shared.subscriptionManager,
rateAppManager: App.shared.rateAppManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class MainSettingsService {
private let passcodeManager: PasscodeManager
private let termsManager: TermsManager
private let systemInfoManager: SystemInfoManager
private let currencyManager: CurrencyManager
private let walletConnectSessionManager: WalletConnectSessionManager
private let subscriptionManager: SubscriptionManager
private let rateAppManager: RateAppManager
Expand All @@ -23,7 +22,7 @@ class MainSettingsService {
private let noWalletRequiredActionsRelay = BehaviorRelay<Bool>(value: false)

init(backupManager: BackupManager, cloudAccountBackupManager: CloudBackupManager, accountRestoreWarningManager: AccountRestoreWarningManager, accountManager: AccountManager, contactBookManager: ContactBookManager, passcodeManager: PasscodeManager, termsManager: TermsManager,
systemInfoManager: SystemInfoManager, currencyManager: CurrencyManager, walletConnectSessionManager: WalletConnectSessionManager, subscriptionManager: SubscriptionManager, rateAppManager: RateAppManager)
systemInfoManager: SystemInfoManager, walletConnectSessionManager: WalletConnectSessionManager, subscriptionManager: SubscriptionManager, rateAppManager: RateAppManager)
{
self.cloudAccountBackupManager = cloudAccountBackupManager
self.backupManager = backupManager
Expand All @@ -33,7 +32,6 @@ class MainSettingsService {
self.passcodeManager = passcodeManager
self.termsManager = termsManager
self.systemInfoManager = systemInfoManager
self.currencyManager = currencyManager
self.walletConnectSessionManager = walletConnectSessionManager
self.subscriptionManager = subscriptionManager
self.rateAppManager = rateAppManager
Expand Down Expand Up @@ -106,18 +104,6 @@ extension MainSettingsService {
walletConnectSessionManager.activePendingRequestsObservable.map(\.count)
}

var currentLanguageDisplayName: String? {
LanguageManager.shared.currentLanguageDisplayName
}

var baseCurrency: Currency {
currencyManager.baseCurrency
}

var baseCurrencyPublisher: AnyPublisher<Currency, Never> {
currencyManager.$baseCurrency
}

var appVersion: String {
systemInfoManager.appVersion.description
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class MainSettingsViewController: ThemeViewController {
private let securityCell = BaseSelectableThemeCell()
private let appearanceCell = BaseSelectableThemeCell()
private let contactBookCell = BaseSelectableThemeCell()
private let baseCurrencyCell = BaseSelectableThemeCell()
private let languageCell = BaseSelectableThemeCell()
private let themeModeCell = BaseSelectableThemeCell()
private let aboutCell = BaseSelectableThemeCell()
private let footerCell = MainSettingsFooterCell()
Expand Down Expand Up @@ -52,6 +50,7 @@ class MainSettingsViewController: ThemeViewController {
title = "settings.title".localized
navigationItem.backBarButtonItem = UIBarButtonItem(title: title, style: .plain, target: nil, action: nil)

tableView.registerHeaderFooter(forClass: HighlightedSubtitleHeaderFooterView.self)
tableView.sectionDataSource = self

tableView.separatorStyle = .none
Expand All @@ -77,12 +76,6 @@ class MainSettingsViewController: ThemeViewController {
contactBookCell.set(backgroundStyle: .lawrence)
syncContactBookCell()

baseCurrencyCell.set(backgroundStyle: .lawrence)
syncBaseCurrency()

languageCell.set(backgroundStyle: .lawrence, isLast: true)
buildTitleValue(cell: languageCell, image: UIImage(named: "globe_24"), title: "settings.language".localized, value: viewModel.currentLanguage)

aboutCell.set(backgroundStyle: .lawrence, isFirst: true)
syncAboutCell()

Expand All @@ -100,7 +93,6 @@ class MainSettingsViewController: ThemeViewController {
subscribe(disposeBag, viewModel.walletConnectCountDriver) { [weak self] tuple in
self?.syncWalletConnectCell(text: tuple?.text, highlighted: tuple?.highlighted ?? false)
}
subscribe(disposeBag, viewModel.baseCurrencyDriver) { [weak self] in self?.syncBaseCurrency(value: $0) }
subscribe(disposeBag, viewModel.aboutAlertDriver) { [weak self] in self?.syncAboutCell(alert: $0) }

subscribe(disposeBag, viewModel.openWalletConnectSignal) { [weak self] in self?.openWalletConnect(mode: $0) }
Expand Down Expand Up @@ -168,10 +160,6 @@ class MainSettingsViewController: ThemeViewController {
)
}

private func syncBaseCurrency(value: String? = nil) {
buildTitleValue(cell: baseCurrencyCell, image: UIImage(named: "usd_24"), title: "settings.base_currency".localized, value: value)
}

private func buildTitleValue(cell: BaseThemeCell, image: UIImage?, title: String, value: String? = nil, badge: String? = nil) {
CellBuilderNew.buildStatic(cell: cell, rootElement: .hStack([
.image24 { (component: ImageComponent) in
Expand Down Expand Up @@ -234,6 +222,15 @@ class MainSettingsViewController: ThemeViewController {
stat(page: .settings, event: .open(page: .blockchainSettings))
}
),
StaticRow(
cell: walletConnectCell,
id: "wallet-connect",
height: .heightCell48,
autoDeselect: true,
action: { [weak self] in
self?.viewModel.onTapWalletConnect()
}
),
tableView.universalRow48(
id: "backup-manager",
image: .local(UIImage(named: "icloud_24")),
Expand All @@ -250,20 +247,6 @@ class MainSettingsViewController: ThemeViewController {
]
}

private var walletConnectRows: [RowProtocol] {
[
StaticRow(
cell: walletConnectCell,
id: "wallet-connect",
height: .heightCell48,
autoDeselect: true,
action: { [weak self] in
self?.viewModel.onTapWalletConnect()
}
),
]
}

private var appearanceRows: [RowProtocol] {
[
StaticRow(
Expand Down Expand Up @@ -301,27 +284,6 @@ class MainSettingsViewController: ThemeViewController {
stat(page: .settings, event: .open(page: .appearance))
}
),
StaticRow(
cell: baseCurrencyCell,
id: "base-currency",
height: .heightCell48,
action: { [weak self] in
self?.navigationController?.pushViewController(BaseCurrencySettingsModule.view().toViewController(title: "settings.base_currency.title".localized), animated: true)

stat(page: .settings, event: .open(page: .baseCurrency))
}
),
StaticRow(
cell: languageCell,
id: "language",
height: .heightCell48,
action: { [weak self] in
let module = LanguageSettingsModule.view().toViewController(title: "settings.language".localized)
self?.navigationController?.pushViewController(module, animated: true)

stat(page: .settings, event: .open(page: .language))
}
),
]
}

Expand Down Expand Up @@ -358,7 +320,7 @@ class MainSettingsViewController: ThemeViewController {
[
tableView.universalRow48(
id: "telegram",
image: .local(UIImage(named: "telegram_24")),
image: .local(UIImage(named: "filled_telegram_24")?.withTintColor(.themeJacob)),
title: .body("Telegram"),
accessoryType: .disclosure,
autoDeselect: true,
Expand All @@ -371,7 +333,7 @@ class MainSettingsViewController: ThemeViewController {
),
tableView.universalRow48(
id: "twitter",
image: .local(UIImage(named: "twitter_24")),
image: .local(UIImage(named: "filled_twitter_24")?.withTintColor(.themeJacob)),
title: .body("Twitter"),
accessoryType: .disclosure,
autoDeselect: true,
Expand Down Expand Up @@ -526,10 +488,20 @@ extension MainSettingsViewController: SectionsDataSource {
func buildSections() -> [SectionProtocol] {
var sections: [SectionProtocol] = [
Section(id: "account", headerState: .margin(height: AppConfig.donateEnabled ? .margin32 : .margin12), rows: accountRows),
Section(id: "wallet_connect", headerState: .margin(height: .margin32), rows: walletConnectRows),
Section(id: "appearance_settings", headerState: .margin(height: .margin32), rows: appearanceRows),
Section(id: "appearance_settings", headerState: .margin(height: .margin32), footerState: .margin(height: .margin24), rows: appearanceRows),
Section(
id: "social",
headerState: .cellType(
hash: "settings.social_networks.label".localized,
binder: { (view: HighlightedSubtitleHeaderFooterView) in
view.bind(text: "settings.social_networks.label".localized, color: .themeJacob, backgroundColor: UIColor.clear)
},
dynamicHeight: { _ in .margin32 }
),
footerState: tableView.sectionFooter(text: "settings.social_networks.footer".localized, topMargin: .margin12, bottomMargin: .zero),
rows: socialRows
),
Section(id: "knowledge", headerState: .margin(height: .margin32), rows: knowledgeRows),
Section(id: "social", headerState: .margin(height: .margin32), rows: socialRows),
Section(id: "about", headerState: .margin(height: .margin32), rows: aboutRows),
Section(id: "footer", headerState: .margin(height: .margin32), footerState: .margin(height: .margin32), rows: footerRows),
]
Expand Down Expand Up @@ -580,3 +552,33 @@ extension MainSettingsViewController: MFMailComposeViewControllerDelegate {
controller.dismiss(animated: true)
}
}

class HighlightedSubtitleHeaderFooterView: UITableViewHeaderFooterView {
private let label = UILabel()

override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)

backgroundView = UIView()

addSubview(label)
label.snp.makeConstraints { maker in
maker.leading.trailing.equalToSuperview().inset(CGFloat.margin32)
maker.centerY.equalToSuperview()
}

label.font = .subhead1
label.textColor = .themeGray
}

@available(*, unavailable)
public required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func bind(text: String?, color: UIColor = .clear, backgroundColor: UIColor = .clear) {
label.text = text?.uppercased()
label.textColor = color
backgroundView?.backgroundColor = backgroundColor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class MainSettingsViewModel {
private let securityCenterAlertRelay: BehaviorRelay<Bool>
private let iCloudSyncAlertRelay: BehaviorRelay<Bool>
private let walletConnectCountRelay: BehaviorRelay<(highlighted: Bool, text: String)?>
private let baseCurrencyRelay: BehaviorRelay<String>
private let aboutAlertRelay: BehaviorRelay<Bool>
private let openWalletConnectRelay = PublishRelay<WalletConnectOpenMode>()
private let openLinkRelay = PublishRelay<String>()
Expand All @@ -25,7 +24,6 @@ class MainSettingsViewModel {
securityCenterAlertRelay = BehaviorRelay(value: !service.isPasscodeSet)
iCloudSyncAlertRelay = BehaviorRelay(value: service.isCloudAvailableError)
walletConnectCountRelay = BehaviorRelay(value: Self.convert(walletConnectSessionCount: service.walletConnectSessionCount, walletConnectPendingRequestCount: service.walletConnectPendingRequestCount))
baseCurrencyRelay = BehaviorRelay(value: service.baseCurrency.code)
aboutAlertRelay = BehaviorRelay(value: !service.termsAccepted)

service.noWalletRequiredActionsObservable
Expand Down Expand Up @@ -62,12 +60,6 @@ class MainSettingsViewModel {
})
.disposed(by: disposeBag)

service.baseCurrencyPublisher
.sink { [weak self] currency in
self?.baseCurrencyRelay.accept(currency.code)
}
.store(in: &cancellables)

service.termsAcceptedPublisher
.sink { [weak self] accepted in
self?.aboutAlertRelay.accept(!accepted)
Expand Down Expand Up @@ -108,18 +100,10 @@ extension MainSettingsViewModel {
walletConnectCountRelay.asDriver()
}

var baseCurrencyDriver: Driver<String> {
baseCurrencyRelay.asDriver()
}

var aboutAlertDriver: Driver<Bool> {
aboutAlertRelay.asDriver()
}

var currentLanguage: String? {
service.currentLanguageDisplayName
}

var appVersion: String {
service.appVersion
}
Expand Down
Loading