mirror of
https://github.com/ErfanRht/MovieLab.git
synced 2026-03-13 10:23:24 +08:00
(add) awareness of other versions
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,3 @@
|
|||||||
lib/modules/api/key_getter.dart
|
|
||||||
|
|
||||||
.VSCodeCounter/
|
.VSCodeCounter/
|
||||||
|
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
|
|||||||
5
lib/constants/app.dart
Normal file
5
lib/constants/app.dart
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const String appVersion = "v3.0.1";
|
||||||
|
|
||||||
|
String? latestVersion;
|
||||||
|
List<String>? supportedVersions;
|
||||||
|
String? secureUrl;
|
||||||
@@ -9,7 +9,9 @@ enum RequestResult {
|
|||||||
SUCCESS,
|
SUCCESS,
|
||||||
FAILURE,
|
FAILURE,
|
||||||
FAILURE_USER_PROBLEM,
|
FAILURE_USER_PROBLEM,
|
||||||
FAILURE_SERVER_PROBLEM
|
FAILURE_SERVER_PROBLEM,
|
||||||
|
FAILURE_IMDB_PROBLEM,
|
||||||
|
FAILURE_VERSION_PROBLEM,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ListName {
|
enum ListName {
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ class APIRequester {
|
|||||||
(apiKeys.length == 1 && apiKeys[0] == "XXXXXXXXXX")) {
|
(apiKeys.length == 1 && apiKeys[0] == "XXXXXXXXXX")) {
|
||||||
var response;
|
var response;
|
||||||
await key_getter().then((result) async {
|
await key_getter().then((result) async {
|
||||||
if (!result) {
|
if (result == RequestResult.FAILURE) {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
print(
|
print(
|
||||||
"You haven't add any api key to the app, so it won't work!\nFor more information check out the documentation at https://github.com/ErfanRht/MovieLab#getting-started");
|
"You haven't add any api key to the app, so it won't work!\nFor more information check out the documentation at https://github.com/ErfanRht/MovieLab#getting-started");
|
||||||
|
|||||||
@@ -3,17 +3,29 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:movielab/.api.dart';
|
import 'package:movielab/.api.dart';
|
||||||
|
import 'package:movielab/constants/app.dart';
|
||||||
|
import 'package:movielab/constants/types.dart';
|
||||||
|
|
||||||
Future<bool> key_getter() async {
|
Future<RequestResult> key_getter() async {
|
||||||
const String url = "";
|
const String url = "";
|
||||||
if (url != "") {
|
if (url != "") {
|
||||||
var response = await http.get(Uri.parse(url)).timeout(
|
var response = await http.get(Uri.parse(url)).timeout(
|
||||||
const Duration(seconds: 10),
|
const Duration(seconds: 10),
|
||||||
);
|
);
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
print(jsonDecode(response.body).length);
|
print(
|
||||||
|
"${jsonDecode(response.body)['keys'].length} api keys has been added.");
|
||||||
}
|
}
|
||||||
apiKeys = [for (dynamic key in jsonDecode(response.body)) key.toString()];
|
apiKeys = [
|
||||||
|
for (dynamic key in jsonDecode(response.body)['keys']) key.toString()
|
||||||
|
];
|
||||||
|
supportedVersions = [
|
||||||
|
for (dynamic version in jsonDecode(response.body)['supported_versions'])
|
||||||
|
version.toString()
|
||||||
|
];
|
||||||
|
latestVersion = jsonDecode(response.body)['latest_version'].toString();
|
||||||
|
secureUrl = jsonDecode(response.body)['secure_url'].toString();
|
||||||
|
return RequestResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return true;
|
return RequestResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:movielab/constants/app.dart';
|
||||||
import 'package:movielab/constants/colors.dart';
|
import 'package:movielab/constants/colors.dart';
|
||||||
import 'package:movielab/pages/shared/app_name.dart';
|
import 'package:movielab/pages/shared/app_name.dart';
|
||||||
import 'package:movielab/widgets/buttons/social_media_button.dart';
|
import 'package:movielab/widgets/buttons/social_media_button.dart';
|
||||||
@@ -37,7 +38,7 @@ class AboutPage extends StatelessWidget {
|
|||||||
height: 10,
|
height: 10,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"Version 2.0.7",
|
"Version ${appVersion.replaceAll('v', '')}",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 17.5,
|
fontSize: 17.5,
|
||||||
color: Colors.white.withOpacity(0.5),
|
color: Colors.white.withOpacity(0.5),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
|
import 'package:movielab/constants/app.dart';
|
||||||
import 'package:movielab/modules/Recommender/Recommender.dart';
|
import 'package:movielab/modules/Recommender/Recommender.dart';
|
||||||
import 'package:movielab/modules/tools/navigate.dart';
|
import 'package:movielab/modules/tools/navigate.dart';
|
||||||
import 'package:movielab/pages/main/main_page.dart';
|
import 'package:movielab/pages/main/main_page.dart';
|
||||||
import 'package:movielab/widgets/error.dart';
|
import 'package:movielab/widgets/error.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import '../../constants/colors.dart';
|
import '../../constants/colors.dart';
|
||||||
import '../../constants/types.dart';
|
import '../../constants/types.dart';
|
||||||
import '../../modules/tools/system_ui_overlay_style.dart';
|
import '../../modules/tools/system_ui_overlay_style.dart';
|
||||||
@@ -27,6 +29,10 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||||||
_loadData();
|
_loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _launchUrl(final String url) async {
|
||||||
|
if (!await launchUrl(Uri.parse(url))) throw 'Could not launch $url';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -67,6 +73,15 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||||||
borderWidth: 10,
|
borderWidth: 10,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
case RequestResult.FAILURE_VERSION_PROBLEM:
|
||||||
|
return ConnectionErrorWidget(
|
||||||
|
isItTryAgain: false,
|
||||||
|
tryAgain: () {
|
||||||
|
_launchUrl("https://erfanrht.github.io/MovieLab-Intro");
|
||||||
|
},
|
||||||
|
errorText:
|
||||||
|
'The version of MovieLab that you are using is outdated.\nFor more information check out:\n${secureUrl ?? "erfanrht.github.io/movielab-intro"}',
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return ConnectionErrorWidget(
|
return ConnectionErrorWidget(
|
||||||
tryAgain: () {
|
tryAgain: () {
|
||||||
@@ -87,7 +102,17 @@ class _SplashScreenState extends State<SplashScreen> {
|
|||||||
if (result == RequestResult.SUCCESS) {
|
if (result == RequestResult.SUCCESS) {
|
||||||
recommender();
|
recommender();
|
||||||
getUserData();
|
getUserData();
|
||||||
Navigate.replaceTo(context, const MainPage());
|
if (supportedVersions != null && supportedVersions!.isNotEmpty) {
|
||||||
|
if (supportedVersions!.contains(appVersion)) {
|
||||||
|
Navigate.replaceTo(context, const MainPage());
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_loadingStatus = RequestResult.FAILURE_VERSION_PROBLEM;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Navigate.replaceTo(context, const MainPage());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
_loadingStatus = result;
|
_loadingStatus = result;
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
|
||||||
import 'package:movielab/constants/colors.dart';
|
import 'package:movielab/constants/colors.dart';
|
||||||
|
|
||||||
class ConnectionErrorWidget extends StatelessWidget {
|
class ConnectionErrorWidget extends StatelessWidget {
|
||||||
final String errorText;
|
final String errorText;
|
||||||
final VoidCallback tryAgain;
|
final bool isItTryAgain;
|
||||||
|
final VoidCallback? tryAgain;
|
||||||
const ConnectionErrorWidget(
|
const ConnectionErrorWidget(
|
||||||
{this.errorText = 'An unexpected error occurred while loading data.',
|
{this.errorText = 'An unexpected error occurred while loading data.',
|
||||||
required this.tryAgain,
|
required this.tryAgain,
|
||||||
Key? key})
|
Key? key,
|
||||||
|
this.isItTryAgain = true})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -25,6 +26,7 @@ class ConnectionErrorWidget extends StatelessWidget {
|
|||||||
onTap: tryAgain,
|
onTap: tryAgain,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
child: Container(
|
child: Container(
|
||||||
|
// width: MediaQuery.of(context).size.width,
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
@@ -34,24 +36,27 @@ class ConnectionErrorWidget extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
errorText,
|
errorText,
|
||||||
style: TextStyle(
|
textAlign: TextAlign.center,
|
||||||
|
softWrap: true,
|
||||||
|
style: const TextStyle(
|
||||||
fontSize: 12.5, fontWeight: FontWeight.w600),
|
fontSize: 12.5, fontWeight: FontWeight.w600),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Row(
|
if (isItTryAgain)
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Text(
|
children: const [
|
||||||
'Try again',
|
Text(
|
||||||
style: TextStyle(
|
'Try again',
|
||||||
fontSize: 12.5,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w600),
|
fontSize: 12.5,
|
||||||
),
|
fontWeight: FontWeight.w600),
|
||||||
const Icon(
|
),
|
||||||
Icons.refresh,
|
Icon(
|
||||||
size: 15,
|
Icons.refresh,
|
||||||
)
|
size: 15,
|
||||||
])
|
)
|
||||||
|
])
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
|||||||
Reference in New Issue
Block a user