-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserProfileViewController.swift
95 lines (90 loc) · 3.39 KB
/
UserProfileViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// UserProfileViewController.swift
// TACOS
//
// Created by 疋田朋也 on 2024/08/25.
//
import UIKit
import FirebaseFirestore
import FirebaseAuth
class UserProfileViewController: UIViewController {
var db = Firestore.firestore()
var created_date:Date?
var displayName:String?
let df = DateFormatter()
private let CreatedDate = UILabel()
private let DisplayName = UILabel()
private let TotalCoin = UILabel()
private let stackView = UIStackView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupView()
getUserdata()
setupStackview()
setupLabels()
setupConstraints()
}
private func setupView(){
self.title = "profile"
view.backgroundColor = .white
}
func getUserdata(){
if LoginManager.shared.isLoggedIn {
let uid = Auth.auth().currentUser?.uid
let userRef = db.collection("Users").document(uid!)
userRef.getDocument { (document, error) in
if let document = document, document.exists {
let data = document.data()
self.df.dateFormat = "yyyy-MM-dd HH:mm:ss"
let date_timestamp = data?["createdAt"] as! Timestamp
self.created_date = date_timestamp.dateValue()
self.displayName = data?["displayName"] as? String
self.DisplayName.text = self.displayName
self.CreatedDate.text = self.df.string(from: self.created_date ?? Date.now)
self.TotalCoin.text = data?["coin"] as? String
print(data?["coin"] ?? "")
} else {
print("Document does not exist")
}
}
} else {
print("ログインしてません")
let Createaccount = CreateAccountViewcontroller()
self.navigationController?.pushViewController(Createaccount, animated: true)
}
}
private func setupLabels(){
DisplayName.textColor = .black
DisplayName.translatesAutoresizingMaskIntoConstraints = false
CreatedDate.textColor = .black
CreatedDate.translatesAutoresizingMaskIntoConstraints = false
TotalCoin.textColor = .black
TotalCoin.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(DisplayName)
stackView.addArrangedSubview(CreatedDate)
stackView.addArrangedSubview(TotalCoin)
}
private func setupConstraints(){
NSLayoutConstraint.activate([
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
])
}
private func setupStackview(){
stackView.axis = .vertical
view.addSubview(stackView)
stackView.translatesAutoresizingMaskIntoConstraints = false
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
#Preview(){
UserProfileViewController()
}