Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EKIRJASTO-77 Remove logo from view Browse books #65

Merged
1 change: 0 additions & 1 deletion Palace/Catalog/TPPCatalogUngroupedFeedViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ - (void)viewDidLoad
self.facetBarView.facetView.delegate = self;
self.facetBarView.facetView.dataSource = self.facetViewDataSource;

[self.facetBarView removeLogo]; //Added by Ellibs
[self.view addSubview:self.facetBarView];
[self.facetBarView autoPinEdgeToSuperviewEdge:ALEdgeLeading];
[self.facetBarView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
Expand Down
1 change: 0 additions & 1 deletion Palace/Holds/TPPHoldsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ - (void)viewDidLoad

self.facetBarView = [[TPPFacetBarView alloc] initWithOrigin:CGPointZero width:self.view.bounds.size.width];
self.facetBarView.delegate = self;
[self.facetBarView removeLogo]; //Added by Ellibs

[self.view addSubview:self.facetBarView];

Expand Down
149 changes: 56 additions & 93 deletions Palace/Views/TPPFacetBarView.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
//
// TTPFacetBarView.swift
//
// Last edited by E-KIRJASTO October 2024
//

import Foundation

@objc protocol TPPFacetBarViewDelegate {
func present(_ viewController: UIViewController)
}

@objcMembers class TPPFacetBarView : UIView {
var entryPointView: TPPEntryPointView = TPPEntryPointView()

private let accountSiteButton = UIButton()
private let borderHeight = 1.0 / UIScreen.main.scale;
private let toolbarHeight = CGFloat(40.0);
/*
TPPFacetBarView is a UIView that has two subviews:
- facetView
- entryPointView

In original Palace project the current library account's logo and name were displayed in a third subview called logoView
- E-kirjasto app does not display the logo or name separately in app's basic views (Browse books, My books, Reservations) and the logoView subview was removed from TPPFacetBarView.
- Also the functionality to show library details (the account page) when user taps said library logo or name, was removed from E-kirjasto app.
*/
@objcMembers class TPPFacetBarView: UIView {

/*
entryPointView
- class TPPEntryPointView
- is visible
- contains the segmented buttons for filtering the books catalogue in app's Browse books view
- see more details of this view in file TPPEntryPointView.swift
*/
var entryPointView: TPPEntryPointView = .init()

private let borderHeight = 1.0 / UIScreen.main.scale
private let toolbarHeight = CGFloat(40.0)

weak var delegate: TPPFacetBarViewDelegate?

/*
facetView
- class TPPFacetView
- hidden view
- the bottom line of the facetView marks the point where the catalogue's book lane title "freezes" for a while, until it's replaced with another lane title
- in other words, the facetView prevents the catalogue book lanes from visually sliding under the catalogue filter buttons when user scrolls the catalogue view up or down
*/
lazy var facetView: TPPFacetView = {
let view = TPPFacetView()

Expand All @@ -21,70 +50,21 @@ import Foundation

topBorderView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.9)
bottomBorderView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.9)

view.addSubview(bottomBorderView)
view.addSubview(topBorderView)

bottomBorderView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets.zero, excludingEdge: .top)
bottomBorderView.autoSetDimension(.height, toSize: borderHeight)
topBorderView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets.zero, excludingEdge: .bottom)
topBorderView.autoSetDimension(.height, toSize:borderHeight)
return view
}()

private lazy var logoView: UIView = {
let logoView = UIView()
logoView.backgroundColor = TPPConfiguration.readerBackgroundColor()

let imageHolder = UIView()
imageHolder.autoSetDimension(.height, toSize: 40.0)
imageHolder.autoSetDimension(.width, toSize: 40.0)
imageHolder.addSubview(imageView)

imageView.autoPinEdgesToSuperviewEdges()

let container = UIView()
logoView.addSubview(container)
container.addSubview(imageHolder)

container.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0))
imageHolder.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10.0, left: 0.0, bottom: 0.0, right: 0.0), excludingEdge: .trailing)

//let titleContainer = UIView()
//titleContainer.addSubview(titleLabel)
//titleLabel.autoPinEdgesToSuperviewEdges()
topBorderView.autoSetDimension(.height, toSize: borderHeight)

//container.addSubview(titleContainer)
//titleContainer.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0), excludingEdge: .leading)
//titleContainer.autoPinEdge(.leading, to: .trailing, of: imageView, withOffset: 10.0)

//logoView.addSubview(accountSiteButton)
//accountSiteButton.autoPinEdgesToSuperviewEdges()
//accountSiteButton.addTarget(self, action: #selector(showAccountPage), for: .touchUpInside)
return logoView
}()

private lazy var titleLabel: UILabel = {
let label = UILabel()
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.textAlignment = .center
label.text = AccountsManager.shared.currentAccount?.name
label.textColor = .gray
label.font = UIFont.boldSystemFont(ofSize: 18.0)
return label
}()

private lazy var imageView: UIImageView = {
let view = UIImageView(image: UIImage(named: "LaunchImageLogo"))
view.contentMode = .scaleAspectFill
return view
}()

@available(*, unavailable)
private override init(frame: CGRect) {
override private init(frame: CGRect) {
super.init(frame: frame)
NotificationCenter.default.addObserver(self, selector: #selector(updateLogo), name: NSNotification.TPPCurrentAccountDidChange, object: nil)
}

@available(*, unavailable)
Expand All @@ -93,62 +73,45 @@ import Foundation
}

init(origin: CGPoint, width: CGFloat) {

super.init(frame: CGRect(x: origin.x, y: origin.y, width: width, height: borderHeight + toolbarHeight + 52.0))
super.init(
frame: CGRect(
x: origin.x,
y: origin.y,
width: width,
height: borderHeight + toolbarHeight + 52.0
)
)

setupViews()
NotificationCenter.default.addObserver(self, selector: #selector(updateLogo), name: NSNotification.TPPCurrentAccountDidChange, object: nil)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

override func draw(_ rect: CGRect) {
super.draw(rect)
//logoView.layer.cornerRadius = logoView.frame.height/2
}

private func setupViews() {
backgroundColor = TPPConfiguration.backgroundColor()
entryPointView.isHidden = false;
facetView.isHidden = true;


entryPointView.isHidden = false
facetView.isHidden = true

addSubview(facetView)
addSubview(logoView)
addSubview(entryPointView)

setupConstraints()
updateLogo()
}

private func setupConstraints() {
entryPointView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets.zero, excludingEdge: .bottom)
facetView.autoPinEdge(toSuperviewEdge: .leading)
facetView.autoPinEdge(toSuperviewEdge: .trailing)

facetView.autoPinEdge(.top, to: .bottom, of: facetView, withOffset: 10.0)
facetView.autoPinEdge(toSuperviewEdge: .bottom, withInset: 10.0)
entryPointView.autoPinEdge(.bottom, to: .top, of: facetView)
logoView.autoPinEdge(.top, to: .bottom, of: facetView, withOffset: 10.0)
logoView.autoPinEdge(toSuperviewEdge: .bottom, withInset: 10.0)
logoView.autoAlignAxis(.vertical, toSameAxisOf: self, withOffset: -15)
logoView.autoConstrainAttribute(.width, to: .width, of: self, withMultiplier: 0.8, relation: .lessThanOrEqual)
}

@objc func updateLogo() {
imageView.image = UIImage(named: "LaunchImageLogo")
//titleLabel.text = AccountsManager.shared.currentAccount?.name
}

@objc func removeLogo() {
self.logoView.removeFromSuperview()
facetView.autoPinEdge(.top, to: .bottom, of: facetView, withOffset: 10.0) //Added by Ellibs
facetView.autoPinEdge(toSuperviewEdge: .bottom, withInset: 10.0)
}

@objc private func showAccountPage() {
guard let homePageUrl = AccountsManager.shared.currentAccount?.homePageUrl, let url = URL(string: homePageUrl) else { return }
let webController = BundledHTMLViewController(fileURL: url, title: AccountsManager.shared.currentAccount?.name.capitalized ?? "")
webController.hidesBottomBarWhenPushed = true
delegate?.present(webController)
}
}