Skip to content

Commit

Permalink
Merge branch 'develop' into webviewError
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaeeun authored Apr 29, 2019
2 parents a9f2eae + 28a62fb commit a83f7ec
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 47 deletions.
6 changes: 3 additions & 3 deletions Toonie/Look/Look.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="KIX-zJ-v7V">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="KIX-zJ-v7V">
<device id="retina5_9" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -164,7 +164,7 @@
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gN6-NB-GFI">
<rect key="frame" x="0.0" y="0.0" width="375" height="56.666666666666664"/>
<connections>
<segue destination="jcd-BY-Dvv" kind="embed" id="OtI-nA-lcC"/>
<segue destination="jcd-BY-Dvv" kind="embed" identifier="topSetting" id="OtI-nA-lcC"/>
</connections>
</containerView>
</subviews>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,50 @@

import UIKit

struct TagStructure {
let tagName: String
var state: Bool
}

final class LookDetailTopSelectViewController: UIViewController {

// MARK: - IBOutlets

@IBOutlet weak var lookDetailTopSelectCollectionView: UICollectionView!

//์ž„์‹œ๋ฐ์ดํ„ฐ
let dummy = ["์ „์ฒด๋ณด๊ธฐ",
"#์œ ๋Ÿฝ์—ฌํ–‰",
"#๊ตญ๋‚ด์—ฌํ–‰",
"#๋ฐ”์บ‰์Šค",
"#์ง€ํ•˜์ฒ ์—ฌํ–‰",
"#๋šœ๋ฒ…์ด์—ฌํ–‰"]
// MARK: - Properties

//collectionView didSelected ํ–ˆ์„์‹œ ํ˜ธ์ถœํ•  ํด๋กœ์ €
var tagDidTapClosure: ((String) -> Void)?
var selectedKeyword: String = ""

//state๋กœ on off ์ง„ํ–‰
var tags = [TagStructure]()

// MARK: - Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
}
setTags()
}

func setTags() {

//๋งจ์ฒ˜์Œ ์ „์ฒด๋ณด๊ธฐ ๊ธฐ๋ณธ์„ธํŒ…
let tagStructure: TagStructure = TagStructure.init(tagName: "์ „์ฒด๋ณด๊ธฐ",
state: true)
tags.append(tagStructure)

KeywordToonListService
.shared
.getKeywords(keyword: selectedKeyword) {(tags) in
for tag in tags ?? [String]() {
self.tags.append(TagStructure.init(tagName: "#"+tag,
state: false))
}
self.lookDetailTopSelectCollectionView.reloadData()
}
}
}

// MARK: - UICollectionViewDataSource
Expand All @@ -30,7 +60,7 @@ extension LookDetailTopSelectViewController: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return dummy.count
return tags.count
}

func collectionView(_ collectionView: UICollectionView,
Expand All @@ -40,34 +70,44 @@ extension LookDetailTopSelectViewController: UICollectionViewDataSource {
.dequeueReusableCell(withReuseIdentifier: "LookDetailTopSelectCell",
for: indexPath) as? LookDetailTopSelectCell
else { return UICollectionViewCell() }
cell.setTitleLabel(text: dummy[indexPath.row])
cell.setCellStatus(bool: indexPath.row == 0 ? true : false)

cell.setTitleLabel(text: tags[indexPath.row].tagName)
cell.setCellStatus(bool: tags[indexPath.row].state)

return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) as? LookDetailTopSelectCell {
for _ in 0...dummy.count {
cell.setCellStatus(bool: false)
}

cell.setCellStatus(bool: !cell.getCellStatus())
func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {

if let closure = self.tagDidTapClosure {
closure(tags[indexPath.row]
.tagName
.replacingOccurrences(of: "#",
with: ""))
}

//์šฐ์„  cell ์ƒํƒœ ๋ชจ๋‘ ์ดˆ๊ธฐํ™”
for index in 0..<tags.count {
tags[index].state = false
}

//์„ ํƒํ•œ cell๋งŒ ์ƒํƒœ ๋ณ€๊ฒฝ
tags[indexPath.row].state = true

self.lookDetailTopSelectCollectionView.reloadData()
}

func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {

let keyword = dummy[indexPath.row]
let keyword = tags[indexPath.row].tagName
let font = UIFont.getAppleSDGothicNeo(option: .medium,
size: 14)
var width = Int(keyword.widthWithConstrainedHeight(height: 17,
font: font))
width += 42
width += 41

return CGSize(width: width, height: 30)
}
Expand All @@ -87,12 +127,12 @@ extension LookDetailTopSelectViewController: UICollectionViewDelegateFlowLayout
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {

let keyword = dummy[indexPath.row]
let keyword = tags[indexPath.row].tagName
let font = UIFont.getAppleSDGothicNeo(option: .medium,
size: 14)
var width = Int(keyword.widthWithConstrainedHeight(height: 17,
font: font))
width += 42
width += 41

return CGSize(width: width, height: 30)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ final class LookDetailViewController: GestureViewController {
@IBOutlet private weak var lookDetailCollectionView: UICollectionView!
@IBOutlet private weak var lookDetailCollectionViewFlowLayout: UICollectionViewFlowLayout!

// MARK: - Properties
var selectedKeyword: String = ""

//์ž„์‹œ๋ฐ์ดํ„ฐ
let dummy = [#imageLiteral(resourceName: "myRecentlyLoadingImg"),
#imageLiteral(resourceName: "sample2"),
Expand Down Expand Up @@ -46,11 +49,28 @@ final class LookDetailViewController: GestureViewController {

override func viewDidLoad() {
super.viewDidLoad()
setLookDeatilTitleLabel(string: "์—ฌํ–‰") //์ž„์‹œ
lookDetailTitleLabel.text = selectedKeyword

setCollectionViewLayout()

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "topSetting" {
if let viewController = segue.destination as? LookDetailTopSelectViewController {
viewController.selectedKeyword = self.selectedKeyword
viewController.tagDidTapClosure = {
(tagString) -> Void in
print("Top ์ปฌ๋ ‰์…˜ ๋ทฐ์˜ ์„ ํƒ๋œ tagString\(tagString)")
/*
To. ์–ด์ง„
์—ฌ๊ธฐ์„œ ๋ฐ›์•„์˜จ tagString์œผ๋กœ toonList ์กฐํšŒํ•˜์‹œ๋ฉด ๋ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
*/
}
}
}
}

// MARK: - IBAction

@IBAction func backButtonDidTap(_ sender: Any) {
Expand All @@ -69,11 +89,7 @@ final class LookDetailViewController: GestureViewController {
bottom: 0,
right: 5 * CommonUtility.getDeviceRatioWidth())
lookDetailCollectionViewFlowLayout.minimumLineSpacing = 1.0 * CommonUtility.getDeviceRatioWidth()
}

func setLookDeatilTitleLabel(string: String) {
lookDetailTitleLabel.text = string
}
}

/// ์ธ์Šคํƒ€ํˆฐ ์ƒ์„ธ์ •๋ณด ํ™”๋ฉด์œผ๋กœ ์ด๋™
func moveDetailToon() {
Expand All @@ -83,6 +99,11 @@ final class LookDetailViewController: GestureViewController {
CommonUtility.sharedInstance.mainNavigationViewController?.pushViewController(viewController,
animated: true)
}

///ํƒ€์ดํ‹€ ์„ธํŒ…
func setLookDetailTitleLabel(titleString: String) {
self.lookDetailTitleLabel.text = titleString
}
}

// MARK: - UICollectionViewDataSource
Expand Down
8 changes: 6 additions & 2 deletions Toonie/Look/LookViewController/LookViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ extension LookViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "Look", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "LookDetailViewController")
guard let viewController = storyboard
.instantiateViewController(withIdentifier: "LookDetailViewController") as? LookDetailViewController
else {
return
}
viewController.selectedKeyword = keywords[indexPath.row]
self.navigationController?.pushViewController(viewController, animated: true)
}

}

// MARK: - UICollectionViewDataSource
Expand Down
19 changes: 17 additions & 2 deletions Toonie/Network/API+Base.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ class API {
return baseURL + "/keywords"
}()

// static let myKeywords = {
// return baseURL + "/mykeywords/\(String(describing: CommonUtility.userToken))"
// }()

static let myKeywords = {
return baseURL + "/mykeywords/\(String(describing: CommonUtility.userToken))"
return baseURL + "/mykeywords"
}()

static let tags = {
Expand All @@ -40,12 +44,23 @@ class API {
static let toons = {
return baseURL + "/toons"
}()

//mykeywords/:token
static let myKeywordsToken = { (token) in
return myKeywords + "/" + token
}

//kewords/:keyword
static let keywordInfo = { (keyword) in
return keywords + "/" + keyword
}

static let worklist = {
static let worklist = {
return baseURL + "/worklist"
}()

static let myWorklist = {
return baseURL + "/worklist/\(CommonUtility.userToken)/default"
}()

}
7 changes: 6 additions & 1 deletion Toonie/Network/Model/Keywords.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ struct Keywords: Codable {

struct MyKeywords: Codable {
let success: Bool?
let token: String?
let myKeywords: [String]?
let token: String?
}

struct KeywordToonList: Codable {
let toonKeyword: String?
let toonTags: [String]?
}
3 changes: 1 addition & 2 deletions Toonie/Network/Requestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ extension Requestable {
guard let encodedUrl = URL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
print("networking - invalid url")
return
}
print("params \(params)")
}

Alamofire.request(encodedUrl,
method: .post,
Expand Down
35 changes: 28 additions & 7 deletions Toonie/Network/Service/KeywordsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class MyKeywordsService: Requestable {

///์ „์ฒด ํ‚ค์›Œ๋“œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒ
func getMyKeywords(completion: @escaping ([String]?) -> Void) {
get(API.myKeywords) { result in
get(API.myKeywordsToken(CommonUtility.userToken)) { result in
switch result {
case .networkSuccess(let data):
if data.resResult.success == false {
return
}
}
completion(data.resResult.myKeywords)
case .networkError(let error):
print(error)
Expand All @@ -55,19 +55,40 @@ class MyKeywordsService: Requestable {
///์„ ํƒํ•œ ํ‚ค์›Œ๋“œ post ํ†ต์‹ 
func postMyKeywords(params: [String: Any],
completion: @escaping () -> Void) {
post((API.myKeywords),
post((API.myKeywordsToken(CommonUtility.userToken)),
params: params) { result in
switch result {
case .networkSuccess(let data):
if data.resResult.success == false {
return
}
completion()
case .networkError(let error):
print(error)
case .networkFail:
print("fail")
}
}
}
}

class KeywordToonListService: Requestable {
typealias NetworkData = KeywordToonList
static let shared = KeywordToonListService()

//์ „์ฒด ํ‚ค์›Œ๋“œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์กฐํšŒ
func getKeywords(keyword: String,
completion: @escaping ([String]?) -> Void) {
get(API.keywordInfo(keyword)) { result in
switch result {
case .networkSuccess(let data):
if data.resResult.success == false {
return
}
completion()
completion(data.resResult.toonTags)
case .networkError(let error):
print(error)
case .networkFail:
print("fail")
}
}
}

}

0 comments on commit a83f7ec

Please sign in to comment.