Skip to content

Commit

Permalink
Merge pull request #27 from descartae/chore/adjust-filter-facilities
Browse files Browse the repository at this point in the history
Chore/adjust filter facilities
  • Loading branch information
filipealva authored Feb 1, 2018
2 parents 8421d1b + 06875ff commit be5182f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ class FilterFacilitiesViewController: UIViewController {

var wasteTypesToFilter: [WasteType] = APIManager.filteringByWasteTypes
var applyFilters: (() -> Void)?
let locationManager = LocationManager.shared

// MARK: Life cycle

override func viewDidLoad() {
super.viewDidLoad()

setupTableView()

if DataStore.wasteTypes.count == 0 {
SVProgressHUD.show()
APIManager.loadData(wasteTypesOnly: true, completionHandler: { _ in
DispatchQueue.main.async {
self.tableView.reloadData()
SVProgressHUD.dismiss()
}
})
}
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -46,6 +57,16 @@ class FilterFacilitiesViewController: UIViewController {
// MARK: Actions

@objc func applySelection() {
guard locationManager.location != nil, !locationManager.shouldAskForAuthorization, !locationManager.isLocationDenied else {
let activateLocation = UIAlertController(title: "Ops!", message: "Você precisa permitir acesso a sua localização para que nós possamos buscar ou filtrar os pontos de coleta mais próximos.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Tudo bem", style: .default, handler: nil)
activateLocation.addAction(okAction)

present(activateLocation, animated: true, completion: nil)

return
}

APIManager.filteringByWasteTypes = wasteTypesToFilter
applyFilters?()
presentingViewController?.dismiss(animated: true, completion: nil)
Expand Down
4 changes: 2 additions & 2 deletions Descartae/Controllers/Intro/IntroViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class IntroViewController: AnimatedPagingScrollViewController {
let lighterGradient = GradientColor(.topToBottom, frame: frame, colors: [secondPageTop, secondPageBottom])
let alphaAnimation = AlphaAnimation(view: view)
alphaAnimation[0] = 1
alphaAnimation[0.5] = 0.8
alphaAnimation[0.5] = 0.9
alphaAnimation[1] = 1
alphaAnimation[1.5] = 0.8
alphaAnimation[1.5] = 0.9
alphaAnimation[2] = 1
let backgroundAnimation = BackgroundColorAnimation(view: view)
backgroundAnimation[0] = darkerGradient
Expand Down
9 changes: 2 additions & 7 deletions Descartae/Managers/APIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct DataStore {
static func resetFacilities() {
facilities = []
after = nil
StateManager.updateStateFor([.facilities, .nextPageIsUnavailable])
StateManager.notifyObersverAboutStateUpdates([.facilities, .nextPageIsUnavailable])
}
}

Expand Down Expand Up @@ -104,13 +104,8 @@ struct APIManager {
DataStore.facilities = facilities
}

// if DataStore.after != nil {
// StateManager.updateStateFor([.nextPageIsAvailable])
// } else {
// StateManager.updateStateFor([.nextPageIsUnavailable])
// }
let stateUpdates: [ObservableState] = DataStore.after != nil ? [.nextPageIsAvailable, .facilities] : [.nextPageIsUnavailable, .facilities]
StateManager.updateStateFor(stateUpdates)
StateManager.notifyObersverAboutStateUpdates(stateUpdates)

completionHandler?(error)
}
Expand Down
2 changes: 1 addition & 1 deletion Descartae/Managers/StateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct StateManager {

// MARK: State update notifications

static func updateStateFor(_ statesToNotify: [ObservableState]) {
static func notifyObersverAboutStateUpdates(_ statesToNotify: [ObservableState]) {
_ = statesToNotify.map { notificationCenter.post(name: $0.notification, object: nil) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TypeOfWasteFilterTableViewCell: UITableViewCell {
func bindWasteTypeData() {
name.text = wasteType.name
if let iconURL = URL(string: wasteType.icons.iosSmallUrl) {
icon.sd_setImage(with: iconURL)
icon.sd_setImage(with: iconURL, placeholderImage: UIImage(named: "icWasteEmpty"), completed: nil)
}
}
}
4 changes: 2 additions & 2 deletions Descartae/Views/Intro/IntroContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class IntroContentView: UIView {
super.awakeFromNib()

switch DeviceType.current {
case .iPhoneSE, .iPhone5, .simulator:
case .iPhoneSE, .iPhone5:
onboardingImageHeight.constant = 200
onboardingImageWidth.constant = 200
onboardingImageTop.constant -= 24
titleTop.constant -= 20
startButtonTop.constant -= 8
case .iPhone6Plus, .iPhone7Plus, .iPhoneX:
case .iPhone6Plus, .iPhone7Plus, .iPhone8Plus, .iPhoneX:
onboardingImageTop.constant += 24
titleTop.constant += 8
startButtonTop.constant += 24
Expand Down

0 comments on commit be5182f

Please sign in to comment.