From 66905eccd793afc9f38de93f21562e1bc28efa6e Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 15 Sep 2016 15:38:48 -0400 Subject: [PATCH] library insets --- .../Library/DownloadTasksController.swift | 42 +- .../Library/EmptyTableConfigExtension.swift | 4 + .../Library/LocalBooksController.swift | 37 +- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Library.storyboard | 392 ++++++++---------- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- 6 files changed, 233 insertions(+), 246 deletions(-) diff --git a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift index 2b49e894..1e3bdc48 100644 --- a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift +++ b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift @@ -10,9 +10,8 @@ import UIKit import CoreData import DZNEmptyDataSet -class DownloadTasksController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { +class DownloadTasksController: UITableViewController, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { - @IBOutlet weak var tableView: UITableView! var timer: NSTimer? // MARK: - Override @@ -26,15 +25,13 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie override func viewDidLoad() { super.viewDidLoad() - - tableView.delegate = self - tableView.dataSource = self - tableView.tableFooterView = UIView() - tableView.estimatedRowHeight = 90.0 - tableView.rowHeight = UITableViewAutomaticDimension - + tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self + tableView.tableFooterView = UIView() + + tableView.estimatedRowHeight = 90.0 + tableView.rowHeight = UITableViewAutomaticDimension } override func viewWillAppear(animated: Bool) { @@ -65,6 +62,15 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie } } + override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + let top = tabBarController!.navigationController!.navigationBar.frame.maxY + let bottom = tabBarController!.tabBar.frame.height + let inset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0) + tableView.contentInset = inset + tableView.scrollIndicatorInsets = inset + } + // MARK: - Methods func refreshProgress() { @@ -81,16 +87,16 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie // MARK: - TableView Data Source - func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return fetchedResultController.sections?.count ?? 0 } - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { guard let sectionInfo = fetchedResultController.sections?[section] else {return 0} return sectionInfo.numberOfObjects } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) self.configureCell(cell, atIndexPath: indexPath) return cell @@ -134,19 +140,19 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie // MARK: Other Data Source - func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { guard tableView.numberOfSections > 1 else {return nil} guard let languageName = fetchedResultController.sections?[section].name else {return nil} return languageName } - func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { + override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { let sectionIndexTitles = fetchedResultController.sectionIndexTitles guard sectionIndexTitles.count > 2 else {return nil} return sectionIndexTitles } - func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int { + override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int { return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index) } @@ -164,13 +170,13 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie // header.textLabel?.font = UIFont.boldSystemFontOfSize(14) // } // - func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { + override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { return true } - func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {} + override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {} - func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { + override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { guard let downloadTask = self.fetchedResultController.objectAtIndexPath(indexPath) as? DownloadTask else {return nil} var actions = [UITableViewRowAction]() diff --git a/Kiwix-iOS/Controller/Library/EmptyTableConfigExtension.swift b/Kiwix-iOS/Controller/Library/EmptyTableConfigExtension.swift index 6a062b66..e4a2a4df 100644 --- a/Kiwix-iOS/Controller/Library/EmptyTableConfigExtension.swift +++ b/Kiwix-iOS/Controller/Library/EmptyTableConfigExtension.swift @@ -45,6 +45,10 @@ extension DownloadTasksController { return NSAttributedString(string: string, attributes: attributes) } + func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat { + return tabBarController!.navigationController!.navigationBar.frame.maxY + } + } extension LocalBooksController { diff --git a/Kiwix-iOS/Controller/Library/LocalBooksController.swift b/Kiwix-iOS/Controller/Library/LocalBooksController.swift index 44960f3c..37d7707f 100644 --- a/Kiwix-iOS/Controller/Library/LocalBooksController.swift +++ b/Kiwix-iOS/Controller/Library/LocalBooksController.swift @@ -11,9 +11,7 @@ import CoreData import Operations import DZNEmptyDataSet -class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { - - @IBOutlet weak var tableView: UITableView! +class LocalBooksController: UITableViewController, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { // MARK: - Override @@ -29,8 +27,6 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self - tableView.delegate = self - tableView.dataSource = self tableView.tableFooterView = UIView() } @@ -54,18 +50,27 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa } } + override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + let top = tabBarController!.navigationController!.navigationBar.frame.maxY + let bottom = tabBarController!.tabBar.frame.height + let inset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0) + tableView.contentInset = inset + tableView.scrollIndicatorInsets = inset + } + // MARK: - TableView Data Source - func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return fetchedResultController.sections?.count ?? 0 } - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { guard let sectionInfo = fetchedResultController.sections?[section] else {return 0} return sectionInfo.numberOfObjects } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) self.configureCell(cell, atIndexPath: indexPath) return cell @@ -84,43 +89,43 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa // MARK: Other Data Source - func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { guard tableView.numberOfSections > 1 else {return nil} guard let languageName = fetchedResultController.sections?[section].name else {return nil} return languageName } - func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { + override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? { let sectionIndexTitles = fetchedResultController.sectionIndexTitles guard sectionIndexTitles.count > 2 else {return nil} return sectionIndexTitles } - func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int { + override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int { return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index) } // MARK: - Table View Delegate - func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { guard tableView.numberOfSections > 1 else {return 0.0} guard let headerText = self.tableView(tableView, titleForHeaderInSection: section) else {return 0.0} guard headerText != "" else {return 0.0} return 20.0 } - func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { guard let header = view as? UITableViewHeaderFooterView else {return} header.textLabel?.font = UIFont.boldSystemFontOfSize(14) } - func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { + override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { return true } - func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {} + override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {} - func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { + override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.remove) { (action, indexPath) -> Void in guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return} let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id) diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 70338d11..63360c27 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.637 + 1.8.649 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Library.storyboard b/Kiwix-iOS/Storyboard/Library.storyboard index ff358684..fac90130 100644 --- a/Kiwix-iOS/Storyboard/Library.storyboard +++ b/Kiwix-iOS/Storyboard/Library.storyboard @@ -127,8 +127,8 @@ - - + + @@ -343,225 +343,197 @@ - + - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -720,6 +692,6 @@ - + diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 41e234dd..2770278f 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.640 + 1.8.652 NSExtension NSExtensionMainStoryboard