From b2f230af18886febe650c630b448a444fba97718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Wed, 20 Mar 2024 15:05:04 +0100 Subject: [PATCH] Add a timer after use of help button --- android/gradle.properties | 4 +-- .../metadata/android/en-US/changelogs/67.txt | 1 + .../metadata/android/fr-FR/changelogs/67.txt | 1 + lib/provider/data.dart | 34 ++++++++++++++++--- lib/ui/screens/home.dart | 11 +++--- pubspec.yaml | 2 +- 6 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/67.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/67.txt diff --git a/android/gradle.properties b/android/gradle.properties index c0b881d..142ae7b 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=0.1.17 -app.versionCode=66 +app.versionName=0.1.18 +app.versionCode=67 diff --git a/fastlane/metadata/android/en-US/changelogs/67.txt b/fastlane/metadata/android/en-US/changelogs/67.txt new file mode 100644 index 0000000..ea389ac --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/67.txt @@ -0,0 +1 @@ +Add a timer after use of "help" button. diff --git a/fastlane/metadata/android/fr-FR/changelogs/67.txt b/fastlane/metadata/android/fr-FR/changelogs/67.txt new file mode 100644 index 0000000..8b856d8 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/67.txt @@ -0,0 +1 @@ +Ajout d'une temporisation pour réactiver le bouton "aide" après usage. diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 64585c0..0ad2253 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundation.dart'; @@ -54,6 +55,7 @@ class Data extends ChangeNotifier { int? _selectedCellValue; bool _showConflicts = false; int _givenTipsCount = 0; + int _givenTipsCountEnableCountdown = 0; String _currentSavedState = ''; void updateParameterLevel(String parameterLevel) { @@ -246,23 +248,45 @@ class Data extends ChangeNotifier { notifyListeners(); } + int get givenTipsCountEnableCountdown => _givenTipsCountEnableCountdown; + int get givenTipsCount => _givenTipsCount; - increaseGivenTipsCount() { + void increaseGivenTipsCount() { _givenTipsCount = _givenTipsCount + 1; + _givenTipsCountEnableCountdown = 60; + const Duration interval = Duration(milliseconds: 500); + Timer.periodic( + interval, + (Timer timer) { + if (_givenTipsCountEnableCountdown == 0) { + timer.cancel(); + notifyListeners(); + } else { + _givenTipsCountEnableCountdown--; + notifyListeners(); + } + }, + ); + saveCurrentGameState(); notifyListeners(); } - setGivenTipsCount(int value) { + void setGivenTipsCount(int value) { _givenTipsCount = value; + _givenTipsCountEnableCountdown = 0; notifyListeners(); } - resetGivenTipsCount() { + bool canGiveTip() { + return (_givenTipsCountEnableCountdown == 0); + } + + void resetGivenTipsCount() { setGivenTipsCount(0); } - selectCell(int? col, int? row) { + void selectCell(int? col, int? row) { _selectedCellCol = col; _selectedCellRow = row; _selectedCellValue = null; @@ -291,7 +315,7 @@ class Data extends ChangeNotifier { _boardConflicts = conflictsCount; } - updateCellValue(int? col, int? row, int value) { + void updateCellValue(int? col, int? row, int value) { if ((col != null) && (row != null)) { if (!_board[row][col].isFixed) { _board[row][col] = Cell( diff --git a/lib/ui/screens/home.dart b/lib/ui/screens/home.dart index af2cfa1..3b86e93 100644 --- a/lib/ui/screens/home.dart +++ b/lib/ui/screens/home.dart @@ -117,13 +117,16 @@ class HomeState extends State<Home> { myProvider.givenTipsCount == 0 ? '' : myProvider.givenTipsCount.toString(), style: const TextStyle(color: Colors.white), ), - child: const Image( - image: AssetImage('assets/icons/button_help.png'), - fit: BoxFit.fill, + child: Container( + padding: EdgeInsets.all(myProvider.givenTipsCountEnableCountdown / 4), + child: const Image( + image: AssetImage('assets/icons/button_help.png'), + fit: BoxFit.fill, + ), ), ), ), - onPressed: () => GameUtils.showTip(myProvider), + onPressed: () => myProvider.canGiveTip() ? GameUtils.showTip(myProvider) : null, )); menuActions.add(const Spacer()); menuActions.add(TextButton( diff --git a/pubspec.yaml b/pubspec.yaml index e4e9a93..9c7e81f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: sudoku description: A sudoku game application. publish_to: 'none' -version: 0.1.17+66 +version: 0.1.18+67 environment: sdk: '^3.0.0' -- GitLab