Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

History Panel

  • Loading branch information
Tim Palade authored and mahmoud-adam85 committed May 11, 2018
1 parent 42da660 commit 4464da03dbd2d0d6038513652d08821997b3d366
@@ -499,6 +499,7 @@
AF77B8C5209B132700E7A0C4 /* CliqzHomePanelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF77B8C4209B132700E7A0C4 /* CliqzHomePanelViewController.swift */; };
AF7FDDBC205949AA00AA2280 /* ExpandableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7FDDAD205949A900AA2280 /* ExpandableView.swift */; };
AF99C8A2206935F0009404FF /* GhosteryButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF99C8A1206935F0009404FF /* GhosteryButton.swift */; };
AF9C111220A051FB003253D3 /* CliqzHistoryPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF9C111120A051FB003253D3 /* CliqzHistoryPanel.swift */; };
AFA1DE072088AF9600B27B8A /* AdBlocker in Resources */ = {isa = PBXBuildFile; fileRef = AFA1DDF82088AF9600B27B8A /* AdBlocker */; };
AFA1DE0A2088BDDB00B27B8A /* BlockListIdentifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA1DE092088BDDB00B27B8A /* BlockListIdentifiers.swift */; };
AFA1DE0C2088BE0500B27B8A /* BlockListFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA1DE0B2088BE0500B27B8A /* BlockListFileManager.swift */; };
@@ -1964,6 +1965,7 @@
AF77B8C4209B132700E7A0C4 /* CliqzHomePanelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliqzHomePanelViewController.swift; sourceTree = "<group>"; };
AF7FDDAD205949A900AA2280 /* ExpandableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExpandableView.swift; sourceTree = "<group>"; };
AF99C8A1206935F0009404FF /* GhosteryButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GhosteryButton.swift; sourceTree = "<group>"; };
AF9C111120A051FB003253D3 /* CliqzHistoryPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliqzHistoryPanel.swift; sourceTree = "<group>"; };
AFA1DDF82088AF9600B27B8A /* AdBlocker */ = {isa = PBXFileReference; lastKnownFileType = folder; path = AdBlocker; sourceTree = "<group>"; };
AFA1DE092088BDDB00B27B8A /* BlockListIdentifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockListIdentifiers.swift; sourceTree = "<group>"; };
AFA1DE0B2088BE0500B27B8A /* BlockListFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockListFileManager.swift; sourceTree = "<group>"; };
@@ -3623,6 +3625,7 @@
children = (
AF77B8C4209B132700E7A0C4 /* CliqzHomePanelViewController.swift */,
AFF2874D209B54F6001E9B59 /* CliqzHomePanels.swift */,
AF9C111120A051FB003253D3 /* CliqzHistoryPanel.swift */,
);
path = HomePanel;
sourceTree = "<group>";
@@ -6453,6 +6456,7 @@
4F69309A2048185600FB0B2E /* TopSitesDataSource.swift in Sources */,
E4CD9F6D1A77DD2800318571 /* ReaderModeStyleViewController.swift in Sources */,
1EEA368120613C17003B6AD5 /* SendCrashReportsTableViewController.swift in Sources */,
AF9C111220A051FB003253D3 /* CliqzHistoryPanel.swift in Sources */,
4F3046B8204FF65800C99162 /* LocationManager.swift in Sources */,
D0FCF7F51FE45842004A7995 /* UserScriptManager.swift in Sources */,
E4A960061ABB9C450069AD6F /* ReaderModeUtils.swift in Sources */,
@@ -7,10 +7,15 @@ import Shared
import Storage
import XCGLogger
import Deferred

/* Cliqz
private typealias SectionNumber = Int
private typealias CategoryNumber = Int
private typealias CategorySpec = (section: SectionNumber?, rows: Int, offset: Int)
*/

typealias SectionNumber = Int
typealias CategoryNumber = Int
typealias CategorySpec = (section: SectionNumber?, rows: Int, offset: Int)

