Commit 8fbda9a6 authored by Maarten Billemont's avatar Maarten Billemont

Some cleanup.

parent 30e64acc
Pipeline #32362610 failed with stage
in 2 minutes and 48 seconds
......@@ -5,7 +5,7 @@
import Foundation
class MPSiteDetailsViewController: UIViewController, MPSiteObserver {
class MPSiteDetailsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MPSiteObserver {
var site: MPSite? {
willSet {
self.site?.observers.unregister( self )
......@@ -17,7 +17,6 @@ class MPSiteDetailsViewController: UIViewController, MPSiteObserver {
}
}
let effectView = UIVisualEffectView( effect: UIBlurEffect( style: .light ) )
let closeButton = MPButton( title: "╳" )
let headingImageView = MPImageView( image: UIImage( named: "icon_sliders" ) )
let headingLabel = UILabel()
......@@ -42,13 +41,14 @@ class MPSiteDetailsViewController: UIViewController, MPSiteObserver {
override func viewDidLoad() {
// - View
self.effectView.contentView.layoutMargins = UIEdgeInsetsMake( 12, 12, 12, 12 )
self.view.backgroundColor = .black
self.contentView.backgroundColor = UIColor( white: 0.9, alpha: 1 )
self.closeButton.button.addTarget( self, action: #selector( close ), for: .touchUpInside )
self.headingImageView.preservesImageRatio = true
self.headingLabel.textColor = .white
self.headingLabel.shadowColor = .black
self.headingImageView.preservesImageRatio = true
if #available( iOS 11.0, * ) {
self.headingLabel.font = UIFont.preferredFont( forTextStyle: .largeTitle )
}
......@@ -57,24 +57,22 @@ class MPSiteDetailsViewController: UIViewController, MPSiteObserver {
}
self.headingLabel.font = UIFont.preferredFont( forTextStyle: .headline )
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.separatorStyle = .none
self.tableView.layer.cornerRadius = 8
let tableViewEffect = UIView( containing: self.tableView, withLayoutMargins: .zero )!
tableViewEffect.layer.shadowRadius = 8
tableViewEffect.layer.shadowOpacity = 0.382
self.tableView.layer.cornerRadius = 8
self.contentView.backgroundColor = UIColor( white: 0.9, alpha: 1 )
self.contentView.layer.shadowOpacity = 1
self.contentView.layer.shadowRadius = 80
// - Hierarchy
self.view.addSubview( self.effectView )
self.effectView.contentView.addSubview( self.contentView )
self.effectView.contentView.addSubview( self.closeButton )
self.view.addSubview( self.contentView )
self.view.addSubview( self.closeButton )
self.contentView.addSubview( self.headingImageView )
self.contentView.addSubview( self.headingLabel )
self.contentView.addSubview( tableViewEffect )
// - Layout
ViewConfiguration( view: self.effectView ).constrainToSuperview().activate()
ViewConfiguration( view: self.contentView )
.constrainTo { $1.leadingAnchor.constraint( equalTo: $0.leadingAnchor ) }
.constrainTo { $1.trailingAnchor.constraint( equalTo: $0.trailingAnchor ) }
......@@ -108,12 +106,24 @@ class MPSiteDetailsViewController: UIViewController, MPSiteObserver {
self.dismiss( animated: true )
}
// MARK: - UITableViewDelegate
// MARK: - UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
fatalError( "tableView(tableView:indexPath:) has not been implemented" )
}
// MARK: - MPSiteObserver
func siteDidChange() {
PearlMainQueue {
self.headingLabel.text = self.site?.siteName
self.contentView.layer.shadowColor = self.site?.color.cgColor
self.view.backgroundColor = self.site?.color
}
}
}
......@@ -53,15 +53,19 @@ class MPQuery {
class Result<V> : NSObject where V: Hashable {
let value: V
let key: String
let attributedKey : NSMutableAttributedString
var keyMatched = Set<String.Index>()
init(value: V, key: String) {
self.value = value
self.key = key
self.attributedKey = NSMutableAttributedString( string: self.key )
}
func keyMatched(at k: String.Index) {
self.keyMatched.insert( k )
self.attributedKey.addAttribute( NSAttributedStringKey.backgroundColor, value: UIColor.red,
range: NSRange( location: k.encodedOffset, length: 1 ) )
}
override func isEqual(_ object: Any?) -> Bool {
......
......@@ -7,6 +7,7 @@ import UIKit
class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUserObserver {
var observers = Observers<MPSitesViewObserver>()
let data = NSMutableArray()
var isSelecting = false
var user: MPUser? {
......@@ -18,7 +19,6 @@ class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUs
self.query = nil
}
}
let data = NSMutableArray()
var selectedSite: MPSite? {
didSet {
self.observers.notify { $0.siteWasSelected( selectedSite: self.selectedSite ) }
......@@ -58,10 +58,10 @@ class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUs
}
func updateSites() {
let newSites = [ MPQuery( self.query ?? "" ).find( self.user?.sortedSites ?? [] ) { $0.siteName } ]
let newSites = NSArray( object: MPQuery( self.query ?? "" ).find( self.user?.sortedSites ?? [] ) { $0.siteName } )
PearlMainQueue {
self.updateDataSource( self.data, toSections: newSites as NSArray, reloadItems: self.data, with: .automatic )
self.updateDataSource( self.data, toSections: newSites, reloadItems: self.data, with: .automatic )
}
}
......@@ -138,19 +138,12 @@ class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUs
}
}
}
override var isHighlighted: Bool {
didSet {
self.highlightedConfiguration.activated = self.isHighlighted
}
}
let indicatorView = UIView()
let passwordLabel = UILabel()
let nameLabel = UILabel()
let copyButton = MPButton( image: nil, title: "copy" )
let highlightedConfiguration = ViewConfiguration()
// MARK: - Life
required init?(coder aDecoder: NSCoder) {
......@@ -212,12 +205,6 @@ class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUs
.activate()
}
override func updateConstraints() {
super.updateConstraints()
self.highlightedConfiguration.activated = self.isHighlighted
}
@objc
func copySite() {
PearlNotMainQueue {
......@@ -250,14 +237,7 @@ class MPSitesView: UITableView, UITableViewDelegate, UITableViewDataSource, MPUs
func siteDidChange() {
PearlMainQueue {
var name: NSAttributedString = NSAttributedString( string: self.site?.siteName ?? "" )
if let result = self.result {
for match in result.keyMatched {
name = strra( name, NSRange( location: match.encodedOffset, length: 1 ),
[ NSAttributedStringKey.backgroundColor: UIColor.red ] )
}
}
self.nameLabel.attributedText = name
self.nameLabel.attributedText = self.result?.attributedKey
self.indicatorView.backgroundColor = self.site?.color.withAlphaComponent( 0.85 )
}
PearlNotMainQueue {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment