Skip to content
Snippets Groups Projects
Commit a34846b2 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '26-do-not-pick-recently-picked-word' into 'master'

Resolve "Do not pick recently picked word"

Closes #26

See merge request !26
parents f61c6ec1 fcc5efb3
No related branches found
No related tags found
1 merge request!26Resolve "Do not pick recently picked word"
Pipeline #2030 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.18 app.versionName=0.1.19
app.versionCode=42 app.versionCode=43
...@@ -9,6 +9,8 @@ class Data extends ChangeNotifier { ...@@ -9,6 +9,8 @@ class Data extends ChangeNotifier {
Map _word = null; Map _word = null;
List _otherWords = []; List _otherWords = [];
List _images = []; List _images = [];
final int _recentWordsCount = 20;
List _recentWords = [];
// game data // game data
int _questionsCount = 0; int _questionsCount = 0;
...@@ -26,9 +28,17 @@ class Data extends ChangeNotifier { ...@@ -26,9 +28,17 @@ class Data extends ChangeNotifier {
set updateWord(Map value) { set updateWord(Map value) {
_word = value; _word = value;
if (value != null && value['key'] != '') {
_recentWords.insert(0, value['key']);
_recentWords = _recentWords.take(_recentWordsCount).toList();
}
notifyListeners(); notifyListeners();
} }
bool isRecentlyPicked(String word) {
return _recentWords.contains(word);
}
List get otherWords => _otherWords; List get otherWords => _otherWords;
set updateOtherWords(List words) { set updateOtherWords(List words) {
......
...@@ -43,12 +43,16 @@ class GamePickImagePage extends StatelessWidget { ...@@ -43,12 +43,16 @@ class GamePickImagePage extends StatelessWidget {
word = words.take(1).toList()[0]; word = words.take(1).toList()[0];
} }
attempts++; attempts++;
} while (attempts < 3);
if ((words != null) && (words.length == _countWords)) { if (
(words != null) && (words.length == _countWords)
&&
!myProvider.isRecentlyPicked(word['key'])
) {
myProvider.updateWord = word; myProvider.updateWord = word;
myProvider.updateImages = words; myProvider.updateImages = words;
} }
} while (myProvider.word != word && attempts < 10);
} }
Future<void> checkWord(Data myProvider, word) async { Future<void> checkWord(Data myProvider, word) async {
...@@ -121,7 +125,13 @@ class GamePickImagePage extends StatelessWidget { ...@@ -121,7 +125,13 @@ class GamePickImagePage extends StatelessWidget {
double imageSize = 130; double imageSize = 130;
String imageAsset = 'assets/placeholder.png'; 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]; imageAsset = 'assets/images/'+word['images'][0];
} }
......
...@@ -45,17 +45,19 @@ class GamePickWordPage extends StatelessWidget { ...@@ -45,17 +45,19 @@ class GamePickWordPage extends StatelessWidget {
images = word['images']; images = word['images'];
} }
attempts++; attempts++;
} while (attempts < 3);
if ( if (
((words != null) && (words.length == _countWords)) ((words != null) && (words.length == _countWords))
&& &&
((images != null) && (images.length == _countImages)) ((images != null) && (images.length == _countImages))
&&
!myProvider.isRecentlyPicked(word['key'])
) { ) {
myProvider.updateWord = word; myProvider.updateWord = word;
myProvider.updateOtherWords = words.skip(1).toList(); myProvider.updateOtherWords = words.skip(1).toList();
myProvider.updateImages = images; myProvider.updateImages = images;
} }
} while (myProvider.word != word && attempts < 10);
} }
Future<void> checkWord(Data myProvider, word) async { Future<void> checkWord(Data myProvider, word) async {
......
...@@ -26,14 +26,15 @@ class RandomPickImage { ...@@ -26,14 +26,15 @@ class RandomPickImage {
// Check we have enough images // Check we have enough images
if ((imageList == null) || (imageList.length < count)) { if ((imageList == null) || (imageList.length < count)) {
print('Not enough images in list for word "'+word+'".'); print('Not enough images in list for word "'+word+'".');
} _images = [];
} else {
// Randomize images list // Randomize images list
imageList.shuffle(); imageList.shuffle();
// Pick first images from shuffled list // Pick first images from shuffled list
_images = imageList.take(count).toList(); _images = imageList.take(count).toList();
} }
}
List get images => _images; List get images => _images;
} }
...@@ -26,8 +26,8 @@ class RandomPickWord { ...@@ -26,8 +26,8 @@ class RandomPickWord {
// Check we have enough words // Check we have enough words
if (wordList.length < count) { if (wordList.length < count) {
print('Not enough words in list.'); print('Not enough words in list.');
} _words = [];
} else {
// Remove empty words // Remove empty words
wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == ''))); wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == '')));
...@@ -37,6 +37,7 @@ class RandomPickWord { ...@@ -37,6 +37,7 @@ class RandomPickWord {
// Pick first words from shuffled list // Pick first words from shuffled list
_words = wordList.take(count).toList(); _words = wordList.take(count).toList();
} }
}
List get words => _words; List get words => _words;
} }
...@@ -7,7 +7,7 @@ packages: ...@@ -7,7 +7,7 @@ packages:
name: async name: async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.5.0" version: "2.7.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
...@@ -87,7 +87,7 @@ packages: ...@@ -87,7 +87,7 @@ packages:
name: meta name: meta
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0" version: "1.4.0"
nested: nested:
dependency: transitive dependency: transitive
description: description:
...@@ -162,7 +162,7 @@ packages: ...@@ -162,7 +162,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.0" version: "0.4.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment