configuration for settings view

This commit is contained in:
loj 2019-04-29 21:04:07 +02:00
parent 6104324a71
commit d73b4b327e
7 changed files with 94 additions and 5 deletions

View File

@ -15,6 +15,7 @@ internal protocol IocContainerProtocol {
var viewFactory: ViewFactoryProtocol { get }
var trxHistoryProvider: TrxHistoryProviderProtocol { get }
var paymentParser: PaymentParserProtocol { get }
var propertyStore: PropertyStoreProtocol { get }
}
@ -37,4 +38,8 @@ internal class IocContainer: IocContainerProtocol {
public lazy var paymentParser: PaymentParserProtocol = {
return PaymentParser()
}()
public lazy var propertyStore: PropertyStoreProtocol = {
return PropertyStore()
}()
}

View File

@ -28,3 +28,26 @@ internal class Localization: Localizable {
return self.languageBundle.localizedString(forKey: text, value: text, table: "InfoPlist")
}
}
extension Localization {
public static func initialLanguage() -> String {
let preferredLanguages = Locale.preferredLanguages
let supportedLanguages = LanguageId.allCases.map { $0.rawValue }
for preferredLanguage in preferredLanguages {
if supportedLanguages.contains(preferredLanguage) {
return preferredLanguage
}
for supportedLanguage in supportedLanguages {
if preferredLanguage.starts(with: supportedLanguage) {
return supportedLanguage
}
}
}
return Constants.defaultLanguage
}
}

View File

@ -24,6 +24,8 @@ internal protocol ViewFactoryProtocol {
func getAddressVC() -> AddressVC
func getQrcVC() -> QrcVC
func getSettingsVC() -> SettingsVC
func getLanguageVC() -> LanguageVC
func getFiatVC() -> FiatVC
}
@ -81,6 +83,14 @@ internal class ViewFactory: ViewFactoryProtocol {
return self.view(withName: "Settings", onStoryboard: "Settings")
}
func getLanguageVC() -> LanguageVC {
return self.view(withName: "Language", onStoryboard: "Language")
}
func getFiatVC() -> FiatVC {
return self.view(withName: "Fiat", onStoryboard: "Fiat")
}
private func view<T>(withName viewName: String, onStoryboard storyboardName: String) -> T {
let sb = UIStoryboard(name: storyboardName, bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: viewName) as! T

View File

@ -18,6 +18,7 @@ internal class SettingsCoordinator: BaseCoordinator {
private var viewFactory: ViewFactoryProtocol
private var localizer: Localizable
private var propertyStore: PropertyStoreProtocol
internal init(navigationController: UINavigationController,
iocContainer: IocContainerProtocol)
@ -26,6 +27,7 @@ internal class SettingsCoordinator: BaseCoordinator {
self.viewFactory = self.iocContainer.viewFactory
self.localizer = self.iocContainer.localizer
self.propertyStore = self.iocContainer.propertyStore
super.init(navigationController: navigationController)
}
@ -47,11 +49,14 @@ extension SettingsCoordinator: SettingsVCDelegate {
}
func settingsVCDelegateLanguageSelectionTouched(sender: SettingsVC) {
let vc = self.viewFactory.getLanguageVC()
self.navigationController.pushViewController(vc, animated: true)
}
func settingsVCDelegateFiatSelectionTouched(sender: SettingsVC) {
self.showFiatView()
}
func settingsVCDelegateNodeSelectionTouched(sender: SettingsVC) {
@ -74,6 +79,29 @@ extension SettingsCoordinator: SettingsVCDelegate {
let vc = self.viewFactory.getSettingsVC()
vc.delegate = self
vc.localizer = self.localizer
vc.viewModel = SettingsVCViewModel(currency: self.propertyStore.currency,
language: self.propertyStore.language,
nodeAddress: self.propertyStore.nodeAddress)
self.navigationController.pushViewController(vc, animated: true)
}
}
extension SettingsCoordinator: FiatVCDelegate {
func fiatVCDelegateBackTouched(sender: FiatVC) {
self.navigationController.popViewController(animated: true)
}
func fiatVCDelegateCellTouched(sender: FiatVC) {
}
private func showFiatView() {
let vc = self.viewFactory.getFiatVC()
vc.delegate = self
vc.localizer = self.localizer
vc.viewModel = FiatVCViewModel(currencies: Constants.currencies)
self.navigationController.pushViewController(vc, animated: true)
}
}

View File

@ -35,6 +35,8 @@ class SettingsVC: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = true
if let index = self.settingsTableView.indexPathForSelectedRow {
self.settingsTableView.deselectRow(at: index, animated: true)
}
@ -95,20 +97,20 @@ class SettingsVC: UIViewController {
private var languageCell: UITableViewCell {
let cell = self.settingsTableView.dequeueReusableCell(withIdentifier: CellIdentifier.twoLabels.rawValue) as! SettingsTwoLabelsTableViewCell
cell.leftLabel.text = self.localizer?.localized("settings.language")
cell.rightLabel.text = "__language__"
cell.rightLabel.text = self.viewModel?.language
return cell
}
private var fiatCell: UITableViewCell {
let cell = self.settingsTableView.dequeueReusableCell(withIdentifier: CellIdentifier.twoLabels.rawValue) as! SettingsTwoLabelsTableViewCell
cell.leftLabel.text = self.localizer?.localized("settings.fiat")
cell.rightLabel.text = "__fiat__"
cell.rightLabel.text = self.viewModel?.currency
return cell
}
private var nodeCell: UITableViewCell {
let cell = self.settingsTableView.dequeueReusableCell(withIdentifier: CellIdentifier.oneLabel.rawValue) as! SettingsOneLabelTableViewCell
cell.leftLabel.text = "__node__"
cell.leftLabel.text = self.viewModel?.nodeAddress
return cell
}

View File

@ -10,5 +10,16 @@ import Foundation
internal struct SettingsVCViewModel {
var currency: String
var language: String
var nodeAddress: String
init(currency: String,
language: String,
nodeAddress: String)
{
self.currency = currency
self.language = language
self.nodeAddress = nodeAddress
}
}

View File

@ -36,6 +36,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.appCoordinator.start()
self.window?.makeKeyAndVisible()
UINavigationBar.appearance().prefersLargeTitles = true
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0),
NSAttributedString.Key.font: UIFont(name: "SourceSansPro-Bold", size: 34)!
]
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedString.Key.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0),
NSAttributedString.Key.font: UIFont(name: "SourceSansPro-Regular", size: 18)!
]
return true
}