parent
979f8cb026
commit
499cb39fdf
@ -1,107 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
|
||||
class EditTokensViewController: UITableViewController { |
||||
|
||||
let session: WalletSession |
||||
let storage: TokensDataStore |
||||
let viewModel = EditTokenViewModel() |
||||
let searchController = UISearchController(searchResultsController: nil) |
||||
var filteredTokens = [TokenObject]() |
||||
|
||||
var isFiltering: Bool { |
||||
return searchController.isActive && !searchBarIsEmpty |
||||
} |
||||
var searchBarIsEmpty: Bool { |
||||
return searchController.searchBar.text?.isEmpty ?? true |
||||
} |
||||
|
||||
init( |
||||
session: WalletSession, |
||||
storage: TokensDataStore |
||||
) { |
||||
self.session = session |
||||
self.storage = storage |
||||
|
||||
super.init(nibName: nil, bundle: nil) |
||||
|
||||
navigationItem.title = viewModel.title |
||||
searchController.searchResultsUpdater = self |
||||
searchController.obscuresBackgroundDuringPresentation = false |
||||
searchController.searchBar.placeholder = R.string.localizable.editTokensSearchBarPlaceholderTitle() |
||||
definesPresentationContext = true |
||||
searchController.searchBar.delegate = self |
||||
tableView.register(R.nib.editTokenTableViewCell(), forCellReuseIdentifier: R.nib.editTokenTableViewCell.name) |
||||
tableView.tableHeaderView = searchController.searchBar |
||||
tableView.separatorStyle = .none |
||||
tableView.separatorInset = .zero |
||||
tableView.rowHeight = UITableViewAutomaticDimension |
||||
} |
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int { |
||||
return 1 |
||||
} |
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
||||
if isFiltering { |
||||
return filteredTokens.count |
||||
} |
||||
return storage.objects.count |
||||
} |
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
||||
let cell = tableView.dequeueReusableCell(withIdentifier: R.nib.editTokenTableViewCell.name, for: indexPath) as! EditTokenTableViewCell |
||||
cell.delegate = self |
||||
let token = self.token(for: indexPath) |
||||
cell.viewModel = EditTokenTableCellViewModel( |
||||
token: token, |
||||
coinTicker: storage.coinTicker(for: token), |
||||
config: session.config |
||||
) |
||||
return cell |
||||
} |
||||
|
||||
func token(for indexPath: IndexPath) -> TokenObject { |
||||
if isFiltering { |
||||
return filteredTokens[indexPath.row] |
||||
} |
||||
return storage.objects[indexPath.row] |
||||
} |
||||
|
||||
func filter(for searchText: String?) { |
||||
let text = searchText?.lowercased() ?? "" |
||||
filteredTokens = storage.objects.filter { $0.name.lowercased().contains(text) || $0.symbol.lowercased().contains(text) } |
||||
tableView.reloadData() |
||||
} |
||||
|
||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { |
||||
return 80 |
||||
} |
||||
|
||||
required init?(coder aDecoder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
} |
||||
|
||||
extension EditTokensViewController: EditTokenTableViewCellDelegate { |
||||
func didChangeState(state: Bool, in cell: EditTokenTableViewCell) { |
||||
|
||||
guard let indexPath = tableView.indexPath(for: cell) else { return } |
||||
|
||||
storage.update(token: token(for: indexPath), action: .isDisabled(!state)) |
||||
} |
||||
} |
||||
|
||||
extension EditTokensViewController: UISearchBarDelegate { |
||||
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { |
||||
filter(for: searchBar.text) |
||||
} |
||||
} |
||||
|
||||
extension EditTokensViewController: UISearchResultsUpdating { |
||||
func updateSearchResults(for searchController: UISearchController) { |
||||
filter(for: searchController.searchBar.text) |
||||
} |
||||
} |
@ -1,67 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
|
||||
struct EditTokenTableCellViewModel { |
||||
|
||||
let token: TokenObject |
||||
let coinTicker: CoinTicker? |
||||
let config: Config |
||||
|
||||
init( |
||||
token: TokenObject, |
||||
coinTicker: CoinTicker?, |
||||
config: Config |
||||
) { |
||||
self.token = token |
||||
self.coinTicker = coinTicker |
||||
self.config = config |
||||
} |
||||
|
||||
var title: String { |
||||
return token.title |
||||
} |
||||
|
||||
var titleFont: UIFont { |
||||
return Fonts.semibold(size: 18)! |
||||
} |
||||
|
||||
var titleTextColor: UIColor { |
||||
return Colors.black |
||||
} |
||||
|
||||
var placeholderImage: UIImage? { |
||||
return R.image.ethereumToken() |
||||
} |
||||
|
||||
var imageUrl: URL? { |
||||
return coinTicker?.imageURL |
||||
} |
||||
|
||||
var isEnabled: Bool { |
||||
return !token.isDisabled |
||||
} |
||||
|
||||
private var isAvailableForChange: Bool { |
||||
return token.contract == TokensDataStore.etherToken(for: config).contract ? true : false |
||||
} |
||||
|
||||
var contractText: String? { |
||||
if !isAvailableForChange { |
||||
return token.contract |
||||
} |
||||
return .none |
||||
} |
||||
|
||||
var isTokenContractLabelHidden: Bool { |
||||
if contractText == nil { |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
|
||||
var isSwitchHidden: Bool { |
||||
return isAvailableForChange |
||||
} |
||||
} |
@ -1,11 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
|
||||
struct EditTokenViewModel { |
||||
|
||||
var title: String { |
||||
return R.string.localizable.tokenTitlecase() |
||||
} |
||||
} |
@ -1,38 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import UIKit |
||||
import Kingfisher |
||||
|
||||
protocol EditTokenTableViewCellDelegate: class { |
||||
func didChangeState(state: Bool, in cell: EditTokenTableViewCell) |
||||
} |
||||
|
||||
class EditTokenTableViewCell: UITableViewCell { |
||||
|
||||
@IBOutlet weak var tokenImageView: UIImageView! |
||||
@IBOutlet weak var tokenLabel: UILabel! |
||||
@IBOutlet weak var tokenEnableSwitch: UISwitch! |
||||
@IBOutlet weak var tokenContractLabel: UILabel! |
||||
weak var delegate: EditTokenTableViewCellDelegate? |
||||
|
||||
var viewModel: EditTokenTableCellViewModel? { |
||||
didSet { |
||||
guard let viewModel = viewModel else { return } |
||||
tokenLabel.text = viewModel.title |
||||
tokenLabel.font = viewModel.titleFont |
||||
tokenLabel.textColor = viewModel.titleTextColor |
||||
tokenEnableSwitch.isOn = viewModel.isEnabled |
||||
tokenContractLabel.text = viewModel.contractText |
||||
tokenContractLabel.isHidden = viewModel.isTokenContractLabelHidden |
||||
tokenEnableSwitch.isHidden = viewModel.isSwitchHidden |
||||
tokenImageView.kf.setImage( |
||||
with: viewModel.imageUrl, |
||||
placeholder: viewModel.placeholderImage |
||||
) |
||||
} |
||||
} |
||||
|
||||
@IBAction func didChangeSwitch(_ sender: UISwitch) { |
||||
delegate?.didChangeState(state: sender.isOn, in: self) |
||||
} |
||||
} |
@ -1,84 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> |
||||
<device id="retina4_7" orientation="portrait"> |
||||
<adaptation id="fullscreen"/> |
||||
</device> |
||||
<dependencies> |
||||
<deployment identifier="iOS"/> |
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> |
||||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/> |
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> |
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
||||
</dependencies> |
||||
<objects> |
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> |
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> |
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="0.0" id="KGk-i7-Jjw" customClass="EditTokenTableViewCell" customModule="Trust" customModuleProvider="target"> |
||||
<rect key="frame" x="0.0" y="0.0" width="319" height="80"/> |
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> |
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> |
||||
<rect key="frame" x="0.0" y="0.0" width="319" height="79.5"/> |
||||
<autoresizingMask key="autoresizingMask"/> |
||||
<subviews> |
||||
<stackView opaque="NO" contentMode="scaleToFill" alignment="top" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="d5W-Lo-p3o"> |
||||
<rect key="frame" x="10" y="10" width="299" height="60"/> |
||||
<subviews> |
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Tfc-cq-2hm"> |
||||
<rect key="frame" x="0.0" y="0.0" width="72" height="50"/> |
||||
<constraints> |
||||
<constraint firstAttribute="width" constant="72" id="uhQ-eN-kxx"/> |
||||
</constraints> |
||||
</imageView> |
||||
<stackView opaque="NO" contentMode="scaleAspectFit" semanticContentAttribute="spatial" axis="vertical" distribution="equalCentering" alignment="top" spacing="-2" translatesAutoresizingMaskIntoConstraints="NO" id="fRy-j2-9ES" userLabel="Label Stack View"> |
||||
<rect key="frame" x="77" y="0.0" width="168" height="55"/> |
||||
<subviews> |
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="Test lable" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.69999999999999996" translatesAutoresizingMaskIntoConstraints="NO" id="gzC-hL-qRv"> |
||||
<rect key="frame" x="0.0" y="0.0" width="73" height="20.5"/> |
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/> |
||||
<nil key="textColor"/> |
||||
<nil key="highlightedColor"/> |
||||
</label> |
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Su7-1W-bDk"> |
||||
<rect key="frame" x="0.0" y="20" width="33" height="35"/> |
||||
<fontDescription key="fontDescription" type="system" pointSize="13"/> |
||||
<nil key="textColor"/> |
||||
<nil key="highlightedColor"/> |
||||
</label> |
||||
</subviews> |
||||
<constraints> |
||||
<constraint firstItem="Su7-1W-bDk" firstAttribute="centerY" secondItem="fRy-j2-9ES" secondAttribute="centerY" constant="10" id="VAL-9W-wbh"/> |
||||
</constraints> |
||||
</stackView> |
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Uf5-TC-p3g"> |
||||
<rect key="frame" x="250" y="0.0" width="51" height="31"/> |
||||
<connections> |
||||
<action selector="didChangeSwitch:" destination="KGk-i7-Jjw" eventType="valueChanged" id="RNY-kW-3Zh"/> |
||||
</connections> |
||||
</switch> |
||||
</subviews> |
||||
<constraints> |
||||
<constraint firstAttribute="bottom" secondItem="Tfc-cq-2hm" secondAttribute="bottom" constant="10" id="85M-T3-zGn"/> |
||||
<constraint firstAttribute="trailing" secondItem="Uf5-TC-p3g" secondAttribute="trailing" id="pKu-nx-1qR"/> |
||||
<constraint firstAttribute="bottom" secondItem="fRy-j2-9ES" secondAttribute="bottom" constant="5" id="sQQ-18-ZYL"/> |
||||
</constraints> |
||||
</stackView> |
||||
</subviews> |
||||
<constraints> |
||||
<constraint firstItem="d5W-Lo-p3o" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" id="8PS-GA-H74"/> |
||||
<constraint firstItem="d5W-Lo-p3o" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="-1" id="YfI-ez-BFb"/> |
||||
<constraint firstItem="d5W-Lo-p3o" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="cS9-mR-210"/> |
||||
<constraint firstItem="d5W-Lo-p3o" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="-6" id="vlf-YR-icm"/> |
||||
</constraints> |
||||
</tableViewCellContentView> |
||||
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/> |
||||
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/> |
||||
<connections> |
||||
<outlet property="tokenContractLabel" destination="Su7-1W-bDk" id="gpT-3O-qkl"/> |
||||
<outlet property="tokenEnableSwitch" destination="Uf5-TC-p3g" id="Lcf-e0-JTA"/> |
||||
<outlet property="tokenImageView" destination="Tfc-cq-2hm" id="QtY-sC-dhw"/> |
||||
<outlet property="tokenLabel" destination="gzC-hL-qRv" id="cHh-cJ-bga"/> |
||||
</connections> |
||||
<point key="canvasLocation" x="33.5" y="72"/> |
||||
</tableViewCell> |
||||
</objects> |
||||
</document> |
Loading…
Reference in new issue