Added "All" option on the question amount spinner
Added a new option on the question amount spinner that allows players to view all questions on a trivia file.
This commit is contained in:
parent
8e84fe2ff5
commit
4045f0207c
|
@ -86,10 +86,21 @@ public class MainActivity extends BaseActivity {
|
|||
}
|
||||
return;
|
||||
}
|
||||
int amount = (int) spinnerNumber.getSelectedItem();
|
||||
String amount = (String) spinnerNumber.getSelectedItem();
|
||||
TriviaCategory category = (TriviaCategory) spinnerCategory.getSelectedItem();
|
||||
TriviaDifficulty difficulty = (TriviaDifficulty) spinnerDifficulty.getSelectedItem();
|
||||
|
||||
if (amount.equals(getString(R.string.ui_all))){
|
||||
// The "All" option is only used for trivia files.
|
||||
new AlertDialog.Builder(this)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(R.string.error_option_all_unavailable)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Put the server address in the TriviaQuery object.
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
String serverKey = getResources().getString(R.string.pref_network_server);
|
||||
|
@ -103,7 +114,7 @@ public class MainActivity extends BaseActivity {
|
|||
sp.edit().putString(serverKey, defaultServer).commit();
|
||||
}
|
||||
|
||||
TriviaQuery query = new TriviaQuery.Builder(amount)
|
||||
TriviaQuery query = new TriviaQuery.Builder(Integer.valueOf(amount))
|
||||
.category(category)
|
||||
.difficulty(difficulty)
|
||||
.base(base)
|
||||
|
@ -114,16 +125,19 @@ public class MainActivity extends BaseActivity {
|
|||
intent.putExtra(TriviaGameActivity.EXTRA_TRIVIA_SOURCE, TriviaSource.SERVER.getName()); // Specify the trivia source.
|
||||
intent.putExtra(TriviaGameActivity.EXTRA_TRIVIA_QUERY, query);
|
||||
intent.putExtra(TriviaGameActivity.EXTRA_TRIVIA_FILTERS,
|
||||
new TriviaFilters.Builder(amount)
|
||||
new TriviaFilters.Builder(Integer.valueOf(amount))
|
||||
.category(category)
|
||||
.difficulty(difficulty)
|
||||
.build());
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
Integer[] numbers = new Integer[50];
|
||||
for (int i = 0; i < 50; ) {
|
||||
numbers[i] = ++i;
|
||||
// Create a String array that holds all options for spinnerNumber.
|
||||
String[] numbers = new String[51];
|
||||
for (int i = 0; i < 51; i++) {
|
||||
// The first entry on the spinner should be the value "All", which is used with the
|
||||
// file trivia source.
|
||||
numbers[i] = i == 0 ? getString(R.string.ui_all) : String.valueOf(i);
|
||||
}
|
||||
spinnerSource.setAdapter(
|
||||
new ArrayAdapter<>(
|
||||
|
@ -133,7 +147,7 @@ public class MainActivity extends BaseActivity {
|
|||
new ArrayAdapter<>(
|
||||
this, android.R.layout.simple_list_item_1, numbers)
|
||||
);
|
||||
spinnerNumber.setSelection(9);
|
||||
spinnerNumber.setSelection(10);
|
||||
|
||||
spinnerCategory.setAdapter(
|
||||
new ArrayAdapter<>(
|
||||
|
@ -154,14 +168,14 @@ public class MainActivity extends BaseActivity {
|
|||
if (extras == null)
|
||||
break;
|
||||
|
||||
int amount = (int) spinnerNumber.getSelectedItem();
|
||||
String amount = (String) spinnerNumber.getSelectedItem();
|
||||
TriviaCategory category = (TriviaCategory) spinnerCategory.getSelectedItem();
|
||||
TriviaDifficulty difficulty = (TriviaDifficulty) spinnerDifficulty.getSelectedItem();
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), TriviaGameActivity.class);
|
||||
// Put filters on the extras object.
|
||||
intent.putExtra(TriviaGameActivity.EXTRA_TRIVIA_FILTERS,
|
||||
new TriviaFilters.Builder(amount)
|
||||
new TriviaFilters.Builder(amount.equals(getString(R.string.ui_all)) ? -1 : Integer.valueOf(amount))
|
||||
.category(category)
|
||||
.difficulty(difficulty)
|
||||
.build());
|
||||
|
|
|
@ -131,7 +131,8 @@ public class ApiUtil {
|
|||
int elements = 0;
|
||||
|
||||
for (JsonElement element : jsonArray) {
|
||||
if (elements++ == filters.getAmount())
|
||||
int amount = filters.getAmount();
|
||||
if (amount > 0 && elements++ == amount)
|
||||
break;
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
TriviaType type = TriviaType.get(object.get("type").getAsString());
|
||||
|
|
|
@ -70,7 +70,8 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="ui_about">About</string>
|
||||
<string name="ui_play">Play</string>
|
||||
<string name="ui_start_game">Start Game</string>
|
||||
<string name="ui_any">Any</string>
|
||||
<string name="ui_any">Any</string>
|
||||
<string name="ui_all">All</string>
|
||||
<string name="ui_true">True</string>
|
||||
<string name="ui_false">False</string>
|
||||
<string name="ui_correct">Correct</string>
|
||||
|
@ -97,6 +98,7 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="error_source_file_android_version_unsupported">Trivia files are not supported in this version of Android.</string>
|
||||
<string name="error_trivia_file_invalid"><b>Invalid trivia file!</b>\n\nTrivia files should be in a plain text JSON format.</string>
|
||||
<string name="error_trivia_file_fetch_unknown">An unknown error occurred while attempting to read the opened file.</string>
|
||||
<string name="error_option_all_unavailable">The selected question amount is only available for the "File" trivia game source.</string>
|
||||
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue