177 lines
6.1 KiB
Swift
177 lines
6.1 KiB
Swift
//
|
|
// SPLoginViewController.swift
|
|
// MoviaBox
|
|
//
|
|
// Created by 佳尔 on 2025/4/25.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPLoginViewController: SPViewController {
|
|
|
|
private lazy var logoImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "login_logo_icon_01"))
|
|
imageView.layer.cornerRadius = 10
|
|
imageView.layer.masksToBounds = true
|
|
return imageView
|
|
}()
|
|
|
|
// private lazy var nameImageView: UIImageView = {
|
|
// let imageView = UIImageView(image: UIImage(named: "login_logo_icon_02"))
|
|
// return imageView
|
|
// }()
|
|
|
|
private lazy var stackView: UIStackView = {
|
|
let stackView = UIStackView(arrangedSubviews: [faceBookButton, appleButton])
|
|
stackView.axis = .vertical
|
|
stackView.spacing = 20
|
|
return stackView
|
|
}()
|
|
|
|
private lazy var faceBookButton: UIButton = {
|
|
let button = createButton(title: "Login with Facebook", titleColor: .colorFFFFFF(), icon: UIImage(named: "facebook_icon_01"), background: .color0866FF())
|
|
button.addTarget(self, action: #selector(handleFaceBookButton), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
private lazy var appleButton: UIButton = {
|
|
let button = createButton(title: "Login with Apple", titleColor: .color333333(), icon: UIImage(named: "apple_icon_01"), background: .colorFFFFFF())
|
|
button.addTarget(self, action: #selector(handleAppleButton), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
private lazy var agreementLabel: YYLabel = {
|
|
let userAgreementStr = "movia_profile_User_Agreement".localized
|
|
let privacyPolicy = "movia_profile_Privacy_Policy".localized
|
|
let agreementStr = String(format: "movia_login_agreement_tip".localized, userAgreementStr, privacyPolicy)
|
|
|
|
let range1 = agreementStr.ocString().range(of: userAgreementStr)
|
|
let range2 = agreementStr.ocString().range(of: privacyPolicy)
|
|
|
|
let text = NSMutableAttributedString(string: agreementStr)
|
|
text.font = .fontMedium(ofSize: 10)
|
|
text.color = .colorB0B0B3()
|
|
|
|
text.setTextHighlight(range1, color: .colorFFFFFF(), backgroundColor: nil) { [weak self] _, _, _, _ in
|
|
guard let self = self else { return }
|
|
let vc = SPWebViewController()
|
|
vc.urlStr = SPUserAgreementWebUrl
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
|
|
text.setTextHighlight(range2, color: .colorFFFFFF(), backgroundColor: nil) { [weak self] _, _, _, _ in
|
|
guard let self = self else { return }
|
|
let vc = SPWebViewController()
|
|
vc.urlStr = SPPrivacyPolicyWebUrl
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
|
|
let textContainer = YYTextContainer(size: CGSize(width: kSPScreenWidth - 150, height: 100))
|
|
|
|
let layout = YYTextLayout(container: textContainer, text: text)
|
|
|
|
let label = YYLabel()
|
|
label.textLayout = layout
|
|
label.textAlignment = .center
|
|
label.numberOfLines = 0
|
|
return label
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.edgesForExtendedLayout = .top
|
|
setBackgroundView(isShowGradient: false)
|
|
|
|
configNavigationBack()
|
|
|
|
_setupUI()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.navigationController?.setNavigationBarHidden(false, animated: true)
|
|
|
|
setNavigationNormalStyle(backgroundColor: .clear, isTranslucent: true)
|
|
}
|
|
|
|
|
|
private func createButton(title: String, titleColor: UIColor, icon: UIImage?, background: UIColor) -> UIButton {
|
|
let button = JXButton(type: .custom)
|
|
button.setBackgroundImage(UIImage(color: background), for: .normal)
|
|
button.setTitle(title, for: .normal)
|
|
button.setTitleColor(titleColor, for: .normal)
|
|
button.jx_font = .fontMedium(ofSize: 14)
|
|
button.space = 12
|
|
button.setImage(icon, for: .normal)
|
|
button.layer.cornerRadius = 8
|
|
button.layer.masksToBounds = true
|
|
button.snp.makeConstraints { make in
|
|
make.height.equalTo(48)
|
|
}
|
|
return button
|
|
}
|
|
|
|
|
|
}
|
|
|
|
extension SPLoginViewController {
|
|
@objc private func handleFaceBookButton() {
|
|
thirdLogin(type: .faceBook)
|
|
}
|
|
|
|
@objc private func handleAppleButton() {
|
|
thirdLogin(type: .apple)
|
|
}
|
|
|
|
private func thirdLogin(type: SPLoginManager.LoginType) {
|
|
SPHUD.show()
|
|
SPLoginManager.manager.thirdLogin(type: type, presentingViewController: self) { [weak self] isFinish in
|
|
SPHUD.dismiss()
|
|
guard let self = self else { return }
|
|
if isFinish {
|
|
self.dismiss(animated: true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SPLoginViewController {
|
|
|
|
private func _setupUI() {
|
|
view.addSubview(logoImageView)
|
|
// view.addSubview(nameImageView)
|
|
view.addSubview(stackView)
|
|
view.addSubview(agreementLabel)
|
|
// view.addSubview(faceBookButton)
|
|
|
|
logoImageView.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview().offset(kSPStatusbarHeight + kSPMainW(120))
|
|
make.width.height.equalTo(120)
|
|
}
|
|
|
|
// nameImageView.snp.makeConstraints { make in
|
|
// make.centerX.equalToSuperview()
|
|
// make.top.equalTo(logoImageView.snp.bottom).offset(24)
|
|
// }
|
|
|
|
stackView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(37)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalTo(logoImageView.snp.bottom).offset(80)
|
|
}
|
|
|
|
let size = agreementLabel.textLayout?.textBoundingSize ?? .zero
|
|
|
|
agreementLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.size.equalTo(size)
|
|
// make.right.lessThanOrEqualToSuperview().offset(-50)
|
|
make.bottom.equalToSuperview().offset(-(kSPTabbarSafeBottomMargin + 20))
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|