Collection view cell selection

This commit is contained in:
Chris Li 2017-01-17 11:28:39 -05:00
parent baf4cf4c4e
commit bb58f40e9b
3 changed files with 36 additions and 28 deletions

View File

@ -84,6 +84,14 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource
return cell
}
// MARK: - UICollectionView Delegate
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let article = fetchedResultController.object(at: indexPath)
guard let url = article.url else {return}
GlobalQueue.shared.add(articleLoadOperation: ArticleLoadOperation(url: url))
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
@ -98,10 +106,10 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource
let fetchRequest = Article.fetchRequest()
let titleDescriptor = NSSortDescriptor(key: "title", ascending: true)
fetchRequest.sortDescriptors = [titleDescriptor]
// var predicates = [NSPredicate]()
// predicates.append(NSPredicate(format: "isBookmarked = true"))
// if let book = self.book { predicates.append(NSPredicate(format: "book == %@", book)) }
// fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)
var predicates = [NSPredicate]()
predicates.append(NSPredicate(format: "isBookmarked = true"))
if let book = self.book { predicates.append(NSPredicate(format: "book == %@", book)) }
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)
let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
controller.delegate = self
try? controller.performFetch()

View File

@ -140,11 +140,12 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OOK-WC-dk5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="5939.130434782609" y="3243.7500000000005"/>
<point key="canvasLocation" x="5006" y="3267"/>
</scene>
<!--Bookmark Article Controller-->
<scene sceneID="VN9-Ad-dWZ">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="KyR-qJ-SWv" userLabel="First Responder" sceneMemberID="firstResponder"/>
<viewController id="xE4-gI-XU7" customClass="BookmarkArticleController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="KsU-SN-Q6B"/>
@ -162,11 +163,11 @@
<rect key="frame" x="0.0" y="28" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ctR-1A-5o0" id="5Nd-fl-Nsl">
<rect key="frame" x="0.0" y="0.0" width="414" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="PgF-nn-SRl">
<rect key="frame" x="15" y="0.0" width="384" height="43"/>
<rect key="frame" x="15" y="0.0" width="384" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
@ -195,13 +196,13 @@
<outlet property="tableView" destination="Qeu-f3-5WZ" id="BuJ-5o-bhv"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="KyR-qJ-SWv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3245" y="3196"/>
<point key="canvasLocation" x="2706" y="2413"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="i96-PS-3ib">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="KtC-fm-L5w" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController id="8sg-ud-siF" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="THl-YC-SF3">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
@ -211,13 +212,13 @@
<segue destination="6ta-bG-bwf" kind="relationship" relationship="rootViewController" id="00r-M0-WcP"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="KtC-fm-L5w" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2384" y="2552"/>
<point key="canvasLocation" x="1843" y="1769"/>
</scene>
<!--Bookmark Books Controller-->
<scene sceneID="g5J-tc-3iG">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="Mda-Cj-fak" userLabel="First Responder" sceneMemberID="firstResponder"/>
<viewController id="6ta-bG-bwf" customClass="BookmarkBooksController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="urC-8o-1iM"/>
@ -232,10 +233,10 @@
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="Cell" id="ZwJ-s2-oXZ" customClass="BasicBookCell" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="0.0" y="56" width="414" height="44"/>
<rect key="frame" x="0.0" y="55.333333333333336" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ZwJ-s2-oXZ" id="acz-8H-Je1">
<rect key="frame" x="0.0" y="0.0" width="381" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="381" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" minimumFontSize="8" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="F5J-kg-p5Y">
@ -326,26 +327,31 @@
<outlet property="tableView" destination="Q7g-uD-S7M" id="EnJ-hw-TgP"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Mda-Cj-fak" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3244.9275362318845" y="2551.630434782609"/>
<point key="canvasLocation" x="2706" y="1769"/>
</scene>
<!--Bookmark Split Controller-->
<scene sceneID="SDm-nf-Wpq">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="XnC-Pf-fz7" userLabel="First Responder" sceneMemberID="firstResponder"/>
<splitViewController id="ALQ-3b-cEW" customClass="BookmarkSplitController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<connections>
<segue destination="8sg-ud-siF" kind="relationship" relationship="masterViewController" id="25F-nw-ITK"/>
<segue destination="hDm-kh-ZLk" kind="relationship" relationship="detailViewController" id="ipW-qc-ph3"/>
</connections>
</splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="XnC-Pf-fz7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1468" y="2878"/>
<point key="canvasLocation" x="928" y="2095"/>
</scene>
<!--BookmarkHUD-->
<scene sceneID="eMu-pk-jX5">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ujq-zq-qYt" userLabel="First Responder" sceneMemberID="firstResponder"/>
<tapGestureRecognizer id="yuw-xk-Asr">
<connections>
<action selector="tapRecognized:" destination="hqG-Qy-2zg" id="Kly-Ex-v4q"/>
</connections>
</tapGestureRecognizer>
<viewController storyboardIdentifier="BookmarkHUD" id="hqG-Qy-2zg" customClass="BookmarkHUD" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="dJR-6a-lyw"/>
@ -452,18 +458,13 @@
<outlet property="messageLabel" destination="OCG-cf-ckk" id="Rtw-js-avy"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ujq-zq-qYt" userLabel="First Responder" sceneMemberID="firstResponder"/>
<tapGestureRecognizer id="yuw-xk-Asr">
<connections>
<action selector="tapRecognized:" destination="hqG-Qy-2zg" id="Kly-Ex-v4q"/>
</connections>
</tapGestureRecognizer>
</objects>
<point key="canvasLocation" x="4099" y="2552"/>
<point key="canvasLocation" x="4099" y="2566"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="IbQ-Ft-djH">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="avJ-P8-fSY" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="hDm-kh-ZLk" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="lNg-T6-EiE">
@ -475,9 +476,8 @@
<segue destination="xE4-gI-XU7" kind="relationship" relationship="rootViewController" id="4H6-ag-m1c"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="avJ-P8-fSY" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2382.608695652174" y="3196.467391304348"/>
<point key="canvasLocation" x="1843" y="2414"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="DnL-5M-iZu">
@ -495,7 +495,7 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sN1-na-d88" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="5031.884057971015" y="3243.7500000000005"/>
<point key="canvasLocation" x="4099" y="3267"/>
</scene>
</scenes>
<resources>

View File

@ -78,7 +78,7 @@ class ArticleLoadOperation: Procedure {
OperationQueue.main.addOperation {
_ = main.searchBar.resignFirstResponder()
main.presentingViewController?.dismiss(animated: self.animated, completion: nil)
main.presentedViewController?.dismiss(animated: self.animated, completion: nil)
main.hideWelcome()
if main.traitCollection.horizontalSizeClass == .compact {