Skip to content

Commit

Permalink
[Feat] 도시 추가 ListVC에 반영(#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Aug 18, 2021
1 parent 0723f19 commit 6d9558f
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct GeneralAPI {
static let baseURL = "https://api.openweathermap.org/data/2.5"
static let appid = "cea1d8866a0ca2c205c2b5e2a30f160c"
static let appid = "c01b53a14126d3873f86c0c8921524be"

/// https://api.openweathermap.org/data/2.5/onecall?appid=cea1d8866a0ca2c205c2b5e2a30f160c&units=metric&lang=kr
///https://api.openweathermap.org/data/2.5/onecall?appid=c01b53a14126d3873f86c0c8921524be&units=metric&lat=36.756866455078125&lon=127.22335105296
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ fileprivate extension NetworkLoggerPlugin {
}
}
}

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

import UIKit

import Then
import SnapKit
import Then

class ListTVC: UITableViewCell {
static let identifier = "ListTVC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

import Then
import SnapKit
import Then

class DailyTVC: UITableViewCell {
// 화~요일별 날씨 테이블 셀 총 10개를 반복하면 됨
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

import Then
import SnapKit
import Then

class DetailTVC: UITableViewCell {
// 일출, 일몰 등등 부분 - 5개 반복
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

import Moya
import Then
import SnapKit
import Then

class MainCVC: UICollectionViewCell {
static let identifier = "MainCVC"
Expand Down Expand Up @@ -158,13 +158,13 @@ class MainCVC: UICollectionViewCell {
}

// MARK: - @objc
@objc func receiveFirstCell(_ notifiction: Notification) {
if let location = notifiction.object as? [String],
let temp = notifiction.object as? [String] {
locationLabel.text = location[0]
tempLabel.text = temp[1]
}
}
// @objc func receiveFirstCell(_ notifiction: Notification) {
// if let location = notifiction.object as? [String],
// let temp = notifiction.object as? [String] {
// locationLabel.text = location[0]
// tempLabel.text = temp[1]
// }
// }

@objc func receiveOtherCell(_ notifiction: Notification) {
if let location = notifiction.object as? [String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import UIKit

import Then
import SafariServices
import SnapKit
import Then

class MapTVC: UITableViewCell {
static let identifier = "MapTVC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

import Then
import SnapKit
import Then

class TimeTempCVC: UICollectionViewCell {
static let identifier = "TimeTempCVC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

import Then
import SnapKit
import Then

class TodayTVC: UITableViewCell {
// 1개만 써주면 됨 오늘~ 웅앵부분
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

import Then
import SnapKit
import Then

class SearchTVC: UITableViewCell {
static let identifier = "SearchTVC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

import Moya
import Then
import SnapKit
import Then

class TimeTempHeaderView: UIView {
// MARK: - Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct WeatherRequest: Codable {
init(_ lat: Double, _ lon: Double, _ exclude: String) {
self.lat = lat
self.lon = lon
self.appid = "cea1d8866a0ca2c205c2b5e2a30f160c"
self.appid = GeneralAPI.appid
self.exclude = exclude
self.units = "metric"
self.lang = "kr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@

import UIKit

import Then
import SnapKit
import Then

class ListViewController: UIViewController {
// MARK: - Properties
var cityList: [ListModel] = [ListModel(subTitle: "마포구", title: "나의 위치", temp: "33"),
ListModel(subTitle: "오전 4:21", title: "하와이", temp: "33")]
var cityList: [ListModel] = [ListModel(subTitle: "", title: "나의 위치", temp: "")]

var firstCellLocation: String = ""

let mainTV = UITableView()
let mainTV = UITableView(frame: .zero, style: .grouped)

// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
configUI()
setupAutoLayout()
setupTableView()
registerNotification()
}

// MARK: - Custom Method
Expand All @@ -44,12 +42,26 @@ class ListViewController: UIViewController {
mainTV.delegate = self
mainTV.dataSource = self
mainTV.register(ListTVC.self, forCellReuseIdentifier: "ListTVC")

mainTV.sectionFooterHeight = 0

mainTV.separatorStyle = .none
mainTV.backgroundColor = .clear
mainTV.contentInsetAdjustmentBehavior = .never
}

func registerNotification() {
NotificationCenter.default.addObserver(self,
selector: #selector(addCity(_:)),
name: NSNotification.Name("appendCity"),
object: nil)
}

// MARK: - setData
func setData(cityList: [ListModel]) {
self.cityList = cityList
}

// MARK: - @objc
@objc func touchupWebButton(_ sender: UIButton) {
let application = UIApplication.shared
Expand All @@ -63,6 +75,14 @@ class ListViewController: UIViewController {
let nextVC = SearchViewController()
self.present(nextVC, animated: true, completion: nil)
}

@objc func addCity(_ notification: Notification) {
print(cityList, "addCity")
if let list = notification.object as? [ListModel] {
cityList.append(contentsOf: list)
}
mainTV.reloadData()
}
}

// MARK: - UITableViewDelegate
Expand Down Expand Up @@ -124,6 +144,7 @@ extension ListViewController: UITableViewDataSource {
listCell.setupFirstCellAutoLayout()
} else {
listCell.setupRemainCellAutoLayout()

}
listCell.setData(subtitle: cityList[indexPath.row].subTitle,
title: cityList[indexPath.row].title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

import MapKit
import Then
import SnapKit
import Then

class SearchViewController: UIViewController {
// MARK: - Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import UIKit
import CoreLocation
import Lottie
import Moya
import Then
import SafariServices
import SnapKit
import Then

class ViewController: UIViewController {
// MARK: - Network
private let weatherProvider = MoyaProvider<WeatherService>(plugins: [NetworkLoggerPlugin(verbose: true)])
var weatherModel: WeatherModel?

// MARK: - Properties
private var myCityList: [String] = ["", "", "", "", ""]

private var cityList = [ListModel(subTitle: "", title: "나의 위치", temp: "")]
var isAddNewCityView: Bool = false
var location: String = ""
var myCurrentLocation: String = ""
Expand Down Expand Up @@ -103,9 +103,7 @@ class ViewController: UIViewController {
configUI()
setupAutoLayout()
setupPageControl()

NotificationCenter.default.addObserver(self, selector: #selector(changePageControl(_:)),
name: NSNotification.Name("pageControl"), object: nil)
registerNotification()
}

// MARK: - Custom Method
Expand Down Expand Up @@ -186,7 +184,7 @@ class ViewController: UIViewController {
}

func setupPageControl() {
pageControl.numberOfPages = myCityList.count
pageControl.numberOfPages = cityList.count
pageControl.setIndicatorImage(UIImage(systemName: "location.fill"), forPage: 0)
}

Expand Down Expand Up @@ -236,20 +234,27 @@ class ViewController: UIViewController {
})
}

func registerNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(changePageControl(_:)),
name: NSNotification.Name("pageControl"), object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(addCity(_:)),
name: NSNotification.Name("appendCity"),
object: nil)
}

// MARK: - @objc
@objc func touchupCancelButton(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}

@objc func touchupAddButton(_ sender: UIButton) {
guard let pvc = self.presentingViewController else { return }
self.dismiss(animated: true) {
pvc.dismiss(animated: true, completion: nil)
pvc.modalPresentationStyle = .overFullScreen
pvc.present(ListViewController(), animated: true) {
// 여기에 노티로 도시이름, 온도 추가해주는 거 쏴줘야 함. )
}
}
cityList.removeFirst()
cityList.append(ListModel(subTitle: String(self.currentTime).toTime("a h:mm", self.timezoneOffset),
title: self.location,
temp: String(Int(self.temperature)) + "º"))
NotificationCenter.default.post(name: NSNotification.Name("appendCity"), object: cityList, userInfo: nil)
presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)
}

@objc func changePageControl(_ notification: Notification) {
Expand All @@ -272,8 +277,17 @@ class ViewController: UIViewController {
nextVC.cityList[0].subTitle = self.myCurrentLocation
nextVC.cityList[0].title = "나의 위치"
nextVC.cityList[0].temp = String(Int(self.temperature)) + "º"
nextVC.setData(cityList: cityList)
present(nextVC, animated: true, completion: nil)
}

@objc func addCity(_ notification: Notification) {
print(cityList, "addCity", "vc")
if let list = notification.object as? [ListModel] {
cityList.append(contentsOf: list)
}
mainCV.reloadData()
}
}

// MARK: - UICollectionViewDelegate
Expand All @@ -288,7 +302,7 @@ extension ViewController: UICollectionViewDelegate {
// MARK: - UICollectionViewDataSource
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return myCityList.count
return 1 + cityList.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
Expand All @@ -302,6 +316,7 @@ extension ViewController: UICollectionViewDataSource {
min: "최저: \(Int(min))º")
setBackgroundView(time: currentTime)
setAnimationView(condition: condition)
print(currentTime)
if isAddNewCityView {
cell.fetchWeather(lat: searchLatitude!, lon: searchLongtitude!, exclude: "")
cell.setData(location: location,
Expand Down Expand Up @@ -363,6 +378,7 @@ extension ViewController {
self.currentTime = currentTime
self.timezoneOffset = timezoneOffset
}
self.cityList = [ListModel(subTitle: self.myCurrentLocation, title: "나의 위치", temp: "\(Int(self.temperature))º")]
self.setupCollectionView()
self.mainCV.reloadData()

Expand Down

0 comments on commit 6d9558f

Please sign in to comment.