Skip to content

Commit 1c4ad83

Browse files
committed
release page
1 parent 288180f commit 1c4ad83

File tree

4 files changed

+91
-47
lines changed

4 files changed

+91
-47
lines changed

lib/common/utils/NavigatorUtils.dart

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:io';
23

34
import 'package:flutter/material.dart';
45
import 'package:gsy_github_app_flutter/page/CodeDetailPage.dart';
@@ -84,7 +85,8 @@ class NavigatorUtils {
8485
}
8586

8687
///文件代码详情
87-
static gotoCodeDetailPage(BuildContext context, {String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
88+
static gotoCodeDetailPage(BuildContext context,
89+
{String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
8890
Navigator.push(
8991
context,
9092
new MaterialPageRoute(
@@ -133,19 +135,43 @@ class NavigatorUtils {
133135
}
134136

135137
///文件代码详情Web
136-
static gotoCodeDetailPageWeb(BuildContext context, {String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
138+
static gotoCodeDetailPageWeb(BuildContext context,
139+
{String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
137140
Navigator.push(
138141
context,
139142
new MaterialPageRoute(
140143
builder: (context) => new CodeDetailPageWeb(
141-
title: title,
142-
userName: userName,
143-
reposName: reposName,
144-
path: path,
145-
data: data,
146-
branch: branch,
147-
htmlUrl: htmlUrl,
148-
)));
144+
title: title,
145+
userName: userName,
146+
reposName: reposName,
147+
path: path,
148+
data: data,
149+
branch: branch,
150+
htmlUrl: htmlUrl,
151+
)));
149152
}
150153

154+
///根据平台跳转文件代码详情Web
155+
static gotoCodeDetailPlatform(BuildContext context,
156+
{String title, String userName, String reposName, String path, String data, String branch, String htmlUrl}) {
157+
if (Platform.isIOS) {
158+
NavigatorUtils.gotoCodeDetailPage(
159+
context,
160+
title: title,
161+
reposName: reposName,
162+
userName: userName,
163+
path: path,
164+
branch: branch,
165+
);
166+
} else {
167+
NavigatorUtils.gotoCodeDetailPageWeb(
168+
context,
169+
title: title,
170+
reposName: reposName,
171+
userName: userName,
172+
path: path,
173+
branch: branch,
174+
);
175+
}
176+
}
151177
}

lib/page/ReleasePage.dart

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
4+
import 'package:fluttertoast/fluttertoast.dart';
25
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
36
import 'package:gsy_github_app_flutter/common/net/Address.dart';
47
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
8+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
9+
import 'package:gsy_github_app_flutter/common/utils/HtmlUtils.dart';
10+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
511
import 'package:gsy_github_app_flutter/widget/GSYCommonOptionWidget.dart';
612
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
713
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
814
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
915
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
1016
import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
17+
import 'package:url_launcher/url_launcher.dart';
1118

1219
/**
1320
* 版本页
@@ -32,26 +39,56 @@ class _ReleasePageState extends GSYListState<ReleasePage> {
3239

3340
final String reposName;
3441

35-
int selectIndex;
42+
int selectIndex = 0;
3643

3744
_ReleasePageState(this.userName, this.reposName);
3845

3946
_renderEventItem(index) {
4047
ReleaseItemViewModel releaseItemViewModel = pullLoadWidgetControl.dataList[index];
4148
return new ReleaseItem(
4249
releaseItemViewModel,
43-
onPressed: () {},
44-
onLongPress: () {},
50+
onPressed: () {
51+
if (selectIndex == 0) {
52+
if (Platform.isIOS) {
53+
NavigatorUtils.gotoCodeDetailPage(
54+
context,
55+
title: releaseItemViewModel.actionTitle,
56+
userName: userName,
57+
reposName: reposName,
58+
data: HtmlUtils.generateHtml(releaseItemViewModel.actionTargetHtml, backgroundColor: GSYColors.webDraculaBackgroundColorString),
59+
);
60+
} else {
61+
String html = HtmlUtils.generateHtml(releaseItemViewModel.actionTargetHtml, backgroundColor: GSYColors.miWhiteString, userBR: false);
62+
CommonUtils.launchWebView(context, releaseItemViewModel.actionTitle, html);
63+
}
64+
}
65+
},
66+
onLongPress: () {
67+
_launchURL();
68+
},
4569
);
4670
}
4771

72+
_launchURL() async {
73+
String url = _getUrl();
74+
if (await canLaunch(url)) {
75+
await launch(url);
76+
} else {
77+
Fluttertoast.showToast(msg: GSYStrings.option_web_launcher_error + ": " + url);
78+
}
79+
}
80+
81+
_getUrl() {
82+
return selectIndex == 0 ? Address.hostWeb + userName + "/" + reposName + "/releases" : Address.hostWeb + userName + "/" + reposName + "/tags";
83+
}
84+
4885
_resolveSelectIndex() {
4986
clearData();
5087
showRefreshLoading();
5188
}
5289

5390
_getDataLogic() async {
54-
return await ReposDao.getRepositoryReleaseDao(userName, reposName, page, needHtml: false, release: selectIndex == 0);
91+
return await ReposDao.getRepositoryReleaseDao(userName, reposName, page, needHtml: Platform.isAndroid, release: selectIndex == 0);
5592
}
5693

5794
@override
@@ -76,7 +113,7 @@ class _ReleasePageState extends GSYListState<ReleasePage> {
76113
@override
77114
Widget build(BuildContext context) {
78115
super.build(context); // See AutomaticKeepAliveClientMixin.
79-
String url = Address.hostWeb + userName + "/" + reposName + "/releases";
116+
String url = _getUrl();
80117
return new Scaffold(
81118
backgroundColor: Color(GSYColors.mainBackgroundColor),
82119
appBar: new AppBar(

lib/page/RepositoryFileListPage.dart

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,14 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
124124
if (CommonUtils.isImageEnd(fileItemViewModel.name)) {
125125
//todo 图片
126126
} else {
127-
if (Platform.isIOS) {
128-
NavigatorUtils.gotoCodeDetailPage(
129-
context,
130-
title: fileItemViewModel.name,
131-
reposName: reposName,
132-
userName: userName,
133-
path: path,
134-
branch: branchControl.currentBranch,
135-
);
136-
137-
138-
} else {
139-
/*CommonUtils.showLoadingDialog(context);
140-
ReposDao.getReposFileDirDao(userName, reposName, path: path, branch: branchControl.currentBranch, text: true, isHtml: true).then((res) {
141-
if (res != null && res.result) {
142-
Navigator.pop(context);
143-
String data = HtmlUtils.resolveHtmlFile(res, "java");
144-
CommonUtils.launchWebView(context, fileItemViewModel.name, data);
145-
}
146-
});*/
147-
NavigatorUtils.gotoCodeDetailPageWeb(
148-
context,
149-
title: fileItemViewModel.name,
150-
reposName: reposName,
151-
userName: userName,
152-
path: path,
153-
branch: branchControl.currentBranch,
154-
);
155-
}
127+
NavigatorUtils.gotoCodeDetailPlatform(
128+
context,
129+
title: fileItemViewModel.name,
130+
reposName: reposName,
131+
userName: userName,
132+
path: path,
133+
branch: branchControl.currentBranch,
134+
);
156135
}
157136
}
158137
}

lib/widget/ReleaseItem.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class ReleaseItem extends StatelessWidget {
2323
child: new GSYCardItem(
2424
child: new InkWell(
2525
onTap: onPressed,
26-
onLongPress: () {},
26+
onLongPress: onLongPress,
2727
child: new Padding(
28-
padding: new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 10.0),
28+
padding: new EdgeInsets.only(left: 10.0, top: 15.0, right: 10.0, bottom: 15.0),
2929
child: new Row(
3030
children: <Widget>[
3131
new Expanded(child: new Text(releaseItemViewModel.actionTitle, style: GSYConstant.smallTextBold)),
@@ -49,7 +49,9 @@ class ReleaseItemViewModel {
4949
ReleaseItemViewModel();
5050

5151
ReleaseItemViewModel.fromMap(map) {
52-
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(map["published_at"]));
52+
if (map["published_at"] != null) {
53+
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(map["published_at"]));
54+
}
5355
actionTitle = map["name"] ?? map["tag_name"];
5456
actionTarget = map["target_commitish"];
5557
actionTargetHtml = map["body_html"];

0 commit comments

Comments
 (0)