Skip to content

Commit

Permalink
ui for add symbols and rearange symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Mar 19, 2024
1 parent 1b4d9aa commit a9b67b9
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 100 deletions.
6 changes: 6 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
640C3FD62A6179E300555161 /* CandleAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640C3FD52A6179E300555161 /* CandleAlignment.swift */; };
640C3FD82A617D4900555161 /* CandlePriceLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640C3FD72A617D4900555161 /* CandlePriceLevel.swift */; };
640C3FDC2A618B2000555161 /* MarketEventSymbols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640C3FDB2A618B2000555161 /* MarketEventSymbols.swift */; };
640F8A532BA9C8D600C7BE22 /* SymbolsDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640F8A522BA9C8D600C7BE22 /* SymbolsDataProvider.swift */; };
640F8A542BA9C8D600C7BE22 /* SymbolsDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640F8A522BA9C8D600C7BE22 /* SymbolsDataProvider.swift */; };
64104FC32A210F2400D1FC41 /* EventCode+Native.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64104FC22A210F2400D1FC41 /* EventCode+Native.swift */; };
64104FC52A26059B00D1FC41 /* ConcurrentSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64104FC42A26059B00D1FC41 /* ConcurrentSet.swift */; };
64104FC72A2613BC00D1FC41 /* ConcurrentArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64104FC62A2613BC00D1FC41 /* ConcurrentArray.swift */; };
Expand Down Expand Up @@ -596,6 +598,7 @@
640C3FD52A6179E300555161 /* CandleAlignment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleAlignment.swift; sourceTree = "<group>"; };
640C3FD72A617D4900555161 /* CandlePriceLevel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandlePriceLevel.swift; sourceTree = "<group>"; };
640C3FDB2A618B2000555161 /* MarketEventSymbols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketEventSymbols.swift; sourceTree = "<group>"; };
640F8A522BA9C8D600C7BE22 /* SymbolsDataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolsDataProvider.swift; sourceTree = "<group>"; };
64104FC02A210DDD00D1FC41 /* FeedTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedTest.swift; sourceTree = "<group>"; };
64104FC22A210F2400D1FC41 /* EventCode+Native.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EventCode+Native.swift"; sourceTree = "<group>"; };
64104FC42A26059B00D1FC41 /* ConcurrentSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrentSet.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1436,6 +1439,7 @@
6482F3D02BA492A60079AC3D /* SymbolsViewController.swift */,
6482F3D62BA49AB70079AC3D /* AddSymbolsViewController.swift */,
6482F3D92BA83AA20079AC3D /* SymbolCell.swift */,
640F8A522BA9C8D600C7BE22 /* SymbolsDataProvider.swift */,
);
path = QuoteTableApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -2253,6 +2257,7 @@
644BD76F2A44746000A0BF99 /* QuoteViewController.swift in Sources */,
644BD7712A44746000A0BF99 /* QuoteTableViewController.swift in Sources */,
644BD75D2A44726F00A0BF99 /* AppDelegate.swift in Sources */,
640F8A542BA9C8D600C7BE22 /* SymbolsDataProvider.swift in Sources */,
644BD77C2A44746C00A0BF99 /* TimeInterval+Ext.swift in Sources */,
644BD77B2A44746C00A0BF99 /* Endpoint+Ext.swift in Sources */,
644BD77D2A44746C00A0BF99 /* MetricCell.swift in Sources */,
Expand Down Expand Up @@ -2288,6 +2293,7 @@
files = (
642528D12A3C534D00A04E41 /* TimeInterval+Ext.swift in Sources */,
64B6273A2A375C0F00196D07 /* QuoteCell.swift in Sources */,
640F8A532BA9C8D600C7BE22 /* SymbolsDataProvider.swift in Sources */,
6482F3D72BA49AB70079AC3D /* AddSymbolsViewController.swift in Sources */,
6469F8D32A3B401700846831 /* Colors.swift in Sources */,
6469F8D62A3B408900846831 /* Endpoint+Ext.swift in Sources */,
Expand Down
74 changes: 34 additions & 40 deletions Samples/QuoteTableApp/AddSymbolsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,51 @@ import DXFeedFramework
class AddSymbolsViewController: UIViewController {
@IBOutlet var searchBar: UISearchBar!
@IBOutlet var symbolsTableView: UITableView!

static let kSymbolsKey = "kSymbolsKey"
var symbols: [String]? = nil
@IBOutlet var titleLabel: UILabel!

var symbols = [String]()
var selectedSymbols = Set<String>()
var dataProvider = SymbolsDataProvider()

override func viewDidLoad() {
reloadData()
selectedSymbols = Set(dataProvider.selectedSymbols)
symbols = dataProvider.allSymbols.sorted()

titleLabel.textColor = .text

symbolsTableView.backgroundColor = .tableBackground
symbolsTableView.separatorStyle = .none

searchBar.searchTextField.textColor = .text
searchBar.searchTextField.attributedPlaceholder = NSAttributedString(
string: "Search symbol",
attributes: [.foregroundColor: UIColor.text!.withAlphaComponent(0.5)]
)
searchBar.barTintColor = .tableBackground
// searchBar.searchTextField.textColor = .text
// searchBar.searchTextField.attributedPlaceholder = NSAttributedString(
// string: "Search symbol",
// attributes: [.foregroundColor: UIColor.text!.withAlphaComponent(0.5)]
// )
// searchBar.barTintColor = .tableBackground
super.viewDidLoad()
view.backgroundColor = .tableBackground
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
DispatchQueue.global(qos: .background).async {
// [weak self] in
self.readIpf()
DispatchQueue.global(qos: .background).async { [weak self] in
self?.readIpf()
}
}

func readIpf() {
let reader = DXInstrumentProfileReader()
do {
let result = try reader.readFromFile(address: "https://demo:[email protected]/ipf?compression=zip")
let result = try reader.readFromFile(address: "https://demo:[email protected]/ipf?TYPE=FOREX,STOCK&compression=zip")
guard let result = result else {
return
}
let stocksData = result.map { ipf in
return ipf.symbol
}
DispatchQueue.main.async {
self.saveLocalSymbols(symbols: stocksData)
self.reloadData()
self.reloadData(symbols: stocksData)
}
print(stocksData)
} catch {
}
}
Expand All @@ -63,36 +65,30 @@ class AddSymbolsViewController: UIViewController {
self.navigationController?.popViewController(animated: true)
}

func reloadData() {
symbols = loadLocalSymbols()?.sorted()
symbolsTableView.reloadData()
}
}

extension AddSymbolsViewController {
func loadLocalSymbols() -> [String]? {
UserDefaults.standard.value(forKey: AddSymbolsViewController.kSymbolsKey) as? [String]
@IBAction func addTouchUpInside(_ sender: UIButton) {
dataProvider.addSymbols(selectedSymbols)
dataProvider.allSymbols = symbols
self.navigationController?.popViewController(animated: true)
}

func saveLocalSymbols(symbols: [String]) {
if symbols.count > 0 {
UserDefaults.standard.setValue(symbols, forKey: AddSymbolsViewController.kSymbolsKey)
}
func reloadData(symbols: [String]) {
self.symbols = symbols.sorted()
symbolsTableView.reloadData()
}
}

extension AddSymbolsViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return symbols?.count ?? 0
return symbols.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "SymbolCellId", for: indexPath)
as? SymbolCell else {
return UITableViewCell()
}
let symbol = symbols?[indexPath.row]
let value = symbol ?? ""
cell.update(symbol: value, check: selectedSymbols.contains(value))
let symbol = symbols[indexPath.row]
cell.update(symbol: symbol, check: selectedSymbols.contains(symbol))
return cell
}

Expand All @@ -101,14 +97,12 @@ extension AddSymbolsViewController: UITableViewDelegate, UITableViewDataSource {
}

func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {

let symbol = symbols?[indexPath.row]
let value = symbol ?? ""
let checked = selectedSymbols.contains(value)
let symbol = symbols[indexPath.row]
let checked = selectedSymbols.contains(symbol)
if checked {
selectedSymbols.remove(value)
selectedSymbols.remove(symbol)
} else {
selectedSymbols.insert(value)
selectedSymbols.insert(symbol)
}
tableView.reloadRows(at: [indexPath], with: .none)
return indexPath
Expand Down
1 change: 1 addition & 0 deletions Samples/QuoteTableApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DXFeedFramework
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIButton.appearance().tintColor = .text
// var thread: Thread? = Thread {
// var endpoint = try? DXEndpoint.create()
// print("execute1 in new thread \(pthread_mach_thread_np(pthread_self()))")
Expand Down
Loading

0 comments on commit a9b67b9

Please sign in to comment.