From a30b2373f95a0b215de47f51611ec05a70a1a003 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 27 Sep 2016 14:31:43 -0400 Subject: [PATCH] Bookmark cell in book detail controller --- .../Library/BookDetailController.swift | 25 ++++++-- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Library.storyboard | 60 +++++++++++++------ Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- .../xcdebugger/Breakpoints_v2.xcbkptlist | 48 +++++++++++++++ Kiwix/CoreData/Classes/Article.swift | 7 +++ Kiwix/CoreData/Classes/Book.swift | 9 --- Kiwix/Operations/ScanLocalBookOperation.swift | 3 + 8 files changed, 123 insertions(+), 33 deletions(-) diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift index d39a8c04..26c295a1 100644 --- a/Kiwix-iOS/Controller/Library/BookDetailController.swift +++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift @@ -7,6 +7,7 @@ // import UIKit +import CoreData import DZNEmptyDataSet class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { @@ -19,12 +20,13 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp @IBOutlet weak var hasIndexIndicator: UILabel! @IBOutlet weak var hasIndexLabel: UILabel! - var context: UnsafeMutablePointer = nil + private(set) var context: UnsafeMutablePointer = nil var book: Book? - var sectionHeaders = [String?]() - var sectionFooters = [String?]() - var cellTitles = [[String]]() + private(set) var sectionHeaders = [String?]() + private(set) var sectionFooters = [String?]() + private(set) var cellTitles = [[String]]() + private(set) var bookmarkCount = 0 override func viewDidLoad() { super.viewDidLoad() @@ -110,6 +112,14 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp } } + func configureBookmarkSection(with book: Book) { + bookmarkCount = Article.fetchBookmarked(in: book, with: NSManagedObjectContext.mainQueueContext).count + guard bookmarkCount > 0 else {return} + sectionHeaders.append(nil) + sectionFooters.append(nil) + cellTitles.append([LocalizedStrings.bookmarks]) + } + func configureBookInfoSection(with book: Book) { sectionHeaders.append(LocalizedStrings.bookInfo) sectionFooters.append(nil) @@ -143,6 +153,7 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp configureIndicators(with: book) configureDescriptionSection(with: book) configureActionSection(with: book) + configureBookmarkSection(with: book) configureBookInfoSection(with: book) configurePIDSection(with: book) configureURLSection(with: book) @@ -185,6 +196,11 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath) cell.textLabel?.text = title return cell + case LocalizedStrings.bookmarks: + let cell = tableView.dequeueReusableCellWithIdentifier("DetailSegueCell", forIndexPath: indexPath) + cell.textLabel?.text = title + cell.detailTextLabel?.text = "\(bookmarkCount)" + return cell default: let cell = tableView.dequeueReusableCellWithIdentifier("RightDetailCell", forIndexPath: indexPath) cell.textLabel?.text = title @@ -266,6 +282,7 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp // static let resume = NSLocalizedString("Resume", comment: comment) // static let cancel = NSLocalizedString("Cancel", comment: comment) + static let bookmarks = NSLocalizedString("Bookmarks", comment: comment) static let bookInfo = NSLocalizedString("Book Info", comment: comment) static let size = NSLocalizedString("Size", comment: comment) static let createDate = NSLocalizedString("Creation Date", comment: comment) diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 298d92d5..a7ad9a5c 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.1146 + 1.8.1183 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Library.storyboard b/Kiwix-iOS/Storyboard/Library.storyboard index fac90130..9d6aa793 100644 --- a/Kiwix-iOS/Storyboard/Library.storyboard +++ b/Kiwix-iOS/Storyboard/Library.storyboard @@ -1,5 +1,5 @@ - + @@ -21,7 +21,7 @@ - +