Skip to content

Commit

Permalink
DEV UPDATE:Add auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
misakajimmy committed Jan 24, 2023
1 parent f2eea2e commit 1aa976a
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 29 deletions.
9 changes: 9 additions & 0 deletions Jsons/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "v1.0.0",
"version_message": "新增xxx功能",
"download_url": {
"android": "https://www.pgyer.com/xxxxxx",
"ios": "https://itunes.apple.com/cn/app/idxxxxxx"
},
"updated_at": "2023-01-01 00:00:00"
}
53 changes: 34 additions & 19 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.eoe_fans">
<application
android:label="eoe_fans"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
package="com.app.eoe_fans">

<application
android:label="eoe_fans"
android:name="${applicationName}"
android:requestLegacyExternalStorage="true"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
android:name="flutterEmbedding"
android:value="2" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.app.eoe_fans.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</manifest>
Binary file added assets/efans2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 23 additions & 2 deletions lib/common/Api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:eoe_fans/models/version.dart';
import 'package:eoe_fans/models/videos.dart';
import 'package:eoe_fans/models/iResponse.dart';
import 'package:eoe_fans/models/videosRequest.dart';
Expand All @@ -17,7 +18,7 @@ class Api {

// Options _options;
static Dio dio =
Dio(BaseOptions(baseUrl: 'https://api.eoe.best/eoefans-api/v1', headers: {
Dio(BaseOptions(baseUrl: 'https://api.eoe.best/eoefans-api/v1', headers: {
'ocp-apim-subscription-key': key,
'Content-Type': 'application/json',
}));
Expand All @@ -41,7 +42,7 @@ class Api {
..result = [];
if (r.statusCode == 200) {
var videoRes =
IResponse<Videos>.fromJson(r.data, (json) => Videos.fromJson(json));
IResponse<Videos>.fromJson(r.data, (json) => Videos.fromJson(json));
print(videoRes.data?.page);
print(videoRes.data?.numResults);
if (videoRes.data != null) {
Expand All @@ -50,4 +51,24 @@ class Api {
}
return tmpVideos;
}

Future<Version> version() async {
var paramsData = ({ 'subscription-key': key});
paramsData.removeWhere((key, value) => value == null);
var r = await dio.get('/tools/version',
queryParameters: paramsData);
var tmpVersion = Version()
..version = ''
..version_message = ''
..download_url = {}
..updated_at = '';
if (r.statusCode == 200) {
var versionRes =
IResponse<Version>.fromJson(r.data, (json) => Version.fromJson(json));
if (versionRes.data != null) {
tmpVersion = versionRes.data!;
}
}
return tmpVersion;
}
}
21 changes: 21 additions & 0 deletions lib/common/CompareVersion.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
bool haveNewVersion(String newVersion, String old) {
if (newVersion == null || newVersion.isEmpty || old == null || old.isEmpty)
return false;
int newVersionInt, oldVersion;
var newList = newVersion.split('.');
var oldList = old.split('.');
if (newList.length == 0 || oldList.length == 0) {
return false;
}
for (int i = 0; i < newList.length; i++) {
newVersionInt = int.parse(newList[i]);
oldVersion = int.parse(oldList[i]);
if (newVersionInt > oldVersion) {
return true;
} else if (newVersionInt < oldVersion) {
return false;
}
}

return false;
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
),
routes: {
'/': (BuildContext context) => MainPage(),
'/main': (BuildContext context) => MainPage(),
'/splash': (BuildContext context) => SplashScreen(),
'/setting': (BuildContext context) => const SettingPage(),
'/theme': (BuildContext context) => const SettingTheme(),
Expand Down
3 changes: 2 additions & 1 deletion lib/models/index.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'cacheConfig.dart' ;
export 'videos.dart' ;
export 'version.dart' ;
export 'video.dart' ;
export 'videos.dart' ;
16 changes: 16 additions & 0 deletions lib/models/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:json_annotation/json_annotation.dart';

part 'version.g.dart';

@JsonSerializable()
class Version {
Version();

late String version;
late String version_message;
late Map<String,dynamic> download_url;
late String updated_at;

factory Version.fromJson(Map<String,dynamic> json) => _$VersionFromJson(json);
Map<String, dynamic> toJson() => _$VersionToJson(this);
}
20 changes: 20 additions & 0 deletions lib/models/version.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions lib/routes/mainPage.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:eoe_fans/common/Api.dart';
import 'package:eoe_fans/common/CompareVersion.dart';
import 'package:eoe_fans/common/Global.dart';
import 'package:eoe_fans/routes/music/musicPage.dart';
import 'package:eoe_fans/routes/picture/picturePage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hgg_app_upgrade/hgg_app_upgrade.dart';
import 'package:provider/provider.dart';

import '../states/ProfileChangeNotifier.dart';
Expand All @@ -21,8 +25,25 @@ class _MainPageState extends State<MainPage> {
const MusicPage(),
];

Future<AppUpgradeInfo?> _checkAppInfo() async {
var r = await Api().version();

if (r.version != '') {
if (haveNewVersion(r.version, Global.packageInfo.version)) {
return AppUpgradeInfo(
title: '新版本 V' + r.version,
contents: r.version_message.split('\n'),
apkDownloadUrl: r.download_url['android'],
force: false,
);
}
}
return null;
}

@override
void initState() {
AppUpgrade.appUpgrade(context, _checkAppInfo());
super.initState();
}

Expand Down
8 changes: 5 additions & 3 deletions lib/routes/setting/aboutUs.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

class AboutUs extends StatefulWidget {
const AboutUs({Key? key}) : super(key: key);
Expand All @@ -24,16 +25,17 @@ class _AboutUsState extends State<AboutUs> {
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(270),
preferredSize: Size.fromHeight(180),
child: AppBar(
centerTitle: true,
flexibleSpace: Container(
height: double.maxFinite,
color: HexColor('#ffe3ef'),
child: Image(
alignment: Alignment.topCenter,
image: AssetImage(
'assets/logo.jpg'),
fit: BoxFit.cover,
'assets/efans2.png'),
fit: BoxFit.contain,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/splashPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _SplashScreenState extends State<SplashScreen> {
startTime() {
_timer = Timer(Duration(milliseconds: 2000), () {
_timer.cancel();
Navigator.of(context).pushReplacementNamed('/');
Navigator.of(context).pushReplacementNamed('/main');
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/video/videoPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _VideoPageState extends State<VideoPage> {
),
),
body: Container(
padding: const EdgeInsets.only(left: 4, right: 4, top: 4),
padding: const EdgeInsets.only(left: 4, right: 4, top: 8),
child: const TabBarView(
children: [
VideoList(origin: true),
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
hgg_app_upgrade:
dependency: "direct main"
description:
name: hgg_app_upgrade
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
http:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.0+1
version: 1.2.0+1

environment:
sdk: '>=2.18.6 <3.0.0'
Expand Down Expand Up @@ -48,6 +48,7 @@ dependencies:
flutter_swiper_null_safety: ^1.0.2
pull_to_refresh: ^2.0.0
settings_ui: ^2.0.2
hgg_app_upgrade: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 1aa976a

Please sign in to comment.