diff --git a/Coinone-iOS/Coinone-iOS.xcodeproj/project.pbxproj b/Coinone-iOS/Coinone-iOS.xcodeproj/project.pbxproj index d980c7d..91ff666 100644 --- a/Coinone-iOS/Coinone-iOS.xcodeproj/project.pbxproj +++ b/Coinone-iOS/Coinone-iOS.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 06A1A45591145692DA4F18C7 /* Pods_Coinone_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E0AB500236EDF60103A408AE /* Pods_Coinone_iOS.framework */; }; + 92AB2FB72671F80D00479451 /* CoinListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92AB2FB62671F80D00479451 /* CoinListService.swift */; }; CC0A1A9726564240000B65B9 /* FilterCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A9626564240000B65B9 /* FilterCollectionViewCell.swift */; }; CC0A1A992656425A000B65B9 /* CoinListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A982656425A000B65B9 /* CoinListTableViewCell.swift */; }; CC0A1A9C265642E9000B65B9 /* TitleCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0A1A9B265642E9000B65B9 /* TitleCollectionReusableView.swift */; }; @@ -61,6 +62,7 @@ /* Begin PBXFileReference section */ 3E2F6097EABAAACC664AB52A /* Pods-Coinone-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Coinone-iOS.debug.xcconfig"; path = "Target Support Files/Pods-Coinone-iOS/Pods-Coinone-iOS.debug.xcconfig"; sourceTree = ""; }; 4BA5E0330054E48E147B52CA /* Pods-Coinone-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Coinone-iOS.release.xcconfig"; path = "Target Support Files/Pods-Coinone-iOS/Pods-Coinone-iOS.release.xcconfig"; sourceTree = ""; }; + 92AB2FB62671F80D00479451 /* CoinListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoinListService.swift; sourceTree = ""; }; CC0A1A9626564240000B65B9 /* FilterCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCollectionViewCell.swift; sourceTree = ""; }; CC0A1A982656425A000B65B9 /* CoinListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoinListTableViewCell.swift; sourceTree = ""; }; CC0A1A9B265642E9000B65B9 /* TitleCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleCollectionReusableView.swift; sourceTree = ""; }; @@ -177,6 +179,7 @@ isa = PBXGroup; children = ( CC3370122667C5D4004F067E /* CoinFilterService.swift */, + 92AB2FB62671F80D00479451 /* CoinListService.swift */, ); path = NetworkServices; sourceTree = ""; @@ -443,6 +446,7 @@ CC0E232D2652241D00B982A0 /* StockModel.swift in Sources */, CCAA9A2B264FACDD008E50BF /* UIColor+.swift in Sources */, CC770CF8265396CF004095A6 /* UILabel+.swift in Sources */, + 92AB2FB72671F80D00479451 /* CoinListService.swift in Sources */, CC0E232B265223FE00B982A0 /* StockTVC.swift in Sources */, CC33700F2667C549004F067E /* APIConstants.swift in Sources */, CC0A1A992656425A000B65B9 /* CoinListTableViewCell.swift in Sources */, diff --git a/Coinone-iOS/Coinone-iOS/Resource/NetworkServices/CoinListService.swift b/Coinone-iOS/Coinone-iOS/Resource/NetworkServices/CoinListService.swift new file mode 100644 index 0000000..eb695b9 --- /dev/null +++ b/Coinone-iOS/Coinone-iOS/Resource/NetworkServices/CoinListService.swift @@ -0,0 +1,61 @@ +// +// CoinListService.swift +// Coinone-iOS +// +// Created by soyeon on 2021/06/10. +// + +import Foundation +import Alamofire + +struct CoinListService { + static let shared = CoinListService() + + func sortCoin(sort: String, + ascending: String, + completion: @escaping (NetworkResult) -> Void) { + let header: HTTPHeaders = ["Content-Type": "application/json"] + let url = APIConstants.coinListURL + APIIndex.init(index: .sort(sort, ascending)).index.getIndex() + let dataRequest = AF.request(url, + method: .get, + encoding: JSONEncoding.default, + headers: header) + dataRequest.responseData { dataResponse in + dump(dataResponse) + print(dataResponse.result) + switch dataResponse.result { + case .success: + guard let statusCode = dataResponse.response?.statusCode else {return} + guard let value = dataResponse.value else {return} + let networkResult = self.judgeStatus(by: statusCode, value) + completion(networkResult) + case .failure: + completion(.pathErr) + } + } + } + + private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { + switch statusCode { + case 200: + return isValidData(data: data) + case 400: return .requestErr + case 500: return .serverErr + default: return .networkFail + } + } + + private func isValidData(data : Data) -> NetworkResult { + let decoder = JSONDecoder() + + guard let decodedData = try? decoder.decode([SortedCoin].self, from: data) + else { return .pathErr} + // 우선 PersonDataModel 형태로 decode(해독)을 한번 거칩니다. 실패하면 pathErr + + // 해독에 성공하면 Person data를 success에 넣어줍니다. + return .success(decodedData) + + } +} + + diff --git a/Coinone-iOS/Coinone-iOS/Source/Cells/StockTVC.swift b/Coinone-iOS/Coinone-iOS/Source/Cells/StockTVC.swift index 00efd23..27db636 100644 --- a/Coinone-iOS/Coinone-iOS/Source/Cells/StockTVC.swift +++ b/Coinone-iOS/Coinone-iOS/Source/Cells/StockTVC.swift @@ -82,7 +82,7 @@ class StockTVC: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() } - + override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } @@ -141,33 +141,31 @@ extension StockTVC { transPriceLabel.snp.makeConstraints { make in make.top.equalTo(backView.snp.top).inset(22) - make.leading.equalTo(backView.snp.leading).inset(279) + make.leading.equalTo(backView.snp.leading).inset(299) make.height.equalTo(17) } } } extension StockTVC { - func setData(coinLogoImageName: String, coinEnglishTitle: String, coinKoreanTitle: String, coinCurrentPrice: Float, riseOrDescent: String, percentage: Float, coinTotalPrice: Float) { - let formatter = NumberFormatter().then { - $0.numberStyle = .decimal - } - - self.logoImage.image = UIImage(named: coinLogoImageName) - self.titleLabel.text = coinEnglishTitle - self.subTitleLabel.text = coinKoreanTitle + func setData(coinLogoImageName: String, coinEnglishTitle: String, coinKoreanTitle: String, coinCurrentPrice: String, riseOrDescent: String, percentage: String, coinTotalPrice: String) { +// self.logoImage.imageFromUrl(coinLogoImageName, defaultImgPath:"https://sopt-8-coinone.s3.ap-northeast-2.amazonaws.com/KLAY.png") + let string = coinLogoImageName + let url = URL(string: string)! + self.logoImage.kf.setImage(with: url) + self.titleLabel.setLabel(text: coinEnglishTitle, textColor: .black, font: .notoSansKRBoldFont(fontSize: 14)) + self.subTitleLabel.setLabel(text: coinKoreanTitle, textColor: .coinGray, font: .notoSansKRMediumFont(fontSize: 10)) if riseOrDescent == "+" { - self.curValueLabel.setLabel(text: "\(formatter.string(from: NSNumber(value: coinCurrentPrice))!)", textColor: .textRed, font: .boldSystemFont(ofSize: 14)) + self.curValueLabel.setLabel(text: coinCurrentPrice, textColor: .textRed, font: .boldSystemFont(ofSize: 14)) self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .textRed, font: .systemFont(ofSize: 14, weight: .regular)) - } else { - self.curValueLabel.setLabel(text: "\(formatter.string(from: NSNumber(value: coinCurrentPrice))!)", textColor: .mainBlue, font: .boldSystemFont(ofSize: 14)) + } + else { + self.curValueLabel.setLabel(text: coinCurrentPrice, textColor: .mainBlue, font: .boldSystemFont(ofSize: 14)) self.rateLabel.setLabel(text: "\(riseOrDescent)\(percentage)%", textColor: .mainBlue, font: .systemFont(ofSize: 14, weight: .regular)) } - - self.transPriceLabel.setLabel(text: "\(formatter.string(from: NSNumber(value:coinTotalPrice))!)억", textColor: .coinGray, font: .systemFont(ofSize: 14, weight: .regular)) - + self.transPriceLabel.setLabel(text: "\(coinTotalPrice.dropLast(8))억", textColor: .coinGray, font: .systemFont(ofSize: 14, weight: .regular)) } } diff --git a/Coinone-iOS/Coinone-iOS/Source/Models/StockModel.swift b/Coinone-iOS/Coinone-iOS/Source/Models/StockModel.swift index 7ef5721..99d31d2 100644 --- a/Coinone-iOS/Coinone-iOS/Source/Models/StockModel.swift +++ b/Coinone-iOS/Coinone-iOS/Source/Models/StockModel.swift @@ -7,10 +7,11 @@ import Foundation struct StockModel { - var logoImage: String! - var title: String! - var subTitle: String! - var curValue: String! - var rate: String! - var transPrice: Int! + var coinLogoImageName: String + var coinEnglishTitle: String + var coinKoreanTitle: String + var coinCurrentPrice: String + var riseOrDescent: String + var percentage: String + var coinTotalPrice: String } diff --git a/Coinone-iOS/Coinone-iOS/Source/ViewControllers/GeoraesoVC.swift b/Coinone-iOS/Coinone-iOS/Source/ViewControllers/GeoraesoVC.swift index bd6ba8e..31d6031 100644 --- a/Coinone-iOS/Coinone-iOS/Source/ViewControllers/GeoraesoVC.swift +++ b/Coinone-iOS/Coinone-iOS/Source/ViewControllers/GeoraesoVC.swift @@ -7,501 +7,529 @@ import Alamofire import UIKit import SnapKit +import Kingfisher class GeoraesoVC: UIViewController { - private var stockList: [StockModel] = [] - var menuTitles: [String] = ["마이", "거래소", "간편구매", "정보"] - - // MARK: - Header UI - private lazy var headerView: UIView = { - let view = UIView() - view.backgroundColor = .clear - return view - }() - - private lazy var logoImage: UIImageView = { - let imageView = UIImageView() - imageView.image = UIImage(named: "logoOnwhite") - return imageView - }() - - private lazy var searchButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "searchOnwhite"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - return button - }() - - - lazy var topCollectionView: UICollectionView = { - let layout = UICollectionViewFlowLayout() - layout.scrollDirection = .horizontal - - let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) - collectionView.isScrollEnabled = false - collectionView.translatesAutoresizingMaskIntoConstraints = false - collectionView.backgroundColor = .clear - return collectionView - }() - - private lazy var myLabel: UILabel = { - let label = UILabel() - label.text = "마이" - label.font = UIFont(name: "NotoSansKR-Bold", size: 16) - label.textColor = UIColor.textGray - return label - }() - private lazy var marketLabel: UILabel = { - let label = UILabel() - label.text = "거래소" - label.font = UIFont(name: "NotoSansKR-Bold", size: 16) - label.textColor = UIColor.black - return label - }() - private lazy var easyTransLabel: UILabel = { - let label = UILabel() - label.text = "간편 구매" - label.font = UIFont(name: "NotoSansKR-Bold", size: 16) - label.textColor = UIColor.textGray - return label - }() - private lazy var infoLabel: UILabel = { - let label = UILabel() - label.text = "정보" - label.font = UIFont(name: "NotoSansKR-Bold", size: 16) - label.textColor = UIColor.textGray - return label - }() - private lazy var lineView: UIView = { - let view = UIView() - view.backgroundColor = .black - return view - }() - - // MARK: - CoinFilter Button UI - private lazy var coinView: UIView = { - let view = UIView() - view.backgroundColor = .white - view.setBorder(borderColor: nil, borderWidth: nil) - - view.addSubview(coinLabel) - view.addSubview(cFilterButton) - - coinLabel.snp.makeConstraints { make in - make.top.equalTo(view.snp.top).inset(6) - make.leading.equalTo(view.snp.leading).inset(8) + private var apiService = CoinListService() + private var stockList: [StockModel] = [StockModel(coinLogoImageName: "coinLogo", + coinEnglishTitle: "XRP", + coinKoreanTitle: "리플", + coinCurrentPrice: "1625", + riseOrDescent: "-", + percentage: "0.37", + coinTotalPrice: "2059"), + StockModel(coinLogoImageName: "coinLogo", + coinEnglishTitle: "XRP", + coinKoreanTitle: "리플", + coinCurrentPrice: "1625", + riseOrDescent: "+", + percentage: "0.37", + coinTotalPrice: "2059")] + + // private var stockList: [StockModel] = [] + var menuTitles: [String] = ["마이", "거래소", "간편구매", "정보"] + + // MARK: - Header UI + private lazy var headerView: UIView = { + let view = UIView() + view.backgroundColor = .clear + return view + }() + + private lazy var logoImage: UIImageView = { + let imageView = UIImageView() + imageView.image = UIImage(named: "logoOnwhite") + return imageView + }() + + private lazy var searchButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "searchOnwhite"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + return button + }() + + + lazy var topCollectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.isScrollEnabled = false + collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.backgroundColor = .clear + return collectionView + }() + + private lazy var myLabel: UILabel = { + let label = UILabel() + label.text = "마이" + label.font = UIFont(name: "NotoSansKR-Bold", size: 16) + label.textColor = UIColor.textGray + return label + }() + private lazy var marketLabel: UILabel = { + let label = UILabel() + label.text = "거래소" + label.font = UIFont(name: "NotoSansKR-Bold", size: 16) + label.textColor = UIColor.black + return label + }() + private lazy var easyTransLabel: UILabel = { + let label = UILabel() + label.text = "간편 구매" + label.font = UIFont(name: "NotoSansKR-Bold", size: 16) + label.textColor = UIColor.textGray + return label + }() + private lazy var infoLabel: UILabel = { + let label = UILabel() + label.text = "정보" + label.font = UIFont(name: "NotoSansKR-Bold", size: 16) + label.textColor = UIColor.textGray + return label + }() + private lazy var lineView: UIView = { + let view = UIView() + view.backgroundColor = .black + return view + }() + + // MARK: - CoinFilter Button UI + private lazy var coinView: UIView = { + let view = UIView() + view.backgroundColor = .white + view.setBorder(borderColor: nil, borderWidth: nil) + + view.addSubview(coinLabel) + view.addSubview(cFilterButton) + + coinLabel.snp.makeConstraints { make in + make.top.equalTo(view.snp.top).inset(6) + make.leading.equalTo(view.snp.leading).inset(8) + } + cFilterButton.snp.makeConstraints { make in + make.centerY.equalTo(coinLabel) + make.leading.equalTo(coinLabel.snp.trailing).inset(-38) + } + return view + }() + private lazy var coinLabel: UILabel = { + let label = UILabel() + label.text = "코인명" + label.font = UIFont(name: "NotoSansKR-Bold", size: 12) + label.textColor = UIColor.textGray + return label + }() + private lazy var cFilterButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "switch"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + return button + }() + + // MARK: - CurValueFilter Button UI + private lazy var curValueView: UIView = { + let view = UIView() + view.backgroundColor = .white + view.setBorder(borderColor: nil, borderWidth: nil) + + view.addSubview(curValueLabel) + view.addSubview(vFilterButton) + + curValueLabel.snp.makeConstraints { make in + make.top.equalTo(view.snp.top).inset(6) + make.leading.equalTo(view.snp.leading).inset(8) + } + vFilterButton.snp.makeConstraints { make in + make.centerY.equalTo(curValueLabel) + make.leading.equalTo(curValueLabel.snp.trailing).inset(-38) + } + + return view + }() + private lazy var curValueLabel: UILabel = { + let label = UILabel() + label.text = "현재가" + label.font = UIFont(name: "NotoSansKR-Bold", size: 12) + label.textColor = UIColor.textGray + return label + }() + private lazy var vFilterButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "switch"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + return button + }() + + // MARK: - RateFilterView UI + private lazy var rateView: UIView = { + let view = UIView() + view.backgroundColor = .white + view.setBorder(borderColor: nil, borderWidth: nil) + + view.addSubview(rateLabel) + view.addSubview(rFilterButton) + + rateLabel.snp.makeConstraints { make in + make.top.equalTo(view.snp.top).inset(6) + make.leading.equalTo(view.snp.leading).inset(8) + } + rFilterButton.snp.makeConstraints { make in + make.centerY.equalTo(rateLabel) + make.leading.equalTo(rateLabel.snp.trailing).inset(-10) + } + + return view + }() + private lazy var rateLabel: UILabel = { + let label = UILabel() + label.text = "등락률" + label.font = UIFont(name: "NotoSansKR-Bold", size: 12) + label.textColor = UIColor.textGray + return label + }() + private lazy var rFilterButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "switch"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + return button + }() + + // MARK: - TransPriceFilterView UI + private lazy var transPriceView: UIView = { + let view = UIView() + view.backgroundColor = .white + view.setBorder(borderColor: nil, borderWidth: nil) + + view.addSubview(transPriceLabel) + view.addSubview(pFilterButton) + + transPriceLabel.snp.makeConstraints { make in + make.top.equalTo(view.snp.top).inset(6) + make.leading.equalTo(view.snp.leading).inset(8) + } + pFilterButton.snp.makeConstraints { make in + make.centerY.equalTo(transPriceLabel) + make.leading.equalTo(transPriceLabel.snp.trailing).inset(-3) + } + + return view + }() + private lazy var transPriceLabel: UILabel = { + let label = UILabel() + label.text = "거래대금" + label.font = UIFont(name: "NotoSansKR-Bold", size: 12) + label.textColor = UIColor(red: 101.0 / 255.0, green: 101.0 / 255.0, blue: 101.0 / 255.0, alpha: 1.0) + return label + }() + private lazy var pFilterButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(named: "switch"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + + return button + }() + + + // MARK: - Table View + private lazy var tableView: UITableView = { + let tableView = UITableView(frame: .zero, style: .plain) + tableView.delegate = self + tableView.dataSource = self + + tableView.backgroundColor = .tableViewGray + tableView.tableFooterView = UIView(frame: .zero) + tableView.separatorStyle = .none + + tableView.register(StockTVC.self, forCellReuseIdentifier: StockTVC.identifier) + + return tableView + }() + + // MARK: - Table Header View + private lazy var tableHeaderView: UIView = { + let view = UIView() + + view.backgroundColor = .tableViewGray + + view.addSubview(tableHeaderLabel) + view.addSubview(foldListButton) + + tableHeaderLabel.snp.makeConstraints { make in + make.leading.equalTo(view.snp.leading).inset(20) + make.centerY.equalTo(view.snp.centerY) + } + foldListButton.snp.makeConstraints { make in + make.trailing.equalTo(view.snp.trailing).inset(20) + make.centerY.equalTo(view.snp.centerY) + make.width.equalTo(10) + make.height.equalTo(6) + } + + return view + }() + + private var tableHeaderLabel: UILabel = { + let label = UILabel() + label.text = "Main Market" + label.font = UIFont.init(name: "NotoSansKR-Bold", size: 12) + label.textColor = UIColor(red: 101.0 / 255.0, green: 101.0 / 255.0, blue: 101.0 / 255.0, alpha: 1.0) + return label + }() + + private let foldListButton: UIButton = { + let button = UIButton() + button.setImage(UIImage(systemName: "chevron.up"), for: .normal) + button.setPreferredSymbolConfiguration(.init(pointSize: 20, + weight: .light, + scale: .large), + forImageIn: .normal) + button.tintColor = .textGray + button.addTarget(self, action: #selector(foldList(_:)), for: .touchUpInside) + + return button + }() + + // MARK: - LifeCycyle Methods + + override func viewDidLoad() { + super.viewDidLoad() + + getStockData() + setConfigure() + + topCollectionView.delegate = self + topCollectionView.dataSource = self + + register() + self.navigationController?.navigationBar.isHidden = true } - cFilterButton.snp.makeConstraints { make in - make.centerY.equalTo(coinLabel) - make.leading.equalTo(coinLabel.snp.trailing).inset(-38) +} + +// MARK: - UI +extension GeoraesoVC { + private func setConfigure() { + setHeaderView() + setTableView() } - return view - }() - private lazy var coinLabel: UILabel = { - let label = UILabel() - label.text = "코인명" - label.font = UIFont(name: "NotoSansKR-Bold", size: 12) - label.textColor = UIColor.textGray - return label - }() - private lazy var cFilterButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "switch"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - return button - }() - - // MARK: - CurValueFilter Button UI - private lazy var curValueView: UIView = { - let view = UIView() - view.backgroundColor = .white - view.setBorder(borderColor: nil, borderWidth: nil) - - view.addSubview(curValueLabel) - view.addSubview(vFilterButton) - curValueLabel.snp.makeConstraints { make in - make.top.equalTo(view.snp.top).inset(6) - make.leading.equalTo(view.snp.leading).inset(8) + private func register() { + self.topCollectionView.register(TopMenuCollectionViewCell.self, forCellWithReuseIdentifier: TopMenuCollectionViewCell.identifier) } - vFilterButton.snp.makeConstraints { make in - make.centerY.equalTo(curValueLabel) - make.leading.equalTo(curValueLabel.snp.trailing).inset(-38) - } - - return view - }() - private lazy var curValueLabel: UILabel = { - let label = UILabel() - label.text = "현재가" - label.font = UIFont(name: "NotoSansKR-Bold", size: 12) - label.textColor = UIColor.textGray - return label - }() - private lazy var vFilterButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "switch"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - return button - }() - - // MARK: - RateFilterView UI - private lazy var rateView: UIView = { - let view = UIView() - view.backgroundColor = .white - view.setBorder(borderColor: nil, borderWidth: nil) - view.addSubview(rateLabel) - view.addSubview(rFilterButton) - - rateLabel.snp.makeConstraints { make in - make.top.equalTo(view.snp.top).inset(6) - make.leading.equalTo(view.snp.leading).inset(8) - } - rFilterButton.snp.makeConstraints { make in - make.centerY.equalTo(rateLabel) - make.leading.equalTo(rateLabel.snp.trailing).inset(-10) + private func setHeaderView() { + view.addSubview(headerView) + + headerView.addSubview(logoImage) + headerView.addSubview(searchButton) + + headerView.addSubview(topCollectionView) + + + headerView.addSubview(coinView) + headerView.addSubview(curValueView) + headerView.addSubview(rateView) + headerView.addSubview(transPriceView) + + headerView.snp.makeConstraints { make in + make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide) + make.height.equalTo(140) + } + + logoImage.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(20) + make.leading.equalTo(headerView.snp.leading).inset(20) + } + searchButton.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(20) + make.leading.equalTo(headerView.snp.leading).inset(339) + } + + topCollectionView.snp.makeConstraints { make in + make.top.equalTo(logoImage.snp.bottom).offset(20) + make.leading.equalTo(headerView).inset(20) + make.trailing.equalTo(headerView).inset(131) + make.height.equalTo(30) + } + + // MARK: - Filter Button Constraints + coinView.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(96) + make.leading.equalTo(headerView.snp.leading).inset(20) + make.width.equalTo(94) + make.height.equalTo(30) + } + curValueView.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(96) + make.leading.equalTo(headerView.snp.leading).inset(118) + make.width.equalTo(94) + make.height.equalTo(30) + } + rateView.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(96) + make.leading.equalTo(headerView.snp.leading).inset(216) + make.width.equalTo(66) + make.height.equalTo(30) + } + transPriceView.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.top).inset(96) + make.leading.equalTo(headerView.snp.leading).inset(286) + make.width.equalTo(70) + make.height.equalTo(30) + } } - return view - }() - private lazy var rateLabel: UILabel = { - let label = UILabel() - label.text = "등락률" - label.font = UIFont(name: "NotoSansKR-Bold", size: 12) - label.textColor = UIColor.textGray - return label - }() - private lazy var rFilterButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "switch"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - return button - }() - - // MARK: - TransPriceFilterView UI - private lazy var transPriceView: UIView = { - let view = UIView() - view.backgroundColor = .white - view.setBorder(borderColor: nil, borderWidth: nil) - - view.addSubview(transPriceLabel) - view.addSubview(pFilterButton) - - transPriceLabel.snp.makeConstraints { make in - make.top.equalTo(view.snp.top).inset(6) - make.leading.equalTo(view.snp.leading).inset(8) - } - pFilterButton.snp.makeConstraints { make in - make.centerY.equalTo(transPriceLabel) - make.leading.equalTo(transPriceLabel.snp.trailing).inset(-3) + private func setTableView() { + view.addSubview(tableView) + + tableView.snp.makeConstraints { make in + make.top.equalTo(headerView.snp.bottom) + make.leading.trailing.equalTo(view.safeAreaLayoutGuide) + make.bottom.equalToSuperview() + } } - return view - }() - private lazy var transPriceLabel: UILabel = { - let label = UILabel() - label.text = "거래대금" - label.font = UIFont(name: "NotoSansKR-Bold", size: 12) - label.textColor = UIColor(red: 101.0 / 255.0, green: 101.0 / 255.0, blue: 101.0 / 255.0, alpha: 1.0) - return label - }() - private lazy var pFilterButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(named: "switch"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - - return button - }() - - - // MARK: - Table View - private lazy var tableView: UITableView = { - let tableView = UITableView(frame: .zero, style: .plain) - tableView.delegate = self - tableView.dataSource = self - - tableView.backgroundColor = .tableViewGray - tableView.tableFooterView = UIView(frame: .zero) - - tableView.register(StockTVC.self, forCellReuseIdentifier: StockTVC.identifier) - - return tableView - }() - - // MARK: - Table Header View - private lazy var tableHeaderView: UIView = { - let view = UIView() - - view.backgroundColor = .tableViewGray - - view.addSubview(tableHeaderLabel) - view.addSubview(foldListButton) - - tableHeaderLabel.snp.makeConstraints { make in - make.leading.equalTo(view.snp.leading).inset(20) - make.centerY.equalTo(view.snp.centerY) - } - foldListButton.snp.makeConstraints { make in - make.trailing.equalTo(view.snp.trailing).inset(20) - make.centerY.equalTo(view.snp.centerY) - make.width.equalTo(10) - make.height.equalTo(6) - } - - return view - }() - - private var tableHeaderLabel: UILabel = { - let label = UILabel() - label.text = "Main Market" - label.font = UIFont.init(name: "NotoSansKR-Bold", size: 12) - label.textColor = UIColor(red: 101.0 / 255.0, green: 101.0 / 255.0, blue: 101.0 / 255.0, alpha: 1.0) - - - return label - }() - private let foldListButton: UIButton = { - let button = UIButton() - button.setImage(UIImage(systemName: "chevron.up"), for: .normal) - button.setPreferredSymbolConfiguration(.init(pointSize: 20, - weight: .light, - scale: .large), - forImageIn: .normal) - button.tintColor = .textGray - button.addTarget(self, action: #selector(foldList(_:)), for: .touchUpInside) - - return button - }() - - - override func viewDidLoad() { - super.viewDidLoad() - - setConfigure() - setDummyData() - - topCollectionView.delegate = self - topCollectionView.dataSource = self - - register() - self.navigationController?.navigationBar.isHidden = true - } - - // MARK: - DummyData - func setDummyData() { - stockList.append(contentsOf: [ - StockModel(logoImage: "", - title: "XRP", - subTitle: "리플", - curValue: "1,625", - rate: "-0.37%", - transPrice: 2059), - StockModel(logoImage: "", - title: "XRP", - subTitle: "리플", - curValue: "1,500", - rate: "-0.37%", - transPrice: 2489), - StockModel(logoImage: "", - title: "XRP", - subTitle: "리플", - curValue: "1,000", - rate: "-0.37%", - transPrice: 1280)]) - } } -// MARK: - UI -extension GeoraesoVC { - private func setConfigure() { - setHeaderView() - setTableView() - } - - private func register() { - self.topCollectionView.register(TopMenuCollectionViewCell.self, forCellWithReuseIdentifier: TopMenuCollectionViewCell.identifier) - } - - private func setHeaderView() { - view.addSubview(headerView) - - headerView.addSubview(logoImage) - headerView.addSubview(searchButton) - - headerView.addSubview(topCollectionView) - - - headerView.addSubview(coinView) - headerView.addSubview(curValueView) - headerView.addSubview(rateView) - headerView.addSubview(transPriceView) - - headerView.snp.makeConstraints { make in - make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide) - make.height.equalTo(140) - } - - logoImage.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(20) - make.leading.equalTo(headerView.snp.leading).inset(20) - } - searchButton.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(20) - make.leading.equalTo(headerView.snp.leading).inset(339) +// MARK: - TableViewDelegate +extension GeoraesoVC: UITableViewDelegate { + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + tableHeaderView } - topCollectionView.snp.makeConstraints { make in - make.top.equalTo(logoImage).inset(20) - make.leading.equalTo(headerView).inset(20) - make.trailing.equalTo(headerView).inset(131) - make.height.equalTo(30) + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + 20 } - // MARK: - Filter Button Constraints - coinView.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(96) - make.leading.equalTo(headerView.snp.leading).inset(20) - make.width.equalTo(94) - make.height.equalTo(30) + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 72 } - curValueView.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(96) - make.leading.equalTo(headerView.snp.leading).inset(118) - make.width.equalTo(94) - make.height.equalTo(30) - } - rateView.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(96) - make.leading.equalTo(headerView.snp.leading).inset(216) - make.width.equalTo(66) - make.height.equalTo(30) - } - transPriceView.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.top).inset(96) - make.leading.equalTo(headerView.snp.leading).inset(286) - make.width.equalTo(70) - make.height.equalTo(30) - } - } - - private func setTableView() { - view.addSubview(tableView) - tableView.snp.makeConstraints { make in - make.top.equalTo(headerView.snp.bottom) - make.leading.trailing.equalTo(view.safeAreaLayoutGuide) - make.bottom.equalToSuperview() + @objc func foldList(_ sender: UIButton) { + print("fold button touched") + + // TODO: - fold list action } - } - -} - -// MARK: - TableViewDelegate -extension GeoraesoVC: UITableViewDelegate { - func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - tableHeaderView - } - - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - 20 - } - - func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return 72 - } - - @objc func foldList(_ sender: UIButton) { - print("fold button touched") - // TODO: - fold list action - } - } // MARK: - TableViewDataSource extension GeoraesoVC: UITableViewDataSource { - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return stockList.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = tableView.dequeueReusableCell(withIdentifier: StockTVC.identifier) as? StockTVC else { - return UITableViewCell() + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return stockList.count } - cell.contentView.backgroundColor = .tableViewGray - let data = stockList[indexPath.row] -// cell.setData(logoPath: data.title, title: data.title, subTitle: data.subTitle, curValue: data.curValue, rate: data.rate, transPrice: data.transPrice) -// cell.setData(coinLogoImageName: data.title, coinEnglishTitle: data.title, coinKoreanTitle: data.subTitle, coinCurrentPrice: data.curValue, riseOrDescent: data.rate, percentage: data.transPrice, coinTotalPrice: <#T##Float#>) - return cell - } + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: StockTVC.identifier) as? StockTVC else { + return UITableViewCell() + } + cell.contentView.backgroundColor = .tableViewGray + + let data = stockList[indexPath.row] + cell.setData(coinLogoImageName: data.coinLogoImageName, coinEnglishTitle: data.coinEnglishTitle, coinKoreanTitle: data.coinKoreanTitle, coinCurrentPrice: data.coinCurrentPrice, riseOrDescent: data.riseOrDescent, percentage: data.percentage, coinTotalPrice: data.coinTotalPrice) + return cell + } } extension UITableView { - func removeExtraCellLines() { - tableFooterView = UIView(frame: .zero) - } + func removeExtraCellLines() { + tableFooterView = UIView(frame: .zero) + } } extension GeoraesoVC: UICollectionViewDelegateFlowLayout { - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let width: CGFloat - switch indexPath.item { - case 1: - width = 45 - case 2: - width = 60 - default: - width = 30 + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + let width: CGFloat + switch indexPath.item { + case 1: + width = 45 + case 2: + width = 60 + default: + width = 30 + } + return CGSize(width: width+self.view.frame.width*10/375, height: 30) } - return CGSize(width: width+self.view.frame.width*10/375, height: 30) - } } // MARK: - UICollectionViewDataSource extension GeoraesoVC: UICollectionViewDataSource { - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return self.menuTitles.count - } - - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let topMenuCell = collectionView.dequeueReusableCell(withReuseIdentifier: TopMenuCollectionViewCell.identifier, for: indexPath) as? TopMenuCollectionViewCell else { - return UICollectionViewCell() + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return self.menuTitles.count } - topMenuCell.titleLabel.setLabel(text: self.menuTitles[indexPath.item], textColor: .textGray, font: .notoSansKRBoldFont(fontSize: 16)) - if indexPath.item == 1 { - topMenuCell.underLineView.isHidden = false - topMenuCell.underLineView.backgroundColor = .black - topMenuCell.titleLabel.textColor = .black + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let topMenuCell = collectionView.dequeueReusableCell(withReuseIdentifier: TopMenuCollectionViewCell.identifier, for: indexPath) as? TopMenuCollectionViewCell else { + return UICollectionViewCell() + } + topMenuCell.titleLabel.setLabel(text: self.menuTitles[indexPath.item], textColor: .textGray, font: .notoSansKRBoldFont(fontSize: 16)) + if indexPath.item == 1 { + topMenuCell.underLineView.isHidden = false + topMenuCell.underLineView.backgroundColor = .black + topMenuCell.titleLabel.textColor = .black + } + topMenuCell.awakeFromNib() + return topMenuCell } - topMenuCell.awakeFromNib() - return topMenuCell - } - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if indexPath.item == 0 && self.navigationController?.parent != nil { - let storyBoard = UIStoryboard(name: "My", bundle: nil) - guard let myViewController = storyBoard.instantiateViewController(identifier: "MyViewController") as? MyViewController else { return } - self.navigationController?.pushViewController(myViewController, animated: false) + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + if indexPath.item == 0 && self.navigationController?.parent != nil { + let storyBoard = UIStoryboard(name: "My", bundle: nil) + guard let myViewController = storyBoard.instantiateViewController(identifier: "MyViewController") as? MyViewController else { return } + self.navigationController?.pushViewController(myViewController, animated: false) + } + if indexPath.item == 0 && self.navigationController?.parent == nil { + self.navigationController?.popViewController(animated: false) + } } - if indexPath.item == 0 && self.navigationController?.parent == nil { - self.navigationController?.popViewController(animated: false) +} + +// MARK: - Network + +extension GeoraesoVC { + func getStockData() { + CoinFilterService.shared.sortCoin(sort: "total-price", ascending: "-1") { + (networkResult) in + switch(networkResult) { + case .success(let data): + var tempCoinList:[StockModel] = [] + guard let data = data as? [SortedCoin] else {return} + for i in 0..