private struct HistoryPanelUX {
static let WelcomeScreenItemTextColor = UIColor.gray
@@ -44,8 +49,12 @@ class HistoryPanel: SiteTableViewController, HomePanel {
private let Today = getDate(0)
private let Yesterday = getDate(-1)
private let ThisWeek = getDate(-7)
/* Cliqz
private var categories: [CategorySpec] = [CategorySpec]() // Category number (index) -> (UI section, row count, cursor offset).
private var sectionLookup = [SectionNumber: CategoryNumber]() // Reverse lookup from UI section to data category.
*/
var categories: [CategorySpec] = [CategorySpec]() // Category number (index) -> (UI section, row count, cursor offset).
var sectionLookup = [SectionNumber: CategoryNumber]() // Reverse lookup from UI section to data category.
var syncDetailText = ""
var hasRecentlyClosed: Bool {
@@ -275,7 +284,7 @@ class HistoryPanel: SiteTableViewController, HomePanel {
}
}
}

fileprivate func siteForIndexPath(_ indexPath: IndexPath) -> Site? {
let offset = self.categories[sectionLookup[indexPath.section]!].offset
return data[indexPath.row + offset]
@@ -300,7 +309,10 @@ class HistoryPanel: SiteTableViewController, HomePanel {
}

// UI sections disappear as categories empty. We need to translate back and forth.
/* Cliqz
private func uiSectionToCategory(_ section: SectionNumber) -> CategoryNumber {
*/
func uiSectionToCategory(_ section: SectionNumber) -> CategoryNumber {
for i in 0..<self.categories.count {
if let s = self.categories[i].section, s == section {
return i
@@ -0,0 +1,250 @@
//
// CliqzHistoryPanel.swift
// Client
//
// Created by Tim Palade on 5/7/18.
// Copyright © 2018 Cliqz. All rights reserved.
//
import UIKit
import Shared
import Storage
import QuartzCore

struct CliqzHistoryPanelUX {
static let iconSize: CGFloat = 44.0
static let iconCornerRadius: CGFloat = 8.0
static let separatorLeftInset: CGFloat = 10.0
}

class CliqzHistoryPanel: HistoryPanel {
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = .clear
tableView.separatorColor = UIColor.white.withAlphaComponent(0.4)
tableView.register(CliqzSiteTableViewCell.self, forCellReuseIdentifier: "CliqzCellIdentifier")
}

override func numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
return 1
}

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

let container = UIView()
let bubble = UIView()
let label = UILabel()

//setup
label.text = self.tableView(tableView, titleForHeaderInSection: section)
label.font = UIFont.boldSystemFont(ofSize: 14)

bubble.addSubview(label)
container.addSubview(bubble)

//styling
bubble.backgroundColor = UIColor.white
bubble.layer.cornerRadius = 10


//constraints
bubble.snp.makeConstraints { (make) in
make.center.equalTo(container)
make.width.equalTo(label.snp.width).multipliedBy(1.5)
make.height.equalTo(20)
}

label.snp.makeConstraints { (make) in
make.center.equalTo(bubble)
}


return container
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30//super.tableView(tableView, heightForHeaderInSection: trueSection(section: section))
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
var title = String()
guard let sl = sectionLookup[trueSection(section: section)] else {return nil}
switch sl {
case 0: return nil
case 1: title = NSLocalizedString("Today", comment: "History tableview section header")
case 2: title = NSLocalizedString("Yesterday", comment: "History tableview section header")
case 3: title = NSLocalizedString("Last week", comment: "History tableview section header")
case 4: title = NSLocalizedString("Last month", comment: "History tableview section header")
default:
assertionFailure("Invalid history section \(section)")
}
return title
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.categories.isIndexValid(trueSection(section: section)) {
return self.categories[uiSectionToCategory(trueSection(section: section))].rows
}
return 0
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CliqzCellIdentifier", for: indexPath) //super.tableView(tableView, cellForRowAt: indexPath)
cell.accessoryType = .none
return configureSite(cell, for: indexPath)
}

override func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
if let site = self.siteForIndexPath(indexPath), let url = URL(string: site.url) {
let visitType = VisitType.typed // Means History, too.
if let homePanelDelegate = homePanelDelegate {
homePanelDelegate.homePanel(self, didSelectURL: url, visitType: visitType)
}
return
}
print("Error: No site or no URL when selecting row.")
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 74
}

override func configureSite(_ cell: UITableViewCell, for indexPath: IndexPath) -> UITableViewCell {
if let site = siteForIndexPath(indexPath), let cell = cell as? CliqzSiteTableViewCell {
cell.setLines(site.title, detailText: site.url)
cell.tag = indexPath.row

LogoLoader.loadLogo(site.tileURL.absoluteString, completionBlock: { (img, logoInfo, error) in
if cell.tag == indexPath.row {
if let img = img {
cell.customImageView.image = img
}
else if let info = logoInfo {
let placeholder = LogoPlaceholder(logoInfo: info)
cell.fakeIt(placeholder)
}
}
})
}
return cell
}


fileprivate func siteForIndexPath(_ indexPath: IndexPath) -> Site? {
let section = trueSection(section: indexPath.section)
let offset = self.categories[sectionLookup[section]!].offset
return data[indexPath.row + offset]
}

fileprivate func trueSection(section: Int) -> Int {
return section + 1
}
}

class CliqzSiteTableViewCell: SiteTableViewCell {

let imageShadowView = UIView()
let customImageView = UIImageView()
var fakeView: UIView? = nil

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
_textLabel.textColor = .white
_textLabel.font = UIFont.boldSystemFont(ofSize: 16)
_textLabel.layer.shadowColor = UIColor.black.cgColor
_textLabel.layer.shadowOpacity = 0.5
_textLabel.layer.shadowRadius = 0.5
_textLabel.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)

_detailTextLabel.textColor = .white
_detailTextLabel.font = UIFont.systemFont(ofSize: 14, weight: UIFontWeightMedium)
_detailTextLabel.layer.shadowColor = UIColor.black.cgColor
_detailTextLabel.layer.shadowOpacity = 0.5
_detailTextLabel.layer.shadowRadius = 0.5
_detailTextLabel.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)

