Renamed ServerImageTableViewCell as RPCDisplaySelectableTableViewCell, modified SaveCustomRPCViewController to display network icons via RPCDisplayTableViewCell

pull/4548/head
Jerome Chan 3 years ago
parent 2f06d5de5f
commit dc1508061f
  1. 8
      AlphaWallet.xcodeproj/project.pbxproj
  2. 4
      AlphaWallet/Features/FeaturesTableViewController.swift
  3. 20
      AlphaWallet/Settings/Types/CustomRpcTableViewSection.swift
  4. 10
      AlphaWallet/Settings/Types/SaveCustomRpcBrowseDataController.swift
  5. 2
      AlphaWallet/Settings/Types/TableViewSection.swift
  6. 6
      AlphaWallet/Settings/ViewControllers/EnabledServersViewController.swift
  7. 1
      AlphaWallet/Settings/ViewControllers/SaveCustomRpcBrowseViewController.swift
  8. 12
      AlphaWallet/Settings/ViewControllers/ServersViewController.swift
  9. 14
      AlphaWallet/Settings/ViewModels/ServerViewModel.swift
  10. 22
      AlphaWallet/Settings/Views/RPCDisplaySelectableTableViewCell.swift

@ -20,7 +20,7 @@
02334299278480CF00492080 /* AddMultipleCustomRpcModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02334298278480CF00492080 /* AddMultipleCustomRpcModel.swift */; };
0233429B278489CC00492080 /* AddMultipleCustomRpcViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0233429A278489CC00492080 /* AddMultipleCustomRpcViewModel.swift */; };
0233429D27849A4F00492080 /* ExecuteOnceOnly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0233429C27849A4F00492080 /* ExecuteOnceOnly.swift */; };
0235A795280D470000E65C61 /* ServerImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0235A794280D470000E65C61 /* ServerImageTableViewCell.swift */; };
0235A795280D470000E65C61 /* RPCDisplaySelectableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0235A794280D470000E65C61 /* RPCDisplaySelectableTableViewCell.swift */; };
024255182816662F009D626E /* StringInsertSpaceBeforeCapitalsTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024255172816662F009D626E /* StringInsertSpaceBeforeCapitalsTestCase.swift */; };
0242551A28168B84009D626E /* FeaturesTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0242551928168B84009D626E /* FeaturesTestCase.swift */; };
0242551C28168C28009D626E /* EnvironmentTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0242551B28168C28009D626E /* EnvironmentTestCase.swift */; };
@ -1152,7 +1152,7 @@
02334298278480CF00492080 /* AddMultipleCustomRpcModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMultipleCustomRpcModel.swift; sourceTree = "<group>"; };
0233429A278489CC00492080 /* AddMultipleCustomRpcViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMultipleCustomRpcViewModel.swift; sourceTree = "<group>"; };
0233429C27849A4F00492080 /* ExecuteOnceOnly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecuteOnceOnly.swift; sourceTree = "<group>"; };
0235A794280D470000E65C61 /* ServerImageTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerImageTableViewCell.swift; sourceTree = "<group>"; };
0235A794280D470000E65C61 /* RPCDisplaySelectableTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RPCDisplaySelectableTableViewCell.swift; sourceTree = "<group>"; };
024255172816662F009D626E /* StringInsertSpaceBeforeCapitalsTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringInsertSpaceBeforeCapitalsTestCase.swift; sourceTree = "<group>"; };
0242551928168B84009D626E /* FeaturesTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturesTestCase.swift; sourceTree = "<group>"; };
0242551B28168C28009D626E /* EnvironmentTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentTestCase.swift; sourceTree = "<group>"; };
@ -4296,7 +4296,7 @@
02F4E8BF27717A5200D89C19 /* SaveCustomRpcBrowseView.swift */,
02D8BF8C277D572600EEE8E9 /* SaveCustomRpcManualEntryView.swift */,
028D4E59277309ED00E7418D /* EmptyTableView.swift */,
0235A794280D470000E65C61 /* ServerImageTableViewCell.swift */,
0235A794280D470000E65C61 /* RPCDisplaySelectableTableViewCell.swift */,
);
path = Views;
sourceTree = "<group>";
@ -6250,7 +6250,7 @@
87DCCB51266F655D003E8EA0 /* WalletSummaryViewModel.swift in Sources */,
296AF9A91F737F6F0058AF78 /* SendRawTransactionRequest.swift in Sources */,
293112121FC4F48400966EEA /* ServiceProvider.swift in Sources */,
0235A795280D470000E65C61 /* ServerImageTableViewCell.swift in Sources */,
0235A795280D470000E65C61 /* RPCDisplaySelectableTableViewCell.swift in Sources */,
2912CD2F1F6A83A100C6CBE3 /* ImportWalletViewController.swift in Sources */,
874DED1724C1BB0E006C8FCE /* SelectTokenViewController.swift in Sources */,
2963B6AD1F981A96003063C1 /* TransactionAppearance.swift in Sources */,

