This commit is contained in:
Chris Li 2016-11-14 13:37:09 -05:00
parent 10cae73ead
commit 0885c123e5
10 changed files with 89 additions and 65 deletions

View File

@ -12,7 +12,7 @@ import ProcedureKit
import MBProgressHUD
import DZNEmptyDataSet
class CloudBooksController: LibraryBaseController, LanguageFilterUpdating, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
class CloudBooksController: CoreDataBaseController, LanguageFilterUpdating, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
private(set) var isRefreshing = false // used to control text on empty table view
private(set) var isOnScreen = false // used to determine if should delay showing lang filter alert

View File

@ -7,7 +7,6 @@
//
import UIKit
import CoreData
class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDelegate {
override func viewDidLoad() {
@ -22,10 +21,10 @@ class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDe
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
guard traitCollection != previousTraitCollection else {return}
let controller: LibraryBaseController? = {
let controller: CoreDataBaseController? = {
let nav = viewControllers.first as? UINavigationController
let tab = nav?.topViewController as? UITabBarController
return tab?.selectedViewController as? LibraryBaseController
return tab?.selectedViewController as? CoreDataBaseController
}()
//controller?.tableView.reloadData()
controller?.tableView.indexPathsForVisibleRows?.forEach({ (indexPath) in
@ -61,49 +60,3 @@ class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDe
return ((viewControllers[safe: 1] as? UINavigationController)?.topViewController is LanguageFilterController)
}
}
class LibraryBaseController: UITableViewController, NSFetchedResultsControllerDelegate {
func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
}
// MARK: - Fetched Result Controller Delegate
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
switch type {
case .insert:
tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
case .delete:
tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
default:
return
}
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .insert:
guard let newIndexPath = newIndexPath else {return}
tableView.insertRows(at: [newIndexPath], with: .fade)
case .delete:
guard let indexPath = indexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
case .update:
guard let indexPath = indexPath, let cell = tableView.cellForRow(at: indexPath) else {return}
configureCell(cell, atIndexPath: indexPath)
case .move:
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.insertRows(at: [newIndexPath], with: .fade)
}
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.endUpdates()
}
}

View File

@ -11,7 +11,7 @@ import CoreData
import ProcedureKit
import DZNEmptyDataSet
class LocalBooksController: LibraryBaseController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
class LocalBooksController: CoreDataBaseController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
// MARK: - Override

View File

@ -0,0 +1,57 @@
//
// CoreDataBaseController.swift
// Kiwix
//
// Created by Chris Li on 11/14/16.
// Copyright © 2016 Wikimedia CH. All rights reserved.
//
import UIKit
import CoreData
class CoreDataBaseController: UITableViewController, NSFetchedResultsControllerDelegate {
func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
}
// MARK: - Fetched Result Controller Delegate
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
switch type {
case .insert:
tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
case .delete:
tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
default:
return
}
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .insert:
guard let newIndexPath = newIndexPath else {return}
tableView.insertRows(at: [newIndexPath], with: .fade)
case .delete:
guard let indexPath = indexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
case .update:
guard let indexPath = indexPath, let cell = tableView.cellForRow(at: indexPath) else {return}
configureCell(cell, atIndexPath: indexPath)
case .move:
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.insertRows(at: [newIndexPath], with: .fade)
}
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.endUpdates()
}
}

View File

