Skip to content

Commit

Permalink
Merge pull request mozilla-mobile#85 from wesj/newHistoryPanel
Browse files Browse the repository at this point in the history
Bug 1116537 - New history panel
  • Loading branch information
wes johnston committed Jan 17, 2015
2 parents 55b0297 + 9b01ded commit 91f225d
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 32 deletions.
26 changes: 26 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
0B79B18B1A3F6DE900DBECB3 /* Site.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB952B1A3B9918000F2B0F /* Site.swift */; };
0B925B491A5C56E1007EA8E7 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; };
0B9E3DE71A23FBD1008A7877 /* TestPanels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B9E3DE31A23FBD1008A7877 /* TestPanels.swift */; };
0BA2E3FC1A69D754000581FA /* History.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3343021A5CADA2000AE428 /* History.swift */; };
0BA2E4001A69D755000581FA /* History.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3343021A5CADA2000AE428 /* History.swift */; };
0BA2E4011A69D755000581FA /* History.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3343021A5CADA2000AE428 /* History.swift */; };
0BA2E4021A69D765000581FA /* SQLiteHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 282DA44F1A68BFEF00A406E2 /* SQLiteHistory.swift */; };
0BA2E4031A69D766000581FA /* SQLiteHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 282DA44F1A68BFEF00A406E2 /* SQLiteHistory.swift */; };
0BA2E4041A69D767000581FA /* SQLiteHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 282DA44F1A68BFEF00A406E2 /* SQLiteHistory.swift */; };
0BA2E4051A69D769000581FA /* HistoryTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3342F81A5CAD94000AE428 /* HistoryTable.swift */; };
0BA2E4061A69D76A000581FA /* HistoryTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3342F81A5CAD94000AE428 /* HistoryTable.swift */; };
0BA2E4071A69D77C000581FA /* BrowserDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3342CC1A5CA893000AE428 /* BrowserDB.swift */; };
0BA2E4081A69D77D000581FA /* BrowserDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3342CC1A5CA893000AE428 /* BrowserDB.swift */; };
0BA2E4091A69D798000581FA /* SwiftData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B0E923E1A6079B0006A606F /* SwiftData.swift */; };
0BA2E40A1A69D799000581FA /* SwiftData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B0E923E1A6079B0006A606F /* SwiftData.swift */; };
0BA2E40B1A69D9CC000581FA /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3342DB1A5CA929000AE428 /* libsqlite3.0.dylib */; };
0BA8964B1A250E6500C1010C /* AccountTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA896491A250E6500C1010C /* AccountTest.swift */; };
0BA8964C1A250E6500C1010C /* TestBookmarks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA8964A1A250E6500C1010C /* TestBookmarks.swift */; };
0BD19A5F1A2530320084FBA7 /* TabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F84B22221A09122500AAB793 /* TabBarViewController.swift */; };
Expand Down Expand Up @@ -437,6 +450,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0BA2E40B1A69D9CC000581FA /* libsqlite3.0.dylib in Frameworks */,
E418D0E01A25634D00CAE47A /* Alamofire.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1175,21 +1189,25 @@
282DA4821A697EC900A406E2 /* BookmarksREST.swift in Sources */,
0BD19A691A2530B60084FBA7 /* BookmarksViewController.swift in Sources */,
0BA8964B1A250E6500C1010C /* AccountTest.swift in Sources */,
0BA2E4091A69D798000581FA /* SwiftData.swift in Sources */,
0BD19A701A2530DE0084FBA7 /* Tabs.swift in Sources */,
0B657B451A3B9CAB005A9E43 /* Site.swift in Sources */,
F84B21DA1A090F8100AAB793 /* ClientTests.swift in Sources */,
E42CCDEE1A23C2C600B794D3 /* Clients.swift in Sources */,
28784D451A39C48900021E35 /* Bytes.swift in Sources */,
0BA2E4071A69D77C000581FA /* BrowserDB.swift in Sources */,
D34DC8611A16C47300D49B7B /* Profile.swift in Sources */,
D34DC8621A16C49600D49B7B /* AccountManager.swift in Sources */,
0BD19A6B1A2530C20084FBA7 /* SiteTableViewController.swift in Sources */,
E42CCE021A24C4E300B794D3 /* ExtensionUtils.swift in Sources */,
28C0779C1A3B065800834FE5 /* TokenServerClientTests.swift in Sources */,
282DA4811A697EB100A406E2 /* RestAPI.swift in Sources */,
0B9E3DE71A23FBD1008A7877 /* TestPanels.swift in Sources */,
0BA2E4051A69D769000581FA /* HistoryTable.swift in Sources */,
D34C5AF31A5E0C9B00E0DF7B /* SWXMLHash.swift in Sources */,
D3FA77971A43B5390010CD32 /* OpenSearch.swift in Sources */,
D3FA777B1A43B2990010CD32 /* SearchTests.swift in Sources */,
0BA2E4021A69D765000581FA /* SQLiteHistory.swift in Sources */,
0B657B461A3B9CAB005A9E43 /* Favicon.swift in Sources */,
D3C744CE1A687D6C004CE85D /* URIFixup.swift in Sources */,
0BD19A6D1A2530C80084FBA7 /* ReaderViewController.swift in Sources */,
Expand All @@ -1210,6 +1228,7 @@
28C077981A3B064000834FE5 /* CryptoTests.swift in Sources */,
0BD19A6A1A2530BB0084FBA7 /* HistoryViewController.swift in Sources */,
0BD19A5F1A2530320084FBA7 /* TabBarViewController.swift in Sources */,
0BA2E3FC1A69D754000581FA /* History.swift in Sources */,
28C0779E1A3B066000834FE5 /* RecordTests.swift in Sources */,
0BE1083A1A1B1ED200D4B712 /* Locking.swift in Sources */,
);
Expand All @@ -1222,22 +1241,27 @@
D3C744CF1A687D6C004CE85D /* URIFixup.swift in Sources */,
0B79B18A1A3F6DE900DBECB3 /* Site.swift in Sources */,
E418D0DA1A251B3200CAE47A /* AccountManager.swift in Sources */,
0BA2E4031A69D766000581FA /* SQLiteHistory.swift in Sources */,
0BA2E4061A69D76A000581FA /* HistoryTable.swift in Sources */,
0BD2C61D1A643B6000BB4BB9 /* Locking.swift in Sources */,
282DA46D1A68C15100A406E2 /* SearchEngines.swift in Sources */,
28784D491A39C48900021E35 /* Bytes.swift in Sources */,
E418D0DC1A251B3200CAE47A /* Clients.swift in Sources */,
0B79B1881A3F6DE000DBECB3 /* Favicon.swift in Sources */,
282DA4741A68C1FE00A406E2 /* OpenSearch.swift in Sources */,
0B925B491A5C56E1007EA8E7 /* Cursor.swift in Sources */,
0BA2E4001A69D755000581FA /* History.swift in Sources */,
28784D1A1A38CA9400021E35 /* Bookmarks.swift in Sources */,
E42CCE031A24C4E300B794D3 /* ExtensionUtils.swift in Sources */,
0BA2E40A1A69D799000581FA /* SwiftData.swift in Sources */,
D34C5AF41A5E0C9B00E0DF7B /* SWXMLHash.swift in Sources */,
E418D0D91A251B3200CAE47A /* Profile.swift in Sources */,
282DA4701A68C16900A406E2 /* FileAccessor.swift in Sources */,
F8708D321A0970B70051AB07 /* ShareViewController.swift in Sources */,
D31A0FC91A65D6D000DC8C7E /* SearchSuggestClient.swift in Sources */,
E418D0DF1A251B3200CAE47A /* RestAPI.swift in Sources */,
28CDA55C1A43C37C005C318C /* ProfilePrefs.swift in Sources */,
0BA2E4081A69D77D000581FA /* BrowserDB.swift in Sources */,
E41A7D4B1A1BE04500245963 /* InitialViewController.swift in Sources */,
0B79B17F1A3F6DD500DBECB3 /* Favicons.swift in Sources */,
E418D0DB1A251B3200CAE47A /* BookmarksREST.swift in Sources */,
Expand All @@ -1261,9 +1285,11 @@
0B3342D71A5CA89E000AE428 /* BrowserDB.swift in Sources */,
D31A0FCA1A65D6D000DC8C7E /* SearchSuggestClient.swift in Sources */,
E42CCE041A24C4E300B794D3 /* ExtensionUtils.swift in Sources */,
0BA2E4041A69D767000581FA /* SQLiteHistory.swift in Sources */,
F8708D2A1A0970B40051AB07 /* ActionViewController.swift in Sources */,
28784D4A1A39C48A00021E35 /* Bytes.swift in Sources */,
282DA4721A68C1D000A406E2 /* HistoryTable.swift in Sources */,
0BA2E4011A69D755000581FA /* History.swift in Sources */,
28784D1B1A38CA9400021E35 /* Bookmarks.swift in Sources */,
D34C5AF51A5E0C9C00E0DF7B /* SWXMLHash.swift in Sources */,
D35179BF1A5C8D5F00E7622E /* SearchEngines.swift in Sources */,
Expand Down
11 changes: 9 additions & 2 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow!
var profile: Profile!

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
profile = RESTAccountProfile(localName: "profile", credential: NSURLCredential(), logoutCallback: { (profile) -> () in
// Nothing to do
})

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window.backgroundColor = UIColor.whiteColor()

