diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift index ce71fff6..4f46766a 100644 --- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift +++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift @@ -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 diff --git a/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift b/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift index 76e70f0f..c124e9d2 100644 --- a/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift +++ b/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift @@ -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) { - tableView.beginUpdates() - } - - func controller(_ controller: NSFetchedResultsController, 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, 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) { - tableView.endUpdates() - } -} diff --git a/Kiwix-iOS/Controller/Library/LocalBooksController.swift b/Kiwix-iOS/Controller/Library/LocalBooksController.swift index f552a2a4..e49003d4 100644 --- a/Kiwix-iOS/Controller/Library/LocalBooksController.swift +++ b/Kiwix-iOS/Controller/Library/LocalBooksController.swift @@ -11,7 +11,7 @@ import CoreData import ProcedureKit import DZNEmptyDataSet -class LocalBooksController: LibraryBaseController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { +class LocalBooksController: CoreDataBaseController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { // MARK: - Override diff --git a/Kiwix-iOS/Controller/Others/CoreDataBaseController.swift b/Kiwix-iOS/Controller/Others/CoreDataBaseController.swift new file mode 100644 index 00000000..398aa434 --- /dev/null +++ b/Kiwix-iOS/Controller/Others/CoreDataBaseController.swift @@ -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) { + tableView.beginUpdates() + } + + func controller(_ controller: NSFetchedResultsController, 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, 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) { + tableView.endUpdates() + } +} diff --git a/Kiwix-iOS/Controller/Search/SearchContainer.swift b/Kiwix-iOS/Controller/Search/SearchContainer.swift index 0870695f..1c64e830 100644 --- a/Kiwix-iOS/Controller/Search/SearchContainer.swift +++ b/Kiwix-iOS/Controller/Search/SearchContainer.swift @@ -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() { diff --git a/Kiwix-iOS/Controller/Search/SearchController.swift b/Kiwix-iOS/Controller/Search/SearchController.swift index 66ae1d10..c79e8861 100644 --- a/Kiwix-iOS/Controller/Search/SearchController.swift +++ b/Kiwix-iOS/Controller/Search/SearchController.swift @@ -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) { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 92213338..10ed7925 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.2599 + 1.8.2613 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Search.storyboard b/Kiwix-iOS/Storyboard/Search.storyboard index 4fbe3e0c..d16121ce 100644 --- a/Kiwix-iOS/Storyboard/Search.storyboard +++ b/Kiwix-iOS/Storyboard/Search.storyboard @@ -29,9 +29,6 @@ - - - @@ -157,11 +154,11 @@ - + - + @@ -172,7 +169,7 @@ + + + + diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 78ef533d..5aee2e6a 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.2599 + 1.8.2613 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index a22cb9c2..407862ea 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -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 = ""; }; 97D0E98D1DDA12980029530E /* MainControllerShowHide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainControllerShowHide.swift; path = old/MainControllerShowHide.swift; sourceTree = ""; }; 97D0E98E1DDA12B30029530E /* MainControllerDelegates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainControllerDelegates.swift; sourceTree = ""; }; + 97D0E9901DDA38490029530E /* CoreDataBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataBaseController.swift; sourceTree = ""; }; 97D4D64E1D874E6E00C1B065 /* SearchOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchOperation.swift; sourceTree = ""; }; 97D6811A1D6E2A7100E5FA99 /* DownloadTasksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadTasksController.swift; sourceTree = ""; }; 97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalQueue.swift; sourceTree = ""; }; @@ -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 */,