diff --git a/android/gradle.properties b/android/gradle.properties index 36521185cc5c605598e95cf9115e19b461b2cb36..bc3f1f33d42a4d39f8b267873089aa00fce652de 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.18 -app.versionCode=42 +app.versionName=0.1.19 +app.versionCode=43 diff --git a/lib/provider/data.dart b/lib/provider/data.dart index f9361ddbd49bea55e68e2ba08ed075cf79452fc1..9d02de73cb1ca11a1c5acc081062693bbac78bb6 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -9,6 +9,8 @@ class Data extends ChangeNotifier { Map _word = null; List _otherWords = []; List _images = []; + final int _recentWordsCount = 20; + List _recentWords = []; // game data int _questionsCount = 0; @@ -26,9 +28,17 @@ class Data extends ChangeNotifier { set updateWord(Map value) { _word = value; + if (value != null && value['key'] != '') { + _recentWords.insert(0, value['key']); + _recentWords = _recentWords.take(_recentWordsCount).toList(); + } notifyListeners(); } + bool isRecentlyPicked(String word) { + return _recentWords.contains(word); + } + List get otherWords => _otherWords; set updateOtherWords(List words) { diff --git a/lib/screens/game_pick_image.dart b/lib/screens/game_pick_image.dart index ff0602547fe950360fe73141a42b7cf8ae92c82e..5a5e21ccc8f9afb0f37260b199a8de7aee8a72c4 100644 --- a/lib/screens/game_pick_image.dart +++ b/lib/screens/game_pick_image.dart @@ -43,12 +43,16 @@ class GamePickImagePage extends StatelessWidget { word = words.take(1).toList()[0]; } attempts++; - } while (attempts < 3); - if ((words != null) && (words.length == _countWords)) { - myProvider.updateWord = word; - myProvider.updateImages = words; - } + if ( + (words != null) && (words.length == _countWords) + && + !myProvider.isRecentlyPicked(word['key']) + ) { + myProvider.updateWord = word; + myProvider.updateImages = words; + } + } while (myProvider.word != word && attempts < 10); } Future<void> checkWord(Data myProvider, word) async { @@ -121,7 +125,13 @@ class GamePickImagePage extends StatelessWidget { double imageSize = 130; String imageAsset = 'assets/placeholder.png'; - if ((word['images'] != null) && (word['images'][0] != null)) { + if ( + (word['images'] != null) + && + (word['images'].length != 0) + && + (word['images'][0] != null) + ) { imageAsset = 'assets/images/'+word['images'][0]; } diff --git a/lib/screens/game_pick_word.dart b/lib/screens/game_pick_word.dart index 19903b4968f211007930963bb7f5a708e557ee8c..3839d8d65480a4a4623d442855f1d0661143b0a8 100644 --- a/lib/screens/game_pick_word.dart +++ b/lib/screens/game_pick_word.dart @@ -45,17 +45,19 @@ class GamePickWordPage extends StatelessWidget { images = word['images']; } attempts++; - } while (attempts < 3); - if ( - ((words != null) && (words.length == _countWords)) - && - ((images != null) && (images.length == _countImages)) - ) { - myProvider.updateWord = word; - myProvider.updateOtherWords = words.skip(1).toList(); - myProvider.updateImages = images; - } + if ( + ((words != null) && (words.length == _countWords)) + && + ((images != null) && (images.length == _countImages)) + && + !myProvider.isRecentlyPicked(word['key']) + ) { + myProvider.updateWord = word; + myProvider.updateOtherWords = words.skip(1).toList(); + myProvider.updateImages = images; + } + } while (myProvider.word != word && attempts < 10); } Future<void> checkWord(Data myProvider, word) async { diff --git a/lib/utils/random_pick_image.dart b/lib/utils/random_pick_image.dart index 15ea47691ac4598bef2bf3375e86eea5c57aac57..1bbf6a4a054bc43f8fbbd3741aeb87d38b48b599 100644 --- a/lib/utils/random_pick_image.dart +++ b/lib/utils/random_pick_image.dart @@ -26,13 +26,14 @@ class RandomPickImage { // Check we have enough images if ((imageList == null) || (imageList.length < count)) { print('Not enough images in list for word "'+word+'".'); - } - - // Randomize images list - imageList.shuffle(); + _images = []; + } else { + // Randomize images list + imageList.shuffle(); - // Pick first images from shuffled list - _images = imageList.take(count).toList(); + // Pick first images from shuffled list + _images = imageList.take(count).toList(); + } } List get images => _images; diff --git a/lib/utils/random_pick_word.dart b/lib/utils/random_pick_word.dart index 78ae51c647991daaef9adbebdbb1524e9859e3f1..169c23945a2d96647e6458b85757b585940b2e0d 100644 --- a/lib/utils/random_pick_word.dart +++ b/lib/utils/random_pick_word.dart @@ -26,16 +26,17 @@ class RandomPickWord { // Check we have enough words if (wordList.length < count) { print('Not enough words in list.'); - } - - // Remove empty words - wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == ''))); + _words = []; + } else { + // Remove empty words + wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == ''))); - // Randomize words list - wordList.shuffle(); + // Randomize words list + wordList.shuffle(); - // Pick first words from shuffled list - _words = wordList.take(count).toList(); + // Pick first words from shuffled list + _words = wordList.take(count).toList(); + } } List get words => _words; diff --git a/pubspec.lock b/pubspec.lock index d096ebd7cc934e1bf3c66d59fce7542e3a7b7ac1..8a4d1aab5760ddfc23287f86ee297cb9dda3f131 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -87,7 +87,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.4.0" nested: dependency: transitive description: @@ -162,7 +162,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.0" typed_data: dependency: transitive description: