diff --git a/android/gradle.properties b/android/gradle.properties index 6a1245fd0088c01173c74d0f2eadf7059db00280..27d2e182d9d1b61241538ad078465bb4f7f6ddbb 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=1.2.12 -app.versionCode=18 +app.versionName=1.2.13 +app.versionCode=19 diff --git a/lib/main.dart b/lib/main.dart index a317c62a527f381023b7d4269324b197fdf9fde7..c107caae1da48a16dd6b5a14e59e07985acfedbe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,15 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; import 'provider/data.dart'; import 'screens/home.dart'; -void main() => runApp(MyApp()); +void main() { + WidgetsFlutterBinding.ensureInitialized(); + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) + .then((value) => runApp(MyApp())); +} class MyApp extends StatelessWidget { @override diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 90afdd2d6827e18345b53a799d26e7b2de6d24c1..bf343bd1c7681e3d3b1d40067a8bf0b2bf531db9 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -2,44 +2,61 @@ import 'package:flutter/foundation.dart'; class Data extends ChangeNotifier { - // randomization bool _searchingCategory = false; bool _searchingLetter = false; + String _category = ''; String _letter = ''; + int _countdown = -1; - bool get searchingCategory => _searchingCategory; + final int _recentCategoriesCount = 15; + final int _recentLettersCount = 10; + List _recentCategories = []; + List _recentLetters = []; - set searchingCategory(bool value) { + + bool get searchingCategory => _searchingCategory; + void setSearchingCategory(bool value) { _searchingCategory = value; notifyListeners(); } bool get searchingLetter => _searchingLetter; - - set searchingLetter(bool value) { + void setSearchingLetter(bool value) { _searchingLetter = value; notifyListeners(); } String get category => _category; - - set updateCategory(String value) { + void updateCategory(String value) { _category = value; + if (value != null && value != '') { + _recentCategories.insert(0, value); + _recentCategories = _recentCategories.take(_recentCategoriesCount).toList(); + } notifyListeners(); } String get letter => _letter; - - set updateLetter(String value) { + void updateLetter(String value) { _letter = value; + if (value != null && value != '') { + _recentLetters.insert(0, value); + _recentLetters = _recentLetters.take(_recentLettersCount).toList(); + } notifyListeners(); } - int get countdown => _countdown; + String recentlyPickedLetter(int count) { + if (_recentLetters.length > count) { + return _recentLetters[count]; + } + return ''; + } - set updateCountdown(int value) { + int get countdown => _countdown; + void updateCountdown(int value) { _countdown = value; notifyListeners(); } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 7ff93304eda4d092000d2836514c0c08642d9080..a6d86a49bb9b4b3d107564b706180cfa7260a2e2 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -30,7 +30,7 @@ class Home extends StatelessWidget { dispose(); } _countdownStart = 10; - myProvider.updateCountdown = _countdownStart; + myProvider.updateCountdown(_countdownStart); _timer = new Timer.periodic( oneSec, (Timer timer) { @@ -38,7 +38,7 @@ class Home extends StatelessWidget { timer.cancel(); } else { _countdownStart--; - myProvider.updateCountdown = _countdownStart; + myProvider.updateCountdown(_countdownStart); } }, ); @@ -50,15 +50,15 @@ class Home extends StatelessWidget { } Future<void> pickCategory(Data myProvider) async { - myProvider.searchingCategory = true; + myProvider.setSearchingCategory(true); RandomPickCategory randomPickCategory; int attempts = 0; do { randomPickCategory = RandomPickCategory(); await randomPickCategory.init(); if (randomPickCategory.category != null) { - myProvider.updateCategory = randomPickCategory.category; - myProvider.searchingCategory = false; + myProvider.updateCategory(randomPickCategory.category); + myProvider.setSearchingCategory(false); break; } attempts++; @@ -66,15 +66,15 @@ class Home extends StatelessWidget { } Future<void> pickLetter(Data myProvider) async { - myProvider.searchingLetter = true; + myProvider.setSearchingLetter(true); RandomPickLetter randomPickLetter; int attempts = 0; do { randomPickLetter = RandomPickLetter(); await randomPickLetter.init(); if (randomPickLetter.letter != null) { - myProvider.updateLetter = randomPickLetter.letter; - myProvider.searchingLetter = false; + myProvider.updateLetter(randomPickLetter.letter); + myProvider.setSearchingLetter(false); break; } attempts++; @@ -87,42 +87,113 @@ class Home extends StatelessWidget { return hslDark.toColor(); } - Container _buildPickedLetterContainer(Data myProvider, Color backgroundColor, double borderWidth) { + Container mainLetterButtonContainer(Data myProvider, Color backgroundColor, double borderWidth) { Color borderColor = darken(backgroundColor); return Container( - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - margin: EdgeInsets.all(borderWidth), - padding: EdgeInsets.all(borderWidth), - decoration: BoxDecoration( - color: backgroundColor, - borderRadius: BorderRadius.circular(borderWidth), - border: Border.all( - color: borderColor, - width: borderWidth, - ), - ), - child: FlatButton( - onPressed: () => pickLetter(myProvider), - child: Text( - myProvider.letter == '' ? "🔀" : myProvider.letter, - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.w600, - color: Colors.black, - ), - ), - ), + margin: EdgeInsets.all(borderWidth), + padding: EdgeInsets.all(borderWidth), + decoration: BoxDecoration( + color: backgroundColor, + borderRadius: BorderRadius.circular(borderWidth), + border: Border.all( + color: borderColor, + width: borderWidth, + ), + ), + child: FlatButton( + onPressed: () => pickLetter(myProvider), + child: Text( + myProvider.letter == '' ? "🔀" : myProvider.letter, + style: TextStyle( + fontSize: 40, + fontWeight: FontWeight.w600, + color: Colors.black, ), - ], + ), ), ); } + Container previousLetterBlockContainer(Data myProvider, int position, bool displayed) { + double spacingWidth = 2; + double borderWidth = 3; + Color backgroundColor = Colors.grey; + Color borderColor = darken(backgroundColor); + Color fontColor = Colors.black; + + String letter = myProvider.recentlyPickedLetter(position); + + if (letter == '' || displayed == false) { + backgroundColor = Colors.white; + borderColor = Colors.white; + fontColor = Colors.white; + } + + return Container( + margin: EdgeInsets.all(spacingWidth), + padding: EdgeInsets.all(spacingWidth), + decoration: BoxDecoration( + color: backgroundColor, + borderRadius: BorderRadius.circular(borderWidth), + border: Border.all( + color: borderColor, + width: borderWidth, + ), + ), + child: Text( + ' ' + letter + ' ', + style: TextStyle( + fontSize: 35.0 - (7 * position), + fontWeight: FontWeight.w600, + color: fontColor, + ), + ), + ); + } + + Container _buildPickedLetterContainer(Data myProvider, Color backgroundColor, double borderWidth) { + int previousLettersCountToShow = 3; + + List <Widget> cells = []; + + // Add previous letters blocks + for (var i = 0; i < previousLettersCountToShow; i++) { + cells.add(TableCell( + verticalAlignment: TableCellVerticalAlignment.middle, + child: previousLetterBlockContainer(myProvider, previousLettersCountToShow - i, true) + )); + } + + // Add current letter block + cells.add(TableCell( + verticalAlignment: TableCellVerticalAlignment.middle, + child: mainLetterButtonContainer(myProvider, backgroundColor, borderWidth) + )); + + // Pad with empty blocks to keep symetrical layout + for (var i = 0; i < previousLettersCountToShow; i++) { + cells.add(TableCell( + verticalAlignment: TableCellVerticalAlignment.middle, + child: previousLetterBlockContainer(myProvider, i + 1, false) + )); + } + + return Container( + margin: EdgeInsets.all(2), + padding: EdgeInsets.all(2), + + child: Table( + defaultColumnWidth: IntrinsicColumnWidth(), + children: [ + TableRow( + children: cells + ), + ] + ) + ); + } + Container _buildPickedCategoryContainer(Data myProvider, Color backgroundColor, double borderWidth) { Color borderColor = darken(backgroundColor); diff --git a/pubspec.lock b/pubspec.lock index 8fe48be6a46a17b55d64d9bf688549189566046f..b6eca0d9a310f699c2be40fd6273acfa381332e9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -73,7 +73,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -141,7 +141,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.1" typed_data: dependency: transitive description: