mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 21:05:09 -04:00
show bookmarks in book detail
This commit is contained in:
parent
bb7bec1b5c
commit
380f740bfc
@ -7,29 +7,107 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
|
||||
class BookmarkController: UIViewController {
|
||||
class BookmarkController: UITableViewController, NSFetchedResultsControllerDelegate {
|
||||
|
||||
var book: Book?
|
||||
|
||||
// MARK: - Overrides
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// MARK: - Navigation
|
||||
|
||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
// Get the new view controller using segue.destinationViewController.
|
||||
// Pass the selected object to the new view controller.
|
||||
// MARK: - Table view data source
|
||||
|
||||
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
||||
return fetchedResultController.sections?.count ?? 0
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
guard let sectionInfo = fetchedResultController.sections?[section] else {return 0}
|
||||
return sectionInfo.numberOfObjects
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
||||
let article = fetchedResultController.objectAtIndexPath(indexPath) as? Article
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
|
||||
cell.textLabel?.text = article?.title
|
||||
return cell
|
||||
}
|
||||
|
||||
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
|
||||
guard let cell = cell as? BookmarkCell else {return}
|
||||
guard let article = fetchedResultController.objectAtIndexPath(indexPath) as? Article else {return}
|
||||
|
||||
cell.thumbImageView.image = {
|
||||
guard let data = article.thumbImageData else {return nil}
|
||||
return UIImage(data: data)
|
||||
}()
|
||||
cell.titleLabel.text = article.title
|
||||
cell.subtitleLabel.text = article.book?.title
|
||||
}
|
||||
|
||||
// MARK: - Fetched Result Controller Delegate
|
||||
|
||||
let managedObjectContext = NSManagedObjectContext.mainQueueContext
|
||||
lazy var fetchedResultController: NSFetchedResultsController = {
|
||||
let fetchRequest = NSFetchRequest(entityName: "Article")
|
||||
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "bookmarkDate", ascending: false),
|
||||
NSSortDescriptor(key: "title", ascending: true)]
|
||||
fetchRequest.predicate = {
|
||||
if let book = self.book {
|
||||
return NSPredicate(format: "book = %@ AND isBookmarked = true", book)
|
||||
} else {
|
||||
return NSPredicate(format: "isBookmarked = true")
|
||||
}
|
||||
}()
|
||||
let controller = NSFetchedResultsController(fetchRequest: fetchRequest,
|
||||
managedObjectContext: self.managedObjectContext,
|
||||
sectionNameKeyPath: nil,
|
||||
cacheName: self.book == nil ? nil : "BookmarksFRC" + NSBundle.appShortVersion)
|
||||
controller.delegate = self
|
||||
controller.performFetch(deleteCache: false)
|
||||
return controller
|
||||
}()
|
||||
|
||||
// MARK: - Fetched Result Controller Delegate
|
||||
|
||||
func controllerWillChangeContent(controller: NSFetchedResultsController) {
|
||||
tableView.beginUpdates()
|
||||
}
|
||||
|
||||
func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
|
||||
switch type {
|
||||
case .Insert:
|
||||
tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
|
||||
case .Delete:
|
||||
tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
|
||||
switch type {
|
||||
case .Insert:
|
||||
guard let newIndexPath = newIndexPath else {return}
|
||||
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
|
||||
case .Delete:
|
||||
guard let indexPath = indexPath else {return}
|
||||
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
|
||||
case .Update:
|
||||
guard let indexPath = indexPath, let cell = tableView.cellForRowAtIndexPath(indexPath) else {return}
|
||||
configureCell(cell, atIndexPath: indexPath)
|
||||
case .Move:
|
||||
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {return}
|
||||
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
|
||||
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
|
||||
}
|
||||
}
|
||||
|
||||
func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||
tableView.endUpdates()
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -256,6 +256,11 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
|
||||
case LocalizedStrings.remove:
|
||||
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)
|
||||
GlobalQueue.shared.addOperation(operation)
|
||||
case LocalizedStrings.bookmarks:
|
||||
guard let controller = UIStoryboard(name: "Bookmark", bundle: nil)
|
||||
.instantiateViewControllerWithIdentifier("BookmarkController") as? BookmarkController else {return}
|
||||
controller.book = book
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
case LocalizedStrings.copyURL:
|
||||
guard let url = book.url else {return}
|
||||
UIPasteboard.generalPasteboard().string = url.absoluteString
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1185</string>
|
||||
<string>1.8.1211</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="CQC-Yj-yBQ">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="CQC-Yj-yBQ">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
@ -19,10 +19,10 @@
|
||||
<color key="sectionIndexBackgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BookmarkCell" rowHeight="66" id="HDv-lO-b6r" customClass="BookmarkCell" customModule="Kiwix" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="100" width="375" height="66"/>
|
||||
<rect key="frame" x="0.0" y="120" width="375" height="66"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="HDv-lO-b6r" id="OAl-D1-ec7">
|
||||
<frame key="frameInset" width="375" height="65.5"/>
|
||||
<frame key="frameInset" width="375" height="65"/>
|
||||
<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="U1x-fn-tr7">
|
||||
@ -64,10 +64,10 @@
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BookmarkSnippetCell" rowHeight="149" id="o5A-Xv-pf5" customClass="BookmarkSnippetCell" customModule="Kiwix" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="166" width="375" height="149"/>
|
||||
<rect key="frame" x="0.0" y="186" width="375" height="149"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="o5A-Xv-pf5" id="KOC-sh-r2Q">
|
||||
<frame key="frameInset" width="375" height="148.5"/>
|
||||
<frame key="frameInset" width="375" height="148"/>
|
||||
<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="Iw0-U5-FqV">
|
||||
@ -180,9 +180,37 @@
|
||||
<point key="canvasLocation" x="1099" y="1137"/>
|
||||
</scene>
|
||||
<!--Bookmark Controller-->
|
||||
<scene sceneID="SVz-ni-k6U">
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="BookmarkController" id="uLf-Kw-kC4" customClass="BookmarkController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="e97-aT-3rg">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="jws-Kz-Krn">
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="jws-Kz-Krn" id="l4Q-UL-tNB">
|
||||
<frame key="frameInset" width="375" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="uLf-Kw-kC4" id="SZg-nM-2l4"/>
|
||||
<outlet property="delegate" destination="uLf-Kw-kC4" id="eAm-IZ-3SL"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="kQh-IS-Ttn" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1455" y="1720"/>
|
||||
</scene>
|
||||
<!--BookmarkHUD-->
|
||||
<scene sceneID="eMu-pk-jX5">
|
||||
<objects>
|
||||
<viewController storyboardIdentifier="BookmarkController" id="hqG-Qy-2zg" customClass="BookmarkController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController storyboardIdentifier="BookmarkHUD" id="hqG-Qy-2zg" customClass="BookmarkHUD" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="dJR-6a-lyw"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="4tE-FX-iOW"/>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1189</string>
|
||||
<string>1.8.1215</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
Loading…
x
Reference in New Issue
Block a user