Skip to content

Commit 288180f

Browse files
committed
release page
1 parent 9cbe24c commit 288180f

File tree

9 files changed

+228
-5
lines changed

9 files changed

+228
-5
lines changed

lib/common/dao/ReposDao.dart

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart';
1010
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
1111
import 'package:gsy_github_app_flutter/widget/PushCoedItem.dart';
1212
import 'package:gsy_github_app_flutter/widget/PushHeader.dart';
13+
import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
1314
import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart';
1415
import 'package:gsy_github_app_flutter/widget/ReposItem.dart';
1516
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
@@ -406,15 +407,45 @@ class ReposDao {
406407
static getReposCommitsInfoDao(userName, reposName, sha) async {
407408
String url = Address.getReposCommitsInfo(userName, reposName, sha);
408409
var res = await HttpManager.netFetch(url, null, null, null);
409-
if (res != null && res.result ) {
410+
if (res != null && res.result) {
410411
PushHeaderViewModel pushHeaderViewModel = PushHeaderViewModel.forMap(res.data);
411412
var files = res.data["files"];
412-
for(int i = 0; i <files.length; i++) {
413-
pushHeaderViewModel.files.add(PushCodeItemViewModel.fromMap(files[i]));
413+
for (int i = 0; i < files.length; i++) {
414+
pushHeaderViewModel.files.add(PushCodeItemViewModel.fromMap(files[i]));
414415
}
415416
return new DataResult(pushHeaderViewModel, true);
416417
} else {
417418
return new DataResult(null, false);
418419
}
419420
}
421+
422+
/**
423+
* 获取仓库的release列表
424+
*/
425+
static getRepositoryReleaseDao(userName, reposName, page, {needHtml = true, release = true}) async {
426+
String url = release
427+
? Address.getReposRelease(userName, reposName) + Address.getPageParams("?", page)
428+
: Address.getReposTag(userName, reposName) + Address.getPageParams("?", page);
429+
430+
var res = await HttpManager.netFetch(
431+
url,
432+
null,
433+
{"Accept": (needHtml ? 'application/vnd.github.html,application/vnd.github.VERSION.raw' : "")},
434+
null,
435+
);
436+
if (res != null && res.result && res.data.length > 0) {
437+
List<ReleaseItemViewModel> list = new List();
438+
var dataList = res.data;
439+
if (dataList == null || dataList.length == 0) {
440+
return new DataResult(null, false);
441+
}
442+
for (int i = 0; i < dataList.length; i++) {
443+
var data = dataList[i];
444+
list.add(ReleaseItemViewModel.fromMap(data));
445+
}
446+
return new DataResult(list, true);
447+
} else {
448+
return new DataResult(null, false);
449+
}
450+
}
420451
}

lib/common/style/GSYStyle.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class GSYStrings {
266266
static const String repos_tab_issue_all = "所有";
267267
static const String repos_tab_issue_open = "打开";
268268
static const String repos_tab_issue_closed = "关闭";
269+
static const String repos_option_release = "版本";
269270

270271
static const String repos_issue_search = "搜索";
271272

@@ -298,6 +299,9 @@ class GSYStrings {
298299
static const String search_title = "搜索";
299300
static const String search_tab_repos = "仓库";
300301
static const String search_tab_user = "用户";
302+
303+
static const String release_tab_release = "版本";
304+
static const String release_tab_tag = "标记";
301305
}
302306

303307
class GSYICons {

lib/common/utils/NavigatorUtils.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:gsy_github_app_flutter/page/LoginPage.dart';
1111
import 'package:gsy_github_app_flutter/page/NotifyPage.dart';
1212
import 'package:gsy_github_app_flutter/page/PersonPage.dart';
1313
import 'package:gsy_github_app_flutter/page/PushDetailPage.dart';
14+
import 'package:gsy_github_app_flutter/page/ReleasePage.dart';
1415
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
1516
import 'package:gsy_github_app_flutter/page/SearchPage.dart';
1617

@@ -50,6 +51,11 @@ class NavigatorUtils {
5051
return Navigator.push(context, new MaterialPageRoute(builder: (context) => new RepositoryDetailPage(userName, reposName)));
5152
}
5253

54+
///仓库版本列表
55+
static Future<Null> goReleasePage(BuildContext context, String userName, String reposName) {
56+
return Navigator.push(context, new MaterialPageRoute(builder: (context) => new ReleasePage(userName, reposName)));
57+
}
58+
5359
///issue详情
5460
static Future<Null> goIssueDetail(BuildContext context, String userName, String reposName, String num, {bool needRightLocalIcon = false}) {
5561
return Navigator.push(

lib/page/NotifyPage.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
1010
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
1111

1212
/**
13+
* 通知消息
1314
* Created by guoshuyu
1415
* Date: 2018-07-24
1516
*/
@@ -103,6 +104,7 @@ class _NotifyPageState extends GSYListState<NotifyPage> {
103104
this.selectIndex = selectIndex;
104105
_resolveSelectIndex();
105106
},
107+
height: 30.0,
106108
margin: const EdgeInsets.all(0.0),
107109
elevation: 0.0,
108110
),

lib/page/ReleasePage.dart

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
3+
import 'package:gsy_github_app_flutter/common/net/Address.dart';
4+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
5+
import 'package:gsy_github_app_flutter/widget/GSYCommonOptionWidget.dart';
6+
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
7+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
8+
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
9+
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
10+
import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
11+
12+
/**
13+
* 版本页
14+
* Created by guoshuyu
15+
* Date: 2018-07-30
16+
*/
17+
18+
class ReleasePage extends StatefulWidget {
19+
final String userName;
20+
21+
final String reposName;
22+
23+
ReleasePage(this.userName, this.reposName);
24+
25+
@override
26+
_ReleasePageState createState() => _ReleasePageState(this.userName, this.reposName);
27+
}
28+
29+
// ignore: mixin_inherits_from_not_object
30+
class _ReleasePageState extends GSYListState<ReleasePage> {
31+
final String userName;
32+
33+
final String reposName;
34+
35+
int selectIndex;
36+
37+
_ReleasePageState(this.userName, this.reposName);
38+
39+
_renderEventItem(index) {
40+
ReleaseItemViewModel releaseItemViewModel = pullLoadWidgetControl.dataList[index];
41+
return new ReleaseItem(
42+
releaseItemViewModel,
43+
onPressed: () {},
44+
onLongPress: () {},
45+
);
46+
}
47+
48+
_resolveSelectIndex() {
49+
clearData();
50+
showRefreshLoading();
51+
}
52+
53+
_getDataLogic() async {
54+
return await ReposDao.getRepositoryReleaseDao(userName, reposName, page, needHtml: false, release: selectIndex == 0);
55+
}
56+
57+
@override
58+
bool get wantKeepAlive => false;
59+
60+
@override
61+
bool get needHeader => false;
62+
63+
@override
64+
bool get isRefreshFirst => true;
65+
66+
@override
67+
requestLoadMore() async {
68+
return await _getDataLogic();
69+
}
70+
71+
@override
72+
requestRefresh() async {
73+
return await _getDataLogic();
74+
}
75+
76+
@override
77+
Widget build(BuildContext context) {
78+
super.build(context); // See AutomaticKeepAliveClientMixin.
79+
String url = Address.hostWeb + userName + "/" + reposName + "/releases";
80+
return new Scaffold(
81+
backgroundColor: Color(GSYColors.mainBackgroundColor),
82+
appBar: new AppBar(
83+
title: GSYTitleBar(
84+
reposName,
85+
rightWidget: new GSYCommonOptionWidget(url),
86+
),
87+
bottom: new GSYSelectItemWidget(
88+
[
89+
GSYStrings.release_tab_release,
90+
GSYStrings.release_tab_tag,
91+
],
92+
(selectIndex) {
93+
this.selectIndex = selectIndex;
94+
_resolveSelectIndex();
95+
},
96+
height: 30.0,
97+
margin: const EdgeInsets.all(0.0),
98+
elevation: 0.0,
99+
),
100+
elevation: 4.0,
101+
),
102+
body: GSYPullLoadWidget(
103+
pullLoadWidgetControl,
104+
(BuildContext context, int index) => _renderEventItem(index),
105+
handleRefresh,
106+
onLoadMore,
107+
refreshKey: refreshIndicatorKey,
108+
),
109+
);
110+
}
111+
}

lib/page/RepositoryDetailPage.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
55
import 'package:gsy_github_app_flutter/common/net/Address.dart';
66
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
77
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
8+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
89
import 'package:gsy_github_app_flutter/page/RepositoryDetailIssueListPage.dart';
910
import 'package:gsy_github_app_flutter/page/RepositoryDetailReadmePage.dart';
1011
import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart';
@@ -223,6 +224,14 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
223224
return list;
224225
}
225226

227+
_getMoreOtherItem() {
228+
return [
229+
new GSYOptionModel(GSYStrings.repos_option_release, GSYStrings.repos_option_release, (model) {
230+
NavigatorUtils.goReleasePage(context, userName, reposName);
231+
}),
232+
];
233+
}
234+
226235
@override
227236
void initState() {
228237
super.initState();
@@ -233,7 +242,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
233242
@override
234243
Widget build(BuildContext context) {
235244
String url = Address.hostWeb + userName + "/" + reposName;
236-
Widget widget = new GSYCommonOptionWidget(url);
245+
Widget widget = new GSYCommonOptionWidget(url, otherList: _getMoreOtherItem());
237246
return new GSYTabBarWidget(
238247
type: GSYTabBarWidget.TOP_TAB,
239248
tarWidgetControl: tarBarControl,

lib/widget/GSYCommonOptionWidget.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class GSYCommonOptionWidget extends StatelessWidget {
6262
Share.share(text);
6363
}),
6464
];
65+
if(otherList != null && otherList.length > 0) {
66+
list.addAll(otherList);
67+
}
6568
return _renderHeaderPopItem(list);
6669
}
6770
}

lib/widget/ReleaseItem.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
3+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
4+
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
5+
6+
/**
7+
* 版本TagItem
8+
* Created by guoshuyu
9+
* Date: 2018-07-30
10+
*/
11+
12+
class ReleaseItem extends StatelessWidget {
13+
final ReleaseItemViewModel releaseItemViewModel;
14+
15+
final GestureTapCallback onPressed;
16+
final GestureLongPressCallback onLongPress;
17+
18+
ReleaseItem(this.releaseItemViewModel, {this.onPressed, this.onLongPress}) : super();
19+
20+
@override
21+
Widget build(BuildContext context) {
22+
return new Container(
23+
child: new GSYCardItem(
24+
child: new InkWell(
25+
onTap: onPressed,
26+
onLongPress: () {},
27+
child: new Padding(
28+
padding: new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 10.0),
29+
child: new Row(
30+
children: <Widget>[
31+
new Expanded(child: new Text(releaseItemViewModel.actionTitle, style: GSYConstant.smallTextBold)),
32+
new Container(child: new Text(releaseItemViewModel.actionTime ?? "", style: GSYConstant.subSmallText)),
33+
],
34+
),
35+
),
36+
),
37+
),
38+
);
39+
}
40+
}
41+
42+
class ReleaseItemViewModel {
43+
String actionTime;
44+
String actionTitle;
45+
String actionMode;
46+
String actionTarget;
47+
String actionTargetHtml;
48+
49+
ReleaseItemViewModel();
50+
51+
ReleaseItemViewModel.fromMap(map) {
52+
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(map["published_at"]));
53+
actionTitle = map["name"] ?? map["tag_name"];
54+
actionTarget = map["target_commitish"];
55+
actionTargetHtml = map["body_html"];
56+
}
57+
}

lib/widget/ReposHeaderItem.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ReposHeaderItem extends StatelessWidget {
5555
child: new Container(
5656
decoration: new BoxDecoration(
5757
image: new DecorationImage(
58-
fit: BoxFit.fitWidth,
58+
fit: BoxFit.cover,
5959
image: new NetworkImage(reposHeaderViewModel.ownerPic),
6060
),
6161
),

0 commit comments

Comments
 (0)