Skip to content

Commit 5da3988

Browse files
committed
feat: 多账户切换部分
1 parent 4d16de0 commit 5da3988

File tree

8 files changed

+183
-3
lines changed

8 files changed

+183
-3
lines changed

NeteaseTVDemo.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
2986B2EC2AB3F3C4002BC0CC /* WKTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2986B2EB2AB3F3C4002BC0CC /* WKTabBarViewController.swift */; };
7575
2986B2EE2AB3F418002BC0CC /* WKRecommendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2986B2ED2AB3F418002BC0CC /* WKRecommendViewController.swift */; };
7676
2986B2F02AB42E54002BC0CC /* WKPlayListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2986B2EF2AB42E54002BC0CC /* WKPlayListTableViewCell.swift */; };
77+
299458052B3AC7BE0015616E /* WKAccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299458032B3AC7BE0015616E /* WKAccountCell.swift */; };
78+
299458062B3AC7BE0015616E /* WKSwitchAccountVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299458042B3AC7BE0015616E /* WKSwitchAccountVC.swift */; };
7779
29A1D6FF2AD4E3E1005EAFC0 /* WKLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1D6FE2AD4E3E1005EAFC0 /* WKLoginViewController.swift */; };
7880
29A1D7012AD4ED8E005EAFC0 /* EFQRCode in Frameworks */ = {isa = PBXBuildFile; productRef = 29A1D7002AD4ED8E005EAFC0 /* EFQRCode */; };
7981
29A1D7042AD647E8005EAFC0 /* WKFindViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A1D7032AD647E8005EAFC0 /* WKFindViewController.swift */; };
@@ -207,6 +209,8 @@
207209
2986B2EB2AB3F3C4002BC0CC /* WKTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKTabBarViewController.swift; sourceTree = "<group>"; };
208210
2986B2ED2AB3F418002BC0CC /* WKRecommendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKRecommendViewController.swift; sourceTree = "<group>"; };
209211
2986B2EF2AB42E54002BC0CC /* WKPlayListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKPlayListTableViewCell.swift; sourceTree = "<group>"; };
212+
299458032B3AC7BE0015616E /* WKAccountCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKAccountCell.swift; sourceTree = "<group>"; };
213+
299458042B3AC7BE0015616E /* WKSwitchAccountVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKSwitchAccountVC.swift; sourceTree = "<group>"; };
210214
29A1D6FE2AD4E3E1005EAFC0 /* WKLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKLoginViewController.swift; sourceTree = "<group>"; };
211215
29A1D7032AD647E8005EAFC0 /* WKFindViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKFindViewController.swift; sourceTree = "<group>"; };
212216
29A1D7052AD65294005EAFC0 /* WKFindModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKFindModel.swift; sourceTree = "<group>"; };
@@ -426,6 +430,8 @@
426430
2969158B2AF246A300ED9298 /* WKAboutViewController.swift */,
427431
295E48EE2AE3AEAD00C259D2 /* WKProfileHeader.swift */,
428432
295E48F02AE3AF5400C259D2 /* WKAvatarView.swift */,
433+
299458032B3AC7BE0015616E /* WKAccountCell.swift */,
434+
299458042B3AC7BE0015616E /* WKSwitchAccountVC.swift */,
429435
);
430436
path = Profile;
431437
sourceTree = "<group>";
@@ -698,6 +704,7 @@
698704
29F2F6202AB190CB00E2F389 /* WKLyricTableViewCell.swift in Sources */,
699705
29A1D7092AD78721005EAFC0 /* WKPodcastViewController.swift in Sources */,
700706
295FA8162A985D3500B35C54 /* ViewController.swift in Sources */,
707+
299458062B3AC7BE0015616E /* WKSwitchAccountVC.swift in Sources */,
701708
297F2E092AD8CD3B002F4F24 /* WKPodcastDetailViewController.swift in Sources */,
702709
297F2E0E2AD8E6B6002F4F24 /* WKUserModel.swift in Sources */,
703710
29DC0E3D2AD252AD00DD314A /* WKRecommendPlaylistVC.swift in Sources */,
@@ -730,6 +737,7 @@
730737
2969157C2AEF48A900ED9298 /* WKMyCollectionVC.swift in Sources */,
731738
2986B2EC2AB3F3C4002BC0CC /* WKTabBarViewController.swift in Sources */,
732739
F4905DF72A98DD9D00C76905 /* WKPlayerError.swift in Sources */,
740+
299458052B3AC7BE0015616E /* WKAccountCell.swift in Sources */,
733741
29EBE67C2ADFA8E20023E9C7 /* WKVideoViewController.swift in Sources */,
734742
296915742AE764E000ED9298 /* WKRecentAlbumListVC.swift in Sources */,
735743
297F2E1D2ADA7DC9002F4F24 /* WKSearchTypeModel.swift in Sources */,

