Skip to content

Commit 2a416ca

Browse files
committed
feat: 多账号切换 ✨
1 parent 5da3988 commit 2a416ca

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

NeteaseTVDemo.xcodeproj/xcuserdata/fengyn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
endingColumnNumber = "9223372036854775807"
2929
startingLineNumber = "1071"
3030
endingLineNumber = "1071"
31-
landmarkName = "judgeProgress()"
31+
landmarkName = "addBufferProgressObserver()"
3232
landmarkType = "7">
3333
</BreakpointContent>
3434
</BreakpointProxy>

NeteaseTVDemo/Modules/Profile/WKAccountCell.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import UIKit
33
import TVUIKit
4+
import NeteaseRequest
45

56
class WKAccountCell: UICollectionViewCell {
67

@@ -19,7 +20,17 @@ class WKAccountCell: UICollectionViewCell {
1920

2021
}
2122

23+
2224
required init?(coder: NSCoder) {
2325
fatalError("init(coder:) has not been implemented")
2426
}
27+
28+
// func loadData(with model: NRProfileModel, isAdd: Bool) {
29+
// if isAdd {
30+
// self.userView.image = UIImage(systemName: "person.crop.circle.badge.plus")
31+
// } else {
32+
// self.userView.image = UIImage(named: "bgImage")
33+
// }
34+
// }
35+
2536
}

NeteaseTVDemo/Modules/Profile/WKProfileViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ extension WKProfileViewController: UITableViewDelegate, UITableViewDataSource {
125125

126126

127127
header.clickAvatarAction = {
128-
let loginVC = WKLoginViewController.creat()
129-
// let loginVC = WKSwitchAccountVC.creat()//TODO:
130-
loginVC.modalPresentationStyle = .blurOverFullScreen
131-
self.present(loginVC, animated: true)
128+
if let am:[WKUserModel] = UserDefaults.standard.codable(forKey: "accounts"), am.count > 0 {
129+
let loginVC = WKSwitchAccountVC.creat()
130+
loginVC.modalPresentationStyle = .blurOverFullScreen
131+
self.present(loginVC, animated: true)
132+
} else {
133+
let loginVC = WKLoginViewController.creat()
134+
loginVC.modalPresentationStyle = .blurOverFullScreen
135+
self.present(loginVC, animated: true)
136+
}
132137
}
133138
return header
134139
}

NeteaseTVDemo/Modules/Profile/WKSwitchAccountVC.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11

22
import UIKit
3-
3+
import Kingfisher
44
class WKSwitchAccountVC: UIViewController {
55

66
@IBOutlet weak var collectionView: UICollectionView!
7+
var accountModels: [WKUserModel] {
8+
if let am:[WKUserModel] = UserDefaults.standard.codable(forKey: "accounts") {
9+
return am
10+
}
11+
return []
12+
}
713
static func creat() -> WKSwitchAccountVC {
814
let vc = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(identifier: String(describing: self)) as! WKSwitchAccountVC
915
return vc
@@ -52,11 +58,37 @@ class WKSwitchAccountVC: UIViewController {
5258

5359
extension WKSwitchAccountVC: UICollectionViewDelegate, UICollectionViewDataSource {
5460
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
55-
return 5
61+
return accountModels.count + 1
5662
}
5763

5864
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
5965
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: WKAccountCell.self), for: indexPath) as! WKAccountCell
66+
if indexPath.row == accountModels.count {
67+
cell.userView.image = UIImage(systemName: "person.crop.circle.badge.plus")
68+
cell.userView.title = ""
69+
} else {
70+
KingfisherManager.shared.retrieveImage(with: URL(string: accountModels[indexPath.row].user.avatarUrl)!, options: nil, progressBlock: nil) { result in
71+
switch result {
72+
case .success(let value):
73+
cell.userView.image = value.image
74+
case .failure(_):
75+
debugPrint("下载图片失败")
76+
}
77+
}
78+
cell.userView.title = accountModels[indexPath.row].user.nickname
79+
}
80+
// cell.loadData(with: nil, isAdd: indexPath.row == accountModels.count)
6081
return cell
6182
}
83+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
84+
if indexPath.row == accountModels.count {
85+
let loginVC = WKLoginViewController.creat()
86+
loginVC.modalPresentationStyle = .blurOverFullScreen
87+
self.present(loginVC, animated: true)
88+
} else {
89+
UserDefaults.standard.setValue(accountModels[indexPath.row].cookie, forKey: "cookie")
90+
cookie = accountModels[indexPath.row].cookie
91+
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "login"), object: nil, userInfo: nil)
92+
}
93+
}
6294
}

0 commit comments

Comments
 (0)