Compare commits
4 Commits
7fb4ddb79f
...
cff137eded
Author | SHA1 | Date |
---|---|---|
luca0N! | cff137eded | |
luca0N! | 02f7b5b444 | |
luca0N! | 8faf300bd0 | |
luca0N! | ec9c2ce07c |
|
@ -26,7 +26,7 @@
|
|||
android:screenOrientation="fullUser"
|
||||
android:configChanges="orientation|screenSize"/>
|
||||
<activity android:name=".settings.SettingsActivity"
|
||||
android:label="@string/ui_settings"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:screenOrientation="fullUser"
|
||||
android:configChanges="orientation|screenSize"/>
|
||||
</application>
|
||||
|
|
|
@ -48,6 +48,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import com.luca0n.joguitos.pluck.R;
|
||||
import com.luca0n.joguitos.pluck.exceptions.NoTriviaResultsException;
|
||||
import com.luca0n.joguitos.pluck.exceptions.InvalidServerResponseException;
|
||||
import com.luca0n.joguitos.pluck.fragments.TriviaGameErrorFragment;
|
||||
import com.luca0n.joguitos.pluck.fragments.TriviaQuestionFragment;
|
||||
import com.luca0n.joguitos.pluck.interfaces.IDownloadTriviaQuestionReceiver;
|
||||
|
@ -142,8 +143,9 @@ public class TriviaGameActivity extends BaseActivity
|
|||
} else {
|
||||
try {
|
||||
this.game = new TriviaGame(ApiUtil.jsonToQuestionArray(json));
|
||||
} catch (NoTriviaResultsException e) {
|
||||
onNoTriviaResults();
|
||||
} catch (Exception e) {
|
||||
//onNoTriviaResults();
|
||||
onException(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -190,8 +192,21 @@ public class TriviaGameActivity extends BaseActivity
|
|||
ft.commit();
|
||||
}
|
||||
|
||||
private void onNoTriviaResults() {
|
||||
String msg = getResources().getString(R.string.error_no_trivia_results);
|
||||
/**
|
||||
* Handles caught exceptions and gives feedback to alert errors to the player.
|
||||
* @param e The caught exception.
|
||||
*/
|
||||
private void onException(Exception e) {
|
||||
// Hide the progress bar.
|
||||
progressBar.setVisibility(View.GONE);
|
||||
String msg;
|
||||
if (e instanceof NoTriviaResultsException)
|
||||
msg = getResources().getString(R.string.error_no_trivia_results);
|
||||
else if (e instanceof InvalidServerResponseException)
|
||||
msg = getResources().getString(R.string.error_server_response_invalid);
|
||||
else
|
||||
msg = getResources().getString(R.string.error_unknown);
|
||||
|
||||
Fragment errorFragment = TriviaGameErrorFragment.newInstance(msg);
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
|
|
@ -92,11 +92,16 @@ public class TriviaQuery implements Serializable {
|
|||
// Load custom server URL.
|
||||
Context c = PluckApplication.getAppContext();
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
|
||||
String key = c.getResources().getString(R.string.pref_network_server);
|
||||
String serverKey = c.getResources().getString(R.string.pref_network_server);
|
||||
// Load default server URL in case the player did not specify a custom server URL.
|
||||
String defaultServer = c.getResources().getString(R.string.pref_network_server_default);
|
||||
String base = sp.getString(serverKey, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
|
||||
|
||||
String base = sp.getString(key, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
|
||||
// Check if the custom server URL preference was empty. If it was, change it to the default URL.
|
||||
if (base.equals("?")){
|
||||
base = defaultServer + "?";
|
||||
sp.edit().putString(serverKey, defaultServer).commit();
|
||||
}
|
||||
|
||||
url.append(base);
|
||||
url.append("amount=").append(this.amount);
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.google.gson.JsonArray;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
|
@ -46,6 +47,7 @@ import java.util.ArrayList;
|
|||
import com.luca0n.joguitos.pluck.R;
|
||||
import com.luca0n.joguitos.pluck.PluckApplication;
|
||||
import com.luca0n.joguitos.pluck.exceptions.NoTriviaResultsException;
|
||||
import com.luca0n.joguitos.pluck.exceptions.InvalidServerResponseException;
|
||||
import com.luca0n.joguitos.pluck.trivia.TriviaQuery;
|
||||
import com.luca0n.joguitos.pluck.trivia.TriviaQuestion;
|
||||
import com.luca0n.joguitos.pluck.trivia.TriviaQuestionBoolean;
|
||||
|
@ -102,8 +104,15 @@ public class ApiUtil {
|
|||
return GET(query.toString());
|
||||
}
|
||||
|
||||
public static ArrayList<TriviaQuestion> jsonToQuestionArray(String json) throws NoTriviaResultsException {
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
public static ArrayList<TriviaQuestion> jsonToQuestionArray(String json)
|
||||
throws NoTriviaResultsException, InvalidServerResponseException {
|
||||
JsonObject jsonObject;
|
||||
try{
|
||||
jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
} catch (JsonSyntaxException e){
|
||||
// Unknown server response.
|
||||
throw new InvalidServerResponseException();
|
||||
}
|
||||
|
||||
if (jsonObject.get("response_code").getAsInt() == 1) {
|
||||
throw new NoTriviaResultsException();
|
||||
|
|
|
@ -83,8 +83,11 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="ui_return_to_menu">Return To Menu</string>
|
||||
|
||||
<!-- Error Strings -->
|
||||
<string name="error_network"><b>Network error!</b>\nCould not connect to a network.\n\nIf Tor is enabled in the game settings, check if Orbot is running and then try again.</string>
|
||||
<string name="error_no_trivia_results"><b>No trivia results!</b>\nWas not able to find trivia questions that satisfied all options.</string>
|
||||
<string name="error_network"><b>Network error!</b>\n\nCould not connect to a network. Check if your custom server address is correct. If Tor is enabled in the game settings, check if Orbot is running and then try again.</string>
|
||||
<string name="error_no_trivia_results"><b>No trivia results!</b>\n\nWas not able to find trivia questions that satisfied all options.</string>
|
||||
<string name="error_server_response_invalid"><b>Server response error!</b>\n\nCould not parse the server response. The server response may be in a unsupported version. If you are using a custom server, make sure the server address points to a valid address and then try again.</string>
|
||||
<string name="error_unknown"><b>An unknown error occurred!</b></string>
|
||||
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
|
||||
<!-- Setting Strings-->
|
||||
|
@ -95,6 +98,6 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="pref_category_network_title">Network</string>
|
||||
<string name="pref_network_tor_title">Connect Using Tor</string>
|
||||
<string name="pref_network_tor_summary">Retrieves trivia data via the Tor network. Requires Orbot (recommended) or a Tor daemon with a SOCKS5 proxy listening on port 9050.</string>
|
||||
<string name="pref_network_server_title">Server URL</string>
|
||||
<string name="pref_network_server_summary">Specifies the server location used by the game to fetch questions.</string>
|
||||
<string name="pref_network_server_title">Server address</string>
|
||||
<string name="pref_network_server_summary">Specifies the server location used by the game to fetch questions. Leave empty to use the default server.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue