Skip to content

Commit 59ab22f

Browse files
committed
增加版本检测
1 parent 9494772 commit 59ab22f

13 files changed

Lines changed: 111 additions & 20 deletions

File tree

‎android/app/build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ android {
3131
applicationId "com.shuyu.gsygithub.gsygithubappflutter"
3232
minSdkVersion 16
3333
targetSdkVersion 27
34-
versionCode 1
35-
versionName "1.0"
34+
versionCode 2
35+
versionName "1.0.1"
3636
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3737
}
3838

‎ios/Runner/Info.plist‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.0.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>1</string>
22+
<string>2</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>NSAppTransportSecurity</key>

‎lib/common/dao/ReposDao.dart‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import 'dart:async';
22
import 'dart:io';
33

44
import 'package:dio/dio.dart';
5+
import 'package:fluttertoast/fluttertoast.dart';
6+
import 'package:get_version/get_version.dart';
7+
import 'package:gsy_github_app_flutter/common/config/Config.dart';
58
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
69
import 'package:gsy_github_app_flutter/common/net/Address.dart';
710
import 'package:gsy_github_app_flutter/common/net/Api.dart';
811
import 'package:gsy_github_app_flutter/common/net/trending/GithubTrending.dart';
12+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
13+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
914
import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart';
1015
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
1116
import 'package:gsy_github_app_flutter/widget/PushCoedItem.dart';
@@ -14,6 +19,7 @@ import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
1419
import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart';
1520
import 'package:gsy_github_app_flutter/widget/ReposItem.dart';
1621
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
22+
import 'package:pub_semver/pub_semver.dart';
1723

1824
/**
1925
* Created by guoshuyu
@@ -448,4 +454,42 @@ class ReposDao {
448454
return new DataResult(null, false);
449455
}
450456
}
457+
458+
/**
459+
* 版本更新
460+
*/
461+
static getNewsVersion(context, showTip) async {
462+
//ios不检查更新
463+
if (Platform.isIOS) {
464+
return;
465+
}
466+
var res = await getRepositoryReleaseDao("CarGuo", 'GSYGithubAppFlutter', 1, needHtml: false);
467+
if (res != null && res.result && res.data.length > 0) {
468+
//github只能有release的versionName,没有code,囧
469+
String versionName = res.data[0].actionTitle;
470+
if (versionName != null) {
471+
if (Config.DEBUG) {
472+
print("versionName " + versionName);
473+
}
474+
var appVersion = await GetVersion.projectVersion;
475+
if (Config.DEBUG) {
476+
print("appVersion " + appVersion);
477+
}
478+
Version versionNameNum = Version.parse(versionName);
479+
Version currentNum = Version.parse(appVersion);
480+
int result = versionNameNum.compareTo(currentNum);
481+
if (Config.DEBUG) {
482+
print("versionNameNum " + versionNameNum.toString() + " currentNum " + currentNum.toString());
483+
}
484+
if (Config.DEBUG) {
485+
print("newsHad " + result.toString());
486+
}
487+
if (result > 0) {
488+
CommonUtils.showUpdateDialog(context, res.data[0].actionTitle + ": " + res.data[0].body);
489+
} else {
490+
if (showTip) Fluttertoast.showToast(msg: GSYStrings.app_not_new_version);
491+
}
492+
}
493+
}
494+
}
451495
}