NeteaseTVDemo/Base.lproj/Main.storyboard

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,83 @@
31723172
</objects>
31733173
<point key="canvasLocation" x="5371" y="11721"/>
31743174
</scene>
3175+
<!--Switch AccountVC-->
3176+
<scene sceneID="qLs-gL-COB">
3177+
<objects>
3178+
<viewController storyboardIdentifier="WKSwitchAccountVC" id="1L7-Cn-AdX" customClass="WKSwitchAccountVC" customModule="NeteaseTVDemo" customModuleProvider="target" sceneMemberID="viewController">
3179+
<layoutGuides>
3180+
<viewControllerLayoutGuide type="top" id="a1J-3J-RiP"/>
3181+
<viewControllerLayoutGuide type="bottom" id="XS6-Ch-Wjt"/>
3182+
</layoutGuides>
3183+
<view key="view" contentMode="scaleToFill" id="xVd-CN-oXK">
3184+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
3185+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3186+
<subviews>
3187+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bgImage" translatesAutoresizingMaskIntoConstraints="NO" id="zQo-qt-9zS">
3188+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
3189+
</imageView>
3190+
<visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PGI-lp-M2V">
3191+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
3192+
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="0Zs-Xh-4nU">
3193+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
3194+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3195+
<subviews>
3196+
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="rfU-9B-cq5">
3197+
<rect key="frame" x="200" y="390" width="1520" height="300"/>
3198+
<constraints>
3199+
<constraint firstAttribute="height" constant="300" id="twQ-gb-8Yh"/>
3200+
</constraints>
3201+
<collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="Qj1-k6-P9U">
3202+
<size key="itemSize" width="128" height="128"/>
3203+
<size key="headerReferenceSize" width="0.0" height="0.0"/>
3204+
<size key="footerReferenceSize" width="0.0" height="0.0"/>
3205+
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
3206+
</collectionViewFlowLayout>
3207+
<cells>
3208+
<collectionViewCell opaque="NO" multipleTouchEnabled="YES" contentMode="center" id="etW-TF-Pf4">
3209+
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
3210+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
3211+
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="dki-Zw-cyz">
3212+
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
3213+
<autoresizingMask key="autoresizingMask"/>
3214+
</collectionViewCellContentView>
3215+
</collectionViewCell>
3216+
</cells>
3217+
<connections>
3218+
<outlet property="dataSource" destination="1L7-Cn-AdX" id="xjf-H4-dKP"/>
3219+
<outlet property="delegate" destination="1L7-Cn-AdX" id="bDY-FP-mCF"/>
3220+
</connections>
3221+
</collectionView>
3222+
</subviews>
3223+
<constraints>
3224+
<constraint firstItem="rfU-9B-cq5" firstAttribute="centerY" secondItem="0Zs-Xh-4nU" secondAttribute="centerY" id="aeo-X7-GE0"/>
3225+
<constraint firstAttribute="trailing" secondItem="rfU-9B-cq5" secondAttribute="trailing" constant="200" id="bRn-Eo-i8K"/>
3226+
<constraint firstItem="rfU-9B-cq5" firstAttribute="leading" secondItem="0Zs-Xh-4nU" secondAttribute="leading" constant="200" id="fcX-4E-Hfw"/>
3227+
</constraints>
3228+
</view>
3229+
<blurEffect style="regular"/>
3230+
</visualEffectView>
3231+
</subviews>
3232+
<viewLayoutGuide key="safeArea" id="Lhm-vb-4lc"/>
3233+
<constraints>
3234+
<constraint firstItem="zQo-qt-9zS" firstAttribute="top" secondItem="xVd-CN-oXK" secondAttribute="top" id="Ae3-rf-pV9"/>
3235+
<constraint firstItem="PGI-lp-M2V" firstAttribute="leading" secondItem="xVd-CN-oXK" secondAttribute="leading" id="I3T-fi-FOc"/>
3236+
<constraint firstAttribute="trailing" secondItem="PGI-lp-M2V" secondAttribute="trailing" id="JVC-Y1-F2a"/>
3237+
<constraint firstAttribute="bottom" secondItem="zQo-qt-9zS" secondAttribute="bottom" id="TfO-B7-fP1"/>
3238+
<constraint firstItem="PGI-lp-M2V" firstAttribute="top" secondItem="xVd-CN-oXK" secondAttribute="top" id="Wt1-xb-KlB"/>
3239+
<constraint firstAttribute="trailing" secondItem="zQo-qt-9zS" secondAttribute="trailing" id="Xq4-PJ-ChS"/>
3240+
<constraint firstItem="zQo-qt-9zS" firstAttribute="leading" secondItem="xVd-CN-oXK" secondAttribute="leading" id="l2t-q4-CX8"/>
3241+
<constraint firstAttribute="bottom" secondItem="PGI-lp-M2V" secondAttribute="bottom" id="qDH-pS-Vgq"/>
3242+
</constraints>
3243+
</view>
3244+
<connections>
3245+
<outlet property="collectionView" destination="rfU-9B-cq5" id="bdi-4Q-QqX"/>
3246+
</connections>
3247+
</viewController>
3248+
<placeholder placeholderIdentifier="IBFirstResponder" id="LCc-t4-SyH" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
3249+
</objects>
3250+
<point key="canvasLocation" x="11298" y="6477"/>
3251+
</scene>
31753252
</scenes>
31763253
<designables>
31773254
<designable name="8Ls-zs-VDy"/>

