Skip to content

Commit

Permalink
Merge pull request #68 from boostcamp3-iOS/feature/LIVE_Keyword_Detail
Browse files Browse the repository at this point in the history
Feature/live keyword detail
  • Loading branch information
kimhyeri authored Feb 11, 2019
2 parents c476725 + ba37ed9 commit 03fdaae
Show file tree
Hide file tree
Showing 24 changed files with 517 additions and 105 deletions.
24 changes: 24 additions & 0 deletions tree/tree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
BC2656C321FD94EE00003413 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656BB21FD94EE00003413 /* NetworkResult.swift */; };
BC2656C421FD94EE00003413 /* NetworkError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656BC21FD94EE00003413 /* NetworkError.swift */; };
BC2656C721FD950900003413 /* Articles.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656C621FD950900003413 /* Articles.swift */; };
BC42C038221138C100E0833B /* Enum+HeaderTitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC42C037221138C100E0833B /* Enum+HeaderTitles.swift */; };
BC5D4E41220B1D17000465B0 /* KeywordDetailGraphCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC5D4E3F220B1D17000465B0 /* KeywordDetailGraphCell.swift */; };
BC5D4E42220B1D17000465B0 /* KeywordDetailGraphCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC5D4E40220B1D17000465B0 /* KeywordDetailGraphCell.xib */; };
BC5D4E4A220B23C8000465B0 /* Graph.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC5D4E49220B23C8000465B0 /* Graph.swift */; };
Expand All @@ -52,6 +53,9 @@
BC5D4E50220C247F000465B0 /* NaverAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC5D4E4F220C247E000465B0 /* NaverAPI.swift */; };
BC63852C2206CBF200074CF3 /* Enum+Countries.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC63852B2206CBF200074CF3 /* Enum+Countries.swift */; };
BC63852E2207442B00074CF3 /* Extension+Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC63852D2207442B00074CF3 /* Extension+Notification.swift */; };
BC649BA2220F5EFA0032ACF2 /* KeywordDetailArticleCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC649BA0220F5EFA0032ACF2 /* KeywordDetailArticleCell.swift */; };
BC649BA3220F5EFA0032ACF2 /* KeywordDetailArticleCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC649BA1220F5EFA0032ACF2 /* KeywordDetailArticleCell.xib */; };
BC649BA8220F68230032ACF2 /* HTMLDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC649BA7220F68230032ACF2 /* HTMLDecodable.swift */; };
BC7969B922002E620003F520 /* TrendDays.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC7969B822002E620003F520 /* TrendDays.swift */; };
BC7969BC22002EB20003F520 /* Live.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BC7969BB22002EB20003F520 /* Live.storyboard */; };
BC7969BF22002EC30003F520 /* LiveViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC7969BE22002EC30003F520 /* LiveViewController.swift */; };
Expand Down Expand Up @@ -129,6 +133,7 @@
BC2656BB21FD94EE00003413 /* NetworkResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
BC2656BC21FD94EE00003413 /* NetworkError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = "<group>"; };
BC2656C621FD950900003413 /* Articles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Articles.swift; sourceTree = "<group>"; };
BC42C037221138C100E0833B /* Enum+HeaderTitles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Enum+HeaderTitles.swift"; sourceTree = "<group>"; };
BC5D4E3F220B1D17000465B0 /* KeywordDetailGraphCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeywordDetailGraphCell.swift; sourceTree = "<group>"; };
BC5D4E40220B1D17000465B0 /* KeywordDetailGraphCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KeywordDetailGraphCell.xib; sourceTree = "<group>"; };
BC5D4E49220B23C8000465B0 /* Graph.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Graph.swift; sourceTree = "<group>"; };
Expand All @@ -137,6 +142,9 @@
BC5D4E4F220C247E000465B0 /* NaverAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NaverAPI.swift; sourceTree = "<group>"; };
BC63852B2206CBF200074CF3 /* Enum+Countries.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Enum+Countries.swift"; sourceTree = "<group>"; };
BC63852D2207442B00074CF3 /* Extension+Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extension+Notification.swift"; sourceTree = "<group>"; };
BC649BA0220F5EFA0032ACF2 /* KeywordDetailArticleCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeywordDetailArticleCell.swift; sourceTree = "<group>"; };
BC649BA1220F5EFA0032ACF2 /* KeywordDetailArticleCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KeywordDetailArticleCell.xib; sourceTree = "<group>"; };
BC649BA7220F68230032ACF2 /* HTMLDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLDecodable.swift; sourceTree = "<group>"; };
BC7969B822002E620003F520 /* TrendDays.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendDays.swift; sourceTree = "<group>"; };
BC7969BB22002EB20003F520 /* Live.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Live.storyboard; sourceTree = "<group>"; };
BC7969BE22002EC30003F520 /* LiveViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -223,6 +231,7 @@
D9C6AB4821FAAD09001C0AB8 /* Controller */,
D9C6AB3621FA9B3E001C0AB8 /* Extension */,
D9C6AB5B21FC151C001C0AB8 /* Helper */,
BC649BA6220F68110032ACF2 /* Protocol */,
35DC0DCE21F6F3C700F30416 /* AppDelegate.swift */,
35DC0DD221F6F3C700F30416 /* Main.storyboard */,
35DC0DD521F6F3CB00F30416 /* Assets.xcassets */,
Expand Down Expand Up @@ -346,11 +355,21 @@
children = (
BC5D4E3F220B1D17000465B0 /* KeywordDetailGraphCell.swift */,
BC5D4E40220B1D17000465B0 /* KeywordDetailGraphCell.xib */,
BC649BA0220F5EFA0032ACF2 /* KeywordDetailArticleCell.swift */,
BC649BA1220F5EFA0032ACF2 /* KeywordDetailArticleCell.xib */,
BC5D4E4D220B730F000465B0 /* GraphView.swift */,
);
path = Detail;
sourceTree = "<group>";
};
BC649BA6220F68110032ACF2 /* Protocol */ = {
isa = PBXGroup;
children = (
BC649BA7220F68230032ACF2 /* HTMLDecodable.swift */,
);
path = Protocol;
sourceTree = "<group>";
};
BC7969BA22002EA60003F520 /* Live */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -454,6 +473,7 @@
BC19FD14220D965E006A9C7D /* Enum+TimeUnitTypes.swift */,
BC19FD16220D9D20006A9C7D /* Enum+LocalizedLanguages.swift */,
6A198CC7220C9F51002421AC /* ArticleTypeEnum.swift */,
BC42C037221138C100E0833B /* Enum+HeaderTitles.swift */,
);
path = Helper;
sourceTree = "<group>";
Expand Down Expand Up @@ -583,6 +603,7 @@
D9DFFB46220EEA7F0047E326 /* ScrapFilterTableViewCell.xib in Resources */,
35DC0DD421F6F3C700F30416 /* Main.storyboard in Resources */,
BC7969BC22002EB20003F520 /* Live.storyboard in Resources */,
BC649BA3220F5EFA0032ACF2 /* KeywordDetailArticleCell.xib in Resources */,
D9C6AB4421FA9CF8001C0AB8 /* Search.storyboard in Resources */,
D9DFFB49220EEA990047E326 /* Scrap.storyboard in Resources */,
BC7969D4220174B40003F520 /* TrendListCell.xib in Resources */,
Expand Down Expand Up @@ -646,6 +667,7 @@
6A5D282C220187F8009EC8ED /* Extension+UIView.swift in Sources */,
BC2656BF21FD94EE00003413 /* APIManager.swift in Sources */,
35CB482021FB6306000D96CF /* ArticleFeedTableViewCell.swift in Sources */,
BC649BA8220F68230032ACF2 /* HTMLDecodable.swift in Sources */,
6A65DA4A2206190C005EB2BC /* ImageCache.swift in Sources */,
BC5D4E4A220B23C8000465B0 /* Graph.swift in Sources */,
BC19FD17220D9D20006A9C7D /* Enum+LocalizedLanguages.swift in Sources */,
Expand Down Expand Up @@ -679,12 +701,14 @@
BC5D4E4E220B730F000465B0 /* GraphView.swift in Sources */,
35DC0DCF21F6F3C700F30416 /* AppDelegate.swift in Sources */,
6A65DA452203D242005EB2BC /* LoadingView.swift in Sources */,
BC649BA2220F5EFA0032ACF2 /* KeywordDetailArticleCell.swift in Sources */,
BC5D4E50220C247F000465B0 /* NaverAPI.swift in Sources */,
BC7969BF22002EC30003F520 /* LiveViewController.swift in Sources */,
BC63852C2206CBF200074CF3 /* Enum+Countries.swift in Sources */,
D9D145C3220B0B7800CC58DA /* TreeData.xcdatamodeld in Sources */,
D9C6AB4E21FAAD0A001C0AB8 /* MainViewController.swift in Sources */,
6AE2D7AE21FEF30D00444622 /* Config.swift in Sources */,
BC42C038221138C100E0833B /* Enum+HeaderTitles.swift in Sources */,
BCD1BB2622057CF800F9C8A8 /* TableViewCell+Animator.swift in Sources */,
D9D145CB220B0B8400CC58DA /* ScrapManager.swift in Sources */,
35CB481D21FAE7C8000D96CF /* ArticleImageViewController.swift in Sources */,
Expand Down
23 changes: 23 additions & 0 deletions tree/tree/Assets.xcassets/back.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "left-arrow.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tree/tree/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
</objects>
<point key="canvasLocation" x="128.80000000000001" y="96.7016491754123"/>
</scene>
<!--LiveViewController-->
<!--LiveNavigationViewController-->
<scene sceneID="kbb-7S-min">
<objects>
<viewControllerPlaceholder storyboardName="Live" referencedIdentifier="LiveViewController" id="m8g-Sr-hO3" sceneMemberID="viewController">
<viewControllerPlaceholder storyboardName="Live" referencedIdentifier="LiveNavigationViewController" id="m8g-Sr-hO3" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Item" image="Live" selectedImage="Live" id="3Bf-Lx-JOT"/>
</viewControllerPlaceholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="tq5-qX-2w4" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
123 changes: 105 additions & 18 deletions tree/tree/Controller/Live/KeywordDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ import UIKit
class KeywordDetailViewController: UIViewController {

@IBOutlet var tableView: UITableView!
@IBOutlet weak var navigationBar: UINavigationBar!

var keywordData: TrendingSearch? {
didSet {
guard let keyword = keywordData?.title.query else { return }
loadGraphData(to: keyword, startDate, endDate)
articleData = keywordData?.articles
}
}
var graphData: Graph? {
didSet {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
var graphData: Graph?

private var startDate: String {
let oneMonth = TimeIntervalTypes.oneMonth.value
let date = Date(timeInterval: -oneMonth, since: Date())
Expand All @@ -30,9 +37,18 @@ class KeywordDetailViewController: UIViewController {
let date = Date(timeInterval: -oneDay, since: Date())
return dateFormatter.string(from: date)
}

private var articleData: [KeywordArticles]? {
didSet {
DispatchQueue.main.async {
self.tableView.reloadSections(IndexSet(arrayLiteral: 1), with: .automatic)
}
}
}
private let timeUnit = TimeUnitTypes.week.value
private let graphCellIdentifier = "KeywordDetailGraphCell"
private let headerCellIdentifier = "TrendListHeaderCell"
private let articleCellIdentifier = "KeywordDetailArticleCell"
private let appleGothicNeoBold = "AppleSDGothicNeo-Bold"
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
Expand All @@ -41,27 +57,47 @@ class KeywordDetailViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
setTableView()
registerXIB()
tableViewSetup()
navigationBar.topItem?.title = keywordData?.title.query
}

@IBAction func backButtonItem(_ sender: UIBarButtonItem) {
self.navigationController?.popViewController(animated: true)
}

private func setTableView() {
let nibName = UINib(nibName: graphCellIdentifier, bundle: nil)
tableView.register(nibName, forCellReuseIdentifier: graphCellIdentifier)
private func registerXIB() {
let graphNib = UINib(nibName: graphCellIdentifier, bundle: nil)
tableView.register(graphNib, forCellReuseIdentifier: graphCellIdentifier)
let headerNib = UINib(nibName: headerCellIdentifier, bundle: nil)
tableView.register(headerNib, forCellReuseIdentifier: headerCellIdentifier)
let articleNib = UINib(nibName: articleCellIdentifier, bundle: nil)
tableView.register(articleNib, forCellReuseIdentifier: articleCellIdentifier)
}

private func tableViewSetup() {
tableView.delegate = self
tableView.dataSource = self
tableView.separatorInset = UIEdgeInsets(
top: 0,
left: UIScreen.main.bounds.width,
bottom: 0,
right: 0
)
}

private func loadGraphData(to keyword: String, _ startDate: String, _ endDate: String) {
let keywordGroups: [[String: Any]] = [[
"groupName": keyword,
"keywords": [keyword]
]]
APIManager.graphData(
APIManager.requestGraphData(
startDate: startDate,
endDate: endDate,
timeUnit: timeUnit,
keywordGroups: keywordGroups
) { (result) in
) { [weak self] (result) in
guard let self = self else { return }
switch result {
case .success(let graphData):
self.graphData = graphData
Expand All @@ -73,20 +109,71 @@ class KeywordDetailViewController: UIViewController {
}

extension KeywordDetailViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func numberOfSections(in tableView: UITableView) -> Int {
if articleData != nil {
return 2
}
return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return 1
default:
if let articleData = articleData {
return articleData.count
}
return 0
}
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard
let cell = tableView.dequeueReusableCell(
withIdentifier: graphCellIdentifier,
for: indexPath
) as? KeywordDetailGraphCell else {
return UITableViewCell()
let headerCell = tableView.dequeueReusableCell(
withIdentifier: headerCellIdentifier
) as? TrendListHeaderCell else {
return UIView()
}
headerCell.headerLabel.font = UIFont(name: appleGothicNeoBold, size: 17)
switch section {
case 0:
headerCell.headerLabel.text = HeaderTitles.changeInteresting.rawValue
default:
headerCell.headerLabel.text = HeaderTitles.relatedArticles.rawValue
}
return headerCell.contentView
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
guard
let cell = tableView.dequeueReusableCell(
withIdentifier: graphCellIdentifier,
for: indexPath
) as? KeywordDetailGraphCell else {
return UITableViewCell()
}
cell.graphData = graphData?.results[0]
return cell
default:
guard
let cell = tableView.dequeueReusableCell(
withIdentifier: articleCellIdentifier,
for: indexPath
) as? KeywordDetailArticleCell else {
return UITableViewCell()
}
if let articleData = articleData {
cell.configure(articleData[indexPath.row])
}
return cell
}
cell.graphData = graphData?.results[0]
return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
Expand Down
5 changes: 3 additions & 2 deletions tree/tree/Controller/Live/LiveViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LiveViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
scrollView.contentInsetAdjustmentBehavior = .never
networkWithServer(Country.usa.info.code)
NotificationCenter.default.addObserver(
self,
Expand Down Expand Up @@ -56,7 +57,7 @@ class LiveViewController: UIViewController {
}

private func networkWithServer(_ geo: String) {
APIManager.getDailyTrends(hl: localizedLanguage, geo: geo) { [weak self] (result) in
APIManager.fetchDailyTrends(hl: localizedLanguage, geo: geo) { [weak self] (result) in
guard let self = self else { return }
switch result {
case .success(let trandData):
Expand Down Expand Up @@ -117,6 +118,6 @@ extension LiveViewController: PushViewControllerDelegate {
return
}
detailViewController.keywordData = rowData
self.present(detailViewController, animated: true, completion: nil)
self.navigationController?.pushViewController(detailViewController, animated: true)
}
}
4 changes: 2 additions & 2 deletions tree/tree/Controller/Search/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class SearchViewController: UIViewController {
self.defaultView?.removeFromSuperview()
self.uiTableView.reloadData()
self.setLoadingView()
APIManager.getArticles(
APIManager.fetchArticles(
keyword: searchKeyword,
keywordLoc: keyword,
lang: language,
Expand Down Expand Up @@ -159,7 +159,7 @@ class SearchViewController: UIViewController {
sort: String) {
if page >= totalPage { return }
page += 1
APIManager.getArticles(
APIManager.fetchArticles(
keyword: keyword,
keywordLoc: keyword,
lang: language,
Expand Down
14 changes: 14 additions & 0 deletions tree/tree/Helper/Enum+HeaderTitles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Enum+HeaderTitles.swift
// tree
//
// Created by ParkSungJoon on 11/02/2019.
// Copyright © 2019 gardener. All rights reserved.
//

import Foundation

enum HeaderTitles: String {
case changeInteresting = "시간 흐름에 따른 관심도 변화"
case relatedArticles = "관심 기사"
}
Loading

0 comments on commit 03fdaae

Please sign in to comment.