Compare commits
2 commits
7d92099a95
...
8e84fe2ff5
Author | SHA1 | Date | |
---|---|---|---|
8e84fe2ff5 | |||
c3c820715b |
1 changed files with 8 additions and 0 deletions
|
@ -43,6 +43,7 @@ import java.net.Proxy;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import com.luca0n.joguitos.pluck.R;
|
import com.luca0n.joguitos.pluck.R;
|
||||||
import com.luca0n.joguitos.pluck.PluckApplication;
|
import com.luca0n.joguitos.pluck.PluckApplication;
|
||||||
|
@ -127,7 +128,11 @@ public class ApiUtil {
|
||||||
|
|
||||||
ArrayList<TriviaQuestion> questions = new ArrayList<>();
|
ArrayList<TriviaQuestion> questions = new ArrayList<>();
|
||||||
|
|
||||||
|
int elements = 0;
|
||||||
|
|
||||||
for (JsonElement element : jsonArray) {
|
for (JsonElement element : jsonArray) {
|
||||||
|
if (elements++ == filters.getAmount())
|
||||||
|
break;
|
||||||
JsonObject object = element.getAsJsonObject();
|
JsonObject object = element.getAsJsonObject();
|
||||||
TriviaType type = TriviaType.get(object.get("type").getAsString());
|
TriviaType type = TriviaType.get(object.get("type").getAsString());
|
||||||
|
|
||||||
|
@ -152,6 +157,9 @@ public class ApiUtil {
|
||||||
if (questions.size() == 0)
|
if (questions.size() == 0)
|
||||||
throw new NoTriviaResultsException();
|
throw new NoTriviaResultsException();
|
||||||
|
|
||||||
|
// Shuffle the question array.
|
||||||
|
Collections.shuffle(questions);
|
||||||
|
|
||||||
return questions;
|
return questions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue