Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MyBoxOffice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
E92D950A21F4B07C00FB386B /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92D950921F4B07C00FB386B /* Extension.swift */; };
EC352FCA21BD0D1100433AAD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC352FC921BD0D1100433AAD /* AppDelegate.swift */; };
EC352FCC21BD0D1100433AAD /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC352FCB21BD0D1100433AAD /* TableViewController.swift */; };
EC352FCF21BD0D1100433AAD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC352FCD21BD0D1100433AAD /* Main.storyboard */; };
Expand All @@ -22,6 +23,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
E92D950921F4B07C00FB386B /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
EC352FC621BD0D1100433AAD /* MyBoxOffice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MyBoxOffice.app; sourceTree = BUILT_PRODUCTS_DIR; };
EC352FC921BD0D1100433AAD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EC352FCB21BD0D1100433AAD /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +83,7 @@
EC352FDB21BD100400433AAD /* CollectionViewController.swift */,
EC352FD021BD0D1100433AAD /* Assets.xcassets */,
EC352FD521BD0D1100433AAD /* Info.plist */,
E92D950921F4B07C00FB386B /* Extension.swift */,
);
path = MyBoxOffice;
sourceTree = "<group>";
Expand Down Expand Up @@ -160,6 +163,7 @@
EC352FCC21BD0D1100433AAD /* TableViewController.swift in Sources */,
EC352FE021BD1F3E00433AAD /* Request.swift in Sources */,
ECFBFF6C21C0CE0200B6CD11 /* MoviesCollectionViewCell.swift in Sources */,
E92D950A21F4B07C00FB386B /* Extension.swift in Sources */,
ECFC304721C6169B006E8586 /* OrderType.swift in Sources */,
EC352FE221BD1F4B00433AAD /* Model.swift in Sources */,
EC352FDE21BD105000433AAD /* InfoViewController.swift in Sources */,
Expand Down
86 changes: 2 additions & 84 deletions MyBoxOffice/CollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ class CollectionViewController: UIViewController, UICollectionViewDataSource, UI

NotificationCenter.default.addObserver(self, selector: #selector(self.didRecieveMovieNotification(_:)), name: DidReceiveMoviesNotification, object: nil)

requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
requestMoviesWithEscaping()
}

@objc func didRecieveMovieNotification(_ noti: Notification) {
Expand Down Expand Up @@ -148,88 +143,11 @@ class CollectionViewController: UIViewController, UICollectionViewDataSource, UI
}

@objc func refresh() {
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
requestMoviesWithEscaping()
self.collectionView.reloadData()
self.refreshControl.endRefreshing()
}

// MARK: - Action sheet
func showActionSheetController() {
let actionSheetController: UIAlertController
actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet)

let reservationRateAction: UIAlertAction
reservationRateAction = UIAlertAction(title: "예매율", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 0
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let curationAction: UIAlertAction
curationAction = UIAlertAction(title: "큐레이션", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 1
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let releaseDateAction: UIAlertAction
releaseDateAction = UIAlertAction(title: "개봉일", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 2
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let cancelAction: UIAlertAction
cancelAction = UIAlertAction(title: "취소", style: UIAlertActionStyle.cancel, handler: nil)

actionSheetController.addAction(reservationRateAction)
actionSheetController.addAction(curationAction)
actionSheetController.addAction(releaseDateAction)
actionSheetController.addAction(cancelAction)

if UIDevice.current.userInterfaceIdiom == .pad {
if let popoverController = actionSheetController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
self.present(actionSheetController, animated: true, completion: nil)
}
}
else {
self.present(actionSheetController, animated: true, completion: nil)
}
}

//Alert `errorMessage` in `viewController`.
func AlertFailMessage(errorMessage: String) {
let actionSheetController: UIAlertController
actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: UIAlertControllerStyle.alert)

let cancelAction: UIAlertAction
cancelAction = UIAlertAction(title: "닫기", style: UIAlertActionStyle.cancel, handler: nil)

actionSheetController.addAction(cancelAction)

self.present(actionSheetController, animated: true, completion: nil)
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
Expand Down
70 changes: 70 additions & 0 deletions MyBoxOffice/Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Extension.swift
// MyBoxOffice
//
// Created by 정화 on 20/01/2019.
// Copyright © 2019 Wongeun Song. All rights reserved.
//

import UIKit

extension UIViewController {
func requestMoviesWithEscaping() {
requestMovies(){
(error) in
if let error = error {
self.alertFailMessage(errorMessage: error.localizedDescription)
}
}
}

//Alert `errorMessage` in `viewController`.
func alertFailMessage(errorMessage: String) {
let actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil)
actionSheetController.addAction(cancelAction)
self.present(actionSheetController, animated: true, completion: nil)
}

// MARK: - Action sheet
func showActionSheetController() {
let actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet)

let reservationRateAction = UIAlertAction(title: "예매율", style: .default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 0
self.requestMoviesWithEscaping()
})

