Skip to content

Commit

Permalink
[Refactor] code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Aug 17, 2021
1 parent 3aaad69 commit 0723f19
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
5BC2ABFB26CA3605005F8447 /* 4806-weather-windy.json in Resources */ = {isa = PBXBuildFile; fileRef = 5BC2ABFA26CA3605005F8447 /* 4806-weather-windy.json */; };
5BC2ABFE26CA362D005F8447 /* 4800-weather-partly-cloudy.json in Resources */ = {isa = PBXBuildFile; fileRef = 5BC2ABFD26CA362D005F8447 /* 4800-weather-partly-cloudy.json */; };
5BC2AC0126CA4492005F8447 /* 4801-weather-partly-shower.json in Resources */ = {isa = PBXBuildFile; fileRef = 5BC2AC0026CA4492005F8447 /* 4801-weather-partly-shower.json */; };
5BC2AC0426CBBAEB005F8447 /* 4793-weather-snow.json in Resources */ = {isa = PBXBuildFile; fileRef = 5BC2AC0326CBBAEB005F8447 /* 4793-weather-snow.json */; };
F78DEE4A9C85B70005C470E0 /* Pods_AppleWeather_Clone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBC475665102F1DB6864322C /* Pods_AppleWeather_Clone.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -90,6 +91,7 @@
5BC2ABFA26CA3605005F8447 /* 4806-weather-windy.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "4806-weather-windy.json"; path = "../../../../../../Downloads/4806-weather-windy.json"; sourceTree = "<group>"; };
5BC2ABFD26CA362D005F8447 /* 4800-weather-partly-cloudy.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "4800-weather-partly-cloudy.json"; path = "../../../../../../Downloads/4800-weather-partly-cloudy.json"; sourceTree = "<group>"; };
5BC2AC0026CA4492005F8447 /* 4801-weather-partly-shower.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "4801-weather-partly-shower.json"; path = "../../../../../../Downloads/4801-weather-partly-shower.json"; sourceTree = "<group>"; };
5BC2AC0326CBBAEB005F8447 /* 4793-weather-snow.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "4793-weather-snow.json"; path = "../../../../../../Downloads/4793-weather-snow.json"; sourceTree = "<group>"; };
63A15E026EC33FF5458AED69 /* Pods-AppleWeather_Clone.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppleWeather_Clone.release.xcconfig"; path = "Target Support Files/Pods-AppleWeather_Clone/Pods-AppleWeather_Clone.release.xcconfig"; sourceTree = "<group>"; };
DBC475665102F1DB6864322C /* Pods_AppleWeather_Clone.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AppleWeather_Clone.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FCCA9BBCAD44D1F20C90CC77 /* Pods-AppleWeather_Clone.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AppleWeather_Clone.debug.xcconfig"; path = "Target Support Files/Pods-AppleWeather_Clone/Pods-AppleWeather_Clone.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,6 +289,7 @@
5BC2ABFD26CA362D005F8447 /* 4800-weather-partly-cloudy.json */,
5BC2AC0026CA4492005F8447 /* 4801-weather-partly-shower.json */,
5BC2ABF026CA2D41005F8447 /* 4799-weather-night.json */,
5BC2AC0326CBBAEB005F8447 /* 4793-weather-snow.json */,
5BC2ABEF26CA2D41005F8447 /* 4803-weather-storm.json */,
5BC2ABEE26CA2D41005F8447 /* 4804-weather-sunny.json */,
);
Expand Down Expand Up @@ -386,6 +389,7 @@
5BC2ABF226CA2D41005F8447 /* 4803-weather-storm.json in Resources */,
5B72C15C26AB3422008A4B6A /* Assets.xcassets in Resources */,
5BC2AC0126CA4492005F8447 /* 4801-weather-partly-shower.json in Resources */,
5BC2AC0426CBBAEB005F8447 /* 4793-weather-snow.json in Resources */,
5BC2ABF126CA2D41005F8447 /* 4804-weather-sunny.json in Resources */,
5BC2ABFE26CA362D005F8447 /* 4800-weather-partly-cloudy.json in Resources */,
5B72C15A26AB341F008A4B6A /* Main.storyboard in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ListTVC: UITableViewCell {
static let identifier = "ListTVC"

// MARK: - Properties
let localLabel = UILabel().then { /// 나의 위치 첫 번째 cell
let subTitleLabel = UILabel().then {
$0.font = .systemFont(ofSize: 12, weight: .semibold)
$0.textColor = .white
$0.textAlignment = .left
}

let myLocalLabel = UILabel().then { /// 나의 위치 첫 번째 cell
let titleLabel = UILabel().then {
$0.font = .systemFont(ofSize: 22, weight: .semibold)
$0.textColor = .white
$0.textAlignment = .left
Expand All @@ -31,18 +31,6 @@ class ListTVC: UITableViewCell {
$0.textColor = .white
$0.textAlignment = .left
}

let timeLabel = UILabel().then {
$0.font = .systemFont(ofSize: 12, weight: .semibold)
$0.textColor = .white
$0.textAlignment = .left
}

let countryLabel = UILabel().then {
$0.font = .systemFont(ofSize: 22, weight: .semibold)
$0.textColor = .white
$0.textAlignment = .left
}

// MARK: - Lifecycle
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
Expand All @@ -69,22 +57,21 @@ class ListTVC: UITableViewCell {

// MARK: - Custom Method
func configUI() {
localLabel.getShadow()
myLocalLabel.getShadow()
subTitleLabel.getShadow()
titleLabel.getShadow()
tempLabel.getShadow()
timeLabel.getShadow()
countryLabel.getShadow()
backgroundColor = .brown
}

func setupFirstCellAutoLayout() { /// first cell
addSubviews([localLabel, myLocalLabel, tempLabel])
addSubviews([subTitleLabel, titleLabel, tempLabel])

localLabel.snp.makeConstraints { make in
subTitleLabel.snp.makeConstraints { make in
make.leading.equalTo(20)
make.bottom.equalTo(myLocalLabel.snp.top).offset(-1)
make.bottom.equalTo(titleLabel.snp.top).offset(-1)
}

myLocalLabel.snp.makeConstraints { make in
titleLabel.snp.makeConstraints { make in
make.leading.equalTo(20)
make.centerY.equalTo(tempLabel.snp.centerY)
}
Expand All @@ -96,14 +83,14 @@ class ListTVC: UITableViewCell {
}

func setupRemainCellAutoLayout() { /// 남은 cell들
addSubviews([timeLabel, countryLabel, tempLabel])
addSubviews([subTitleLabel, titleLabel, tempLabel])

timeLabel.snp.makeConstraints { make in
subTitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(15)
make.leading.equalTo(20)
}

countryLabel.snp.makeConstraints { make in
titleLabel.snp.makeConstraints { make in
make.leading.equalTo(20)
make.centerY.equalTo(tempLabel.snp.centerY)

Expand All @@ -117,28 +104,21 @@ class ListTVC: UITableViewCell {

// MARK: - @objc
@objc func changeToC(_ sender: Notification) {
let temp = Int(tempLabel.text!)!
tempLabel.text = "\(Int(5*(temp - 32)/9))" + "º"
let temp = Double(tempLabel.text!)!
tempLabel.text = "\(round((temp - 32)/1.8))"
print("F -> C", temp)
}

@objc func changeToF(_ sender: Notification) {
let temp = Int(tempLabel.text!)!
tempLabel.text = "\(Int(9*temp/5) + 32)" + "º"
let temp = Double(tempLabel.text!)!
tempLabel.text = "\(temp*1.8 + 32)"
print("C -> F", temp)
}

// MARK: - setFirstCellData
func setFirstCellData(local: String, myLocal: String, temp: String) {
localLabel.text = local
myLocalLabel.text = myLocal
tempLabel.text = temp
}

// MARK: - setFirstCellData
func setCellData(time: String, country: String, temp: String) {
timeLabel.text = time
countryLabel.text = country
// MARK: - setData
func setData(subtitle: String, title: String, temp: String) {
subTitleLabel.text = subtitle
titleLabel.text = title
tempLabel.text = temp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class MainCVC: UICollectionViewCell {
super.init(frame: frame)
configUI()
setupAutoLayout()
NotificationCenter.default.addObserver(self, selector: #selector(receiveFirstCell(_:)),
name: NSNotification.Name("clickFirstCell"), object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(receiveFirstCell(_:)),
// name: NSNotification.Name("clickFirstCell"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveOtherCell(_:)),
name: NSNotification.Name("clickOtherCell"), object: nil)
name: NSNotification.Name("clickCell"), object: nil)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -281,7 +281,7 @@ extension MainCVC: UITableViewDataSource {
rain: dailyList[indexPath.row + 1].rain,
high: dailyList[indexPath.row + 1].temp.max,
low: dailyList[indexPath.row + 1].temp.min)
print(self.timezoneOffset, "dpd")
print(self.timezoneOffset, "timezoneOffset")
return dailyCell

} else if indexPath.row < 8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ListFooterView: UIView {

// MARK: - Custom Method
func configUI() {

}

func setupAutoLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extension String {
dateFormatter.dateFormat = format
dateFormatter.locale = Locale(identifier: "ko_KR")
dateFormatter.timeZone = TimeZone(secondsFromGMT: timezone)

return dateFormatter.string(from: date as Date)
}

Expand Down Expand Up @@ -73,6 +72,8 @@ extension String {
return "4806-weather-windy"
case "튼구름":
return "4806-weather-windy"
case "":
return "4793-weather-snow"
default:
return "4800-weather-partly-cloudy"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension UILabel {
func getShadow() {
self.layer.shadowOffset = CGSize(width: 2, height: 2)
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.3
self.layer.shadowOpacity = 0.2
self.layer.masksToBounds = false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

struct ListModel {
var time: String
var country: String
var subTitle: String
var title: String
var temp: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import SnapKit

class ListViewController: UIViewController {
// MARK: - Properties
var cityList: [ListModel] = [ListModel(time: "마포구", country: "나의 위치", temp: "33"),
ListModel(time: "오전 4:21", country: "하와이", temp: "33"),
ListModel(time: "오전 6:21", country: "도쿄", temp: "22"),
ListModel(time: "오전 7:21", country: "Chiyoda", temp: "18"),
ListModel(time: "오전 8:21", country: "로스엔젤레스", temp: "33")]

let mainTV = UITableView()
var cityList: [ListModel] = [ListModel(subTitle: "마포구", title: "나의 위치", temp: "33"),
ListModel(subTitle: "오전 4:21", title: "하와이", temp: "33")]

var firstCellLocation: String = ""

let mainTV = UITableView()

// MARK: - Lifecycle
override func viewDidLoad() {
Expand Down Expand Up @@ -57,7 +54,6 @@ class ListViewController: UIViewController {
@objc func touchupWebButton(_ sender: UIButton) {
let application = UIApplication.shared
let weatherURL = URL(string: "https://weather.com/ko-KR/weather/today/")!

if application.canOpenURL(weatherURL) {
application.open(weatherURL, options: [:], completionHandler: nil)
}
Expand Down Expand Up @@ -121,45 +117,33 @@ extension ListViewController: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let listCell = tableView.dequeueReusableCell(withIdentifier: ListTVC.identifier, for: indexPath) as? ListTVC
else { return UITableViewCell() }
listCell.selectionStyle = .none
if indexPath.row == 0 {
guard let listCell = tableView.dequeueReusableCell(withIdentifier: ListTVC.identifier, for: indexPath) as? ListTVC
else { return UITableViewCell() }
listCell.setupFirstCellAutoLayout()
listCell.selectionStyle = .none
listCell.backgroundView = UIImageView.init(image: UIImage(named: "img_rain"))
listCell.setFirstCellData(local: firstCellLocation,
myLocal: cityList[indexPath.row].country,
temp: cityList[indexPath.row].temp)
return listCell
} else {
guard let listCell = tableView.dequeueReusableCell(withIdentifier: ListTVC.identifier, for: indexPath) as? ListTVC
else { return UITableViewCell() }
listCell.setupRemainCellAutoLayout()
listCell.selectionStyle = .none
listCell.backgroundView = UIImageView.init(image: UIImage(named: "img_sun"))
listCell.setCellData(time: cityList[indexPath.row].time,
country: cityList[indexPath.row].country,
temp: cityList[indexPath.row].temp)
return listCell
}
}

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let moveCell = cityList[sourceIndexPath.row]
cityList.remove(at: sourceIndexPath.row)
cityList.insert(moveCell, at: destinationIndexPath.row)
listCell.setData(subtitle: cityList[indexPath.row].subTitle,
title: cityList[indexPath.row].title,
temp: cityList[indexPath.row].temp)

return listCell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
dismiss(animated: true) {
NotificationCenter.default.post(name: NSNotification.Name("pageControl"), object: indexPath.row)
if indexPath.row == 0 {
NotificationCenter.default.post(name: NSNotification.Name("clickFirstCell"),
object: [self.firstCellLocation, self.cityList[0].temp])
NotificationCenter.default.post(name: NSNotification.Name("clickCell"),
object: [self.cityList[indexPath.row].subTitle,
self.cityList[indexPath.row].temp])
} else {
NotificationCenter.default.post(name: NSNotification.Name("clickOtherCell"),
object: [self.cityList[indexPath.row].country, self.cityList[indexPath.row].temp])
NotificationCenter.default.post(name: NSNotification.Name("clickCell"),
object: [self.cityList[indexPath.row].title,
self.cityList[indexPath.row].temp])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class SearchViewController: UIViewController {
searchTV.delegate = self
searchTV.dataSource = self
searchTV.register(SearchTVC.self, forCellReuseIdentifier: "SearchTVC")

searchTV.separatorStyle = .none
}

Expand Down
Loading

0 comments on commit 0723f19

Please sign in to comment.