refactor: Minor code and UI improvements

This commit is contained in:
Andrea Busi
2021-03-23 19:09:43 +01:00
parent 88c0cda3a4
commit f7eeef58df
6 changed files with 50 additions and 12 deletions
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (weak, nonatomic, nullable, readonly) UIView *bannerContainerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bannerContainerHeightConstraint;
@property (nonatomic, readonly) BOOL isBannerVisible;
- (void)refreshUI;
@@ -17,6 +17,13 @@
@implementation EQNBaseViewController
#pragma mark - Accessories
- (BOOL)isBannerVisible
{
return ![EQNPurchaseUtility isProVersionEnabled];
}
#pragma mark - View Lifecycle
- (void)viewDidLoad
@@ -52,7 +59,7 @@
- (void)handleAdBanner
{
// ad banner mut be displayed only for non pro users
if ([EQNPurchaseUtility isProVersionEnabled]) {
if (!self.isBannerVisible) {
[self hideAdBanner];
return;
}
@@ -17,9 +17,9 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
// MARK: - State
override var availableFilters: [EQNFiltroMappa] {
// trick to show filtersView
[ .unGiorno ]
override var isFilterViewVisible: Bool {
// a custom filter view id displayed
true
}
weak var delegate: SeismicNetworksMapDetailViewControllerDelegate?
@@ -33,7 +33,7 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
private lazy var seismicFiltersView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .lightGray
view.backgroundColor = AppTheme.Colors.lightGray
// label with current selecte filter
view.addSubview(seismicsFilterLabel)
@@ -12,14 +12,22 @@ import MapKit
class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
/// Current filter
var filter = EQNFiltroMappa.unGiorno {
didSet {
updateUI()
}
}
/// Available filters
var availableFilters: [EQNFiltroMappa] {
[.unGiorno, .dodiciOre, .seiOre, .dueOre, .unOra, .dieciMinuti]
}
/// If `true`, the filter view is visible. Could be overridden by a subclass with a custom filter view
var isFilterViewVisible: Bool {
!availableFilters.isEmpty
}
// MARK: - Internal
/// Annotations displayed on the map
private var mapAnnotations = [MKAnnotation]()
@@ -57,7 +65,7 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
lazy var filtersView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .lightGray
view.backgroundColor = AppTheme.Colors.lightGray
// label with current selecte filter
view.addSubview(filterLabel)
@@ -106,13 +114,11 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
// MARK: - Private
private func setupUI() {
let isFilterVisible = !availableFilters.isEmpty
view.backgroundColor = .white
view.addSubview(mapView)
view.addSubview(closeButton)
view.addSubview(containerView)
if isFilterVisible {
if isFilterViewVisible {
view.addSubview(filtersView)
}
@@ -124,18 +130,21 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
bannerContainerHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: 55.0)
bannerContainerHeightConstraint?.isActive = true
if isFilterVisible {
view.backgroundColor = filtersView.backgroundColor // trick to simulate a bigger filters view
if isFilterViewVisible {
filtersView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
filtersView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
filtersView.bottomAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
filtersView.heightAnchor.constraint(equalToConstant: 40.0).isActive = true
}
if isFilterViewVisible && !isBannerVisible {
view.backgroundColor = filtersView.backgroundColor // trick to simulate a bigger filters view
}
mapView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
mapView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
mapView.bottomAnchor.constraint(equalTo: (isFilterVisible ? filtersView : containerView).topAnchor).isActive = true
mapView.bottomAnchor.constraint(equalTo: (isFilterViewVisible ? filtersView : containerView).topAnchor).isActive = true
}
// MARK: - View Lifecycle
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xCA",
"green" : "0xCA",
"red" : "0xCA"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -18,6 +18,7 @@ class AppTheme: NSObject {
static let green = UIColor(named: "Green")!
static let gray = UIColor(named: "Gray")!
static let darkGray = UIColor(named: "Gray (dark)")!
static let lightGray = UIColor(named: "Gray (light)")!
}
static let shared = AppTheme()