diff --git a/Kiwix-iOS/Controller/Main/MainController.swift b/Kiwix-iOS/Controller/Main/MainController.swift index 8698e108..1c79f9f6 100644 --- a/Kiwix-iOS/Controller/Main/MainController.swift +++ b/Kiwix-iOS/Controller/Main/MainController.swift @@ -7,6 +7,7 @@ // import UIKit +import WebKit class MainController: UIViewController { @@ -18,7 +19,6 @@ class MainController: UIViewController { override func viewDidLoad() { super.viewDidLoad() -// webView.loadRequest(URLRequest(url: URL(string: "about:blank")!)) navigationItem.titleView = searchBar searchBar.delegate = self buttons.delegate = self diff --git a/Kiwix-iOS/Controller/Main/MainDelegates.swift b/Kiwix-iOS/Controller/Main/MainDelegates.swift index 5af15634..36561057 100644 --- a/Kiwix-iOS/Controller/Main/MainDelegates.swift +++ b/Kiwix-iOS/Controller/Main/MainDelegates.swift @@ -95,7 +95,6 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate { present(controller, animated: true, completion: nil) return false } - controllers.navigationList.startLoading(requestURL: url) return true } @@ -107,8 +106,8 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate { guard let title = JS.getTitle(from: webView) else {return} searchBar.title = title - buttons.back.tintColor = controllers.navigationList.canGoBack ? nil : UIColor.gray - buttons.forward.tintColor = controllers.navigationList.canGoForward ? nil : UIColor.gray + buttons.back.tintColor = webView.canGoBack ? nil : UIColor.gray + buttons.forward.tintColor = webView.canGoForward ? nil : UIColor.gray } func webView(_ webView: UIWebView, didFailLoadWithError error: Error) { @@ -128,11 +127,11 @@ extension MainController { extension MainController: ButtonDelegates, SearchContainerDelegate { func didTapBackButton() { -// navigationList.goBack(webView: webView) + webView.goBack() } func didTapForwardButton() { -// navigationList.goForward(webView: webView) + webView.goForward() } func didTapTOCButton() { @@ -152,19 +151,9 @@ extension MainController: ButtonDelegates, SearchContainerDelegate { } func didLongPressBackButton() { - let controller = controllers.navigationList - controller.type = .back - controller.delegate = self - let nav = UINavigationController(rootViewController: controller) - present(nav, animated: true, completion: nil) } func didLongPressForwardButton() { - let controller = controllers.navigationList - controller.type = .forward - controller.delegate = self - let nav = UINavigationController(rootViewController: controller) - present(nav, animated: true, completion: nil) } func didLongPressBookmarkButton() { @@ -174,12 +163,12 @@ extension MainController: ButtonDelegates, SearchContainerDelegate { // MARK: - NavigationListControllerDelegate -extension MainController: NavigationListControllerDelegate { - func load(url: URL) { - let request = URLRequest(url: url) - webView.loadRequest(request) - } -} +//extension MainController: NavigationListControllerDelegate { +// func load(url: URL) { +// let request = URLRequest(url: url) +// webView.loadRequest(request) +// } +//} // MARK: - SearchContainerDelegate diff --git a/Kiwix-iOS/Controller/Main/NavigationList.swift b/Kiwix-iOS/Controller/Main/NavigationList.swift deleted file mode 100644 index ce8f2c19..00000000 --- a/Kiwix-iOS/Controller/Main/NavigationList.swift +++ /dev/null @@ -1,75 +0,0 @@ -// -// NavigationStack.swift -// Kiwix -// -// Created by Chris Li on 11/20/16. -// Copyright © 2016 Chris Li. All rights reserved. -// - -import UIKit - -class NavigationList { - private var urls = [URL]() - private var currentIndex: Int? - - var currentURL: URL? { - guard let currentIndex = currentIndex else {return nil} - return urls.indices.contains(currentIndex) ? urls[currentIndex] : nil - } - - func webViewStartLoading(requestURL: URL) { - guard currentURL != requestURL else {return} - - if let index = currentIndex { - urls.removeLast(urls.count - index - 1) - urls.append(requestURL) - self.currentIndex = index + 1 - } else { - urls.append(requestURL) - self.currentIndex = 0 - } - } - - func goBack(webView: UIWebView, backListIndex: Int = 0) { - guard let currentIndex = currentIndex else {return} - let index = currentIndex - 1 - backListIndex - guard index >= 0 else {return} - self.currentIndex = index - - guard let url = currentURL else {return} - let request = URLRequest(url: url) - webView.loadRequest(request) - } - - func goForward(webView: UIWebView, forwardListIndex: Int = 0) { - guard let currentIndex = currentIndex else {return} - let index = currentIndex + 1 + forwardListIndex - guard index <= urls.count - 1 else {return} - self.currentIndex = index - - guard let url = currentURL else {return} - let request = URLRequest(url: url) - webView.loadRequest(request) - } - - var backList: [URL] { - guard let currentIndex = currentIndex else {return [URL]()} - return Array(urls.prefix(currentIndex)) - } - - var forwardList: [URL] { - guard let currentIndex = currentIndex else {return [URL]()} - return Array(urls.suffix(urls.count - currentIndex - 1)) - } - - var canGoBack: Bool { - guard let currentIndex = currentIndex else {return false} - return currentIndex >= 1 && urls.indices.contains(currentIndex - 1) - } - - var canGoForward: Bool { - guard let currentIndex = currentIndex else {return false} - return currentIndex >= 0 && urls.indices.contains(currentIndex + 1) - } -} - diff --git a/Kiwix-iOS/Controller/Main/NavigationListController.swift b/Kiwix-iOS/Controller/Main/NavigationListController.swift index de95eb4f..378003c3 100644 --- a/Kiwix-iOS/Controller/Main/NavigationListController.swift +++ b/Kiwix-iOS/Controller/Main/NavigationListController.swift @@ -2,123 +2,94 @@ // NavigationListController.swift // Kiwix // -// Created by Chris Li on 11/21/16. +// Created by Chris Li on 11/25/16. // Copyright © 2016 Chris Li. All rights reserved. // import UIKit class NavigationListController: UITableViewController { - - var type: NavigationListType = .back - weak var delegate: NavigationListControllerDelegate? - private var urls = [URL]() - private var currentIndex: Int? - + override func viewDidLoad() { super.viewDidLoad() - navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(dismiss(sender:))) + + // Uncomment the following line to preserve selection between presentations + // self.clearsSelectionOnViewWillAppear = false + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem() } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - tableView.reloadData() - } - - func dismiss(sender: UIBarButtonItem) { - dismiss(animated: true, completion: nil) - } - - // MARK: - Navigation List - - func startLoading(requestURL: URL) { - if let index = currentIndex { - if index == urls.count - 1 { - urls.append(requestURL) - currentIndex = index + 1 - } else { - if requestURL == urls[index] { - - } else if requestURL == urls[index + 1] { - currentIndex = index + 1 - } else { - urls.removeLast(urls.count - index - 1) - urls.append(requestURL) - currentIndex = index + 1 - } - } - } else { - urls.append(requestURL) - currentIndex = 0 - } - } - - func urlMapping(indexPath: IndexPath) -> Int? { - guard let currentIndex = currentIndex else {return nil} - switch type { - case .back: - return currentIndex - indexPath.row - 1 - case .forward: - return currentIndex + indexPath.row + 1 - } - } - - var canGoBack: Bool { - guard let index = currentIndex else {return false} - return index >= 1 - } - - var canGoForward: Bool { - guard let index = currentIndex else {return false} - return index <= urls.count - 2 + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { - return 1 + // #warning Incomplete implementation, return the number of sections + return 0 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - guard let currentIndex = currentIndex else {return 0} - switch type { - case .back: - return currentIndex - case .forward: - return urls.count - currentIndex - 1 - } + // #warning Incomplete implementation, return the number of rows + return 0 } + /* override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) - - if let index = urlMapping(indexPath: indexPath) { - let url = urls[index] - cell.textLabel?.text = url.lastPathComponent - } + let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) + + // Configure the cell... - return cell } - - // MARK: - Table view delegate - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - dismiss(animated: true, completion: nil) - if let index = urlMapping(indexPath: indexPath) { - let url = urls[index] - currentIndex = index - delegate?.load(url: url) - } - + */ + + /* + // Override to support conditional editing of the table view. + override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { + // Return false if you do not want the specified item to be editable. + return true } -} + */ -protocol NavigationListControllerDelegate: class { - func load(url: URL) -} + /* + // Override to support editing the table view. + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == .delete { + // Delete the row from the data source + tableView.deleteRows(at: [indexPath], with: .fade) + } else if editingStyle == .insert { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + + /* + // Override to support rearranging the table view. + override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { + + } + */ + + /* + // Override to support conditional rearranging of the table view. + override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { + // Return false if you do not want the item to be re-orderable. + return true + } + */ + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ -enum NavigationListType { - case back, forward } diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index bf12c00c..484703f4 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.3227 + 1.8.3265 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Main.storyboard b/Kiwix-iOS/Storyboard/Main.storyboard index 212332f6..308d0e37 100644 --- a/Kiwix-iOS/Storyboard/Main.storyboard +++ b/Kiwix-iOS/Storyboard/Main.storyboard @@ -100,14 +100,14 @@ - + - + - + - + - + - +