| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- //
- // LNPotentialUserViewController.swift
- // Gami
- //
- // Created by OneeChan on 2026/3/10.
- //
- import Foundation
- import UIKit
- import SnapKit
- import MJRefresh
- extension UIView {
- func pushToPotentialUsers() {
- let vc = LNPotentialUserViewController()
- navigationController?.pushViewController(vc, animated: true)
- }
- }
- class LNPotentialUserViewController: LNViewController {
- private let emptyView = LNNoMoreDataView()
- private let tableView = UITableView()
- private var users: [LNPotentialUserVO] = []
- private var isLoading = false
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- setupViews()
- tableView.mj_header?.beginRefreshing()
- }
- }
- extension LNPotentialUserViewController: UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- users.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(
- withIdentifier: LNPotentialUserItemCell.className,
- for: indexPath
- ) as! LNPotentialUserItemCell
-
- let item = users[indexPath.row]
- cell.update(item)
- return cell
- }
- }
- extension LNPotentialUserViewController {
- private func setupViews() {
- title = .init(key: "B00116")
-
- emptyView.isHidden = true
- view.addSubview(emptyView)
- emptyView.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.centerY.equalToSuperview().multipliedBy(0.6)
- }
-
- let header = MJRefreshNormalHeader { [weak self] in
- guard let self else { return }
- self.loadList()
- }
- header.lastUpdatedTimeLabel?.isHidden = true
- header.stateLabel?.isHidden = true
- tableView.mj_header = header
-
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.backgroundColor = .clear
- tableView.allowsSelection = false
- tableView.register(LNPotentialUserItemCell.self, forCellReuseIdentifier: LNPotentialUserItemCell.className)
- view.addSubview(tableView)
- tableView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
- }
-
- private func loadList() {
- guard !isLoading else { return }
- isLoading = true
-
- LNGameMateManager.shared.getPotentialUsers { [weak self] res in
- guard let self else { return }
- isLoading = false
- if let list = res?.list {
- users = list
- tableView.reloadData()
-
- if users.isEmpty {
- emptyView.showNoData(tips: .init(key: "B00124"))
- } else {
- emptyView.hide()
- }
- } else {
- if users.isEmpty {
- emptyView.showNetworkError()
- }
- }
-
- tableView.mj_header?.endRefreshing()
- }
- }
- }
- private class LNPotentialUserItemCell: UITableViewCell {
- private let avatar = UIImageView()
- private let onlineView = LNOnlineView()
-
- private let nameLabel = UILabel()
- private let genderView = LNGenderView()
- private let newTag = UIView()
- private let chatButton = UIButton()
-
- private var curItem: LNPotentialUserVO?
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func update(_ item: LNPotentialUserVO) {
- avatar.showAvatar(item.avatar)
- nameLabel.text = item.nickname
- genderView.update(item.gender, item.age)
-
- newTag.isHidden = !item.newRegister
- onlineView.isHidden = !item.online
-
- if item.contacted {
- chatButton.setTitle(.init(key: "B00117"), for: .normal)
- } else {
- chatButton.setTitle(.init(key: "B00123"), for: .normal)
- }
-
- curItem = item
- }
- }
- private extension LNPotentialUserItemCell {
- func setupViews() {
- backgroundColor = .clear
- selectionStyle = .none
-
- let container = UIView()
- container.onTap { [weak self] in
- guard let self else { return }
- guard let curItem else { return }
- pushToProfile(uid: curItem.userNo)
- }
- contentView.addSubview(container)
- container.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview().inset(16)
- make.top.equalToSuperview().offset(16)
- make.bottom.equalToSuperview().offset(4)
- }
-
- avatar.layer.cornerRadius = 20
- avatar.clipsToBounds = true
- container.addSubview(avatar)
- avatar.snp.makeConstraints { make in
- make.verticalEdges.equalToSuperview().inset(10)
- make.leading.equalToSuperview().offset(5)
- make.width.height.equalTo(40)
- }
-
- onlineView.offset = 5
- container.addSubview(onlineView)
- onlineView.snp.makeConstraints { make in
- make.edges.equalTo(avatar).inset(-1)
- }
-
- let infoView = UIStackView()
- infoView.axis = .vertical
- infoView.spacing = 4
- infoView.isUserInteractionEnabled = false
- infoView.alignment = .leading
- container.addSubview(infoView)
- infoView.snp.makeConstraints { make in
- make.leading.equalTo(avatar.snp.trailing).offset(13)
- make.centerY.equalToSuperview()
- }
-
- let nameContainer = UIView()
- infoView.addArrangedSubview(nameContainer)
-
- nameLabel.font = .heading_h4
- nameLabel.textColor = .text_5
- nameContainer.addSubview(nameLabel)
- nameLabel.snp.makeConstraints { make in
- make.leading.verticalEdges.equalToSuperview()
- }
-
- nameContainer.addSubview(genderView)
- genderView.snp.makeConstraints { make in
- make.leading.equalTo(nameLabel.snp.trailing).offset(4)
- make.centerY.equalTo(nameLabel)
- make.trailing.lessThanOrEqualToSuperview()
- }
-
- newTag.layer.cornerRadius = 7.5
- newTag.clipsToBounds = true
- newTag.backgroundColor = .primary_3
- infoView.addArrangedSubview(newTag)
-
- let newLabel = UILabel()
- newLabel.text = "New"
- newLabel.font = .body_xs
- newLabel.textColor = .text_1
- newTag.addSubview(newLabel)
- newLabel.snp.makeConstraints { make in
- make.verticalEdges.equalToSuperview().inset(0.5)
- make.horizontalEdges.equalToSuperview().inset(6)
- }
-
- chatButton.setBackgroundImage(.primary_7, for: .normal)
- chatButton.setTitle(.init(key: "B00123"), for: .normal)
- chatButton.titleLabel?.font = .heading_h5
- chatButton.setTitleColor(.text_1, for: .normal)
- chatButton.layer.cornerRadius = 11
- chatButton.clipsToBounds = true
- chatButton.backgroundColor = .fill_2
- chatButton.contentEdgeInsets = .init(top: 0, left: 16, bottom: 0, right: 16)
- chatButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- guard let curItem else { return }
- pushToChat(uid: curItem.userNo)
- curItem.contacted = true
- update(curItem)
- }), for: .touchUpInside)
- container.addSubview(chatButton)
- chatButton.snp.makeConstraints { make in
- make.trailing.equalToSuperview()
- make.centerY.equalToSuperview()
- make.height.equalTo(22)
- }
- }
- }
|