Repository navigation
Expand file tree
/
Copy pathReleasePage.dart
More file actions
158 lines (134 loc) · 4.65 KB
/
Copy pathReleasePage.dart
File metadata and controls
158 lines (134 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/HtmlUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYCommonOptionWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
import 'package:url_launcher/url_launcher.dart';
/**
* 版本页
* Created by guoshuyu
* Date: 2018-07-30
*/
class ReleasePage extends StatefulWidget {
final String userName;
final String reposName;
final String releaseUrl;
final String tagUrl;
ReleasePage(this.userName, this.reposName, this.releaseUrl, this.tagUrl);
@override
_ReleasePageState createState() => _ReleasePageState(this.userName, this.reposName, this.releaseUrl, this.tagUrl);
}
// ignore: mixin_inherits_from_not_object
class _ReleasePageState extends State<ReleasePage> with AutomaticKeepAliveClientMixin<ReleasePage>, GSYListState<ReleasePage> {
final String userName;
final String reposName;
final String releaseUrl;
final String tagUrl;
final OptionControl titleOptionControl = new OptionControl();
int selectIndex = 0;
_ReleasePageState(this.userName, this.reposName, this.releaseUrl, this.tagUrl);
_renderEventItem(index) {
ReleaseItemViewModel releaseItemViewModel = ReleaseItemViewModel.fromMap(pullLoadWidgetControl.dataList[index]);
return new ReleaseItem(
releaseItemViewModel,
onPressed: () {
if (selectIndex == 0) {
if (Platform.isIOS) {
NavigatorUtils.gotoCodeDetailPage(
context,
title: releaseItemViewModel.actionTitle,
userName: userName,
reposName: reposName,
data: HtmlUtils.generateHtml(releaseItemViewModel.actionTargetHtml, backgroundColor: GSYColors.webDraculaBackgroundColorString),
);
} else {
String html = HtmlUtils.generateHtml(releaseItemViewModel.actionTargetHtml, backgroundColor: GSYColors.miWhiteString, userBR: false);
CommonUtils.launchWebView(context, releaseItemViewModel.actionTitle, html);
}
}
},
onLongPress: () {
_launchURL();
},
);
}
_launchURL() async {
String url = _getUrl();
if (await canLaunch(url)) {
await launch(url);
} else {
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).option_web_launcher_error + ": " + url);
}
}
_getUrl() {
return selectIndex == 0 ? releaseUrl : tagUrl;
}
_resolveSelectIndex() {
clearData();
showRefreshLoading();
}
_getDataLogic() async {
return await ReposDao.getRepositoryReleaseDao(userName, reposName, page, needHtml: Platform.isAndroid, release: selectIndex == 0);
}
@override
bool get wantKeepAlive => false;
@override
bool get needHeader => false;
@override
bool get isRefreshFirst => true;
@override
requestLoadMore() async {
return await _getDataLogic();
}
@override
requestRefresh() async {
setState(() {
titleOptionControl.url = _getUrl();
});
return await _getDataLogic();
}
@override
Widget build(BuildContext context) {
super.build(context); // See AutomaticKeepAliveClientMixin.
String url = _getUrl();
return new Scaffold(
backgroundColor: Color(GSYColors.mainBackgroundColor),
appBar: new AppBar(
title: GSYTitleBar(
reposName,
rightWidget: new GSYCommonOptionWidget(titleOptionControl),
),
bottom: new GSYSelectItemWidget(
[
CommonUtils.getLocale(context).release_tab_release,
CommonUtils.getLocale(context).release_tab_tag,
],
(selectIndex) {
this.selectIndex = selectIndex;
_resolveSelectIndex();
},
height: 30.0,
margin: const EdgeInsets.all(0.0),
elevation: 0.0,
),
elevation: 4.0,
),
body: GSYPullLoadWidget(
pullLoadWidgetControl,
(BuildContext context, int index) => _renderEventItem(index),
handleRefresh,
onLoadMore,
refreshKey: refreshIndicatorKey,
),
);
}
}