Added custom server URL support
Added custom server URL support, changed spaces to tabs and added/changed some preference summary strings. Based on #9.
This commit is contained in:
parent
23e4b4c19d
commit
7fb4ddb79f
|
@ -23,10 +23,16 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
|
|
||||||
package com.luca0n.joguitos.pluck.trivia;
|
package com.luca0n.joguitos.pluck.trivia;
|
||||||
|
|
||||||
|
import com.luca0n.joguitos.pluck.PluckApplication;
|
||||||
|
import com.luca0n.joguitos.pluck.R;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
public class TriviaQuery implements Serializable {
|
public class TriviaQuery implements Serializable {
|
||||||
private static final String BASE = "https://opentdb.com/api.php?";
|
|
||||||
private static final int DEFAULT_AMOUNT = 10;
|
private static final int DEFAULT_AMOUNT = 10;
|
||||||
|
|
||||||
private final int amount;
|
private final int amount;
|
||||||
|
@ -83,7 +89,16 @@ public class TriviaQuery implements Serializable {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder url = new StringBuilder();
|
StringBuilder url = new StringBuilder();
|
||||||
|
|
||||||
url.append(BASE);
|
// Load custom server URL.
|
||||||
|
Context c = PluckApplication.getAppContext();
|
||||||
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
|
||||||
|
String key = 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(key, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
|
||||||
|
|
||||||
|
url.append(base);
|
||||||
url.append("amount=").append(this.amount);
|
url.append("amount=").append(this.amount);
|
||||||
|
|
||||||
if (this.category != null & this.category != TriviaCategory.ANY) {
|
if (this.category != null & this.category != TriviaCategory.ANY) {
|
||||||
|
|
|
@ -26,4 +26,6 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<string name="pref_category_sound">pref_key_category_sound</string>
|
<string name="pref_category_sound">pref_key_category_sound</string>
|
||||||
<string name="pref_sound_answer">pref_sound_answer</string>
|
<string name="pref_sound_answer">pref_sound_answer</string>
|
||||||
<string name="pref_network_tor">pref_network_tor</string>
|
<string name="pref_network_tor">pref_network_tor</string>
|
||||||
|
<string name="pref_network_server">pref_network_server</string>
|
||||||
|
<string name="pref_network_server_default">https://opentdb.com/api.php</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -90,8 +90,11 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<!-- Setting Strings-->
|
<!-- Setting Strings-->
|
||||||
<string name="pref_category_sound_title">Sound</string>
|
<string name="pref_category_sound_title">Sound</string>
|
||||||
<string name="pref_sound_answer_title">Answer Sound Effect</string>
|
<string name="pref_sound_answer_title">Answer Sound Effect</string>
|
||||||
|
<string name="pref_sound_answer_summary">Toggles game sound effects.</string>
|
||||||
|
|
||||||
<string name="pref_category_network_title">Network</string>
|
<string name="pref_category_network_title">Network</string>
|
||||||
<string name="pref_network_tor_title">Connect using Tor</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.</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>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -31,16 +31,21 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="@string/pref_sound_answer"
|
android:key="@string/pref_sound_answer"
|
||||||
android:title="@string/pref_sound_answer_title" />
|
android:title="@string/pref_sound_answer_title"
|
||||||
|
android:summary="@string/pref_sound_answer_summary" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/pref_category_network_title">
|
android:title="@string/pref_category_network_title">
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="@string/pref_network_server_default"
|
||||||
|
android:key="@string/pref_network_server"
|
||||||
|
android:title="@string/pref_network_server_title"
|
||||||
|
android:summary="@string/pref_network_server_summary" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/pref_network_tor"
|
android:key="@string/pref_network_tor"
|
||||||
android:title="@string/pref_network_tor_title"
|
android:title="@string/pref_network_tor_title"
|
||||||
android:summary="@string/pref_network_tor_summary" />
|
android:summary="@string/pref_network_tor_summary" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Reference in New Issue