203 lines
7.1 KiB
Swift
203 lines
7.1 KiB
Swift
//
|
|
// VPDeleteAccountViewController.swift
|
|
// Veloria
|
|
//
|
|
// Created by 湖南秦九 on 2025/6/4.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class VPDeleteAccountViewController: VPViewController {
|
|
|
|
private lazy var scrollView: VPScrollView = {
|
|
let scrollView = VPScrollView()
|
|
return scrollView
|
|
}()
|
|
|
|
private lazy var iconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "warning_icon_01"))
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var iconTextLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 14)
|
|
label.textColor = .colorBE0069()
|
|
label.text = "DeleteAccount_tips_1".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var stackView: UIStackView = {
|
|
let view = UIStackView()
|
|
view.axis = .vertical
|
|
view.spacing = 18
|
|
|
|
|
|
view.addArrangedSubview(contentView1)
|
|
view.addArrangedSubview(contentView3)
|
|
view.addArrangedSubview(contentView2)
|
|
|
|
return view
|
|
}()
|
|
|
|
private lazy var contentView1: VPDeleteAccountNormalView = {
|
|
let view = VPDeleteAccountNormalView()
|
|
view.text = "DeleteAccount_tips_2".localized
|
|
return view
|
|
}()
|
|
|
|
private lazy var contentView2: VPDeleteAccountNormalView = {
|
|
let view = VPDeleteAccountNormalView()
|
|
view.text = "DeleteAccount_tips_3".localized
|
|
return view
|
|
}()
|
|
|
|
private lazy var contentView3: VPDeleteAccountDetailView = {
|
|
let view = VPDeleteAccountDetailView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var checkButton: UIButton = {
|
|
let button = UIButton(type: .custom)
|
|
button.setImage(UIImage(named: "choice_icon_01"), for: .normal)
|
|
button.setImage(UIImage(named: "choice_icon_01_selected"), for: .selected)
|
|
button.setImage(UIImage(named: "choice_icon_01_selected"), for: [.selected, .highlighted])
|
|
button.addTarget(self, action: #selector(handleCheckButton), for: .touchUpInside)
|
|
button.setContentHuggingPriority(.required, for: .horizontal)
|
|
button.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
return button
|
|
}()
|
|
|
|
private lazy var checkLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontMedium(ofSize: 14)
|
|
label.textColor = .colorFFFFFF()
|
|
label.numberOfLines = 0
|
|
label.text = "DeleteAccount_tips_4".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var deleteButton: UIButton = {
|
|
let config = UIButton.Configuration.plain()
|
|
let button = VPGradientButton(configuration: config)
|
|
button.layer.cornerRadius = 24
|
|
button.layer.masksToBounds = true
|
|
button.isEnabled = false
|
|
button.locations = [0, 1]
|
|
button.startPoint = .init(x: 0, y: 0.3)
|
|
button.endPoint = .init(x: 1, y: 0.8)
|
|
button.addTarget(self, action: #selector(handleDeleteButton), for: .touchUpInside)
|
|
|
|
button.configurationUpdateHandler = { button in
|
|
guard let button = button as? VPGradientButton else { return }
|
|
let title = "Delete Account".localized
|
|
|
|
if button.isEnabled {
|
|
button.configuration?.attributedTitle = .createAttributedString(string: title, color: .colorFFFFFF(), font: .fontRegular(ofSize: 14))
|
|
button.bt_setGradientBorder()
|
|
button.colors = [UIColor.color05CEA0(alpha: 0.3).cgColor, UIColor.color7C174F(alpha: 0.3).cgColor]
|
|
} else {
|
|
button.configuration?.attributedTitle = .createAttributedString(string: title, color: .color8B8B8B(), font: .fontRegular(ofSize: 14))
|
|
button.bt_removeGradientBorder()
|
|
button.colors = [UIColor.color272A30().cgColor, UIColor.color272A30().cgColor]
|
|
}
|
|
}
|
|
|
|
return button
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.bgImageView.isHidden = true
|
|
self.view.backgroundColor = .color080B16()
|
|
self.title = "Account Deletion".localized
|
|
|
|
vp_setupUI()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.navigationController?.setNavigationBarHidden(false, animated: true)
|
|
self.setNavigationNormalStyle()
|
|
}
|
|
|
|
|
|
}
|
|
|
|
extension VPDeleteAccountViewController {
|
|
|
|
@objc private func handleCheckButton() {
|
|
self.checkButton.isSelected = !self.checkButton.isSelected
|
|
self.deleteButton.isEnabled = self.checkButton.isSelected
|
|
}
|
|
|
|
@objc private func handleDeleteButton() {
|
|
let alert = VPAlertView(title: "kDeleteAccountAlertTitle".localized, subtitle: "kDeleteAccountAlertText".localized, icon: UIImage(named: "alert_icon_01"), normalButtonText: "Delete Forever".localized, highlightButtonText: "Cancel".localized)
|
|
alert.show()
|
|
|
|
alert.clickNormalButton = {
|
|
VPLoginManager.manager.deleteAccount { [weak self] isFinish in
|
|
guard let self = self else { return }
|
|
if isFinish {
|
|
self.navigationController?.popViewController(animated: true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension VPDeleteAccountViewController {
|
|
|
|
private func vp_setupUI() {
|
|
view.addSubview(scrollView)
|
|
scrollView.addSubview(iconImageView)
|
|
scrollView.addSubview(iconTextLabel)
|
|
scrollView.addSubview(stackView)
|
|
scrollView.addSubview(checkButton)
|
|
scrollView.addSubview(checkLabel)
|
|
scrollView.addSubview(deleteButton)
|
|
|
|
scrollView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(UIScreen.navBarHeight)
|
|
}
|
|
|
|
iconImageView.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview().offset(10)
|
|
}
|
|
|
|
iconTextLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(iconImageView.snp.bottom).offset(12)
|
|
}
|
|
|
|
stackView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(iconTextLabel.snp.bottom).offset(18)
|
|
}
|
|
|
|
checkButton.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.top.equalTo(stackView.snp.bottom).offset(25)
|
|
}
|
|
|
|
checkLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(checkButton.snp.right).offset(10)
|
|
make.right.lessThanOrEqualTo(stackView)
|
|
make.top.equalTo(checkButton).offset(2)
|
|
}
|
|
|
|
deleteButton.snp.makeConstraints { make in
|
|
make.left.equalTo(stackView)
|
|
make.right.equalTo(stackView)
|
|
make.top.equalTo(checkLabel.snp.bottom).offset(20)
|
|
make.height.equalTo(48)
|
|
make.bottom.equalToSuperview().offset(-(UIScreen.tabbarSafeBottomMargin + 20))
|
|
}
|
|
}
|
|
|
|
}
|