Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favorites issue #18 #34

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
32 changes: 32 additions & 0 deletions ReduxMovieDB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
8076FB13208B6BFF00513FAC /* MainStateAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8076FB12208B6BFF00513FAC /* MainStateAction.swift */; };
80BFF62021D4911A00D99771 /* MovieListViewStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80BFF61F21D4911A00D99771 /* MovieListViewStateTests.swift */; };
8F78D29FD15515E0A0DB290B /* Pods_ReduxMovieDBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95329AAEB8BDA5A98456AF4B /* Pods_ReduxMovieDBTests.framework */; };
946FA2FA23590C9D00ABB62E /* Boolean.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946FA2F923590C9D00ABB62E /* Boolean.swift */; };
94B596762347FC5600FBECA5 /* FavoritesStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94B596752347FC5600FBECA5 /* FavoritesStorage.swift */; };
94B596792347FD9700FBECA5 /* MemoryFavoritesStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94B596782347FD9700FBECA5 /* MemoryFavoritesStorageTests.swift */; };
94B5967B234800BE00FBECA5 /* UserDefaultsFavoritesStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94B5967A234800BE00FBECA5 /* UserDefaultsFavoritesStorageTests.swift */; };
94CDE0A723438A6A00545FF1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 94CDE0A923438A6A00545FF1 /* Localizable.strings */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -73,6 +77,10 @@
80673CC920323AA70091B48F /* Pages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pages.swift; sourceTree = "<group>"; };
8076FB12208B6BFF00513FAC /* MainStateAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainStateAction.swift; sourceTree = "<group>"; };
80BFF61F21D4911A00D99771 /* MovieListViewStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieListViewStateTests.swift; sourceTree = "<group>"; };
946FA2F923590C9D00ABB62E /* Boolean.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Boolean.swift; sourceTree = "<group>"; };
94B596752347FC5600FBECA5 /* FavoritesStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesStorage.swift; sourceTree = "<group>"; };
94B596782347FD9700FBECA5 /* MemoryFavoritesStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryFavoritesStorageTests.swift; sourceTree = "<group>"; };
94B5967A234800BE00FBECA5 /* UserDefaultsFavoritesStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsFavoritesStorageTests.swift; sourceTree = "<group>"; };
94CDE0A823438A6A00545FF1 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
94CDE0AA23438AD700545FF1 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
95329AAEB8BDA5A98456AF4B /* Pods_ReduxMovieDBTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ReduxMovieDBTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -124,6 +132,7 @@
80673C8B2030C3DA0091B48F /* ReduxMovieDB */ = {
isa = PBXGroup;
children = (
94B596742347FC4000FBECA5 /* Storages */,
8076FB14208B6CBF00513FAC /* API */,
80673CBA2031253F0091B48F /* Model */,
8076FB11208B6BE200513FAC /* Actions */,
Expand All @@ -145,6 +154,7 @@
80673CA02030C3DA0091B48F /* ReduxMovieDBTests */ = {
isa = PBXGroup;
children = (
94B596772347FD6700FBECA5 /* Storages */,
80BFF61B21D490CF00D99771 /* State */,
80BFF61E21D490FA00D99771 /* ViewState */,
80673CA32030C3DA0091B48F /* Info.plist */,
Expand Down Expand Up @@ -178,6 +188,7 @@
children = (
80673CBD20313EA20091B48F /* UIImageView+MoviePoster.swift */,
805B438B21989719004A7C28 /* UITableView+DiffUpdate.swift */,
946FA2F923590C9D00ABB62E /* Boolean.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -241,6 +252,23 @@
name = Frameworks;
sourceTree = "<group>";
};
94B596742347FC4000FBECA5 /* Storages */ = {
isa = PBXGroup;
children = (
94B596752347FC5600FBECA5 /* FavoritesStorage.swift */,
);
path = Storages;
sourceTree = "<group>";
};
94B596772347FD6700FBECA5 /* Storages */ = {
isa = PBXGroup;
children = (
94B596782347FD9700FBECA5 /* MemoryFavoritesStorageTests.swift */,
94B5967A234800BE00FBECA5 /* UserDefaultsFavoritesStorageTests.swift */,
);
path = Storages;
sourceTree = "<group>";
};
D4C24798534322BDDE0E79FC /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -438,9 +466,11 @@
80673C8F2030C3DA0091B48F /* SplitViewController.swift in Sources */,
800E401F217FA5E300C2A3BD /* Movie+Differentiable.swift in Sources */,
80673C8D2030C3DA0091B48F /* AppDelegate.swift in Sources */,
94B596762347FC5600FBECA5 /* FavoritesStorage.swift in Sources */,
80673CC620322A6C0091B48F /* Genre.swift in Sources */,
80673CB32030E6090091B48F /* MovieListViewState.swift in Sources */,
80673CB9203125300091B48F /* TMDB.swift in Sources */,
946FA2FA23590C9D00ABB62E /* Boolean.swift in Sources */,
80673CB72030F5FC0091B48F /* MovieDetailViewState.swift in Sources */,
80673CB52030F5430091B48F /* MovieDetailViewController.swift in Sources */,
80673CBE20313EA20091B48F /* UIImageView+MoviePoster.swift in Sources */,
Expand All @@ -456,6 +486,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
94B5967B234800BE00FBECA5 /* UserDefaultsFavoritesStorageTests.swift in Sources */,
94B596792347FD9700FBECA5 /* MemoryFavoritesStorageTests.swift in Sources */,
80673CA22030C3DA0091B48F /* MainStateTests.swift in Sources */,
802CD6A221D6A8D2000FF852 /* MovieDetailViewStateTests.swift in Sources */,
80BFF62021D4911A00D99771 /* MovieListViewStateTests.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions ReduxMovieDB/Actions/MainStateAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ enum MainStateAction: Action {
case search(String)
case cancelSearch

case toggleShowFavorites
case toggleFavoriteMovie

case collapseSplitDetail
case separateSplitDetail
}
32 changes: 28 additions & 4 deletions ReduxMovieDB/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="y8f-Tw-W0j">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="y8f-Tw-W0j">
<device id="retina5_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -81,7 +80,17 @@
<color key="textColor" red="0.97592383620000001" green="0.97666221860000002" blue="0.97603815790000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="★" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4OE-hb-zB6">
<rect key="frame" x="378" y="10" width="21" height="24"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="4OE-hb-zB6" secondAttribute="trailing" constant="15" id="7oJ-6Z-TIT"/>
<constraint firstItem="4OE-hb-zB6" firstAttribute="centerY" secondItem="TfE-wm-NBw" secondAttribute="centerY" id="kS6-VK-HxA"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" red="0.17712351679999999" green="0.1773587465" blue="0.15801239010000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -97,6 +106,7 @@
<inset key="separatorInset" minX="15" minY="0.0" maxX="0.0" maxY="0.0"/>
<connections>
<outlet property="icon" destination="yJC-PJ-vQg" id="QHh-we-qJ8"/>
<outlet property="isFavorite" destination="4OE-hb-zB6" id="BL2-cI-nEh"/>
<outlet property="subtitle" destination="6wP-SE-YYM" id="EYt-rZ-Hpz"/>
<outlet property="title" destination="dhr-G6-2bg" id="rM0-Mh-TUk"/>
</connections>
Expand All @@ -116,8 +126,11 @@
</constraints>
<viewLayoutGuide key="safeArea" id="Nmf-CA-XHz"/>
</view>
<navigationItem key="navigationItem" title="Movies" id="DtV-Zi-nxq"/>
<navigationItem key="navigationItem" title="Movies" id="DtV-Zi-nxq">
<barButtonItem key="rightBarButtonItem" title="☆" id="uy1-Pd-qiH"/>
</navigationItem>
<connections>
<outlet property="favoritesToggleItem" destination="uy1-Pd-qiH" id="EKD-0k-tYR"/>
<outlet property="moviesTableView" destination="T9p-xD-xhB" id="sXr-4W-ryV"/>
<outlet property="searchBar" destination="s2C-Qn-OmZ" id="vyE-N6-7uk"/>
<segue destination="uXz-1h-md8" kind="showDetail" identifier="showDetail" id="lRy-w0-UwQ"/>
Expand Down Expand Up @@ -176,13 +189,23 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<color key="backgroundColor" red="0.17712351679999999" green="0.1773587465" blue="0.15801239010000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YQB-SK-IlZ">
<rect key="frame" x="364" y="-10" width="42" height="46"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<inset key="contentEdgeInsets" minX="8" minY="8" maxX="8" maxY="8"/>
<state key="normal" title="☆">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="SZz-kM-MD8" secondAttribute="trailing" id="9OU-za-Oqh"/>
<constraint firstAttribute="bottom" secondItem="SZz-kM-MD8" secondAttribute="bottom" id="iw4-Zi-oPL"/>
<constraint firstItem="SZz-kM-MD8" firstAttribute="top" secondItem="hEO-bK-WB0" secondAttribute="top" id="lmW-eN-6LF"/>
<constraint firstAttribute="trailing" secondItem="YQB-SK-IlZ" secondAttribute="trailing" constant="8" id="qeL-m3-oHJ"/>
<constraint firstItem="SZz-kM-MD8" firstAttribute="leading" secondItem="hEO-bK-WB0" secondAttribute="leading" id="rc6-4k-Rw2"/>
<constraint firstAttribute="bottom" secondItem="YQB-SK-IlZ" secondAttribute="bottom" constant="8" id="ufi-gR-CL7"/>
</constraints>
</view>
<sections>
Expand Down Expand Up @@ -302,6 +325,7 @@
</tableView>
<navigationItem key="navigationItem" id="dvu-Tb-ZtK"/>
<connections>
<outlet property="favoriteButton" destination="YQB-SK-IlZ" id="WsQ-EQ-W5r"/>
<outlet property="genreLabel" destination="vPN-A7-Hc4" id="BF7-cL-Pys"/>
<outlet property="genreValue" destination="gQ6-IS-urL" id="3xl-uA-01d"/>
<outlet property="overviewLabel" destination="O1h-c3-fp1" id="UbE-06-iNn"/>
Expand Down
29 changes: 22 additions & 7 deletions ReduxMovieDB/Controllers/MovieDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ class MovieDetailViewController: UITableViewController {
@IBOutlet weak var genreValue: UILabel!
@IBOutlet weak var overviewLabel: UILabel!
@IBOutlet weak var overviewValue: UILabel!

@IBOutlet weak var favoriteButton: UIButton! {
didSet {
favoriteButton
.rx
.tap
.subscribe { [weak self] (event) in
guard case .next = event else { return }
mainStore.dispatch(MainStateAction.toggleFavoriteMovie)
self?.favoriteButton.setTitle(mainStore.state.isCurrentFavorite.star, for: .normal)
}.disposed(by: disposeBag)
}
}

@IBOutlet weak var posterImageView: UIImageView!

private let posterViewHeight: CGFloat = 300
Expand Down Expand Up @@ -78,7 +90,7 @@ class MovieDetailViewController: UITableViewController {

return defaultHeight
}

func setupPosterView() {
posterView = tableView.tableHeaderView
tableView.tableHeaderView = nil
Expand Down Expand Up @@ -122,13 +134,16 @@ extension MovieDetailViewController: StoreSubscriber {
releaseDateValue.text = state.date
genreValue.text = state.genres
overviewValue.text = state.overview

if let isFavorite = state.isFavorite {
favoriteButton.setTitle(isFavorite.star, for: .normal)
favoriteButton.isEnabled = true
} else {
favoriteButton.isEnabled = false
}

tableView.endUpdates()

if let movie = state.movie {
posterImageView.setPosterForMovie(movie)
} else {
posterImageView.image = nil
}
posterImageView.setPosterForMovie(state.poster)
}
}
21 changes: 19 additions & 2 deletions ReduxMovieDB/Controllers/MovieListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ class MovieListViewController: UIViewController {
.disposed(by: disposeBag)
}
}

@IBOutlet weak var favoritesToggleItem: UIBarButtonItem! {
didSet {
favoritesToggleItem
.rx
.tap
.subscribe { [weak self] (event) in
guard case .next = event else { return }
mainStore.dispatch(MainStateAction.toggleShowFavorites)
self?.favoritesToggleItem.title = mainStore.state.isFavoritesList.star
}.disposed(by: disposeBag)
}
}

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -120,7 +133,8 @@ class MovieListTableViewCell: UITableViewCell {
@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var subtitle: UILabel!

@IBOutlet weak var isFavorite: UILabel!

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

Expand All @@ -131,9 +145,12 @@ class MovieListTableViewCell: UITableViewCell {
didSet {
guard let movie = movie else { return }

icon.setPosterForMovie(movie)
icon.setPosterForMovie(movie.posterPath)
title.text = movie.title
subtitle.text = movie.releaseDate?.description ?? ""

let isFavorite = movie.id.map { favoritesStore.isFavorite(id: $0) } ?? false
self.isFavorite.isHidden = !isFavorite
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions ReduxMovieDB/Extensions/Boolean.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Extension.swift
// ReduxMovieDB
//
// Created by Aleksei Cherepanov on 17.10.2019.
// Copyright © 2019 Matheus Cardoso. All rights reserved.
//

import Foundation

extension Bool {
var star: String { return self ? "★" : "☆" }
}
4 changes: 2 additions & 2 deletions ReduxMovieDB/Extensions/UIImageView+MoviePoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ extension UIImageView {
return "https://image.tmdb.org/t/p/w500"
}

func setPosterForMovie(_ movie: Movie) {
func setPosterForMovie(_ path: String?) {
let placeholder = UIImage(named: "poster_placeholder")

guard let posterPath = movie.posterPath,
guard let posterPath = path,
let imageURL = URL(string: "\(imageBaseUrl)\(posterPath)") else {
image = placeholder
return
Expand Down
Loading