mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 05:18:31 -04:00
separate CoreDataTableBaseController
This commit is contained in:
parent
0758d73cb3
commit
2f7e0e9a6c
@ -12,7 +12,7 @@ import ProcedureKit
|
||||
import MBProgressHUD
|
||||
import DZNEmptyDataSet
|
||||
|
||||
class CloudBooksController: LibraryBaseController, UITableViewDelegate, UITableViewDataSource, LanguageFilterUpdating, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
class CloudBooksController: CoreDataTableBaseController, UITableViewDelegate, UITableViewDataSource, 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
|
||||
private(set) var langFilterAlertPending = false
|
||||
|
@ -10,7 +10,7 @@ import UIKit
|
||||
import CoreData
|
||||
import DZNEmptyDataSet
|
||||
|
||||
class DownloadTasksController: LibraryBaseController, UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
class DownloadTasksController: CoreDataTableBaseController, UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
var timer: Timer?
|
||||
|
||||
// MARK: - Override
|
||||
|
@ -22,10 +22,10 @@ class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDe
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
guard traitCollection != previousTraitCollection else {return}
|
||||
let controller: LibraryBaseController? = {
|
||||
let controller: CoreDataTableBaseController? = {
|
||||
let nav = viewControllers.first as? UINavigationController
|
||||
let tab = nav?.topViewController as? UITabBarController
|
||||
return tab?.selectedViewController as? LibraryBaseController
|
||||
return tab?.selectedViewController as? CoreDataTableBaseController
|
||||
}()
|
||||
controller?.tableView.indexPathsForVisibleRows?.forEach({ (indexPath) in
|
||||
guard let cell = controller?.tableView.cellForRow(at: indexPath) else {return}
|
||||
@ -60,48 +60,3 @@ class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDe
|
||||
return ((viewControllers[safe: 1] as? UINavigationController)?.topViewController is LanguageFilterController)
|
||||
}
|
||||
}
|
||||
|
||||
class LibraryBaseController: UIViewController, NSFetchedResultsControllerDelegate {
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
|
||||
func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import CoreData
|
||||
import ProcedureKit
|
||||
import DZNEmptyDataSet
|
||||
|
||||
class LocalBooksController: LibraryBaseController, UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
class LocalBooksController: CoreDataTableBaseController, UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
|
||||
// MARK: - Override
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
//
|
||||
// CoreDataTableBaseController.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 11/26/16.
|
||||
// Copyright © 2016 Chris Li. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import CoreData
|
||||
|
||||
|
||||
class CoreDataTableBaseController: UIViewController, NSFetchedResultsControllerDelegate {
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
|
||||
func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3342</string>
|
||||
<string>1.8.3345</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3342</string>
|
||||
<string>1.8.3345</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -42,6 +42,7 @@
|
||||
973208271DD2238B00EDD3DC /* GlobalQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6811C1D6F70AC00E5FA99 /* GlobalQueue.swift */; };
|
||||
973208291DD223DB00EDD3DC /* RefreshLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973208281DD223DB00EDD3DC /* RefreshLibrary.swift */; };
|
||||
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
|
||||
973A5C921DEA3F5600C7804C /* CoreDataTableBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */; };
|
||||
973BCD1A1CEB402900F10B44 /* KiwixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCD181CEB402900F10B44 /* KiwixTests.swift */; };
|
||||
973DD40F1D343F2F009D45DB /* libicudata.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4041D343F2F009D45DB /* libicudata.a */; };
|
||||
973DD4101D343F2F009D45DB /* libicui18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD4051D343F2F009D45DB /* libicui18n.a */; };
|
||||
@ -189,6 +190,7 @@
|
||||
973208251DD21E9C00EDD3DC /* CoreDataContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataContainer.swift; sourceTree = "<group>"; };
|
||||
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RefreshLibrary.swift; sourceTree = "<group>"; };
|
||||
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
|
||||
973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataTableBaseController.swift; sourceTree = "<group>"; };
|
||||
973BCD001CEB3FA500F10B44 /* Kiwix_OSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXTests.swift; sourceTree = "<group>"; };
|
||||
973BCD021CEB3FA500F10B44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
973BCD0B1CEB3FA500F10B44 /* Kiwix_OSXUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Kiwix_OSXUITests.swift; sourceTree = "<group>"; };
|
||||
@ -625,6 +627,7 @@
|
||||
children = (
|
||||
970E7F7C1DA0305000741290 /* Alerts.swift */,
|
||||
970E7F7E1DA0305000741290 /* TableOfContentsController.swift */,
|
||||
973A5C911DEA3F5600C7804C /* CoreDataTableBaseController.swift */,
|
||||
970E7F7F1DA0305000741290 /* WelcomeController.swift */,
|
||||
);
|
||||
path = Others;
|
||||
@ -1183,6 +1186,7 @@
|
||||
97D681311D6F70EC00E5FA99 /* 1.5.xcmappingmodel in Sources */,
|
||||
9732075C1DD136BB00EDD3DC /* CoreDataExtension.swift in Sources */,
|
||||
973208271DD2238B00EDD3DC /* GlobalQueue.swift in Sources */,
|
||||
973A5C921DEA3F5600C7804C /* CoreDataTableBaseController.swift in Sources */,
|
||||
97A1FD181D6F71CE00A80EE2 /* SearchResult.swift in Sources */,
|
||||
973207A11DD1983D00EDD3DC /* LocalBooksController.swift in Sources */,
|
||||
977AE7F91DD8F22400F1E581 /* SearchBar.swift in Sources */,
|
||||
|
Loading…
x
Reference in New Issue
Block a user