diff --git a/Kiwix-iOS/Controller/ControllerRetainer.swift b/Kiwix-iOS/Controller/ControllerRetainer.swift index c3ad9662..edac0e42 100644 --- a/Kiwix-iOS/Controller/ControllerRetainer.swift +++ b/Kiwix-iOS/Controller/ControllerRetainer.swift @@ -10,37 +10,54 @@ import UIKit class ControllerRetainer { static let shared = ControllerRetainer() - private init() {} + private init() { + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ControllerRetainer.removeStrongReference), name: UIApplicationDidReceiveMemoryWarningNotification, object: nil) + } + + deinit { + NSNotificationCenter.defaultCenter().removeObserver(self, name: UIApplicationDidReceiveMemoryWarningNotification, object: nil) + } + + @objc func removeStrongReference() { + search = nil + bookmark = nil + } // MARK: - Search - var searchStore: SearchController? - var search: SearchController { - let controller = searchStore ?? UIStoryboard.search.instantiateInitialViewController() as? SearchController - searchStore = controller - return controller! + private var search: SearchController? + + class var search: SearchController { + let controller = ControllerRetainer.shared.search ?? UIStoryboard(name: "Search", bundle: nil).instantiateInitialViewController() as! SearchController + ControllerRetainer.shared.search = controller + return controller } + // MARK: - Bookmark + + private var bookmark: UINavigationController? + + class var bookmark: UINavigationController { + let controller = ControllerRetainer.shared.bookmark ?? UIStoryboard(name: "Bookmark", bundle: nil).instantiateInitialViewController() as! UINavigationController + ControllerRetainer.shared.bookmark = controller + return controller + } + + private var bookmarkStar: BookmarkController? + + class var bookmarkStar: BookmarkController { + let controller = ControllerRetainer.shared.bookmarkStar ?? UIStoryboard(name: "Bookmark", bundle: nil).instantiateViewControllerWithIdentifier("BookmarkController") as! BookmarkController + ControllerRetainer.shared.bookmarkStar = controller + return controller + } // MARK: - Library - private var libraryStore: UIViewController? - private func releaseLibrary() {libraryStore = nil} + private var library: UIViewController? - var library: UIViewController { - let controller = libraryStore ?? UIStoryboard.library.instantiateInitialViewController() - libraryStore = controller + class var library: UIViewController { + let controller = ControllerRetainer.shared.bookmarkStar ?? UIStoryboard(name: "Library", bundle: nil).instantiateInitialViewController() + ControllerRetainer.shared.library = controller! return controller! } - - func didDismissLibrary() { - if #available(iOS 10, *) { - NSTimer.scheduledTimerWithTimeInterval(120.0, repeats: false, block: { (timer) in - self.libraryStore = nil - }) - } else { - NSTimer.scheduledTimerWithTimeInterval(120.0, target: self, selector: Selector("releaseLibrary"), userInfo: nil, repeats: false) - } - } - } diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift index d0dd0a19..a4098171 100644 --- a/Kiwix-iOS/Controller/Library/BookDetailController.swift +++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift @@ -19,6 +19,7 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN @IBOutlet weak var hasIndexIndicator: UILabel! @IBOutlet weak var hasIndexLabel: UILabel! + var context: UnsafeMutablePointer = nil typealias Strings = LocalizedStrings.BookDetail var book: Book? @@ -37,8 +38,22 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN hasIndexIndicator.layer.cornerRadius = 2.0 hasPicIndicator.layer.masksToBounds = true hasIndexIndicator.layer.masksToBounds = true - + } + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) configureViews() + book?.downloadTask?.addObserver(self, forKeyPath: "stateRaw", options: .New, context: context) + } + + override func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + book?.downloadTask?.removeObserver(self, forKeyPath: "stateRaw", context: context) + } + + override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { + guard context == self.context else {return} + } func configureViews() { diff --git a/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift b/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift index 6f63cfb6..d012d24e 100644 --- a/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift +++ b/Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift @@ -26,9 +26,7 @@ class LibrarySplitViewController: UISplitViewController, UISplitViewControllerDe } func dismiss() { - dismissViewControllerAnimated(true) { - ControllerRetainer.shared.didDismissLibrary() - } + dismissViewControllerAnimated(true, completion: nil) } // MARK: - UISplitViewControllerDelegate diff --git a/Kiwix-iOS/Controller/Main/MainController.swift b/Kiwix-iOS/Controller/Main/MainController.swift index 486fa586..dc22bec0 100644 --- a/Kiwix-iOS/Controller/Main/MainController.swift +++ b/Kiwix-iOS/Controller/Main/MainController.swift @@ -20,8 +20,6 @@ class MainController: UIViewController { @IBOutlet weak var tocLeadSpacing: NSLayoutConstraint! var tableOfContentsController: TableOfContentsController? - var bookmarkController: BookmarkController? - var bookmarkNav: UIViewController? var settingController: UIViewController? var welcomeController: UIViewController? let searchBar = SearchBar() @@ -82,8 +80,6 @@ class MainController: UIViewController { override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() tableOfContentsController = nil - bookmarkController = nil - bookmarkNav = nil settingController = nil welcomeController = nil } @@ -236,7 +232,7 @@ class MainController: UIViewController { } func showLibraryButtonTapped() { - let controller = ControllerRetainer.shared.library + let controller = ControllerRetainer.library controller.modalPresentationStyle = .FullScreen presentViewController(controller, animated: true, completion: nil) } diff --git a/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift b/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift index a8c289a3..0de962b6 100644 --- a/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift +++ b/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift @@ -32,8 +32,7 @@ extension MainController: LPTBarButtonItemDelegate, TableOfContentsDelegate, Zim let operation = UpdateWidgetDataSourceOperation() GlobalQueue.shared.addOperation(operation) - guard let controller = bookmarkController ?? UIStoryboard.main.initViewController("BookmarkController", type: BookmarkController.self) else {return} - bookmarkController = controller + let controller = ControllerRetainer.bookmarkStar controller.bookmarkAdded = article.isBookmarked controller.transitioningDelegate = self controller.modalPresentationStyle = .OverFullScreen @@ -79,11 +78,11 @@ extension MainController: LPTBarButtonItemDelegate, TableOfContentsDelegate, Zim } func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { - ControllerRetainer.shared.search.startSearch(searchText, delayed: true) + ControllerRetainer.search.startSearch(searchText, delayed: true) } func searchBarSearchButtonClicked(searchBar: UISearchBar) { - ControllerRetainer.shared.search.searchResultTBVC?.selectFirstResultIfPossible() + ControllerRetainer.search.searchResultTBVC?.selectFirstResultIfPossible() } // MARK: - UIPopoverPresentationControllerDelegate diff --git a/Kiwix-iOS/Controller/Main/MainControllerShowHide.swift b/Kiwix-iOS/Controller/Main/MainControllerShowHide.swift index 1582f706..7bb25a1b 100644 --- a/Kiwix-iOS/Controller/Main/MainControllerShowHide.swift +++ b/Kiwix-iOS/Controller/Main/MainControllerShowHide.swift @@ -51,7 +51,7 @@ extension MainController { } private func showSearchResultController(animated animated: Bool) { - let controller = ControllerRetainer.shared.search + let controller = ControllerRetainer.search guard !childViewControllers.contains(controller) else {return} addChildViewController(controller) controller.view.translatesAutoresizingMaskIntoConstraints = false @@ -150,8 +150,7 @@ extension MainController { // MARK: - Show Bookmark func showBookmarkTBVC() { - guard let controller = bookmarkNav ?? UIStoryboard.main.initViewController("BookmarkNav", type: UINavigationController.self) else {return} - bookmarkNav = controller + let controller = ControllerRetainer.bookmark controller.modalPresentationStyle = .FormSheet presentViewController(controller, animated: true, completion: nil) } diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 87672311..f5ab7d0d 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.7.1685 + 1.7.1706 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Bookmark.storyboard b/Kiwix-iOS/Storyboard/Bookmark.storyboard new file mode 100644 index 00000000..41040d97 --- /dev/null +++ b/Kiwix-iOS/Storyboard/Bookmark.storyboard @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kiwix-iOS/Storyboard/Main.storyboard b/Kiwix-iOS/Storyboard/Main.storyboard index 994db377..c86fcf8d 100644 --- a/Kiwix-iOS/Storyboard/Main.storyboard +++ b/Kiwix-iOS/Storyboard/Main.storyboard @@ -1,162 +1,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -237,14 +86,14 @@ - - - - + + + + @@ -261,15 +110,15 @@ - - - - + + + + @@ -402,11 +251,11 @@ + - @@ -421,10 +270,10 @@ + - @@ -436,9 +285,9 @@ - + @@ -485,143 +334,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 3e18bae2..461e1b16 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.7.2146 + 1.7.2193 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index f16dc9ed..77867d37 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -110,6 +110,7 @@ 97C005D61D64B3B0004352E8 /* Library.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C005D51D64B3B0004352E8 /* Library.storyboard */; }; 97C005D81D64B99E004352E8 /* LibrarySplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97C005D71D64B99E004352E8 /* LibrarySplitViewController.swift */; }; 97C005DC1D64BEFE004352E8 /* CloudBooksController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97C005DB1D64BEFE004352E8 /* CloudBooksController.swift */; }; + 97C601DC1D7F15C400362D4F /* Bookmark.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C601DB1D7F15C400362D4F /* Bookmark.storyboard */; }; 97D452BE1D1723FF0033666F /* CollectionViewCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */; }; 97D55EF61D2075180081B523 /* TableOfContentsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D55EF51D2075180081B523 /* TableOfContentsController.swift */; }; 97D6811B1D6E2A7100E5FA99 /* DownloadTasksController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6811A1D6E2A7100E5FA99 /* DownloadTasksController.swift */; }; @@ -332,6 +333,7 @@ 97C005D51D64B3B0004352E8 /* Library.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Library.storyboard; path = "Kiwix-iOS/Storyboard/Library.storyboard"; sourceTree = SOURCE_ROOT; }; 97C005D71D64B99E004352E8 /* LibrarySplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LibrarySplitViewController.swift; path = "Kiwix-iOS/Controller/Library/LibrarySplitViewController.swift"; sourceTree = SOURCE_ROOT; }; 97C005DB1D64BEFE004352E8 /* CloudBooksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CloudBooksController.swift; sourceTree = ""; }; + 97C601DB1D7F15C400362D4F /* Bookmark.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Bookmark.storyboard; sourceTree = ""; }; 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCells.swift; sourceTree = ""; }; 97D55EF51D2075180081B523 /* TableOfContentsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableOfContentsController.swift; path = "Kiwix-iOS/Controller/TableOfContentsController.swift"; sourceTree = SOURCE_ROOT; }; 97D6811A1D6E2A7100E5FA99 /* DownloadTasksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadTasksController.swift; sourceTree = ""; }; @@ -789,13 +791,14 @@ isa = PBXGroup; children = ( 975227CA1D0227E8001D1DDE /* Main.storyboard */, + 97C601DB1D7F15C400362D4F /* Bookmark.storyboard */, 97C005D51D64B3B0004352E8 /* Library.storyboard */, 97F03CE11D2440470040D26E /* Search.storyboard */, 975227CB1D0227E8001D1DDE /* Setting.storyboard */, 9734E54D1D289D060061C39B /* Welcome.storyboard */, ); name = Storyboards; - path = Kiwix; + path = Storyboard; sourceTree = ""; }; 978C58821C1CCDAF0077AE47 /* Controllers */ = { @@ -1272,6 +1275,7 @@ 971A10161D022872007FC62C /* Assets.xcassets in Resources */, 971A10771D022F05007FC62C /* Localizable.stringsdict in Resources */, 97E850CB1D2DA5B300A9F688 /* About.html in Resources */, + 97C601DC1D7F15C400362D4F /* Bookmark.storyboard in Resources */, 975227CD1D0227E8001D1DDE /* Main.storyboard in Resources */, 975227CE1D0227E8001D1DDE /* Setting.storyboard in Resources */, 971A10801D022F74007FC62C /* Pic_I.png in Resources */, diff --git a/Kiwix.xcodeproj/project.xcworkspace/xcuserdata/Chrisli.xcuserdatad/UserInterfaceState.xcuserstate b/Kiwix.xcodeproj/project.xcworkspace/xcuserdata/Chrisli.xcuserdatad/UserInterfaceState.xcuserstate index ef7b79f3..582c4c24 100644 Binary files a/Kiwix.xcodeproj/project.xcworkspace/xcuserdata/Chrisli.xcuserdatad/UserInterfaceState.xcuserstate and b/Kiwix.xcodeproj/project.xcworkspace/xcuserdata/Chrisli.xcuserdatad/UserInterfaceState.xcuserstate differ