‎lib/common/net/Address.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Address {
66
static const String hostWeb = "https://github.com/";
77
static const String downloadUrl = 'https://www.pgyer.com/GSYGithubApp';
88
static const String graphicHost = 'https://ghchart.rshah.org/';
9+
static const String updateUrl = 'https://www.pgyer.com/vj2B';
910

1011
///获取授权 post
1112
static getAuthorization() {

‎lib/common/style/GSYStyle.dart‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,17 @@ class GSYConstant {
150150
fontSize: normalTextSize,
151151
);
152152

153-
static const normalTextMitWhiteBold = TextStyle(color: Color(GSYColors.miWhite), fontSize: normalTextSize, fontWeight: FontWeight.bold);
153+
static const normalTextMitWhiteBold = TextStyle(
154+
color: Color(GSYColors.miWhite),
155+
fontSize: normalTextSize,
156+
fontWeight: FontWeight.bold,
157+
);
158+
159+
static const normalTextActionWhiteBold = TextStyle(
160+
color: Color(GSYColors.actionBlue),
161+
fontSize: normalTextSize,
162+
fontWeight: FontWeight.bold,
163+
);
154164

155165
static const normalTextLight = TextStyle(
156166
color: Color(GSYColors.primaryLightValue),
@@ -206,6 +216,9 @@ class GSYStrings {
206216
static const String app_close = "关闭";
207217
static const String app_version = "版本";
208218

219+
static const String app_not_new_version = "没有新版本";
220+
static const String app_version_title = "版本更新";
221+
209222
static const String nothing_now = "目前什么都没有。";
210223
static const String loading_text = "努力加载中···";
211224

‎lib/common/utils/CommonUtils.dart‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import 'dart:async';
22
import 'dart:convert';
33

44
import 'package:flutter/material.dart';
5+
import 'package:gsy_github_app_flutter/common/net/Address.dart';
56
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
67
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
78
import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart';
89
import 'package:gsy_github_app_flutter/widget/IssueEditDIalog.dart';
910
import 'package:flutter_spinkit/flutter_spinkit.dart';
11+
import 'package:path/path.dart';
12+
import 'package:url_launcher/url_launcher.dart';
1013

1114
/**
1215
* 通用逻辑
@@ -105,8 +108,7 @@ class CommonUtils {
105108
if (url.startsWith("http")) {
106109
NavigatorUtils.goGSYWebView(context, url, title);
107110
} else {
108-
NavigatorUtils.goGSYWebView(
109-
context, new Uri.dataFromString(url, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString(), title);
111+
NavigatorUtils.goGSYWebView(context, new Uri.dataFromString(url, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString(), title);
110112
}
111113
}
112114

@@ -203,4 +205,29 @@ class CommonUtils {
203205
);
204206
});
205207
}
208+
209+
///版本更新
210+
static Future<Null> showUpdateDialog(BuildContext context, String contentMsg) {
211+
return showDialog(
212+
context: context,
213+
builder: (BuildContext context) {
214+
return AlertDialog(
215+
title: new Text(GSYStrings.app_version_title),
216+
content: new Text(contentMsg),
217+
actions: <Widget>[
218+
new FlatButton(
219+
onPressed: () {
220+
Navigator.pop(context);
221+
},
222+
child: new Text(GSYStrings.app_cancel)),
223+
new FlatButton(
224+
onPressed: () {
225+
launch(Address.updateUrl);
226+
Navigator.pop(context);
227+
},
228+
child: new Text(GSYStrings.app_ok)),
229+
],
230+
);
231+
});
232+
}
206233
}

‎lib/page/DynamicPage.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_redux/flutter_redux.dart';
55
import 'package:gsy_github_app_flutter/common/config/Config.dart';
66
import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
7+
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
78
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
89
import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
910
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
@@ -73,6 +74,8 @@ class _DynamicPageState extends GSYListState<DynamicPage> {
7374
@override
7475
void initState() {
7576
super.initState();
77+
ReposDao.getNewsVersion(context, false);
78+
7679
}
7780

7881
@override

‎lib/page/HomePage.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ class HomePage extends StatelessWidget {
5858
},
5959
));
6060
}
61+
62+
63+
64+
6165
}

‎lib/page/RepositoryFileListPage.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
5151
_renderEventItem(index) {
5252
FileItemViewModel fileItemViewModel = pullLoadWidgetControl.dataList[index];
5353
IconData iconData = (fileItemViewModel.type == "file") ? GSYICons.REPOS_ITEM_FILE : GSYICons.REPOS_ITEM_DIR;
54-
Widget trailing = (fileItemViewModel.type == "file") ? null : new Icon(GSYICons.REPOS_ITEM_NEXT, size: 12.0);
54+
Widget trailing = (fileItemViewModel.type == "file") ? null : new Icon(GSYICons.REPOS_ITEM_NEXT, size: 14.0);
5555
return new GSYCardItem(
5656
margin: EdgeInsets.only(left: 10.0, top: 5.0, right: 10.0, bottom: 5.0),
5757
child: new ListTile(

‎lib/widget/GSYCardItem.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class GSYCardItem extends StatelessWidget {
1313
final RoundedRectangleBorder shape;
1414
final double elevation;
1515

16+
1617
GSYCardItem({@required this.child, this.margin, this.color, this.shape, this.elevation = 5.0});
1718

1819
@override

0 commit comments

Comments
 (0)