diff --git a/android/app/build.gradle b/android/app/build.gradle index 97d9332..a4908e7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -25,6 +25,12 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +def keystoreProperties = new Properties() + def keystorePropertiesFile = rootProject.file('key.properties') + if (keystorePropertiesFile.exists()) { + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + } + android { compileSdkVersion flutter.compileSdkVersion @@ -50,13 +56,19 @@ android { versionName flutterVersionName } - buildTypes { - release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug - } - } + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword keystoreProperties['storePassword'] + } + } + buildTypes { + release { + signingConfig signingConfigs.release + } + } } flutter { diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 08ad43b..dde8a7b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ with TickerPr c++; }); } + else { + return true; + } } else if(noti.type == InputType.backSpace) { if(c > 0 && !onAnimation) { diff --git a/lib/event_bus.dart b/lib/event_bus.dart index d9d8db6..c774a64 100644 --- a/lib/event_bus.dart +++ b/lib/event_bus.dart @@ -1,12 +1,10 @@ /* * @Author : Linloir * @Date : 2022-03-05 21:50:33 - * @LastEditTime : 2022-03-05 23:15:18 + * @LastEditTime : 2022-03-07 10:26:04 * @Description : Event bus class */ -import 'package:flutter/material.dart'; - typedef EventCallBack = void Function(dynamic args); final EventBus mainBus = EventBus(); diff --git a/lib/generator.dart b/lib/generator.dart index 6c98883..f9f1f84 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-03-06 15:03:57 - * @LastEditTime : 2022-03-07 08:34:56 + * @LastEditTime : 2022-03-07 11:16:16 * @Description : Word generator */ @@ -15,13 +15,13 @@ abstract class Words { static String _cache = ""; //static Map explainations = {}; - static Future importWordsDatabase({int length = 5}) async { + static Future importWordsDatabase({int length = 5}) async { //explainations.clear(); if(length != _length || dataBase.isEmpty){ _length = length; dataBase.clear(); _cache = ""; - var data = await rootBundle.loadString('popular.txt'); + var data = await rootBundle.loadString('assets/popular.txt'); // LineSplitter.split(data).forEach((line) { // int seperatePos = line.indexOf(','); // if(seperatePos != length + 2) { @@ -38,14 +38,20 @@ abstract class Words { } _cache = line + "s"; }); - print('Imported ${dataBase.length}'); } + if(dataBase.isEmpty) { + return false; + } + return true; } - static Future generateWord() async{ + static Future generateWord() async{ int bound = dataBase.length; if(bound == 0) { - await Words.importWordsDatabase(); + var import = await Words.importWordsDatabase(); + if(!import) { + return null; + } bound = dataBase.length; } var rng = Random(); diff --git a/lib/offline.dart b/lib/offline.dart index f614b1b..ecc0d15 100644 --- a/lib/offline.dart +++ b/lib/offline.dart @@ -1,7 +1,7 @@ /* * @Author : Linloir * @Date : 2022-03-05 20:41:41 - * @LastEditTime : 2022-03-07 09:30:56 + * @LastEditTime : 2022-03-07 11:05:14 * @Description : Offline page */ @@ -40,8 +40,8 @@ class _OfflinePageState extends State with TickerProviderStateMixin actions: [AnimatedSwitcher( duration: const Duration(milliseconds: 750), reverseDuration: const Duration(milliseconds: 750), - switchInCurve: Curves.bounceInOut, - switchOutCurve: Curves.bounceInOut, + switchInCurve: Curves.bounceOut, + switchOutCurve: Curves.bounceIn, transitionBuilder: (child, animation) { var rotateAnimation = Tween(begin: 0, end: 2 * pi).animate(animation); var opacAnimation = Tween(begin: 0, end: 1).animate(animation); diff --git a/lib/show_dialogs.dart b/lib/show_dialogs.dart new file mode 100644 index 0000000..e027280 --- /dev/null +++ b/lib/show_dialogs.dart @@ -0,0 +1,54 @@ +/* + * @Author : Linloir + * @Date : 2022-03-07 10:28:38 + * @LastEditTime : 2022-03-07 10:59:46 + * @Description : Show import failed dialog + */ + +import 'package:flutter/material.dart'; + +Future showFailedDialog({required context}) { + return showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('Error Occurred'), + content: const Text('Something went wrong when importing dictionary, nothing is imported.'), + actions: [ + TextButton( + child: const Text('Retry'), + onPressed: () => Navigator.of(context).pop(true), + ), + TextButton( + child: const Text('Ignore'), + onPressed: () => Navigator.of(context).pop(), + ) + ], + ); + } + ); +} + +Future showLoadingDialog({required context}) { + return showDialog( + context: context, + builder: (context) { + return UnconstrainedBox( + child: SizedBox( + width: 280, + child: AlertDialog( + contentPadding: const EdgeInsets.all(50.0), + content: Align( + alignment: Alignment.center, + child: CircularProgressIndicator( + color: Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.grey[850], + strokeWidth: 6.0, + ), + ), + ), + ), + ); + }, + barrierDismissible: false, + ); +} \ No newline at end of file diff --git a/lib/validation_provider.dart b/lib/validation_provider.dart index ef48cd1..4d6dd81 100644 --- a/lib/validation_provider.dart +++ b/lib/validation_provider.dart @@ -1,11 +1,12 @@ /* * @Author : Linloir * @Date : 2022-03-05 21:40:51 - * @LastEditTime : 2022-03-07 08:10:08 + * @LastEditTime : 2022-03-07 11:15:55 * @Description : Validation Provider class */ import 'package:flutter/material.dart'; +import 'show_dialogs.dart'; import './event_bus.dart'; import './generator.dart'; @@ -39,8 +40,22 @@ class _ValidationProviderState extends State { } void _newGame() async{ - answer = await Words.generateWord(); - print('Generated answer $answer'); + showLoadingDialog(context: context); + var generated = await Words.generateWord(); + Navigator.of(context).pop(); + while(generated == null) { + var retry = await showFailedDialog(context: context); + if(retry == null) { + Navigator.of(context).popUntil(ModalRoute.withName('/')); + break; + } + else { + showLoadingDialog(context: context); + generated = await Words.generateWord(); + Navigator.of(context).pop(); + } + } + answer = generated ?? ""; answer = answer.toUpperCase(); letterMap = {}; answer.split('').forEach((c) { @@ -95,7 +110,6 @@ class _ValidationProviderState extends State { @override void initState(){ super.initState(); - _newGame(); mainBus.onBus(event: "NewGame", onEvent: _onNewGame); mainBus.onBus(event: "Result", onEvent: _onGameEnd); } diff --git a/pubspec.lock b/pubspec.lock index 9b41ab4..7e78bae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,56 +5,56 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.8.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.1" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.4" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" flutter: @@ -66,7 +66,7 @@ packages: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.4" flutter_test: @@ -78,35 +78,35 @@ packages: dependency: transitive description: name: lints - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.11" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.1.3" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.0" sky_engine: @@ -118,56 +118,56 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.4.8" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.1" sdks: diff --git a/pubspec.yaml b/pubspec.yaml index b1f4f61..681548a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,7 +64,7 @@ flutter: assets: - assets/unixWords.txt - assets/ospd.txt - - popular.txt + - assets/popular.txt # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.