Skip to content

Commit

Permalink
Add SearchTokenCell (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbernutz authored and xavierLowmiller committed Jun 20, 2020
1 parent 3c8d6ea commit 93f6f8e
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Cineaste.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
3F7ABD5620F5C71E004B069E /* String+Locale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F941B6C20F527E5008A4407 /* String+Locale.swift */; };
3F7B66C62353B81600464BCC /* ContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F7B66C52353B81600464BCC /* ContextMenu.swift */; };
3F7D1D4F23D4A84900BA530F /* SearchMovieDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F7D1D4E23D4A84900BA530F /* SearchMovieDataSource.swift */; };
3F7D1D5123D4AEB400BA530F /* SearchTokenCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F7D1D5023D4AEB400BA530F /* SearchTokenCell.swift */; };
3F8065BC238AE3220087D6EA /* DateFormatter+Cineaste.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F8065BB238AE3220087D6EA /* DateFormatter+Cineaste.swift */; };
3F80F27222359E5C007E03C5 /* UIView+SlideIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F80F27122359E5C007E03C5 /* UIView+SlideIn.swift */; };
3F85488A21039778007A322E /* IndexPath+Last.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F85488821039778007A322E /* IndexPath+Last.swift */; };
Expand Down Expand Up @@ -252,6 +253,7 @@
3F75665B2381737E007E2DE8 /* UIViewController+ShareMovie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+ShareMovie.swift"; sourceTree = "<group>"; };
3F7B66C52353B81600464BCC /* ContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextMenu.swift; sourceTree = "<group>"; };
3F7D1D4E23D4A84900BA530F /* SearchMovieDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchMovieDataSource.swift; sourceTree = "<group>"; };
3F7D1D5023D4AEB400BA530F /* SearchTokenCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTokenCell.swift; sourceTree = "<group>"; };
3F8065BB238AE3220087D6EA /* DateFormatter+Cineaste.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Cineaste.swift"; sourceTree = "<group>"; };
3F80F27122359E5C007E03C5 /* UIView+SlideIn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+SlideIn.swift"; sourceTree = "<group>"; };
3F83BE771FF39DFC00E584E9 /* Instantiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Instantiable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -601,6 +603,7 @@
6409298F22DBAB0C0011AB96 /* SearchMoviesViewController+SwipeHint.swift */,
3FD722CB20264B720046DEAC /* SearchMoviesViewController+UITableView.swift */,
3FD722CD20264BF80046DEAC /* SearchMoviesViewController+Webservice.swift */,
3F7D1D5023D4AEB400BA530F /* SearchTokenCell.swift */,
);
path = SearchMovies;
sourceTree = "<group>";
Expand Down Expand Up @@ -1089,6 +1092,7 @@
3FF095D5210325D100ADFB86 /* SettingsViewController+UIDocumentPicker.swift in Sources */,
3FF7910220DE274A007B7D37 /* SettingsCell.swift in Sources */,
3FF7910420DE274A007B7D37 /* SettingsDetailViewController.swift in Sources */,
3F7D1D5123D4AEB400BA530F /* SearchTokenCell.swift in Sources */,
4ED2FC7D22666D89007BDE06 /* CoreDataMigrator.swift in Sources */,
3F0C1D1322A4395E00F0F52A /* ShortcutIdentifier.swift in Sources */,
3FF7910620DE274A007B7D37 /* Model.xcdatamodeld in Sources */,
Expand Down
37 changes: 36 additions & 1 deletion Cineaste/Storyboards/Base.lproj/Search.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,41 @@
<outlet property="title" destination="AYE-99-Bh1" id="Z9y-W7-ZXm"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="SearchTokenCell" id="siu-ys-alf" customClass="SearchTokenCell" customModule="Cineaste_App" customModuleProvider="target">
<rect key="frame" x="0.0" y="128" width="414" height="145"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="siu-ys-alf" id="SM0-PY-tUJ">
<rect key="frame" x="0.0" y="0.0" width="414" height="145"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BRJ-zl-ued">
<rect key="frame" x="102" y="20" width="292" height="105"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="xqS-rw-5fJ">
<rect key="frame" x="32" y="52.5" width="40" height="40"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="Gye-5T-gTc"/>
<constraint firstAttribute="width" secondItem="xqS-rw-5fJ" secondAttribute="height" id="wWh-lB-khI"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstItem="BRJ-zl-ued" firstAttribute="top" secondItem="SM0-PY-tUJ" secondAttribute="top" constant="20" symbolic="YES" id="Cgh-Fz-T5l"/>
<constraint firstAttribute="trailing" secondItem="BRJ-zl-ued" secondAttribute="trailing" constant="20" symbolic="YES" id="HC2-ZJ-aiy"/>
<constraint firstItem="xqS-rw-5fJ" firstAttribute="leading" secondItem="SM0-PY-tUJ" secondAttribute="leading" constant="32" id="IKJ-BR-zej"/>
<constraint firstItem="xqS-rw-5fJ" firstAttribute="centerY" secondItem="SM0-PY-tUJ" secondAttribute="centerY" id="UGL-GQ-kwI"/>
<constraint firstAttribute="bottom" secondItem="BRJ-zl-ued" secondAttribute="bottom" constant="20" symbolic="YES" id="WvH-FX-eTI"/>
<constraint firstItem="BRJ-zl-ued" firstAttribute="leading" secondItem="xqS-rw-5fJ" secondAttribute="trailing" constant="30" id="ltz-nj-Ids"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="title" destination="BRJ-zl-ued" id="lKx-Fb-qbA"/>
<outlet property="tokenIcon" destination="xqS-rw-5fJ" id="qMR-nM-bvj"/>
</connections>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
Expand Down Expand Up @@ -166,7 +201,7 @@
<viewLayoutGuide key="safeArea" id="7FF-lZ-CXt"/>
</view>
</objects>
<point key="canvasLocation" x="4876" y="5.8470764617691158"/>
<point key="canvasLocation" x="4875.36231884058" y="5.3571428571428568"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="nqO-6w-fBm">
Expand Down
68 changes: 60 additions & 8 deletions Cineaste/ViewController/SearchMovies/SearchMovieDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,79 @@
import UIKit

