Files
suixinkan_uikit/suixinkan/UI/Common/AppStatusBadge.swift

117 lines
3.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppStatusBadge.swift
// suixinkan
//
import SnapKit
import UIKit
/// / badge
final class AppStatusBadge: UIView {
///
enum Tone {
case info
case success
case warning
case danger
case neutral
}
/// badge
enum OrderBadgeStyle {
case photographer
case deposit
}
private let label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
label.textAlignment = .center
addSubview(label)
applyOrderBadgeStyle(.photographer)
layer.cornerRadius = AppRadius.xs
clipsToBounds = true
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/// badge 14sp / 12sp
func applyOrderBadgeStyle(_ style: OrderBadgeStyle) {
switch style {
case .photographer:
label.font = .app(.bodyMedium)
label.snp.remakeConstraints { make in
make.edges.equalToSuperview().inset(
UIEdgeInsets(top: 0, left: AppSpacing.xxs, bottom: 0, right: AppSpacing.xxs)
)
}
case .deposit:
label.font = .app(.caption)
label.snp.remakeConstraints { make in
make.edges.equalToSuperview().inset(
UIEdgeInsets(top: 2, left: AppSpacing.xs, bottom: 2, right: AppSpacing.xs)
)
}
}
}
///
func apply(tone: Tone, text: String) {
label.text = text
switch tone {
case .info:
label.textColor = AppColor.info
backgroundColor = AppColor.infoBackground
case .success:
label.textColor = AppColor.success
backgroundColor = AppColor.successBackground
case .warning:
label.textColor = AppColor.warning
backgroundColor = AppColor.warningBackground
case .danger:
label.textColor = AppColor.danger
backgroundColor = AppColor.dangerBackground
case .neutral:
label.textColor = OrderTokens.depositRefunded
backgroundColor = OrderTokens.depositRefundedBackground
}
}
/// Android `OrderView`
func applyOrderStatus(_ status: Int, text: String) {
applyOrderBadgeStyle(.photographer)
switch status {
case 18:
apply(tone: .info, text: text)
case 30:
apply(tone: .success, text: text)
case 50:
apply(tone: .danger, text: text)
default:
apply(tone: .warning, text: text)
}
}
/// Android `DepositOrderCard`
func applyDepositOrderStatus(_ status: Int, text: String) {
applyOrderBadgeStyle(.deposit)
switch status {
case 20:
apply(tone: .info, text: text)
case 30:
label.text = text
label.textColor = OrderTokens.depositSuccess
backgroundColor = OrderTokens.depositSuccessBackground
case 50:
apply(tone: .neutral, text: text)
default:
apply(tone: .warning, text: text)
}
}
}