@ -32,7 +32,7 @@ class FeaturesTableViewController: UITableViewController {
super.init(nibName: nil, bundle: nil)
tableView.dataSource = self
tableView.delegate = self
tableView.register(DisplayTableViewCell.self)
tableView.register(RPCDisplayTableViewCell.self)
}
required init?(coder: NSCoder) {
@ -46,7 +46,7 @@ class FeaturesTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: DisplayTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let cell: RPCDisplayTableViewCell = tableView.dequeueReusableCell(for: indexPath)
return configure(cell: cell, at: indexPath)
}

@ -13,10 +13,6 @@ class CustomRpcTableViewSection: NSObject, TableViewSection {
// MARK: - Properties
// MARK: Static
static let cellIdentifier: String = "RPCTableViewCell"
// MARK: Private
private let mode: EnabledServersViewModel.Mode
@ -43,21 +39,9 @@ class CustomRpcTableViewSection: NSObject, TableViewSection {
return filtered ? filteredList.count : customRpcList.count
}
func cellAt(row: Int, from tableView: UITableView) -> UITableViewCell {
func serverAt(row: Int) -> CustomRPC {
let selectedRow = filtered ? filteredList[row] : customRpcList[row]
// We are using the default UITableViewCell with a custom style so we cannot register the cell to the table.
var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: CustomRpcTableViewSection.cellIdentifier)
if cell == nil {
// This does put the cell into the tableview cache somehow.
cell = UITableViewCell(style: .subtitle, reuseIdentifier: CustomRpcTableViewSection.cellIdentifier)
cell.textLabel?.textColor = Style.RPCServerTableView.Cell.text.color
cell.detailTextLabel?.textColor = Style.RPCServerTableView.Cell.detailedText.color
}
cell.textLabel?.text = selectedRow.chainName
cell.detailTextLabel?.text = "ChainID: \(selectedRow.chainID)"
cell.tintColor = Style.RPCServerTableView.Cell.tint.color
cell.accessoryType = isMarked(chainID: selectedRow.chainID) ? .checkmark : .none
return cell
return selectedRow
}
func didSelect(row: Int) {

@ -127,8 +127,12 @@ extension SaveCustomRpcBrowseDataController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard indexPath.section < tableViewSection.count else { return UITableViewCell() }
let cell: RPCDisplayTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let section = tableViewSection[indexPath.section]
return section.cellAt(row: indexPath.row, from: tableView)
let server = section.serverAt(row: indexPath.row)
let viewModel = ServerImageViewModel(server: .server(.custom(server)), selected: section.isMarked(chainID: server.chainID))
cell.configure(viewModel: viewModel)
return cell
}
}
@ -162,6 +166,10 @@ extension SaveCustomRpcBrowseDataController: UITableViewDelegate {
nil
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
80.0
}
}
// MARK: - EnableServerHeaderViewDelegate

