Skip to content

Commit e9d4592

Browse files
committed
issue 状态信息
1 parent 915b4bb commit e9d4592

File tree

7 files changed

+73
-12
lines changed

7 files changed

+73
-12
lines changed

lib/common/dao/ReposDao.dart

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ class ReposDao {
9191
if (data == null || data.length == 0) {
9292
return new DataResult(null, false);
9393
}
94+
Repository repository = Repository.fromJson(data);
95+
var issueResult = await ReposDao.getRepositoryIssueStatusDao(userName, reposName);
96+
if (issueResult != null && issueResult.result) {
97+
repository.allIssueCount = int.parse(issueResult.data);
98+
}
9499
if (needDb) {
95-
provider.insert(fullName, json.encode(data));
100+
provider.insert(fullName, json.encode(repository.toJson()));
96101
}
97-
saveHistoryDao(fullName, DateTime.now(), json.encode(data));
98-
return new DataResult(Repository.fromJson(data), true);
102+
saveHistoryDao(fullName, DateTime.now(), json.encode(repository.toJson()));
103+
return new DataResult(repository, true);
99104
} else {
100105
return new DataResult(null, false);
101106
}
@@ -662,6 +667,30 @@ class ReposDao {
662667
}
663668
}
664669

670+
/**
671+
* 获取issue总数
672+
*/
673+
static getRepositoryIssueStatusDao(userName, repository) async {
674+
String url = Address.getReposIssue(userName, repository, null, null, null) + "&per_page=1";
675+
var res = await HttpManager.netFetch(url, null, null, null);
676+
if (res != null && res.result && res.headers != null) {
677+
try {
678+
List<String> link = res.headers['link'];
679+
if (link != null) {
680+
int indexStart = link[0].lastIndexOf("page=") + 5;
681+
int indexEnd = link[0].lastIndexOf(">");
682+
if (indexStart >= 0 && indexEnd >= 0) {
683+
String count = link[0].substring(indexStart, indexEnd);
684+
return new DataResult(count, true);
685+
}
686+
}
687+
} catch (e) {
688+
print(e);
689+
}
690+
}
691+
return new DataResult(null, false);
692+
}
693+
665694
/**
666695
* 获取阅读历史
667696
*/

