Compare commits

...

2 Commits

Author SHA1 Message Date
luca0N! 8e84fe2ff5
Finished filter support
The game now limits trivia file questions based on the question amount picked by the player on `MainActivity`.
2021-03-16 01:00:19 -03:00
luca0N! c3c820715b
Randomized question order 2021-03-16 00:57:42 -03:00
1 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import java.net.Proxy;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import com.luca0n.joguitos.pluck.R;
import com.luca0n.joguitos.pluck.PluckApplication;
@ -127,7 +128,11 @@ public class ApiUtil {
ArrayList<TriviaQuestion> questions = new ArrayList<>();
int elements = 0;
for (JsonElement element : jsonArray) {
if (elements++ == filters.getAmount())
break;
JsonObject object = element.getAsJsonObject();
TriviaType type = TriviaType.get(object.get("type").getAsString());
@ -152,6 +157,9 @@ public class ApiUtil {
if (questions.size() == 0)
throw new NoTriviaResultsException();
// Shuffle the question array.
Collections.shuffle(questions);
return questions;
}
}