let curationAction = UIAlertAction(title: "큐레이션", style: .default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 1
self.requestMoviesWithEscaping()

})

let releaseDateAction = UIAlertAction(title: "개봉일", style: .default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 2
self.requestMoviesWithEscaping()
})

let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

actionSheetController.addAction(reservationRateAction)
actionSheetController.addAction(curationAction)
actionSheetController.addAction(releaseDateAction)
actionSheetController.addAction(cancelAction)

if UIDevice.current.userInterfaceIdiom == .pad {
if let popoverController = actionSheetController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
self.present(actionSheetController, animated: true, completion: nil)
}
}
else {
self.present(actionSheetController, animated: true, completion: nil)
}
}


}
7 changes: 7 additions & 0 deletions MyBoxOffice/MoviesTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ class MoviesTableViewCell: UITableViewCell {

var movieId: String?

override func prepareForReuse() {
titleLabel.text = nil
infoLabel.text = nil
dateLabel.text = nil
thumbImageView.image = nil
gradeImageView.image = nil
}
}
3 changes: 3 additions & 0 deletions MyBoxOffice/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ func requestMovieComments(id: String, completion: @escaping(_ error: Error?) ->

dataTask.resume()
}



93 changes: 6 additions & 87 deletions MyBoxOffice/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD
return movies.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell: MoviesTableViewCell = tableView.dequeueReusableCell(withIdentifier: self.movieCellIdentifier, for: indexPath) as? MoviesTableViewCell ?? MoviesTableViewCell()
Expand Down Expand Up @@ -94,17 +95,13 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

AddPullToRefresh()
addPullToRefresh()

//Add Observer for movies data
NotificationCenter.default.addObserver(self, selector: #selector(self.didRecieveMoviesNotification(_:)), name: DidReceiveMoviesNotification, object: nil)

requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
self.requestMoviesWithEscaping()

}

@objc func didRecieveMoviesNotification(_ noti: Notification) {
Expand All @@ -126,99 +123,21 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD
}

// MARK: - Refresh
func AddPullToRefresh() {
func addPullToRefresh() {
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}

self.refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
}

@objc func refresh() {
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
self.requestMoviesWithEscaping()
self.tableView.reloadData()
self.refreshControl.endRefreshing()
}

// MARK: - Action sheet
func showActionSheetController() {
let actionSheetController: UIAlertController
actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet)

let reservationRateAction: UIAlertAction
reservationRateAction = UIAlertAction(title: "예매율", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 0
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let curationAction: UIAlertAction
curationAction = UIAlertAction(title: "큐레이션", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 1
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let releaseDateAction: UIAlertAction
releaseDateAction = UIAlertAction(title: "개봉일", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in
OrderType.orderTypeProperty = 2
requestMovies(){
(error) in
if let error = error {
self.AlertFailMessage(errorMessage: error.localizedDescription)
}
}
})

let cancelAction: UIAlertAction
cancelAction = UIAlertAction(title: "취소", style: UIAlertActionStyle.cancel, handler: nil)

actionSheetController.addAction(reservationRateAction)
actionSheetController.addAction(curationAction)
actionSheetController.addAction(releaseDateAction)
actionSheetController.addAction(cancelAction)

if UIDevice.current.userInterfaceIdiom == .pad {
if let popoverController = actionSheetController.popoverPresentationController {
popoverController.sourceView = self.view
popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
self.present(actionSheetController, animated: true, completion: nil)
}
}
else {
self.present(actionSheetController, animated: true, completion: nil)
}
}

//Alert `errorMessage` in `viewController`.
func AlertFailMessage(errorMessage: String) {
let actionSheetController: UIAlertController
actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: UIAlertControllerStyle.alert)

let cancelAction: UIAlertAction
cancelAction = UIAlertAction(title: "닫기", style: UIAlertActionStyle.cancel, handler: nil)

actionSheetController.addAction(cancelAction)

self.present(actionSheetController, animated: true, completion: nil)
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
Expand Down