NeteaseTVDemo/Modules/Login/WKLoginViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ class WKLoginViewController: UIViewController {
7474
//
7575
do {
7676
let userModel: NRProfileModel = try await fetchAccountInfo(cookie: cookie)
77-
UserDefaults.standard.set(codable: userModel, forKey: "userModel")
77+
let newAccount = WKUserModel(isSelected: true, user: userModel, cookie: cookie)
78+
var accounts: [WKUserModel] = UserDefaults.standard.codable(forKey: "accounts") ?? []
79+
accounts.removeAll { $0.user.userId == userModel.userId }
80+
accounts.append(newAccount)
81+
UserDefaults.standard.set(codable: accounts, forKey: "accounts")
82+
UserDefaults.standard.set(codable: accounts.last?.user, forKey: "userModel")
7883
} catch {
7984
print(error)
8085
}

NeteaseTVDemo/Modules/Login/WKUserModel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import NeteaseRequest
55
struct WKUserModel: Codable {
66
var isSelected: Bool
77
var user: NRProfileModel
8-
9-
init(isSelected: Bool, user: NRProfileModel) {
8+
var cookie: String
9+
10+
init(isSelected: Bool, user: NRProfileModel, cookie: String) {
1011
self.isSelected = isSelected
1112
self.user = user
13+
self.cookie = cookie
1214
}
1315
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import UIKit
3+
import TVUIKit
4+
5+
class WKAccountCell: UICollectionViewCell {
6+
7+
let userView = TVMonogramView()
8+
9+
override init(frame: CGRect) {
10+
super.init(frame: frame)
11+
({(view: TVMonogramView) in
12+
view.image = UIImage(named: "bgImage")
13+
view.title = "名字"
14+
self.contentView.addSubview(view)
15+
view.snp.makeConstraints { make in
16+
make.edges.equalTo(self.contentView)
17+
}
18+
})(userView)
19+
20+
}
21+
22+
required init?(coder: NSCoder) {
23+
fatalError("init(coder:) has not been implemented")
24+
}
25+
}

NeteaseTVDemo/Modules/Profile/WKProfileViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ extension WKProfileViewController: UITableViewDelegate, UITableViewDataSource {
126126

127127
header.clickAvatarAction = {
128128
let loginVC = WKLoginViewController.creat()
129+
// let loginVC = WKSwitchAccountVC.creat()//TODO:
129130
loginVC.modalPresentationStyle = .blurOverFullScreen
130131
self.present(loginVC, animated: true)
131132
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
import UIKit
3+
4+
class WKSwitchAccountVC: UIViewController {
5+
6+
@IBOutlet weak var collectionView: UICollectionView!
7+
static func creat() -> WKSwitchAccountVC {
8+
let vc = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(identifier: String(describing: self)) as! WKSwitchAccountVC
9+
return vc
10+
}
11+
12+
override func viewDidLoad() {
13+
super.viewDidLoad()
14+
collectionView.register(WKAccountCell.self, forCellWithReuseIdentifier: String(describing: WKAccountCell.self))
15+
collectionView.collectionViewLayout = makeSwitchAccountLayout()
16+
}
17+
18+
func makeSwitchAccountLayout () -> UICollectionViewLayout {
19+
20+
UICollectionViewCompositionalLayout {
21+
[weak self] _, _ in
22+
return self?.makeGridLayoutSection()
23+
}
24+
25+
26+
}
27+
28+
func makeGridLayoutSection() -> NSCollectionLayoutSection {
29+
30+
// let style = styleOverride ?? Settings.displayStyle
31+
// let heightDimension = NSCollectionLayoutDimension.estimated(380)
32+
let item = NSCollectionLayoutItem(layoutSize: NSCollectionLayoutSize(
33+
widthDimension: .fractionalWidth(1/5),
34+
heightDimension: .fractionalHeight(1)
35+
))
36+
let hSpacing: CGFloat = 30
37+
item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: hSpacing, bottom: 0, trailing: hSpacing)
38+
let group = NSCollectionLayoutGroup.horizontalGroup(with: NSCollectionLayoutSize(
39+
widthDimension: .fractionalWidth(1),
40+
heightDimension:.fractionalHeight(1)
41+
), repeatingSubitem: item, count: 5)
42+
let vSpacing: CGFloat = 0
43+
let baseSpacing: CGFloat = 0
44+
group.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: .fixed(baseSpacing), top: .fixed(vSpacing), trailing: .fixed(0), bottom: .fixed(vSpacing))
45+
let section = NSCollectionLayoutSection(group: group)
46+
section.interGroupSpacing = 0
47+
return section
48+
}
49+
50+
51+
}
52+
53+
extension WKSwitchAccountVC: UICollectionViewDelegate, UICollectionViewDataSource {
54+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
55+
return 5
56+
}
57+
58+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
59+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: WKAccountCell.self), for: indexPath) as! WKAccountCell
60+
return cell
61+
}
62+
}

0 commit comments

Comments
 (0)