[Feature] Locations list #10
@ -6,12 +6,17 @@
|
|||||||
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Combine
|
||||||
|
import Foundation
|
||||||
|
|
||||||
protocol LocationsListViewModeling: AnyObject {
|
protocol LocationsListViewModeling: AnyObject {
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
var coordinator: LocationsListCoordination? { get set }
|
var coordinator: LocationsListCoordination? { get set }
|
||||||
|
|
||||||
|
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { get }
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
func openAddLocation()
|
func openAddLocation()
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Combine
|
||||||
import Core
|
import Core
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@ -15,6 +16,8 @@ class LocationsListViewController: BaseViewController {
|
|||||||
|
|
||||||
private let viewModel: LocationsListViewModeling
|
private let viewModel: LocationsListViewModeling
|
||||||
|
|
||||||
|
private var cancellables: Set<AnyCancellable> = []
|
||||||
|
|
||||||
// MARK: Outlets
|
// MARK: Outlets
|
||||||
|
|
||||||
private lazy var error = ErrorMessageView()
|
private lazy var error = ErrorMessageView()
|
||||||
@ -46,6 +49,7 @@ class LocationsListViewController: BaseViewController {
|
|||||||
|
|
||||||
setupBar()
|
setupBar()
|
||||||
setupView()
|
setupView()
|
||||||
|
bindViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,12 +76,7 @@ private extension LocationsListViewController {
|
|||||||
view.addSubview(table)
|
view.addSubview(table)
|
||||||
view.addSubview(error)
|
view.addSubview(error)
|
||||||
view.addSubview(loading)
|
view.addSubview(loading)
|
||||||
|
|
||||||
error.isHidden = true
|
|
||||||
error.onRetry = { print("RETRY BUTTON PRESSED!") }
|
error.onRetry = { print("RETRY BUTTON PRESSED!") }
|
||||||
|
|
||||||
loading.isHidden = true
|
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
error.widthAnchor.constraint(equalToConstant: 300),
|
error.widthAnchor.constraint(equalToConstant: 300),
|
||||||
view.centerXAnchor.constraint(equalTo: error.centerXAnchor),
|
view.centerXAnchor.constraint(equalTo: error.centerXAnchor),
|
||||||
@ -91,6 +90,19 @@ private extension LocationsListViewController {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bindViewModel() {
|
||||||
|
viewModel
|
||||||
|
.viewStatusPublisher
|
||||||
|
.receive(on: RunLoop.main)
|
||||||
|
.sink { viewStatus in
|
||||||
|
self.navigationItem.rightBarButtonItem?.isEnabled = viewStatus == .loaded
|
||||||
|
self.error.isHidden = viewStatus != .error
|
||||||
|
self.loading.isHidden = viewStatus != .loading
|
||||||
|
self.table.isHidden = viewStatus != .loaded
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
}
|
||||||
|
|
||||||
@objc func addLocationPressed() {
|
@objc func addLocationPressed() {
|
||||||
viewModel.openAddLocation()
|
viewModel.openAddLocation()
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ class LocationsListViewModel: ObservableObject {
|
|||||||
|
|
||||||
weak var coordinator: LocationsListCoordination?
|
weak var coordinator: LocationsListCoordination?
|
||||||
|
|
||||||
|
@Published private var viewStatus: LocationsListViewStatus = .initialised
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
init(coordinator: LocationsListCoordination) {
|
init(coordinator: LocationsListCoordination) {
|
||||||
@ -27,6 +29,10 @@ class LocationsListViewModel: ObservableObject {
|
|||||||
|
|
||||||
extension LocationsListViewModel: LocationsListViewModeling {
|
extension LocationsListViewModel: LocationsListViewModeling {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { $viewStatus }
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
func openAddLocation() {
|
func openAddLocation() {
|
||||||
@ -34,3 +40,12 @@ extension LocationsListViewModel: LocationsListViewModeling {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Enumerations
|
||||||
|
|
||||||
|
enum LocationsListViewStatus {
|
||||||
|
case initialised
|
||||||
|
case loading
|
||||||
|
case loaded
|
||||||
|
case error
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user