lib/common/model/Repository.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Repository extends Object with _$RepositorySerializerMixin {
9393

9494
RepositoryPermissions permissions;
9595

96+
///issue总数,不参加序列化
97+
int allIssueCount;
98+
9699
Repository(
97100
this.id,
98101
this.size,

lib/common/style/GSYStyle.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ class GSYStrings {
299299
static const String repos_tab_issue_open = "打开";
300300
static const String repos_tab_issue_closed = "关闭";
301301
static const String repos_option_release = "版本";
302+
static const String repos_all_issue_count = "所有Issue数:";
303+
static const String repos_open_issue_count = "开启Issue数:";
304+
static const String repos_close_issue_count = "关闭Issue数:";
302305

303306
static const String repos_issue_search = "搜索";
304307

@@ -336,7 +339,6 @@ class GSYStrings {
336339
static const String release_tab_release = "版本";
337340
static const String release_tab_tag = "标记";
338341

339-
340342
static const String user_profile_name = "名字";
341343
static const String user_profile_email = "邮箱";
342344
static const String user_profile_link = "链接";
@@ -350,7 +352,7 @@ class GSYICons {
350352

351353
static const String DEFAULT_USER_ICON = 'static/images/logo.png';
352354
static const String DEFAULT_IMAGE = 'static/images/default_img.png';
353-
static const String DEFAULT_REMOTE_PIC = 'https://raw.githubusercontent.com/CarGuo/GSYGithubAppFlutter/master/static/images/logo.png';
355+
static const String DEFAULT_REMOTE_PIC = 'https://raw.githubusercontent.com/CarGuo/GSYGithubAppFlutter/master/static/images/logo.png';
354356

355357
static const IconData HOME = const IconData(0xe624, fontFamily: GSYICons.FONT_FAMILY);
356358
static const IconData MORE = const IconData(0xe674, fontFamily: GSYICons.FONT_FAMILY);

lib/common/utils/CommonUtils.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ class CommonUtils {
203203
});
204204
}
205205

206-
static Future<Null> showCommitOptionDialog(BuildContext context, List commitMaps, ValueChanged<int> onTap) {
206+
static Future<Null> showCommitOptionDialog(BuildContext context, List<String> commitMaps, ValueChanged<int> onTap,
207+
{width = 250.0, height = 400.0}) {
207208
return showDialog(
208209
context: context,
209210
builder: (BuildContext context) {
210211
return Center(
211212
child: new Container(
212-
width: 250.0,
213-
height: 400.0,
213+
width: width,
214+
height: height,
214215
padding: new EdgeInsets.all(4.0),
215216
margin: new EdgeInsets.all(20.0),
216217
decoration: new BoxDecoration(
@@ -221,13 +222,12 @@ class CommonUtils {
221222
child: new ListView.builder(
222223
itemCount: commitMaps.length,
223224
itemBuilder: (context, index) {
224-
String itemName = commitMaps[index]["message"] + " " + commitMaps[index]["sha"].substring(0, 4);
225225
return GSYFlexButton(
226226
maxLines: 2,
227227
mainAxisAlignment: MainAxisAlignment.start,
228228
fontSize: 14.0,
229229
color: Color(GSYColors.primaryValue),
230-
text: itemName,
230+
text: commitMaps[index],
231231
textColor: Color(GSYColors.white),
232232
onPress: () {
233233
Navigator.pop(context);

lib/common/utils/EventUtils.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ class EventUtils {
147147
} else if (event.payload.commits.length == 1) {
148148
NavigatorUtils.goPushDetailPage(context, owner, repositoryName, event.payload.commits[0].sha, true);
149149
} else {
150-
CommonUtils.showCommitOptionDialog(context, event.payload.commits, (index) {
150+
List<String> list = new List();
151+
for (int i = 0; i < event.payload.commits.length; i++) {
152+
list.add(event.payload.commits[i].message + " " + event.payload.commits[i].sha.substring(0, 4));
153+
}
154+
CommonUtils.showCommitOptionDialog(context, list, (index) {
151155
NavigatorUtils.goPushDetailPage(context, owner, repositoryName, event.payload.commits[index].sha, true);
152156
});
153157
}

lib/page/RepostoryDetailInfoPage.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
4949

5050
ReposDetailInfoPageState(this.userName, this.reposName, this.reposDetailParentControl, this.titleOptionControl);
5151

52+
///渲染时间Item或者提交Item
5253
_renderEventItem(index) {
5354
if (index == 0) {
5455
return new ReposHeaderItem(ReposHeaderViewModel.fromHttpMap(userName, reposName, repository), (index) {
@@ -59,6 +60,7 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
5960
}
6061

6162
if (selectIndex == 1) {
63+
///提交
6264
return new EventItem(
6365
EventViewModel.fromCommitMap(pullLoadWidgetControl.dataList[index - 1]),
6466
onPressed: () {
@@ -76,6 +78,7 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
7678
);
7779
}
7880

81+
///获取列表
7982
_getDataLogic() async {
8083
if (selectIndex == 1) {
8184
return await ReposDao.getReposCommitsDao(
@@ -95,6 +98,7 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
9598
);
9699
}
97100

101+
///获取详情
98102
_getReposDetail() {
99103
ReposDao.getRepositoryDetailDao(userName, reposName, reposDetailParentControl.currentBranch).then((result) {
100104
if (result != null && result.result) {

lib/widget/ReposHeaderItem.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class ReposHeaderItem extends StatelessWidget {
126126
crossAxisAlignment: CrossAxisAlignment.center,
127127
mainAxisAlignment: MainAxisAlignment.center,
128128
children: <Widget>[
129+
///star状态
129130
_getBottomItem(
130131
GSYICons.REPOS_ITEM_STAR,
131132
reposHeaderViewModel.repositoryStar,
@@ -134,6 +135,7 @@ class ReposHeaderItem extends StatelessWidget {
134135
userName: reposHeaderViewModel.ownerName, reposName: reposHeaderViewModel.repositoryName);
135136
},
136137
),
138+
///fork状态
137139
new Container(width: 0.3, height: 25.0, color: Color(GSYColors.subLightTextColor)),
138140
_getBottomItem(
139141
GSYICons.REPOS_ITEM_FORK,
@@ -143,6 +145,7 @@ class ReposHeaderItem extends StatelessWidget {
143145
userName: reposHeaderViewModel.ownerName, reposName: reposHeaderViewModel.repositoryName);
144146
},
145147
),
148+
///订阅状态
146149
new Container(width: 0.3, height: 25.0, color: Color(GSYColors.subLightTextColor)),
147150
_getBottomItem(
148151
GSYICons.REPOS_ITEM_WATCH,
@@ -152,11 +155,23 @@ class ReposHeaderItem extends StatelessWidget {
152155
userName: reposHeaderViewModel.ownerName, reposName: reposHeaderViewModel.repositoryName);
153156
},
154157
),
158+
///issue状态
155159
new Container(width: 0.3, height: 25.0, color: Color(GSYColors.subLightTextColor)),
156160
_getBottomItem(
157161
GSYICons.REPOS_ITEM_ISSUE,
158162
reposHeaderViewModel.repositoryIssue,
159-
() {},
163+
() {
164+
if (reposHeaderViewModel.allIssueCount == null || reposHeaderViewModel.allIssueCount <= 0) {
165+
return;
166+
}
167+
List<String> list = [
168+
GSYStrings.repos_all_issue_count + reposHeaderViewModel.allIssueCount.toString(),
169+
GSYStrings.repos_open_issue_count + reposHeaderViewModel.openIssuesCount.toString(),
170+
GSYStrings.repos_close_issue_count +
171+
(reposHeaderViewModel.allIssueCount - reposHeaderViewModel.openIssuesCount).toString(),
172+
];
173+
CommonUtils.showCommitOptionDialog(context, list, (index) {}, height: 150.0);
174+
},
160175
),
161176
],
162177
)),
@@ -195,6 +210,8 @@ class ReposHeaderViewModel {
195210
String created_at = "";
196211
String push_at = "";
197212
String license = "";
213+
int allIssueCount = 0;
214+
int openIssuesCount = 0;
198215
bool repositoryStared = false;
199216
bool repositoryForked = false;
200217
bool repositoryWatched = false;
@@ -209,6 +226,8 @@ class ReposHeaderViewModel {
209226
}
210227
this.ownerPic = map.owner.avatar_url;
211228
this.repositoryName = reposName;
229+
this.allIssueCount = map.allIssueCount;
230+
this.openIssuesCount = map.openIssuesCount;
212231
this.repositoryStar = map.watchersCount != null ? map.watchersCount.toString() : "";
213232
this.repositoryFork = map.forksCount != null ? map.forksCount.toString() : "";
214233
this.repositoryWatch = map.subscribersCount != null ? map.subscribersCount.toString() : "";

0 commit comments

Comments
 (0)