separatorInset = UIEdgeInsets(top: 0, left: CliqzHistoryPanelUX.separatorLeftInset, bottom: 0, right: 0)
contentView.addSubview(customImageView)
contentView.addSubview(imageShadowView)
setupImageShadow()

customImageView.layer.cornerRadius = CliqzHistoryPanelUX.iconCornerRadius
customImageView.clipsToBounds = true
}


override func updateConstraints() {

customImageView.snp.remakeConstraints { (make) in
make.size.equalTo(CliqzHistoryPanelUX.iconSize)
make.centerY.equalToSuperview()
make.leading.equalToSuperview().offset(8)
}

super.updateConstraints()
}

override func setHighlighted(_ highlighted: Bool, animated: Bool) {
if highlighted {
self.backgroundColor = UIColor.white.withAlphaComponent(0.2)
}
else {
self.backgroundColor = UIColor.clear
}
}

override func setSelected(_ selected: Bool, animated: Bool) {
if selected {
self.backgroundColor = UIColor.white.withAlphaComponent(0.2)
}
else {
self.backgroundColor = UIColor.clear
}
}

override func prepareForReuse() {
super.prepareForReuse()
separatorInset = UIEdgeInsets(top: 0, left: CliqzHistoryPanelUX.separatorLeftInset, bottom: 0, right: 0)
setupImageShadow()
fakeView = nil
}

func fakeIt(_ view: UIView) {
contentView.addSubview(view)
view.snp.makeConstraints { (make) in
make.edges.equalTo(self.customImageView)
}
contentView.bringSubview(toFront: view)
view.layer.cornerRadius = CliqzHistoryPanelUX.iconCornerRadius
fakeView = view
}

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

private func setupImageShadow() {

imageShadowView.clipsToBounds = false
imageShadowView.backgroundColor = .white
contentView.sendSubview(toBack: imageShadowView)
contentView.bringSubview(toFront: customImageView)

imageShadowView.snp.remakeConstraints { (make) in
make.size.equalTo(CliqzHistoryPanelUX.iconSize)
make.center.equalTo(customImageView.snp.center)
}

imageShadowView.layer.cornerRadius = CliqzHistoryPanelUX.iconCornerRadius
imageShadowView.layer.shadowColor = UIColor.black.cgColor
imageShadowView.layer.shadowOpacity = 0.5
imageShadowView.layer.shadowRadius = 0.5
imageShadowView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
}
}

extension Array {
func isIndexValid(_ index: Int) -> Bool {
return index >= 0 && index < self.count
}
}
@@ -37,7 +37,7 @@ class CliqzHomePanels {

HomePanelDescriptor(
makeViewController: { profile in
let history = HistoryPanel()
let history = CliqzHistoryPanel()
history.profile = profile
let controller = UINavigationController(rootViewController: history)
controller.setNavigationBarHidden(true, animated: false)

0 comments on commit 4464da0

Please sign in to comment.