Skip to content

Instantly share code, notes, and snippets.

@asobolevsky
Created November 29, 2019 13:38
Show Gist options
  • Save asobolevsky/134848e4e4bb95cf4e8eadf803d2268e to your computer and use it in GitHub Desktop.
Save asobolevsky/134848e4e4bb95cf4e8eadf803d2268e to your computer and use it in GitHub Desktop.
var ordersList: Order? {
didSet {
var fullLabelAddressFromAndStatusLabel = ""
var fullLabelAddressToAndStatusLabel = ""
var statusStringLengthFrom = 0
var statusStringLengthTo = 0
orderFirstTimeLabel.text = ""
orderSecondTimeLabel.text = ""
//print("\nordersList: \(String(describing: ordersList))")
//Данные по водителю
var carInfo = ""
setupProfileImage()//аватарка
driverName.text = ordersList?.driver?.fullName
if let carModel = ordersList?.driver?.transportType {
carInfo = carModel + " • "
}
if let stateNumber = ordersList?.driver?.stateNumber {
carInfo += stateNumber
}
driverCar.text = carInfo
if let driverRating = ordersList?.driver?.rating {
driverRatingLabel.text = String(Double(driverRating))
}
//print("\nordersList.points: \(String(describing: ordersList?.points))")
//MARK: - Для Завершенных заказов (ИСТОРИЯ)
if ordersList?.statusValue == "completed" {
if
let point = ordersList?.points?.firstObject as? OrderPoint,
let startPoint = point.isStartPoint as? Bool,
startPoint,
let orderAddressFrom = point.address,
let statusAndDate = point.statusAndDateTime?.lastObject as? StatusAndDateTime
{
fullLabelAddressFromAndStatusLabel = orderAddressFrom
statusStringLengthFrom = orderAddressFrom.characters.count
setupStatusTime(statusAndDate.date, label: orderFirstTimeLabel)
}
if
let point = ordersList?.points?.lastObject as? OrderPoint,
let endPoint = point.isEndPoint as? Bool,
endPoint,
let orderAddressTo = point.address,
let statusAndDate = point.statusAndDateTime?.lastObject as? StatusAndDateTime
{
fullLabelAddressToAndStatusLabel = orderAddressTo
statusStringLengthTo = orderAddressTo.characters.count
setupStatusTime(statusAndDate.date, label: orderSecondTimeLabel)
}
orderFirstPointImageView.image = UIImage(named: "CompletedPointIcon")
smallCurrentPointImageView.isHidden = true
orderSecondPointImageView.image = UIImage(named: "CompletedPointIcon")
fullLabelAddressFromAndStatusLabel += "\nВодитель на месте"
fullLabelAddressToAndStatusLabel += "\nЗаказ завершен"
if
let numberOfOrder = ordersList?.idValue,
let dateFinish = ordersList?.dateFinished
{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "d MMM YYYY"
dateFormatter.locale = Locale(identifier: "ru_RU")
let date = dateFormatter.string(from: dateFinish)
orderNumberAndStatusLabel.text = "№\(Int(numberOfOrder)) • \(date)"
}
if let price = ordersList?.priceTotal?.rublesString {
orderPriceLabel.text = "\(price)₽"
}
if let fullTime = ordersList?.time.minutesString.timeAgoDisplay() {
orderFullTimeLabel.text = fullTime
}
if let countOfPoints = ordersList?.points?.count {
if countOfPoints == 2 {
anotherAddressCount.isHidden = true
} else {
let count = countOfPoints - 2
anotherAddressCount.isHidden = false
anotherAddressCount.text = "\(count) адрес(а/ов)"//FIXME: окончание в зависимости от количества других адресов
}
}
}
orderAddressFromAndStatusLabel.attributedText =
getAttrString(fullString: fullLabelAddressFromAndStatusLabel,
statusStringLength: statusStringLengthFrom)
orderAddressToAndStatusLabel.attributedText =
getAttrString(fullString: fullLabelAddressToAndStatusLabel,
statusStringLength: statusStringLengthTo)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment