|
|
@@ -19,15 +19,68 @@ extension UIView {
|
|
|
|
|
|
|
|
|
class LNMineViewController: LNViewController {
|
|
|
+ private let stackView = UIStackView()
|
|
|
+
|
|
|
+ private let userView = UIView()
|
|
|
+ private let avatar = UIImageView()
|
|
|
+ private let userNameLabel = UILabel()
|
|
|
+ private let idLabel = UILabel()
|
|
|
+ private let toProfileView = UIView()
|
|
|
+
|
|
|
+ private let loginView = UIView()
|
|
|
+
|
|
|
+ private let diamondLabel = UILabel()
|
|
|
+
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
setupViews()
|
|
|
+ updateUserContent()
|
|
|
+ updateWalletContent()
|
|
|
+
|
|
|
+ LNEventDeliver.addObserver(self)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension LNMineViewController: LNProfileManagerNotify, LNPurchaseManagerNotify {
|
|
|
+ func onUserInfoChanged(userInfo: LNUserProfileInfo) {
|
|
|
+ guard userInfo.id.isMyUid else { return }
|
|
|
+ updateUserContent()
|
|
|
+ }
|
|
|
+
|
|
|
+ func onUserWalletInfoChanged(info: LNUserWalletInfo) {
|
|
|
+ updateWalletContent()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
extension LNMineViewController {
|
|
|
+ private func updateWalletContent() {
|
|
|
+ if let info = myWalletInfo {
|
|
|
+ diamondLabel.text = "\(info.diamond)"
|
|
|
+ } else {
|
|
|
+ diamondLabel.text = "0"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func updateUserContent() {
|
|
|
+ if let myUserInfo {
|
|
|
+ loginView.isHidden = true
|
|
|
+ userView.isHidden = false
|
|
|
+
|
|
|
+ avatar.sd_setImage(with: URL(string: myUserInfo.avatar))
|
|
|
+ userNameLabel.text = myUserInfo.nickname
|
|
|
+ idLabel.text = myUserInfo.id
|
|
|
+ } else {
|
|
|
+ loginView.isHidden = false
|
|
|
+ userView.isHidden = true
|
|
|
+
|
|
|
+ avatar.image = .init(named: "ic_profile_login_avatar")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func setupViews() {
|
|
|
+ title = .init(key: "我的页")
|
|
|
+ view.backgroundColor = .primary_1
|
|
|
|
|
|
let topCover = UIImageView()
|
|
|
topCover.image = .init(named: "ic_main_top_bg")
|
|
|
@@ -35,6 +88,449 @@ extension LNMineViewController {
|
|
|
topCover.snp.makeConstraints { make in
|
|
|
make.top.leading.trailing.equalToSuperview()
|
|
|
}
|
|
|
+
|
|
|
+ stackView.axis = .vertical
|
|
|
+ stackView.spacing = 14
|
|
|
+ view.addSubview(stackView)
|
|
|
+ stackView.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalToSuperview().offset(20)
|
|
|
+ }
|
|
|
+
|
|
|
+ let itemViews: [UIView] = [
|
|
|
+ buildBaseInfo(),
|
|
|
+ buildGameMate(),
|
|
|
+ buildWallet(),
|
|
|
+ buildOrder()
|
|
|
+ ]
|
|
|
+ itemViews.forEach {
|
|
|
+ stackView.addArrangedSubview($0)
|
|
|
+ }
|
|
|
+
|
|
|
+ let logoutButton = buildLogout()
|
|
|
+ view.addSubview(logoutButton)
|
|
|
+ logoutButton.snp.makeConstraints { make in
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-50)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildBaseInfo() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+
|
|
|
+ avatar.layer.borderColor = UIColor.fill.cgColor
|
|
|
+ avatar.layer.borderWidth = 2
|
|
|
+ avatar.layer.cornerRadius = 37.5
|
|
|
+ avatar.clipsToBounds = true
|
|
|
+ container.addSubview(avatar)
|
|
|
+ avatar.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.verticalEdges.equalToSuperview()
|
|
|
+ make.width.height.equalTo(75)
|
|
|
+ }
|
|
|
+
|
|
|
+ let editButton = UIButton()
|
|
|
+ editButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ self.view.pushToEditProfile()
|
|
|
+ }), for: .touchUpInside)
|
|
|
+ editButton.setImage(.init(named: "ic_profile_avatar_edit"), for: .normal)
|
|
|
+ container.addSubview(editButton)
|
|
|
+ editButton.snp.makeConstraints { make in
|
|
|
+ make.trailing.bottom.equalTo(avatar)
|
|
|
+ }
|
|
|
+
|
|
|
+ let userView = buildUserView()
|
|
|
+ container.addSubview(userView)
|
|
|
+ userView.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalTo(avatar.snp.trailing).offset(16)
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let loginView = buildLogin()
|
|
|
+ container.addSubview(loginView)
|
|
|
+ loginView.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalTo(avatar.snp.trailing).offset(16)
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildUserView() -> UIView {
|
|
|
+ let profileLabel = UILabel()
|
|
|
+ profileLabel.text = .init(key: "个人页")
|
|
|
+ profileLabel.font = .body_xs
|
|
|
+ profileLabel.textColor = .text_4
|
|
|
+ toProfileView.addSubview(profileLabel)
|
|
|
+ profileLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let config = UIImage.SymbolConfiguration(pointSize: 8)
|
|
|
+ let arrow = UIImageView()
|
|
|
+ arrow.tintColor = .text_4
|
|
|
+ arrow.image = .init(systemName: "chevron.forward", withConfiguration: config)
|
|
|
+ arrow.contentMode = .center
|
|
|
+ toProfileView.addSubview(arrow)
|
|
|
+ arrow.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalTo(profileLabel.snp.trailing).offset(2)
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ make.width.height.equalTo(14)
|
|
|
+ }
|
|
|
+
|
|
|
+ toProfileView.onTap { [weak self] in
|
|
|
+ guard let self else { return }
|
|
|
+ self.view.pushToProfile(uid: myUid)
|
|
|
+ }
|
|
|
+ userView.addSubview(toProfileView)
|
|
|
+ toProfileView.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ userNameLabel.font = .heading_h2
|
|
|
+ userNameLabel.textColor = .text_5
|
|
|
+ userView.addSubview(userNameLabel)
|
|
|
+ userNameLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview()
|
|
|
+ make.trailing.lessThanOrEqualTo(toProfileView.snp.leading).offset(-16)
|
|
|
+ }
|
|
|
+
|
|
|
+ let idTitle = UILabel()
|
|
|
+ idTitle.text = "ID"
|
|
|
+ idTitle.font = .body_s
|
|
|
+ idTitle.textColor = .text_3
|
|
|
+ userView.addSubview(idTitle)
|
|
|
+ idTitle.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(userNameLabel.snp.bottom).offset(4)
|
|
|
+ make.leading.bottom.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ idLabel.font = .body_xs
|
|
|
+ idLabel.textColor = .text_4
|
|
|
+ userView.addSubview(idLabel)
|
|
|
+ idLabel.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalTo(idTitle)
|
|
|
+ make.leading.equalTo(idTitle.snp.trailing).offset(4)
|
|
|
+ }
|
|
|
+
|
|
|
+ let copyIdButton = UIButton()
|
|
|
+ copyIdButton.setImage(.init(named: ""), for: .normal)
|
|
|
+ userView.addSubview(copyIdButton)
|
|
|
+ copyIdButton.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalTo(idTitle)
|
|
|
+ make.leading.equalTo(idLabel.snp.trailing).offset(4)
|
|
|
+ make.trailing.lessThanOrEqualTo(toProfileView.snp.leading).offset(-16)
|
|
|
+ }
|
|
|
+
|
|
|
+ return userView
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildGameMate() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+
|
|
|
+ let qr = buildQRView()
|
|
|
+ container.addSubview(qr)
|
|
|
+ qr.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview()
|
|
|
+ make.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let share = buildShare()
|
|
|
+ container.addSubview(share)
|
|
|
+ share.snp.makeConstraints { make in
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ make.verticalEdges.equalToSuperview()
|
|
|
+ make.leading.equalTo(qr.snp.trailing).offset(11)
|
|
|
+ make.width.equalTo(qr)
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildQRView() -> UIView {
|
|
|
+ let ic = UIImageView()
|
|
|
+ ic.image = .init(named: "ic_profile_qr")
|
|
|
+
|
|
|
+
|
|
|
+ let label = UILabel()
|
|
|
+ label.font = .heading_h3
|
|
|
+ label.textColor = .init(hex: "#01327B")
|
|
|
+ label.numberOfLines = 0
|
|
|
+ ic.addSubview(label)
|
|
|
+ label.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview().inset(10)
|
|
|
+ make.trailing.equalToSuperview().offset(-50)
|
|
|
+ }
|
|
|
+
|
|
|
+ let text: String = .init(key: "Generate QR code")
|
|
|
+ let attrStr = NSMutableAttributedString(string: text)
|
|
|
+
|
|
|
+ attrStr.append(.init(string: " "))
|
|
|
+
|
|
|
+ let image: UIImage = .init(named: "ic_profile_qr_arrow")!
|
|
|
+ let arrow = NSTextAttachment(image: image)
|
|
|
+ arrow.bounds = .init(x: 0,
|
|
|
+ y: -(label.font.ascender - image.size.height) / 2,
|
|
|
+ width: image.size.width,
|
|
|
+ height: image.size.height)
|
|
|
+ attrStr.append(NSAttributedString(attachment: arrow))
|
|
|
+ label.attributedText = attrStr
|
|
|
+
|
|
|
+ return ic
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildShare() -> UIView {
|
|
|
+ let ic = UIImageView()
|
|
|
+ ic.image = .init(named: "ic_profile_share")
|
|
|
+
|
|
|
+ let label = UILabel()
|
|
|
+ label.font = .heading_h3
|
|
|
+ label.textColor = .init(hex: "#0A625F")
|
|
|
+ label.numberOfLines = 0
|
|
|
+ ic.addSubview(label)
|
|
|
+ label.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview().inset(10)
|
|
|
+ make.trailing.equalToSuperview().offset(-50)
|
|
|
+ }
|
|
|
+
|
|
|
+ let text: String = .init(key: "Share with friends")
|
|
|
+ let attrStr = NSMutableAttributedString(string: text)
|
|
|
+
|
|
|
+ attrStr.append(.init(string: " "))
|
|
|
+
|
|
|
+ let image: UIImage = .init(named: "ic_profile_share_arrow")!
|
|
|
+ let arrow = NSTextAttachment(image: image)
|
|
|
+ arrow.bounds = .init(x: 0,
|
|
|
+ y: -(label.font.ascender - image.size.height) / 2,
|
|
|
+ width: image.size.width,
|
|
|
+ height: image.size.height)
|
|
|
+ attrStr.append(NSAttributedString(attachment: arrow))
|
|
|
+ label.attributedText = attrStr
|
|
|
+
|
|
|
+ return ic
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildWallet() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.backgroundColor = .fill
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+
|
|
|
+ let walletIc = UIImageView()
|
|
|
+ walletIc.image = .init(named: "ic_profile_wallet")
|
|
|
+ container.addSubview(walletIc)
|
|
|
+ walletIc.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.top.equalToSuperview().offset(16)
|
|
|
+ make.bottom.equalToSuperview().offset(-16)
|
|
|
+ }
|
|
|
+
|
|
|
+ let title = UILabel()
|
|
|
+ title.font = .heading_h3
|
|
|
+ title.textColor = .text_5
|
|
|
+ title.text = .init(key: "My Wallet")
|
|
|
+ container.addSubview(title)
|
|
|
+ title.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalTo(walletIc.snp.trailing).offset(10)
|
|
|
+ }
|
|
|
+
|
|
|
+ let config = UIImage.SymbolConfiguration(pointSize: 10)
|
|
|
+ let arrow = UIImageView()
|
|
|
+ arrow.tintColor = .text_4
|
|
|
+ arrow.image = .init(systemName: "chevron.forward", withConfiguration: config)
|
|
|
+ arrow.contentMode = .center
|
|
|
+ container.addSubview(arrow)
|
|
|
+ arrow.snp.makeConstraints { make in
|
|
|
+ make.trailing.equalToSuperview().offset(-16)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(16)
|
|
|
+ }
|
|
|
+
|
|
|
+ diamondLabel.font = .heading_h4
|
|
|
+ diamondLabel.textColor = .text_5
|
|
|
+ container.addSubview(diamondLabel)
|
|
|
+ diamondLabel.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalTo(arrow.snp.leading).offset(-3)
|
|
|
+ }
|
|
|
+
|
|
|
+ let diamondIc = UIImageView()
|
|
|
+ diamondIc.image = .init(named: "ic_diamond")
|
|
|
+ container.addSubview(diamondIc)
|
|
|
+ diamondIc.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalTo(diamondLabel.snp.leading).offset(-3)
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildOrder() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.backgroundColor = .fill
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+
|
|
|
+ let orderIc = UIImageView()
|
|
|
+ orderIc.image = .init(named: "ic_profile_order")
|
|
|
+ container.addSubview(orderIc)
|
|
|
+ orderIc.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.top.equalToSuperview().offset(12)
|
|
|
+ }
|
|
|
+
|
|
|
+ let title = UILabel()
|
|
|
+ title.font = .heading_h3
|
|
|
+ title.textColor = .text_5
|
|
|
+ title.text = .init(key: "My Order")
|
|
|
+ container.addSubview(title)
|
|
|
+ title.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalTo(orderIc)
|
|
|
+ make.leading.equalTo(orderIc.snp.trailing).offset(10)
|
|
|
+ }
|
|
|
+
|
|
|
+ let line = UIView()
|
|
|
+ line.backgroundColor = .fill_3
|
|
|
+ container.addSubview(line)
|
|
|
+ line.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(19)
|
|
|
+ make.height.equalTo(0.5)
|
|
|
+ make.top.equalTo(title.snp.bottom).offset(10)
|
|
|
+ }
|
|
|
+
|
|
|
+ let stackView = UIStackView()
|
|
|
+ stackView.axis = .horizontal
|
|
|
+ stackView.distribution = .equalSpacing
|
|
|
+ container.addSubview(stackView)
|
|
|
+ stackView.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalTo(line.snp.bottom).offset(10)
|
|
|
+ make.bottom.equalToSuperview().offset(-12)
|
|
|
+ }
|
|
|
+
|
|
|
+ let pending = buildOrderSubItemView(icName: "ic_order_pending", title: .init(key: "待付款"))
|
|
|
+ stackView.addArrangedSubview(pending)
|
|
|
+ pending.onTap {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let finish = buildOrderSubItemView(icName: "ic_order_done", title: .init(key: "已完成"))
|
|
|
+ stackView.addArrangedSubview(finish)
|
|
|
+ finish.onTap {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let refund = buildOrderSubItemView(icName: "ic_order_refund", title: .init(key: "退款"))
|
|
|
+ stackView.addArrangedSubview(refund)
|
|
|
+ refund.onTap {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let all = buildOrderSubItemView(icName: "ic_order_all", title: .init(key: "全部订单"))
|
|
|
+ stackView.addArrangedSubview(all)
|
|
|
+ all.onTap {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildLogout() -> UIView {
|
|
|
+ let button = UIButton()
|
|
|
+ button.layer.cornerRadius = 15
|
|
|
+ button.layer.borderColor = UIColor.fill_4.cgColor
|
|
|
+ button.layer.borderWidth = 1
|
|
|
+ view.addSubview(button)
|
|
|
+ button.snp.makeConstraints { make in
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-50)
|
|
|
+ }
|
|
|
+
|
|
|
+ let title = UILabel()
|
|
|
+ title.text = .init(key: "Logout")
|
|
|
+ title.font = .body_s
|
|
|
+ title.textColor = .text_4
|
|
|
+ button.addSubview(title)
|
|
|
+ title.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(30)
|
|
|
+ make.verticalEdges.equalToSuperview().inset(7)
|
|
|
+ }
|
|
|
+
|
|
|
+ return button
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildOrderSubItemView(icName: String, title: String) -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+
|
|
|
+ let ic = UIImageView()
|
|
|
+ ic.image = .init(named: icName)
|
|
|
+ container.addSubview(ic)
|
|
|
+ ic.snp.makeConstraints { make in
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let label = UILabel()
|
|
|
+ label.text = title
|
|
|
+ label.font = .body_s
|
|
|
+ label.textColor = .text_4
|
|
|
+ label.textAlignment = .center
|
|
|
+ container.addSubview(label)
|
|
|
+ label.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ make.top.equalTo(ic.snp.bottom).offset(3)
|
|
|
+ make.width.greaterThanOrEqualTo(43)
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildLogin() -> UIView {
|
|
|
+ let button = UIButton()
|
|
|
+ button.setBackgroundImage(.primary_7, for: .normal)
|
|
|
+ button.layer.cornerRadius = 8
|
|
|
+ button.clipsToBounds = true
|
|
|
+ loginView.addSubview(button)
|
|
|
+ button.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview().offset(-10)
|
|
|
+ }
|
|
|
+
|
|
|
+ let login = UILabel()
|
|
|
+ login.text = .init(key: "login")
|
|
|
+ login.font = .body_s
|
|
|
+ login.textColor = .text_1
|
|
|
+ button.addSubview(login)
|
|
|
+ login.snp.makeConstraints { make in
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.verticalEdges.equalToSuperview().inset(7)
|
|
|
+ }
|
|
|
+
|
|
|
+ let title = UILabel()
|
|
|
+ title.text = .init(key: "点击登陆")
|
|
|
+ title.font = .heading_h2
|
|
|
+ title.textColor = .text_5
|
|
|
+ loginView.addSubview(title)
|
|
|
+ title.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let desc = UILabel()
|
|
|
+ desc.text = .init(key: "登陆更精彩")
|
|
|
+ desc.font = .body_xs
|
|
|
+ desc.textColor = .text_4
|
|
|
+ loginView.addSubview(desc)
|
|
|
+ desc.snp.makeConstraints { make in
|
|
|
+ make.leading.bottom.equalToSuperview()
|
|
|
+ make.top.equalTo(title.snp.bottom).offset(4)
|
|
|
+ }
|
|
|
+
|
|
|
+ return loginView
|
|
|
}
|
|
|
}
|
|
|
|