@ -11,14 +11,17 @@ import UIKit
class SearchContainer: UIViewController {
@IBOutlet weak var dimView: UIView!
var delegate: SearchContainerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(handleDimViewTap))
dimView.addGestureRecognizer(tap)
}
func handleDimViewTap() {

View File

@ -79,8 +79,8 @@ class SearchTableViewController: UIViewController, DZNEmptyDataSetSource, DZNEmp
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(SearchTableViewController.keyboardDidShow(_:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(SearchTableViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(_:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.2599</string>
<string>1.8.2613</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -29,9 +29,6 @@
</view>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wyO-bR-owd" customClass="SearchRoundedCornerView" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="115" y="64" width="538" height="910"/>
<connections>
<segue destination="vSQ-RM-B8e" kind="embed" id="eNB-iH-uRa"/>
</connections>
</containerView>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="l6w-E8-vrr" customClass="SearchRoundedCornerView" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="115" y="64" width="538" height="910"/>
@ -157,11 +154,11 @@
<viewControllerLayoutGuide type="bottom" id="fIX-c6-nY4"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="HEy-pW-bRk">
<rect key="frame" x="0.0" y="0.0" width="538" height="910"/>
<rect key="frame" x="0.0" y="0.0" width="538" height="717"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="nDJ-c8-oj6">
<rect key="frame" x="0.0" y="108" width="538" height="802"/>
<rect key="frame" x="0.0" y="108" width="538" height="609"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CheckMarkBookCell" id="BZj-UA-kZf" customClass="CheckMarkBookCell" customModule="Kiwix">
@ -172,7 +169,7 @@
<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="GW1-dh-vyc">
<rect key="frame" x="48" y="6" width="450" height="19.5"/>
<rect key="frame" x="48" y="6" width="450" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="19.5" id="o3M-qV-F9K"/>
</constraints>
@ -188,13 +185,13 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="b2I-tp-w9c">
<rect key="frame" x="48" y="25.5" width="450" height="12.5"/>
<rect key="frame" x="48" y="26" width="450" height="12"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Opy-5E-UzW">
<rect key="frame" x="42" y="6" width="2" height="31.5"/>
<rect key="frame" x="42" y="6" width="2" height="32"/>
<color key="backgroundColor" red="1" green="0.40000000000000002" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="4" id="gxc-MY-b04"/>
@ -285,7 +282,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="R0s-FA-lXA" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1852" y="-1003.4482758620691"/>
<point key="canvasLocation" x="1852" y="-1461"/>
</scene>
<!--Search Result Controller-->
<scene sceneID="g1P-db-EbE">
@ -525,7 +522,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RyG-of-G9K" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2785" y="-1004"/>
<point key="canvasLocation" x="2523" y="-1461"/>
</scene>
<!--Search Container-->
<scene sceneID="Rcv-85-TOv">
@ -543,12 +540,22 @@
<rect key="frame" x="0.0" y="64" width="768" height="960"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="0.5" colorSpace="calibratedWhite"/>
</view>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TwU-1D-XoU" customClass="SearchRoundedCornerView" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="115" y="64" width="538" height="717"/>
<connections>
<segue destination="vSQ-RM-B8e" kind="embed" id="5c8-AT-w6g"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="TwU-1D-XoU" firstAttribute="width" secondItem="4ma-1x-rrV" secondAttribute="width" multiplier="0.7" id="8Ra-9F-JD4"/>
<constraint firstAttribute="trailing" secondItem="aYO-40-lc1" secondAttribute="trailing" id="BVS-ar-WL4"/>
<constraint firstItem="TwU-1D-XoU" firstAttribute="height" secondItem="4ma-1x-rrV" secondAttribute="height" multiplier="0.7" id="FMO-4e-tUF"/>
<constraint firstItem="aYO-40-lc1" firstAttribute="leading" secondItem="4ma-1x-rrV" secondAttribute="leading" id="I4h-o0-seW"/>
<constraint firstItem="TwU-1D-XoU" firstAttribute="centerX" secondItem="4ma-1x-rrV" secondAttribute="centerX" id="Ic8-db-q3b"/>
<constraint firstItem="io0-SJ-WNQ" firstAttribute="top" secondItem="aYO-40-lc1" secondAttribute="bottom" id="kHq-Kc-KeD"/>
<constraint firstItem="TwU-1D-XoU" firstAttribute="top" secondItem="BED-lt-fDm" secondAttribute="bottom" id="r7L-V0-bRc"/>
<constraint firstItem="aYO-40-lc1" firstAttribute="top" secondItem="BED-lt-fDm" secondAttribute="bottom" id="tGo-AF-P3V"/>
</constraints>
<variation key="default">

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.8.2599</string>
<string>1.8.2613</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>

View File

@ -97,6 +97,7 @@
97C601DC1D7F15C400362D4F /* Bookmark.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C601DB1D7F15C400362D4F /* Bookmark.storyboard */; };
97C601DE1D7F342100362D4F /* HTMLHeading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97C601DD1D7F342100362D4F /* HTMLHeading.swift */; };
97D0E98F1DDA12B30029530E /* MainControllerDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D0E98E1DDA12B30029530E /* MainControllerDelegates.swift */; };
97D0E9911DDA38490029530E /* CoreDataBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D0E9901DDA38490029530E /* CoreDataBaseController.swift */; };
97D681311D6F70EC00E5FA99 /* 1.5.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 97D6812F1D6F70EC00E5FA99 /* 1.5.xcmappingmodel */; };
97D681321D6F70EC00E5FA99 /* MigrationPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D681301D6F70EC00E5FA99 /* MigrationPolicy.swift */; };
97D681371D6F711A00E5FA99 /* Article.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D681331D6F711A00E5FA99 /* Article.swift */; };
@ -268,6 +269,7 @@
97D0E98C1DDA12980029530E /* MainControllerDelegates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainControllerDelegates.swift; path = old/MainControllerDelegates.swift; sourceTree = "<group>"; };
97D0E98D1DDA12980029530E /* MainControllerShowHide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainControllerShowHide.swift; path = old/MainControllerShowHide.swift; sourceTree = "<group>"; };
97D0E98E1DDA12B30029530E /* MainControllerDelegates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainControllerDelegates.swift; sourceTree = "<group>"; };
97D0E9901DDA38490029530E /* CoreDataBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBaseController.swift; sourceTree = "<group>"; };
97D4D64E1D874E6E00C1B065 /* SearchOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchOperation.swift; sourceTree = "<group>"; };
97D6811A1D6E2A7100E5FA99 /* DownloadTasksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadTasksController.swift; sourceTree = "<group>"; };
97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalQueue.swift; sourceTree = "<group>"; };
@ -624,6 +626,7 @@
isa = PBXGroup;
children = (
970E7F7C1DA0305000741290 /* Alerts.swift */,
97D0E9901DDA38490029530E /* CoreDataBaseController.swift */,
970E7F7D1DA0305000741290 /* ControllerRetainer.swift */,
970E7F7E1DA0305000741290 /* TableOfContentsController.swift */,
970E7F7F1DA0305000741290 /* WelcomeController.swift */,
@ -1128,6 +1131,7 @@
973207A21DD1983D00EDD3DC /* BookDetailController.swift in Sources */,
973208231DD19C7600EDD3DC /* DownloadProgress.swift in Sources */,
97A1FD161D6F71CE00A80EE2 /* DirectoryMonitor.swift in Sources */,
97D0E9911DDA38490029530E /* CoreDataBaseController.swift in Sources */,
9726591D1D90A64600D1DFFB /* Notifications.swift in Sources */,
971A102C1D022AD5007FC62C /* BarButtonItems.swift in Sources */,
97D0E98F1DDA12B30029530E /* MainControllerDelegates.swift in Sources */,