@ -9,7 +9,7 @@ import UIKit
protocol TableViewSection: class {
func addMarked(chainID: Int)
func cellAt(row: Int, from tableView: UITableView) -> UITableViewCell
func serverAt(row: Int) -> CustomRPC
func didSelect(row: Int)
func filter(phrase: String) -> Int
func headerHeight() -> CGFloat

@ -22,7 +22,7 @@ class EnabledServersViewController: UIViewController {
tableView.separatorStyle = .singleLine
tableView.backgroundColor = GroupedTable.Color.background
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableView.register(ServerImageTableViewCell.self)
tableView.register(RPCDisplaySelectableTableViewCell.self)
tableView.dataSource = self
tableView.isEditing = false
@ -171,9 +171,9 @@ extension EnabledServersViewController: UITableViewDelegate, UITableViewDataSour
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: ServerImageTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let cell: RPCDisplaySelectableTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let server = viewModel.server(for: indexPath)
let cellViewModel = ServerImageViewModel(server: server, selected: viewModel.isServerSelected(server))
let cellViewModel = ServerImageViewModel(server: .server(server), selected: viewModel.isServerSelected(server))
cell.configure(viewModel: cellViewModel)
return cell

@ -48,6 +48,7 @@ class SaveCustomRpcBrowseViewController: UIViewController {
tableViewController.tableView.backgroundColor = GroupedTable.Color.background
tableViewController.tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableViewController.tableView.isEditing = false
tableViewController.tableView.register(RPCDisplayTableViewCell.self)
return tableViewController
}()

@ -51,7 +51,7 @@ class ServersViewController: UIViewController {
tableView.separatorStyle = .singleLine
tableView.backgroundColor = GroupedTable.Color.background
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableView.register(ServerTableViewCell.self)
tableView.register(RPCDisplaySelectableTableViewCell.self)
return tableView
}()
@ -107,15 +107,19 @@ extension ServersViewController: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: ServerTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let cell: RPCDisplaySelectableTableViewCell = tableView.dequeueReusableCell(for: indexPath)
cell.selectionStyle = .none
let server = viewModel.server(for: indexPath)
let cellViewModel = ServerViewModel(server: server, selected: viewModel.isServerSelected(server))
let rpcServerOrAuto = viewModel.server(for: indexPath)
let cellViewModel = ServerImageViewModel(server: rpcServerOrAuto, selected: viewModel.isServerSelected(rpcServerOrAuto))
cell.configure(viewModel: cellViewModel)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

@ -24,7 +24,7 @@ protocol ServerImageTableViewCellViewModelType {
var secondaryText: String { get }
var secondaryFontColor: UIColor { get }
var selectionStyle: UITableViewCell.SelectionStyle { get set }
var server: RPCServer { get }
var server: RPCServerOrAuto { get }
var serverColor: UIColor { get }
}
@ -66,10 +66,10 @@ struct ServerViewModel: ServerTableViewCellViewModelType {
struct ServerImageViewModel: ServerImageTableViewCellViewModelType {
let isSelected: Bool
let server: RPCServer
let server: RPCServerOrAuto
let isTopSeparatorHidden: Bool
init(server: RPCServer, selected: Bool) {
init(server: RPCServerOrAuto, selected: Bool) {
self.server = server
self.isSelected = selected
self.isTopSeparatorHidden = true
@ -86,7 +86,13 @@ struct ServerImageViewModel: ServerImageTableViewCellViewModelType {
var primaryFontColor: UIColor = R.color.black()!
var secondaryText: String {
return "ChainID: \(server.chainID)"
switch server {
case .auto:
return ""
case .server(let rpcServer):
return "ChainID: \(rpcServer.chainID)"
}
}
var secondaryFont: UIFont = R.font.sourceSansProRegular(size: 15.0)!
var secondaryFontColor: UIColor = R.color.dove()!

@ -7,7 +7,7 @@
import UIKit
class ServerImageTableViewCell: UITableViewCell {
class RPCDisplaySelectableTableViewCell: UITableViewCell {
// MARK: - Properties
@ -46,6 +46,7 @@ class ServerImageTableViewCell: UITableViewCell {
chainIconView.translatesAutoresizingMaskIntoConstraints = false
infoView.translatesAutoresizingMaskIntoConstraints = false
accessoryImageView.translatesAutoresizingMaskIntoConstraints = false
chainIconView.contentMode = .scaleAspectFit
addSubview(topSeparator)
addSubview(chainIconView)
addSubview(infoView)
@ -74,6 +75,8 @@ class ServerImageTableViewCell: UITableViewCell {
accessoryImageView.centerYAnchor.constraint(equalTo: centerYAnchor),
accessoryImageView.topAnchor.constraint(greaterThanOrEqualToSystemSpacingBelow: topAnchor, multiplier: 1.0),
accessoryImageView.bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: bottomAnchor, multiplier: 1.0),
heightAnchor.constraint(equalToConstant: 80.0)
])
}
@ -84,9 +87,14 @@ class ServerImageTableViewCell: UITableViewCell {
}
private func configureChainIconView(viewModel: ServerImageTableViewCellViewModelType) {
let imageSubscription = RPCServerImageFetcher.instance.image(server: viewModel.server)
switch viewModel.server {
case .auto:
chainIconView.image = R.image.launch_icon()!
case .server(let server):
let imageSubscription = RPCServerImageFetcher.instance.image(server: server)
chainIconView.subscribable = imageSubscription
}
}
private func configureInfoView(viewModel: ServerImageTableViewCellViewModelType) {
infoView.configure(viewModel: viewModel)
@ -153,3 +161,13 @@ private class ServerInformationView: UIView {
])
}
}
class RPCDisplayTableViewCell: RPCDisplaySelectableTableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Loading…
Cancel
Save