| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- //
- // LNWalletViewController.swift
- // Lanu
- //
- // Created by OneeChan on 2025/12/24.
- //
- import Foundation
- import UIKit
- import SnapKit
- extension UIView {
- func pushToWallet() {
- let vc = LNWalletViewController()
- navigationController?.pushViewController(vc, animated: true)
- }
- }
- class LNWalletViewController: LNViewController {
- private let coinLabel = UILabel()
- private let diamondLabel = UILabel()
- private let beanLabel = UILabel()
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- showNavigationBar = false
- setupViews()
-
- updateWalletInfo()
- LNEventDeliver.addObserver(self)
- LNPurchaseManager.shared.reloadWalletInfo()
- }
- }
- extension LNWalletViewController: LNPurchaseManagerNotify {
- func onUserWalletInfoChanged(info: LNUserWalletInfo) {
- updateWalletInfo()
- }
- }
- extension LNWalletViewController {
- private func updateWalletInfo() {
- diamondLabel.text = myWalletInfo.diamond.toDisplay
- coinLabel.text = myWalletInfo.coin.toDisplay
- beanLabel.text = myWalletInfo.bean.toDisplay
- }
-
- private func setupViews() {
- view.backgroundColor = .primary_1
-
- let topCover = UIImageView()
- topCover.image = .init(named: "ic_home_top_bg")
- view.addSubview(topCover)
- topCover.snp.makeConstraints { make in
- make.top.leading.trailing.equalToSuperview()
- }
-
- let naviBar = buildFakeNavBar()
- view.addSubview(naviBar)
- naviBar.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview()
- make.top.equalToSuperview()
- }
-
- let stackView = UIStackView()
- stackView.axis = .vertical
- stackView.spacing = 16
- view.addSubview(stackView)
- stackView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview().inset(16)
- make.top.equalTo(naviBar.snp.bottom).offset(16)
- }
-
- stackView.addArrangedSubview(buildWallet())
-
- if myUserInfo.playmate {
- stackView.addArrangedSubview(buildIncome())
- }
- }
-
- private func buildFakeNavBar() -> UIView {
- let fakeBar = UIView()
- fakeBar.snp.makeConstraints { make in
- make.height.equalTo((navigationController?.navigationBar.bounds.height ?? 44) + UIView.statusBarHeight)
- }
-
- let barView = UIView()
- fakeBar.addSubview(barView)
- barView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview()
- make.bottom.equalToSuperview()
- make.height.equalTo(navigationController?.navigationBar.bounds.height ?? 44)
- }
-
- let closeButton = UIButton(type: .system)
- closeButton.setImage(UIImage(systemName: "chevron.backward"), for: .normal)
- closeButton.tintColor = .text_5
- closeButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- navigationController?.popViewController(animated: true)
- }), for: .touchUpInside)
- closeButton.translatesAutoresizingMaskIntoConstraints = false
- barView.addSubview(closeButton)
- closeButton.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(16)
- make.centerY.equalToSuperview()
- make.width.height.equalTo(24)
- }
-
- let titleLabel = UILabel()
- titleLabel.text = .init(key: "A00215")
- titleLabel.font = .heading_h2
- titleLabel.textColor = .text_5
- barView.addSubview(titleLabel)
- titleLabel.snp.makeConstraints { make in
- make.center.equalToSuperview()
- }
-
- let history = UIButton()
- history.setImage(.init(named: "ic_wallet_history"), for: .normal)
- history.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- view.pushToWebView(.init(url: .walletHistoryUrl, showNavigationBar: false))
- }), for: .touchUpInside)
- barView.addSubview(history)
- history.snp.makeConstraints { make in
- make.trailing.equalToSuperview().offset(-16)
- make.centerY.equalToSuperview()
- make.width.height.equalTo(30)
- }
-
- return fakeBar
- }
-
- private func buildWallet() -> UIView {
- let container = UIView()
- container.layer.cornerRadius = 12
- container.backgroundColor = .fill
-
- let titleView = UIView()
- container.addSubview(titleView)
- titleView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview()
- make.top.equalToSuperview()
- make.height.equalTo(40)
- }
-
- let titleLabel = UILabel()
- titleLabel.text = .init(key: "A00268")
- titleLabel.font = .heading_h3
- titleLabel.textColor = .text_5
- titleView.addSubview(titleLabel)
- titleLabel.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(16)
- make.centerY.equalToSuperview()
- }
-
- let coinView = buildCoinView()
- container.addSubview(coinView)
- coinView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview().inset(16)
- make.top.equalTo(titleView.snp.bottom)
- make.height.equalTo(64)
- }
-
- let diamondView = buildDiamondView()
- container.addSubview(diamondView)
- diamondView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview().inset(16)
- make.top.equalTo(coinView.snp.bottom).offset(10)
- make.height.equalTo(64)
- make.bottom.equalToSuperview().offset(-12)
- }
-
- return container
- }
-
- private func buildCoinView() -> UIView {
- let container = UIView()
- container.backgroundColor = .init(hex: "#FFC4000D")
- container.layer.cornerRadius = 12
- container.onTap { [weak self] in
- guard let self else { return }
- view.pushToCoinView()
- }
-
- let coin = UIImageView.coinImageView(true)
- container.addSubview(coin)
- coin.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(14)
- make.centerY.equalToSuperview()
- make.width.height.equalTo(42)
- }
-
- let textView = UIView()
- container.addSubview(textView)
- textView.snp.makeConstraints { make in
- make.leading.equalTo(coin.snp.trailing).offset(8)
- make.centerY.equalToSuperview()
- }
-
- coinLabel.text = "0"
- coinLabel.font = .heading_h1_5
- coinLabel.textColor = .text_5
- textView.addSubview(coinLabel)
- coinLabel.snp.makeConstraints { make in
- make.leading.top.equalToSuperview()
- make.trailing.equalToSuperview()
- }
-
- let descLabel = UILabel()
- descLabel.text = .init(key: "A00216")
- descLabel.font = .heading_h5
- descLabel.textColor = .text_5
- textView.addSubview(descLabel)
- descLabel.snp.makeConstraints { make in
- make.leading.trailing.bottom.equalToSuperview()
- make.top.equalTo(coinLabel.snp.bottom).offset(-5)
- }
-
- let jumpButton = UIButton()
- jumpButton.setBackgroundImage(.primary_8, for: .normal)
- jumpButton.layer.cornerRadius = 12
- jumpButton.clipsToBounds = true
- jumpButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- view.pushToCoinView()
- }), for: .touchUpInside)
- container.addSubview(jumpButton)
- jumpButton.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.trailing.equalToSuperview().offset(-14)
- make.height.equalTo(24)
- }
-
- let contentView = UIView()
- contentView.isUserInteractionEnabled = false
- jumpButton.addSubview(contentView)
- contentView.snp.makeConstraints { make in
- make.center.equalToSuperview()
- make.leading.greaterThanOrEqualToSuperview().offset(8)
- }
-
- let jumpTitleLabel = UILabel()
- jumpTitleLabel.text = .init(key: "A00279")
- jumpTitleLabel.font = .heading_h5
- jumpTitleLabel.textColor = .text_1
- contentView.addSubview(jumpTitleLabel)
- jumpTitleLabel.snp.makeConstraints { make in
- make.leading.verticalEdges.equalToSuperview()
- }
-
- let arrow = UIImageView.arrowImageView(size: 10)
- arrow.tintColor = .white
- contentView.addSubview(arrow)
- arrow.snp.makeConstraints { make in
- make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
- make.centerY.equalToSuperview()
- make.trailing.equalToSuperview()
- }
-
- return container
- }
-
- private func buildDiamondView() -> UIView {
- let container = UIView()
- container.backgroundColor = .init(hex: "#008FFF0D")
- container.layer.cornerRadius = 12
- container.onTap { [weak self] in
- guard let self else { return }
- view.pushToDiamondView()
- }
-
- let diamond = UIImageView.diamondImageView(true)
- container.addSubview(diamond)
- diamond.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(14)
- make.centerY.equalToSuperview()
- make.width.height.equalTo(42)
- }
-
- let textView = UIView()
- container.addSubview(textView)
- textView.snp.makeConstraints { make in
- make.leading.equalTo(diamond.snp.trailing).offset(8)
- make.centerY.equalToSuperview()
- }
-
- diamondLabel.text = "0"
- diamondLabel.font = .heading_h1_5
- diamondLabel.textColor = .text_5
- textView.addSubview(diamondLabel)
- diamondLabel.snp.makeConstraints { make in
- make.leading.top.equalToSuperview()
- make.trailing.equalToSuperview()
- }
-
- let descLabel = UILabel()
- descLabel.text = .init(key: "A00217")
- descLabel.font = .heading_h5
- descLabel.textColor = .text_5
- textView.addSubview(descLabel)
- descLabel.snp.makeConstraints { make in
- make.leading.trailing.bottom.equalToSuperview()
- make.top.equalTo(diamondLabel.snp.bottom).offset(-5)
- }
-
- let jumpButton = UIButton()
- jumpButton.setBackgroundImage(.primary_8, for: .normal)
- jumpButton.layer.cornerRadius = 12
- jumpButton.clipsToBounds = true
- jumpButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- view.pushToDiamondView()
- }), for: .touchUpInside)
- container.addSubview(jumpButton)
- jumpButton.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.trailing.equalToSuperview().offset(-14)
- make.height.equalTo(24)
- }
-
- let contentView = UIView()
- contentView.isUserInteractionEnabled = false
- jumpButton.addSubview(contentView)
- contentView.snp.makeConstraints { make in
- make.center.equalToSuperview()
- make.leading.greaterThanOrEqualToSuperview().offset(8)
- }
-
- let jumpTitleLabel = UILabel()
- jumpTitleLabel.text = .init(key: "A00279")
- jumpTitleLabel.font = .heading_h5
- jumpTitleLabel.textColor = .text_1
- contentView.addSubview(jumpTitleLabel)
- jumpTitleLabel.snp.makeConstraints { make in
- make.leading.verticalEdges.equalToSuperview()
- }
-
- let arrow = UIImageView.arrowImageView(size: 10)
- arrow.tintColor = .white
- contentView.addSubview(arrow)
- arrow.snp.makeConstraints { make in
- make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
- make.centerY.equalToSuperview()
- make.trailing.equalToSuperview()
- }
-
- return container
- }
-
- private func buildIncome() -> UIView {
- let container = UIView()
- container.layer.cornerRadius = 12
- container.backgroundColor = .fill
-
- let titleView = UIView()
- container.addSubview(titleView)
- titleView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview()
- make.top.equalToSuperview()
- make.height.equalTo(40)
- }
-
- let titleLabel = UILabel()
- titleLabel.text = .init(key: "A00276")
- titleLabel.font = .heading_h3
- titleLabel.textColor = .text_5
- titleView.addSubview(titleLabel)
- titleLabel.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(16)
- make.centerY.equalToSuperview()
- }
-
- let beanView = buildBeanView()
- container.addSubview(beanView)
- beanView.snp.makeConstraints { make in
- make.directionalHorizontalEdges.equalToSuperview().inset(16)
- make.top.equalTo(titleView.snp.bottom)
- make.height.equalTo(64)
- make.bottom.equalToSuperview().offset(-10)
- }
-
- return container
- }
-
- private func buildBeanView() -> UIView {
- let container = UIView()
- container.backgroundColor = .init(hex: "#FF73000D")
- container.layer.cornerRadius = 12
-
- let bean = UIImageView.beanImageView()
- container.addSubview(bean)
- bean.snp.makeConstraints { make in
- make.leading.equalToSuperview().offset(14)
- make.centerY.equalToSuperview()
- make.width.height.equalTo(42)
- }
-
- let textView = UIView()
- container.addSubview(textView)
- textView.snp.makeConstraints { make in
- make.leading.equalTo(bean.snp.trailing).offset(8)
- make.centerY.equalToSuperview()
- }
-
- beanLabel.text = myWalletInfo.bean.toDisplay
- beanLabel.font = .heading_h1_5
- beanLabel.textColor = .text_5
- textView.addSubview(beanLabel)
- beanLabel.snp.makeConstraints { make in
- make.leading.bottom.equalToSuperview()
- make.trailing.equalToSuperview()
- }
-
- let descLabel = UILabel()
- descLabel.text = .init(key: "A00277")
- descLabel.font = .heading_h5
- descLabel.textColor = .text_5
- textView.addSubview(descLabel)
- descLabel.snp.makeConstraints { make in
- make.leading.trailing.top.equalToSuperview()
- make.bottom.equalTo(beanLabel.snp.top)
- }
-
- // let jumpButton = UIButton()
- // jumpButton.setBackgroundImage(.primary_8, for: .normal)
- // jumpButton.layer.cornerRadius = 12
- // jumpButton.clipsToBounds = true
- // container.addSubview(jumpButton)
- // jumpButton.snp.makeConstraints { make in
- // make.centerY.equalToSuperview()
- // make.trailing.equalToSuperview().offset(-14)
- // make.height.equalTo(24)
- // }
- //
- // let contentView = UIView()
- // jumpButton.addSubview(contentView)
- // contentView.snp.makeConstraints { make in
- // make.center.equalToSuperview()
- // make.leading.greaterThanOrEqualToSuperview().offset(8)
- // }
-
- // let jumpTitleLabel = UILabel()
- // jumpTitleLabel.text = .init(key: "Details")
- // jumpTitleLabel.font = .heading_h5
- // jumpTitleLabel.textColor = .text_1
- // contentView.addSubview(jumpTitleLabel)
- // jumpTitleLabel.snp.makeConstraints { make in
- // make.leading.verticalEdges.equalToSuperview()
- // }
- //
- // let arrow = UIImageView.arrowImageView(size: 10)
- // arrow.tintColor = .white
- // contentView.addSubview(arrow)
- // arrow.snp.makeConstraints { make in
- // make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
- // make.centerY.equalToSuperview()
- // make.trailing.equalToSuperview()
- // }
-
- return container
- }
- }
- #if DEBUG
- import SwiftUI
- struct LNWalletViewControllerPreview: UIViewControllerRepresentable {
- func makeUIViewController(context: Context) -> some UIViewController {
- LNWalletViewController()
- }
-
- func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
- }
- #Preview(body: {
- LNWalletViewControllerPreview()
- })
- #endif
|