self.window.rootViewController = BrowserViewController()

let controller = BrowserViewController()
controller.profile = profile
self.window.rootViewController = controller
self.window.makeKeyAndVisible()

return true
}

Expand Down
2 changes: 1 addition & 1 deletion Client/DataAccess/SQL/BrowserDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BrowserDB {
return Cursor(status: .Failure, msg: "Invalid table name")
}

private let debug_enabled = false
private let debug_enabled = true
private func debug(err: NSError) {
debug("\(err.code): \(err.localizedDescription)")
}
Expand Down
2 changes: 1 addition & 1 deletion Client/DataAccess/SQL/HistoryTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HistoryTable: Table {
debug("Insert into \(name) \(item)")
if let site = item as? Site {
let query = "INSERT INTO \(self.name) (guid, url, title) VALUES (?,?,?)"
let args = [site.guid, site.url, site.title]
let args: [AnyObject?] = [site.guid, site.url, site.title]
if let error = db.executeChange(query, withArgs: args) {
err = error
return 0
Expand Down
3 changes: 1 addition & 2 deletions Client/DataAccess/SQL/SQLiteHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class SqliteHistory : History {
if err != nil {
self.debug("Clear failed: \(err!.localizedDescription)")
}
complete(success: err == nil)
}
}

Expand All @@ -44,7 +43,7 @@ class SqliteHistory : History {
}
}

private let debug_enabled = false
private let debug_enabled = true
private func debug(msg: String) {
if debug_enabled {
println("HistorySqlite: " + msg)
Expand Down
12 changes: 11 additions & 1 deletion Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ private let ToolbarHeight: CGFloat = 44
class BrowserViewController: UIViewController {
private var toolbar: BrowserToolbar!
private let tabManager = TabManager()
var profile: Profile!

override func viewDidLoad() {
let headerView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.ExtraLight))
Expand Down Expand Up @@ -43,7 +44,6 @@ class BrowserViewController: UIViewController {

extension BrowserViewController: BrowserToolbarDelegate {
func didBeginEditing() {
let profile = MockAccountProfile()
let controller = TabBarViewController()
controller.profile = profile
controller.delegate = self
Expand Down Expand Up @@ -156,6 +156,16 @@ extension BrowserViewController: WKNavigationDelegate {
toolbar.updateFowardStatus(webView.canGoForward)
}

func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
let notificationCenter = NSNotificationCenter.defaultCenter()
var info = [NSObject: AnyObject]()
info["url"] = webView.URL
info["title"] = webView.title

notificationCenter.postNotificationName("LocationChange", object: self, userInfo: info)
}


override func observeValueForKeyPath(keyPath: String, ofObject object:
AnyObject, change:[NSObject: AnyObject], context:
UnsafeMutablePointer<Void>) {
Expand Down
101 changes: 89 additions & 12 deletions Client/Frontend/History/HistoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,106 @@

import UIKit

class HistoryViewController: UIViewController, ToolbarViewProtocol {
class HistoryViewController: UITableViewController, UrlViewController {
private let CELL_IDENTIFIER = "HISTORY_CELL"
private let HEADER_IDENTIFIER = "HISTORY_HEADER"

var history: Cursor? = nil
var _profile: Profile? = nil
var delegate: UrlViewControllerDelegate? = nil

var profile: Profile! {
get {
return _profile
}

set (profile) {
self._profile = profile
profile.history.get(nil, options: nil, complete: { (data: Cursor) -> Void in
if data.status != .Success {
println("Err: \(data.statusMessage)")
} else {
self.history = data
}
})
}
}

var profile: Profile!
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
tableView.registerClass(CustomCell.self, forCellReuseIdentifier: CELL_IDENTIFIER)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if var hist = self.history {
return hist.count
}
return 0
}

// UITableViewController doesn't let us specify a style for recycling views. We override the default style here.
private class CustomCell : UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
// ignore the style argument, use our own to override
super.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
textLabel?.font = UIFont(name: "FiraSans-SemiBold", size: 13)
textLabel?.textColor = UIColor.darkGrayColor()
indentationWidth = 20

detailTextLabel?.textColor = UIColor.lightGrayColor()
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

private let FAVICON_SIZE = 32
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) as UITableViewCell

if var hist = self.history {
if let site = hist[indexPath.row] as? Site {
// cell.imageView?.image = site.icon
cell.textLabel?.text = site.title
cell.detailTextLabel?.text = site.url
}
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
return cell
}
*/

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
}

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0
}

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if var hist = self.history {
if let site = hist[indexPath.row] as? Site {
if let url = NSURL(string: site.url) {
delegate?.didClickUrl(NSURL(string: site.url)!)
} else {
println("Error creating url for \(site.url)")
}
return
} else {
println("Could not find a site for \(indexPath)")
}
} else {
println("Could not get history")
}
}
}
6 changes: 3 additions & 3 deletions Client/Frontend/History/HistoryViewController.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HistoryViewController" customModule="ToolbarExperiment" customModuleProvider="target">
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HistoryViewController" customModule="Client" customModuleProvider="target">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
Expand Down
11 changes: 7 additions & 4 deletions Client/Frontend/TabBar/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import UIKit
private let ReuseIdentifier = "cell"
private let SuggestionsLimitCount = 3

protocol SearchViewControllerDelegate: class {
func didClickSearchResult(url: NSURL)
// A delegate to support clicking on rows in the view controller
// This needs to be accessible to objc for UIViewControllers to call it
@objc
protocol UrlViewControllerDelegate: class {
func didClickUrl(url: NSURL)
}

class SearchViewController: UIViewController {
weak var delegate: SearchViewControllerDelegate?
weak var delegate: UrlViewControllerDelegate?
private var tableView = UITableView()
private var sortedEngines = [OpenSearchEngine]()
private var suggestClient: SearchSuggestClient?
Expand Down Expand Up @@ -151,7 +154,7 @@ extension SearchViewController: UITableViewDelegate {
}

if let url = url {
delegate?.didClickSearchResult(url)
delegate?.didClickUrl(url)
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions Client/Frontend/TabBar/TabBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ protocol TabBarViewControllerDelegate: class {
func didEnterURL(url: NSURL)
}

class TabBarViewController: UIViewController, UITextFieldDelegate, SearchViewControllerDelegate {
// A protocol to support clicking on rows in the view controller
// This needs to be accessible to objc for UIViewControllers to implement it
@objc
protocol UrlViewController: class {
var delegate: UrlViewControllerDelegate? { get set }
}

class TabBarViewController: UIViewController, UITextFieldDelegate, UrlViewControllerDelegate {
var profile: Profile!
var notificationToken: NSObjectProtocol!
var panels: [ToolbarItem]!
Expand Down Expand Up @@ -59,6 +66,9 @@ class TabBarViewController: UIViewController, UITextFieldDelegate, SearchViewCon
hideCurrentViewController()
var vc = self.panels[newButtonIndex].generator(profile: self.profile)
self.showViewController(vc)
if let v = vc as? UrlViewController {
v.delegate = self
}

_selectedButtonIndex = newButtonIndex
}
Expand Down Expand Up @@ -266,7 +276,7 @@ class TabBarViewController: UIViewController, UITextFieldDelegate, SearchViewCon
return true
}

func didClickSearchResult(url: NSURL) {
func didClickUrl(url: NSURL) {
delegate?.didEnterURL(url)
dismissViewControllerAnimated(true, completion: nil)
}
Expand Down
2 changes: 1 addition & 1 deletion Providers/BookmarksREST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation
import Alamofire

public class BookmarksRESTModelFactory: BookmarksModelFactory, ShareToDestination {
class BookmarksRESTModelFactory: BookmarksModelFactory, ShareToDestination {
private let profile: RESTAccountProfile
private let sink: MemoryBookmarksSink = MemoryBookmarksSink()

Expand Down
Loading

0 comments on commit 91f225d

Please sign in to comment.