Skip to content

Commit 1e2c631

Browse files
committed
【修改信息】 compare
1 parent da79b05 commit 1e2c631

File tree

5 files changed

+309
-9
lines changed

5 files changed

+309
-9
lines changed

ZLGitHubClient/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ CHECKOUT OPTIONS:
351351
:git: https://github.com/ExistOrLive/ZLGithubOAuth.git
352352
:tag: 1.3.1
353353
ZLGitRemoteService:
354-
:commit: 717402a1e211fed4f4ec5ea21ab32cd9471987cf
354+
:commit: fd499dd4e8cfa9bc5b7f07d81ff3df67ca9a2d3e
355355
:git: https://github.com/ExistOrLive/ZLGitRemoteService.git
356356
ZLUIUtilities:
357357
:git: https://github.com/ExistOrLive/ZLUIUtilities.git

ZLGitHubClient/ZLGitHubClient.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
7407C8AA2DDA59570052A413 /* ZLPatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8A92DDA59530052A413 /* ZLPatchView.swift */; };
4343
7407C8B52DDB89420052A413 /* ZLCommitInfoFilePathHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8B42DDB89350052A413 /* ZLCommitInfoFilePathHeaderView.swift */; };
4444
7407C8B72DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8B62DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift */; };
45+
7407C8B92DDB9B530052A413 /* ZLCompareCommitController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8B82DDB9B490052A413 /* ZLCompareCommitController.swift */; };
46+
7407C8BB2DDBA21E0052A413 /* ZLCompareCommitFilesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7407C8BA2DDBA20F0052A413 /* ZLCompareCommitFilesController.swift */; };
4547
740C2F2B2830F9E300DAFF0E /* ZLExploreChildListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2F2A2830F9E300DAFF0E /* ZLExploreChildListController.swift */; };
4648
740C2F362832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2F352832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift */; };
4749
740C2FBC2838D46400DAFF0E /* ZLStarRepoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740C2FBB2838D46400DAFF0E /* ZLStarRepoViewController.swift */; };
@@ -354,6 +356,8 @@
354356
7407C8A92DDA59530052A413 /* ZLPatchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLPatchView.swift; sourceTree = "<group>"; };
355357
7407C8B42DDB89350052A413 /* ZLCommitInfoFilePathHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCommitInfoFilePathHeaderView.swift; sourceTree = "<group>"; };
356358
7407C8B62DDB8CF10052A413 /* ZLCommitInfoFilePathHeaderViewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCommitInfoFilePathHeaderViewData.swift; sourceTree = "<group>"; };
359+
7407C8B82DDB9B490052A413 /* ZLCompareCommitController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCompareCommitController.swift; sourceTree = "<group>"; };
360+
7407C8BA2DDBA20F0052A413 /* ZLCompareCommitFilesController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLCompareCommitFilesController.swift; sourceTree = "<group>"; };
357361
7408EC222533BD72001DA1EC /* ZLGithubAppKey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZLGithubAppKey.h; sourceTree = "<group>"; };
358362
740C2F2A2830F9E300DAFF0E /* ZLExploreChildListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLExploreChildListController.swift; sourceTree = "<group>"; };
359363
740C2F352832A1E100DAFF0E /* ZLBaseCardTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZLBaseCardTableViewCell.swift; sourceTree = "<group>"; };
@@ -872,6 +876,8 @@
872876
7403A35B2DD0E6FB009141E1 /* Commit */ = {
873877
isa = PBXGroup;
874878
children = (
879+
7407C8BA2DDBA20F0052A413 /* ZLCompareCommitFilesController.swift */,
880+
7407C8B82DDB9B490052A413 /* ZLCompareCommitController.swift */,
875881
7403A35C2DD0E9AB009141E1 /* ZLCommitInfoController.swift */,
876882
);
877883
path = Commit;
@@ -2818,6 +2824,7 @@
28182824
files = (
28192825
74591A842D89C079002A9CF7 /* ZLWorkboardTableViewSectionHeaderData.swift in Sources */,
28202826
74C3F8C922D1E2DB0086A3F9 /* ZLLoginViewModel.swift in Sources */,
2827+
7407C8BB2DDBA21E0052A413 /* ZLCompareCommitFilesController.swift in Sources */,
28212828
7456B74A279DC4AA0033AFB1 /* ZLIssueMileStoneCellData.swift in Sources */,
28222829
74FCBDA623142F1300DDE46A /* ZLEditProfileController.swift in Sources */,
28232830
7434CA852393EA1A00763220 /* ZLPushEventTableViewCellData.swift in Sources */,
@@ -2987,6 +2994,7 @@
29872994
7451F149247A99400047A186 /* ZLRepoForkedReposController.swift in Sources */,
29882995
74F837D127D9047E00109BAB /* ZLIssueOperateCell.swift in Sources */,
29892996
742935C725B911A2001CD142 /* ZLGithubCollectedRepoModel.swift in Sources */,
2997+
7407C8B92DDB9B530052A413 /* ZLCompareCommitController.swift in Sources */,
29902998
7456B73D279C99180033AFB1 /* ZLIssueMilestoneCell.swift in Sources */,
29912999
749DBC8224B38C0C00D02B2C /* ZLGollumEventTableViewCellData.swift in Sources */,
29923000
7444B2A22567C1B400488EF0 /* ZLWorkboardViewController.swift in Sources */,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// ZLRepoCompareCommitController.swift
3+
// ZLGitHubClient
4+
//
5+
// Created by 朱猛 on 2025/5/20.
6+
// Copyright © 2025 ZM. All rights reserved.
7+
//
8+
9+
//
10+
// ZLRepoCommitController.swift
11+
// ZLGitHubClient
12+
//
13+
// Created by 朱猛 on 2020/3/16.
14+
// Copyright © 2020 ZM. All rights reserved.
15+
//
16+
17+
import UIKit
18+
import ZMMVVM
19+
import ZLUIUtilities
20+
import ZLGitRemoteService
21+
22+
class ZLRepoCompareCommitController: ZMTableViewController {
23+
24+
@objc var login: String?
25+
@objc var repoName: String?
26+
@objc var baseRef: String?
27+
@objc var headRef: String?
28+
29+
var model: ZLGithubCompareModel?
30+
31+
override func viewDidLoad() {
32+
super.viewDidLoad()
33+
viewStatus = .loading
34+
refreshLoadNewData()
35+
}
36+
37+
override func setupUI() {
38+
super.setupUI()
39+
40+
self.title = ZLLocalizedString(string: "commits", comment: "提交")
41+
42+
tableView.contentInsetAdjustmentBehavior = .automatic
43+
tableView.contentInset = UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
44+
setRefreshViews(types: [.header])
45+
tableView.register(ZLCommitTableViewCell.self,
46+
forCellReuseIdentifier: "ZLCommitTableViewCell")
47+
}
48+
49+
override func refreshLoadNewData() {
50+
loadData(isLoadNew: true)
51+
}
52+
53+
54+
55+
}
56+
57+
58+
extension ZLRepoCompareCommitController {
59+
func loadData(isLoadNew: Bool) {
60+
61+
ZLRepoServiceShared()?.getRepoCommitCompare(withLogin: login ?? "",
62+
repoName: repoName ?? "",
63+
baseRef: baseRef ?? "",
64+
headRef: headRef ?? "",
65+
serialNumber: NSString.generateSerialNumber())
66+
{ [weak self] resultModel in
67+
guard let self else { return }
68+
if resultModel.result == true, let model = resultModel.data as? ZLGithubCompareModel {
69+
self.model = model
70+
let cellDataArray: [ZLCommitTableViewCellData] = model.commits.map {
71+
let cellData = ZLCommitTableViewCellData(commitModel: $0)
72+
return cellData
73+
}
74+
self.zm_addSubViewModels(cellDataArray)
75+
76+
self.sectionDataArray.forEach { $0.zm_removeFromSuperViewModel() }
77+
self.sectionDataArray = [ZMBaseTableViewSectionData(cellDatas: cellDataArray)]
78+
79+
self.tableView.reloadData()
80+
81+
self.endRefreshViews(noMoreData: true )
82+
self.viewStatus = self.tableViewProxy.isEmpty ? .empty : .normal
83+
84+
} else {
85+
self.endRefreshViews()
86+
self.viewStatus = self.tableViewProxy.isEmpty ? .error : .normal
87+
88+
if let errorModel = resultModel.data as? ZLGithubRequestErrorModel {
89+
ZLToastView.showMessage(errorModel.message)
90+
}
91+
}
92+
}
93+
94+
}
95+
96+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
//
2+
// ZLCompareCommitFilesController.swift
3+
// ZLGitHubClient
4+
//
5+
// Created by 朱猛 on 2025/5/20.
6+
// Copyright © 2025 ZM. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import ZLGitRemoteService
11+
import ZLUIUtilities
12+
import ZLUtilities
13+
import ZMMVVM
14+
15+
class ZLCompareCommitFilesController: ZMTableViewController {
16+
17+
@objc var login: String?
18+
@objc var repoName: String?
19+
@objc var baseRef: String?
20+
@objc var headRef: String?
21+
22+
var model: ZLGithubCompareModel?
23+
var lastIndex = 0
24+
let per_page = 10
25+
26+
@objc init() {
27+
super.init(style: .plain)
28+
}
29+
30+
required init?(coder: NSCoder) {
31+
fatalError("init(coder:) has not been implemented")
32+
}
33+
34+
override func viewDidLoad() {
35+
super.viewDidLoad()
36+
viewStatus = .loading
37+
refreshLoadNewData()
38+
}
39+
40+
override func setupUI() {
41+
super.setupUI()
42+
43+
self.title = ZLLocalizedString(string: "commits", comment: "提交")
44+
45+
46+
tableView.register(ZLCommitInfoPatchCell.self,
47+
forCellReuseIdentifier: "ZLCommitInfoPatchCell")
48+
tableView.register(ZLCommitInfoFilePathHeaderView.self,
49+
forHeaderFooterViewReuseIdentifier: "ZLCommitInfoFilePathHeaderView")
50+
tableView.register(ZLCommonSectionHeaderFooterView.self,
51+
forHeaderFooterViewReuseIdentifier: "ZLCommonSectionHeaderFooterView")
52+
53+
self.setRefreshViews(types: [.header,.footer])
54+
}
55+
56+
override func refreshLoadNewData() {
57+
requestCompareInfo()
58+
}
59+
60+
override func refreshLoadMoreData() {
61+
generateMoreFileData()
62+
}
63+
64+
}
65+
66+
67+
68+
69+
// MARK: - Request
70+
extension ZLCompareCommitFilesController {
71+
72+
func requestCompareInfo() {
73+
74+
ZLRepoServiceShared()?.getRepoCommitCompare(withLogin: login ?? "",
75+
repoName: repoName ?? "",
76+
baseRef: baseRef ?? "",
77+
headRef: headRef ?? "",
78+
serialNumber: NSString.generateSerialNumber())
79+
{ [weak self] resultModel in
80+
guard let self else { return }
81+
if resultModel.result == true,
82+
let model = resultModel.data as? ZLGithubCompareModel {
83+
84+
self.model = model
85+
self.lastIndex = 0
86+
87+
let sectionDatas = self.generateFirstPageSectionDatas(data: model)
88+
89+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(200), execute: {
90+
91+
self.sectionDataArray.forEach { $0.zm_removeFromSuperViewModel() }
92+
93+
sectionDatas.forEach { $0.zm_addSuperViewModel(self) }
94+
95+
96+
self.sectionDataArray = sectionDatas
97+
98+
self.tableView.reloadData()
99+
self.endRefreshViews(noMoreData: model.files.count <= self.lastIndex)
100+
self.viewStatus = self.tableViewProxy.isEmpty ? .empty : .normal
101+
})
102+
103+
} else {
104+
if let errorModel = resultModel.data as? ZLGithubRequestErrorModel {
105+
ZLToastView.showMessage(errorModel.message)
106+
}
107+
self.endRefreshViews()
108+
self.viewStatus = self.tableViewProxy.isEmpty ? .error : .normal
109+
}
110+
}
111+
}
112+
113+
func generateMoreFileData() {
114+
let sectionDatas = self.generateNextPageFileData()
115+
116+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(200), execute: {
117+
118+
119+
sectionDatas.forEach { $0.zm_addSuperViewModel(self) }
120+
121+
122+
self.sectionDataArray.append(contentsOf: sectionDatas)
123+
124+
self.tableView.reloadData()
125+
126+
self.endRefreshViews(noMoreData: (self.model?.files.count ?? 0) <= self.lastIndex)
127+
})
128+
}
129+
130+
}
131+
132+
// MARK: - generate Data
133+
extension ZLCompareCommitFilesController {
134+
135+
@objc dynamic func generateFirstPageSectionDatas(data: ZLGithubCompareModel) -> [ZMBaseTableViewSectionData] {
136+
var sectionDatas: [ZMBaseTableViewSectionData] = []
137+
138+
139+
var files = data.files
140+
if files.count > per_page {
141+
files = Array(files[0..<per_page])
142+
self.lastIndex = per_page
143+
} else {
144+
self.lastIndex = files.count
145+
}
146+
147+
148+
let fileSectionDatas = files.map({ fileModel in
149+
let sectionData = ZMBaseTableViewSectionData()
150+
sectionData.headerData = ZLCommitInfoFilePathHeaderViewData(filePath:fileModel.filename)
151+
sectionData.cellDatas = [ZLCommitInfoPatchCellData(model: fileModel,
152+
cellHeight: nil)]
153+
return sectionData
154+
})
155+
sectionDatas.append(contentsOf: fileSectionDatas)
156+
157+
return sectionDatas
158+
}
159+
160+
@objc dynamic func generateNextPageFileData() -> [ZMBaseTableViewSectionData] {
161+
guard let model else { return [] }
162+
163+
var files = model.files
164+
let newLastIndex = self.lastIndex + self.per_page
165+
if files.count > newLastIndex {
166+
files = Array(files[self.lastIndex..<newLastIndex])
167+
self.lastIndex = newLastIndex
168+
} else {
169+
files = Array(files[self.lastIndex..<files.count])
170+
self.lastIndex = model.files.count
171+
}
172+
173+
let fileSectionDatas = files.map({ fileModel in
174+
let sectionData = ZMBaseTableViewSectionData()
175+
sectionData.headerData = ZLCommitInfoFilePathHeaderViewData(filePath:fileModel.filename)
176+
sectionData.cellDatas = [ZLCommitInfoPatchCellData(model: fileModel,
177+
cellHeight: nil)]
178+
return sectionData
179+
})
180+
181+
return fileSectionDatas
182+
}
183+
}
184+
185+
186+

ZLGitHubClient/ZLGitHubClient/Class/UI/ZLReuseView/ZLPullRequestTableViewCell/viewmodel/ZLPullRequestHeaderTableViewCellData.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,25 @@ extension ZLPullRequestHeaderTableViewCellData: ZLPullRequestHeaderTableViewCell
9696
}
9797
}
9898
func onFileButtonClicked() {
99-
100-
if let url = URL(string: "\(data.repository?.pullRequest?.url ?? "")/files"), let vc = ZLUIRouter.getVC(key: ZLUIRouter.WebContentController, params: ["requestURL": url]) {
101-
self.zm_viewController?.navigationController?.pushViewController(vc, animated: true)
102-
}
99+
let vc = ZLCompareCommitFilesController()
100+
vc.login = data.repository?.owner.login
101+
vc.repoName = data.repository?.name
102+
vc.baseRef = data.repository?.pullRequest?.baseRefOid
103+
vc.headRef = data.repository?.pullRequest?.headRefOid
104+
self.zm_viewController?.navigationController?.pushViewController(vc,animated: true)
105+
// if let url = URL(string: "\(data.repository?.pullRequest?.url ?? "")/files"), let vc = ZLUIRouter.getVC(key: ZLUIRouter.WebContentController, params: ["requestURL": url]) {
106+
// self.zm_viewController?.navigationController?.pushViewController(vc, animated: true)
107+
// }
103108
}
104109
func onCommitButtonClicked() {
105-
106-
if let url = URL(string: "\(data.repository?.pullRequest?.url ?? "")/commits"), let vc = ZLUIRouter.getVC(key: ZLUIRouter.WebContentController, params: ["requestURL": url]) {
107-
self.zm_viewController?.navigationController?.pushViewController(vc, animated: true)
108-
}
110+
let vc = ZLRepoCompareCommitController()
111+
vc.login = data.repository?.owner.login
112+
vc.repoName = data.repository?.name
113+
vc.baseRef = data.repository?.pullRequest?.baseRefOid
114+
vc.headRef = data.repository?.pullRequest?.headRefOid
115+
self.zm_viewController?.navigationController?.pushViewController(vc,animated: true)
116+
// if let url = URL(string: "\(data.repository?.pullRequest?.url ?? "")/commits"), let vc = ZLUIRouter.getVC(key: ZLUIRouter.WebContentController, params: ["requestURL": url]) {
117+
// self.zm_viewController?.navigationController?.pushViewController(vc, animated: true)
118+
// }
109119
}
110120
}

0 commit comments

Comments
 (0)