Skip to content

Commit da79b05

Browse files
committed
【修改信息】 commit 优化
1 parent 80e789b commit da79b05

14 files changed

Lines changed: 15913 additions & 282 deletions

File tree

ZLGitHubClient/ZLGitHubClient.xcodeproj/project.pbxproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
7403A3652DD0F26C009141E1 /* ZLCommitInfoPatchCellData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7403A3642DD0F25A009141E1 /* ZLCommitInfoPatchCellData.swift */; };
4040
7403A36E2DD253B7009141E1 /* ZLReportHeightWebViewV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7403A36D2DD253B5009141E1 /* ZLReportHeightWebViewV2.swift */; };
4141
7407C8A52DD3A5C80052A413 /* gitpatchV2.html in Resources */ = {isa = PBXBuildFile; fileRef = 7407C8A42DD3A5B80052A413 /* gitpatchV2.html */; };
42-
7407C8A72DD8CA660052A413 /* gitpatchV2.css in Resources */ = {isa = PBXBuildFile; fileRef = 7407C8A62DD8CA660052A413 /* gitpatchV2.css */; };
42+
7407C8AA2DDA59570052A413 /* ZLPatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8A92DDA59530052A413 /* ZLPatchView.swift */; };
43+
7407C8B52DDB89420052A413 /* ZLCommitInfoFilePathHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8B42DDB89350052A413 /* ZLCommitInfoFilePathHeaderView.swift */; };
44+
7407C8B72DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8B62DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift */; };
4345
740C2F2B2830F9E300DAFF0E /* ZLExploreChildListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2F2A2830F9E300DAFF0E /* ZLExploreChildListController.swift */; };
4446
740C2F362832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2F352832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift */; };
4547
740C2FBC2838D46400DAFF0E /* ZLStarRepoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2FBB2838D46400DAFF0E /* ZLStarRepoViewController.swift */; };
@@ -349,7 +351,9 @@
349351
7403A3642DD0F25A009141E1 /* ZLCommitInfoPatchCellData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCommitInfoPatchCellData.swift; sourceTree = "<group>"; };
350352
7403A36D2DD253B5009141E1 /* ZLReportHeightWebViewV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLReportHeightWebViewV2.swift; sourceTree = "<group>"; };
351353
7407C8A42DD3A5B80052A413 /* gitpatchV2.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = gitpatchV2.html; sourceTree = "<group>"; };
352-
7407C8A62DD8CA660052A413 /* gitpatchV2.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = gitpatchV2.css; sourceTree = "<group>"; };
354+
7407C8A92DDA59530052A413 /* ZLPatchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPatchView.swift; sourceTree = "<group>"; };
355+
7407C8B42DDB89350052A413 /* ZLCommitInfoFilePathHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCommitInfoFilePathHeaderView.swift; sourceTree = "<group>"; };
356+
7407C8B62DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCommitInfoFilePathHeaderViewData.swift; sourceTree = "<group>"; };
353357
7408EC222533BD72001DA1EC /* ZLGithubAppKey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZLGithubAppKey.h; sourceTree = "<group>"; };
354358
740C2F2A2830F9E300DAFF0E /* ZLExploreChildListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLExploreChildListController.swift; sourceTree = "<group>"; };
355359
740C2F352832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLBaseCardTableViewCell.swift; sourceTree = "<group>"; };
@@ -760,6 +764,7 @@
760764
366DB83A241F3178002A0896 /* view */ = {
761765
isa = PBXGroup;
762766
children = (
767+
7407C8B42DDB89350052A413 /* ZLCommitInfoFilePathHeaderView.swift */,
763768
7403A3622DD0F071009141E1 /* ZLCommitInfoPatchCell.swift */,
764769
7403A35E2DD0EA47009141E1 /* ZLCommitInfoHeaderCell.swift */,
765770
366DB83B241F31A3002A0896 /* ZLCommitTableViewCell.swift */,
@@ -770,6 +775,7 @@
770775
366DB844241F4539002A0896 /* viewModel */ = {
771776
isa = PBXGroup;
772777
children = (
778+
7407C8B62DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift */,
773779
7403A3642DD0F25A009141E1 /* ZLCommitInfoPatchCellData.swift */,
774780
7403A3602DD0EC58009141E1 /* ZLCommitInfoHeaderCellData.swift */,
775781
366DB845241F4566002A0896 /* ZLCommitTableViewCellData.swift */,
@@ -874,12 +880,19 @@
874880
7403A3692DD24C42009141E1 /* GitPatch */ = {
875881
isa = PBXGroup;
876882
children = (
877-
7407C8A62DD8CA660052A413 /* gitpatchV2.css */,
878883
7407C8A42DD3A5B80052A413 /* gitpatchV2.html */,
879884
);
880885
path = GitPatch;
881886
sourceTree = "<group>";
882887
};
888+
7407C8A82DDA59450052A413 /* ZLPatchView */ = {
889+
isa = PBXGroup;
890+
children = (
891+
7407C8A92DDA59530052A413 /* ZLPatchView.swift */,
892+
);
893+
path = ZLPatchView;
894+
sourceTree = "<group>";
895+
};
883896
740C2F342832A1BD00DAFF0E /* ZLBaseCardTableViewCell */ = {
884897
isa = PBXGroup;
885898
children = (
@@ -1915,6 +1928,7 @@
19151928
74C861C222F0259700A30B79 /* ZLReuseView */ = {
19161929
isa = PBXGroup;
19171930
children = (
1931+
7407C8A82DDA59450052A413 /* ZLPatchView */,
19181932
7403A3432DCF9CED009141E1 /* ZLReleaseTableViewCell */,
19191933
74F9CEF32D9AEC90008E3920 /* ZLDiscussionTableViewCell */,
19201934
7466363C2D95B5A700FC69EC /* ZLWebView */,
@@ -2619,7 +2633,6 @@
26192633
745D48C9257249D700E67AEE /* github_style_markdown.css in Resources */,
26202634
7426C7A12562EF6B00DFDA04 /* github_style.css in Resources */,
26212635
74C861CA22F02BED00A30B79 /* ZLGitHubClientLocalizable.strings in Resources */,
2622-
7407C8A72DD8CA660052A413 /* gitpatchV2.css in Resources */,
26232636
0ADF903721D4B01900BF86CD /* Assets.xcassets in Resources */,
26242637
7436AC8621EB815800F03276 /* SYDCenteralFactoryConfig.plist in Resources */,
26252638
0ADF903521D4B01900BF86CD /* Main.storyboard in Resources */,
@@ -2810,6 +2823,7 @@
28102823
7434CA852393EA1A00763220 /* ZLPushEventTableViewCellData.swift in Sources */,
28112824
7403A3452DCF9D89009141E1 /* ZLReleaseTableViewCell.swift in Sources */,
28122825
74634D4F2766408500A042F4 /* ZLOrgInfoHeaderCellData.swift in Sources */,
2826+
7407C8AA2DDA59570052A413 /* ZLPatchView.swift in Sources */,
28132827
743425C7230AC6AD0031AD7D /* ZLRepoInfoController.swift in Sources */,
28142828
74209D5424B66D820068891E /* ZLRepoLanguagesPercentView.swift in Sources */,
28152829
747FCA1525FFAA2B00D2C39B /* Fixed_Repo.intentdefinition in Sources */,
@@ -2859,6 +2873,7 @@
28592873
7467ABBC27F704A300F8905B /* ZLPresenterMessageModel.swift in Sources */,
28602874
74EAB99D260B7D5800784695 /* ZLPullRequestHeaderTableViewCellData.swift in Sources */,
28612875
749DBC8424B39EEF00D02B2C /* ZLIssueCommentEventTableViewCell.swift in Sources */,
2876+
7407C8B72DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift in Sources */,
28622877
7403A3582DD0B88F009141E1 /* ZLReleaseInfoDescriptionCell.swift in Sources */,
28632878
74DB05B223F138840009FEAC /* ZLGistTableViewCell.swift in Sources */,
28642879
7496BF522600D57000DDD1BD /* ZLIssueTimelineTableViewCell.swift in Sources */,
@@ -3007,6 +3022,7 @@
30073022
744F655D281FC95C0045DCE9 /* ZLMyDiscussionsController.swift in Sources */,
30083023
74DF713323B1073100DB2BD5 /* ZLAboutViewController.swift in Sources */,
30093024
74299ECE27CA85A30095224E /* ZLSubmitCommentView.swift in Sources */,
3025+
7407C8B52DDB89420052A413 /* ZLCommitInfoFilePathHeaderView.swift in Sources */,
30103026
749DBC8E24B3D61000D02B2C /* ZLPullRequestEventTableViewCell.swift in Sources */,
30113027
743D225F2624ADA400C0B9FD /* ZLSearchGithubItemListSecondViewModel.swift in Sources */,
30123028
743D22712624C5C400C0B9FD /* ZLSearchItemTableViewCellData.swift in Sources */,

ZLGitHubClient/ZLGitHubClient/Class/UI/Commit/ZLCommitInfoController.swift

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class ZLCommitInfoController: ZMTableViewController {
1919
@objc var repoName: String?
2020
@objc var ref: String?
2121

22-
23-
2422
// model
2523
var model: ZLGithubCommitModel?
24+
25+
var lastIndex: Int = 0
26+
27+
var per_page: Int = 10
2628

2729

2830
@objc init() {
29-
super.init()
31+
super.init(style: .plain)
3032
}
3133

32-
33-
3434
required init?(coder: NSCoder) {
3535
fatalError("init(coder:) has not been implemented")
3636
}
@@ -52,13 +52,17 @@ class ZLCommitInfoController: ZMTableViewController {
5252

5353
self.zmNavigationBar.addRightView(moreButton)
5454

55-
tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 20, right: 0)
55+
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
5656
tableView.register(ZLCommitInfoHeaderCell.self,
5757
forCellReuseIdentifier: "ZLCommitInfoHeaderCell")
5858
tableView.register(ZLCommitInfoPatchCell.self,
5959
forCellReuseIdentifier: "ZLCommitInfoPatchCell")
60+
tableView.register(ZLCommitInfoFilePathHeaderView.self,
61+
forHeaderFooterViewReuseIdentifier: "ZLCommitInfoFilePathHeaderView")
62+
tableView.register(ZLCommonSectionHeaderFooterView.self,
63+
forHeaderFooterViewReuseIdentifier: "ZLCommonSectionHeaderFooterView")
6064

61-
self.setRefreshViews(types: [.header])
65+
self.setRefreshViews(types: [.header,.footer])
6266
}
6367

6468
lazy var moreButton: UIButton = {
@@ -80,6 +84,10 @@ class ZLCommitInfoController: ZMTableViewController {
8084
requestCommitInfo()
8185
}
8286

87+
override func refreshLoadMoreData() {
88+
generateMoreFileData()
89+
}
90+
8391

8492
}
8593

@@ -96,7 +104,7 @@ extension ZLCommitInfoController {
96104
}
97105

98106

99-
//
107+
// MARK: - Request
100108
extension ZLCommitInfoController {
101109

102110
func requestCommitInfo() {
@@ -111,21 +119,21 @@ extension ZLCommitInfoController {
111119
if resultModel.result,
112120
let data = resultModel.data as? ZLGithubCommitModel {
113121
self.model = data
122+
self.lastIndex = 0
114123

115-
var cellDatas: [ZMBaseTableViewCellViewModel] = [ZLCommitInfoHeaderCellData(model: data)]
116-
117-
cellDatas.append(contentsOf: data.files.map({ model in
118-
return ZLCommitInfoPatchCellData(model: model, cellHeight: nil)
119-
}))
124+
let sectionDatas = self.generateFirstPageSectionDatas(data: data)
120125

121-
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(400), execute: {
122-
self.zm_addSubViewModels(cellDatas)
126+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(200), execute: {
123127

124128
self.sectionDataArray.forEach { $0.zm_removeFromSuperViewModel() }
125-
self.sectionDataArray = [ZMBaseTableViewSectionData(cellDatas: cellDatas)]
129+
130+
sectionDatas.forEach { $0.zm_addSuperViewModel(self) }
131+
132+
133+
self.sectionDataArray = sectionDatas
126134

127135
self.tableView.reloadData()
128-
self.endRefreshViews(noMoreData: true)
136+
self.endRefreshViews(noMoreData: data.files.count <= self.lastIndex)
129137
self.viewStatus = self.tableViewProxy.isEmpty ? .empty : .normal
130138
})
131139

@@ -139,28 +147,81 @@ extension ZLCommitInfoController {
139147
})
140148
}
141149

142-
// func requestCommitDiffInfo() {
143-
//
144-
//
145-
// ZLRepoServiceShared()?.getRepoCommitDiff(withLogin: login ?? "",
146-
// repoName: repoName ?? "",
147-
// ref: ref ?? "",
148-
// serialNumber: NSString.generateSerialNumber(),
149-
// completeHandle: { [weak self](resultModel: ZLOperationResultModel) in
150-
// guard let self else { return }
151-
//
152-
// if resultModel.result,
153-
// let data = resultModel.data as? String {
154-
//
155-
// let cellData = ZLCommitInfoPatchCellData(patchStr: data, cellHeight: nil)
156-
// self.zm_addSubViewModels([cellData])
157-
// self.sectionDataArray.first?.cellDatas.append(cellData)
158-
// self.tableView.reloadData()
159-
//
160-
// }
161-
//
162-
// })
163-
// }
150+
func generateMoreFileData() {
151+
let sectionDatas = self.generateNextPageFileData()
152+
153+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(200), execute: {
154+
155+
156+
sectionDatas.forEach { $0.zm_addSuperViewModel(self) }
157+
158+
159+
self.sectionDataArray.append(contentsOf: sectionDatas)
160+
161+
self.tableView.reloadData()
162+
163+
self.endRefreshViews(noMoreData: (self.model?.files.count ?? 0) <= self.lastIndex)
164+
})
165+
}
164166

165167
}
166168

169+
// MARK: - generate Data
170+
extension ZLCommitInfoController {
171+
172+
@objc dynamic func generateFirstPageSectionDatas(data: ZLGithubCommitModel) -> [ZMBaseTableViewSectionData] {
173+
var sectionDatas: [ZMBaseTableViewSectionData] = []
174+
175+
sectionDatas.append(ZMBaseTableViewSectionData(
176+
cellDatas: [ZLCommitInfoHeaderCellData(model: data)],
177+
headerData: ZLCommonSectionHeaderFooterViewDataV2(backColor: .clear, viewHeight: 8),
178+
footerData: ZLCommonSectionHeaderFooterViewDataV2(backColor: .clear, viewHeight: 8)))
179+
180+
181+
var files = data.files
182+
if files.count > per_page {
183+
files = Array(files[0..<per_page])
184+
self.lastIndex = per_page
185+
} else {
186+
self.lastIndex = files.count
187+
}
188+
189+
190+
let fileSectionDatas = files.map({ fileModel in
191+
let sectionData = ZMBaseTableViewSectionData()
192+
sectionData.headerData = ZLCommitInfoFilePathHeaderViewData(filePath:fileModel.filename)
193+
sectionData.cellDatas = [ZLCommitInfoPatchCellData(model: fileModel,
194+
cellHeight: nil)]
195+
return sectionData
196+
})
197+
sectionDatas.append(contentsOf: fileSectionDatas)
198+
199+
return sectionDatas
200+
}
201+
202+
@objc dynamic func generateNextPageFileData() -> [ZMBaseTableViewSectionData] {
203+
guard let model else { return [] }
204+
205+
var files = model.files
206+
let newLastIndex = self.lastIndex + self.per_page
207+
if files.count > newLastIndex {
208+
files = Array(files[self.lastIndex..<newLastIndex])
209+
self.lastIndex = newLastIndex
210+
} else {
211+
files = Array(files[self.lastIndex..<files.count])
212+
self.lastIndex = model.files.count
213+
}
214+
215+
let fileSectionDatas = files.map({ fileModel in
216+
let sectionData = ZMBaseTableViewSectionData()
217+
sectionData.headerData = ZLCommitInfoFilePathHeaderViewData(filePath:fileModel.filename)
218+
sectionData.cellDatas = [ZLCommitInfoPatchCellData(model: fileModel,
219+
cellHeight: nil)]
220+
return sectionData
221+
})
222+
223+
return fileSectionDatas
224+
}
225+
}
226+
227+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// ZLCommitInfoFilePathHeaderView.swift
3+
// ZLGitHubClient
4+
//
5+
// Created by 朱猛 on 2025/5/19.
6+
// Copyright © 2025 ZM. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import ZMMVVM
11+
12+
class ZLCommitInfoFilePathHeaderView: UITableViewHeaderFooterView {
13+
14+
var viewData: ZLCommitInfoFilePathHeaderViewData? {
15+
zm_viewModel as? ZLCommitInfoFilePathHeaderViewData
16+
}
17+
18+
lazy var titleLabel: UILabel = {
19+
let label = UILabel()
20+
label.font = .zlMediumFont(withSize: 16)
21+
label.textColor = .label(withName: "ZLLabelColor1")
22+
label.numberOfLines = 2
23+
label.lineBreakMode = .byTruncatingHead
24+
return label
25+
}()
26+
27+
override init(reuseIdentifier: String?) {
28+
super.init(reuseIdentifier: reuseIdentifier)
29+
30+
contentView.backgroundColor = .back(withName: "ZLCellBack")
31+
contentView.addSubview(self.titleLabel)
32+
33+
self.titleLabel.snp.makeConstraints { (make) in
34+
make.left.equalTo(10)
35+
make.right.equalTo(-10)
36+
make.top.equalTo(10)
37+
make.bottom.equalTo(-10)
38+
}
39+
}
40+
41+
required init?(coder: NSCoder) {
42+
fatalError("init(coder:) has not been implemented")
43+
}
44+
45+
}
46+
47+
extension ZLCommitInfoFilePathHeaderView: ZMBaseViewUpdatableWithViewData {
48+
func zm_fillWithViewData(viewData: ZLCommitInfoFilePathHeaderViewData) {
49+
self.titleLabel.text = viewData.filePath
50+
}
51+
}

0 commit comments

Comments
 (0)