class SearchMovieDataSource: NSObject, UITableViewDataSource {
enum Mode {
case discover
case manualSearch
}

var mode: Mode = .discover
var movies: [Movie] = []
var currentPage: Int?
var totalResults: Int?

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard mode == .manualSearch else { return nil }

switch section {
case .tokens:
return "Genres"
case .movies:
return "Movies"
default:
return nil
}
}

func numberOfSections(in tableView: UITableView) -> Int {
switch mode {
case .discover:
return 1
case .manualSearch:
return 2
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
movies.count
switch (mode, section) {
case (.discover, _),
(.manualSearch, .movies):
return movies.count
case (.manualSearch, .tokens):
return 1
default:
return 0
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SearchMoviesCell = tableView.dequeueCell(identifier: SearchMoviesCell.identifier)

let movie = movies[indexPath.row]
switch (mode, indexPath.section) {
case (.discover, _),
(.manualSearch, .movies):
let cell: SearchMoviesCell = tableView.dequeueCell(identifier: SearchMoviesCell.identifier)

let movie = movies[indexPath.row]

cell.configure(with: movie)
cell.configure(with: movie)

if let numberOfMovies = totalResults,
indexPath.isLast(of: numberOfMovies) {
tableView.tableFooterView = UIView()
if let numberOfMovies = totalResults,
indexPath.isLast(of: numberOfMovies) {
tableView.tableFooterView = UIView()
}

return cell
case (.manualSearch, .tokens):
let cell: SearchTokenCell = tableView.dequeueCell(identifier: SearchTokenCell.identifier)
cell.configure()
return cell
default:
fatalError("The impossible has happened")
}

return cell
}
}

private extension Int {
static let tokens = 0
static let movies = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ extension SearchMoviesViewController: UISearchControllerDelegate {
}
}

extension SearchMoviesViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
dataSource.mode = .manualSearch
tableView.reloadData()
}

func textFieldDidEndEditing(_ textField: UITextField) {
dataSource.mode = .discover
tableView.reloadData()
}
}

extension SearchMoviesViewController: UISearchResultsUpdating {
internal func updateSearchResults(for searchController: UISearchController) {
searchDelayTimer?.invalidate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class SearchMoviesViewController: UIViewController {
navigationItem.hidesSearchBarWhenScrolling = false

definesPresentationContext = true

resultSearchController.searchBar.searchTextField.delegate = self
}

// MARK: - Custom functions
Expand Down
22 changes: 22 additions & 0 deletions Cineaste/ViewController/SearchMovies/SearchTokenCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// SearchTokenCell.swift
// Cineaste App
//
// Created by Felizia Bernutz on 19.01.20.
// Copyright © 2020 spacepandas.de. All rights reserved.
//

import UIKit

class SearchTokenCell: UITableViewCell {
static let identifier = "SearchTokenCell"

@IBOutlet weak var tokenIcon: UIImageView!
@IBOutlet weak var title: UILabel!

func configure() {
tokenIcon.image = UIImage.searchIcon
title.text = "Horror"
}

}

0 comments on commit 93f6f8e

Please sign in to comment.