Compare commits

...

2 commits

Author SHA1 Message Date
7fb4ddb79f
Added custom server URL support
Added custom server URL support, changed spaces to tabs and added/changed some preference summary strings.

Based on #9.
2021-03-09 23:36:14 -03:00
23e4b4c19d
Added label to settings activity
Label added to settings activity and changed spaces to tabs.
2021-03-09 23:33:03 -03:00
6 changed files with 151 additions and 127 deletions

View file

@ -1,33 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.luca0n.joguitos.pluck"> package="com.luca0n.joguitos.pluck">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name=".PluckApplication" android:name=".PluckApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme.Dark">
<activity android:name=".activities.MainActivity"> <activity android:name=".activities.MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".activities.TriviaGameActivity" <activity android:name=".activities.TriviaGameActivity"
android:screenOrientation="fullUser" android:screenOrientation="fullUser"
android:configChanges="orientation|screenSize"/> android:configChanges="orientation|screenSize"/>
<activity android:name=".activities.TriviaGameResultsActivity" <activity android:name=".activities.TriviaGameResultsActivity"
android:screenOrientation="fullUser" android:screenOrientation="fullUser"
android:configChanges="orientation|screenSize"/> android:configChanges="orientation|screenSize"/>
<activity android:name=".settings.SettingsActivity" <activity android:name=".settings.SettingsActivity"
android:screenOrientation="fullUser" android:label="@string/ui_settings"
android:configChanges="orientation|screenSize"/> android:screenOrientation="fullUser"
</application> android:configChanges="orientation|screenSize"/>
</application>
</manifest> </manifest>

View file

@ -31,30 +31,28 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class SettingsActivity extends AppCompatActivity { public class SettingsActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null)
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(null);
}
getFragmentManager() getFragmentManager()
.beginTransaction() .beginTransaction()
.replace(android.R.id.content, new SettingsFragment()) .replace(android.R.id.content, new SettingsFragment())
.commit(); .commit();
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
} }

View file

@ -23,79 +23,94 @@ 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;
private final TriviaCategory category; private final TriviaCategory category;
private final TriviaDifficulty difficulty; private final TriviaDifficulty difficulty;
private final TriviaType type; private final TriviaType type;
private TriviaQuery(Builder builder) { private TriviaQuery(Builder builder) {
this.amount = builder.amount; this.amount = builder.amount;
this.category = builder.category; this.category = builder.category;
this.difficulty = builder.difficulty; this.difficulty = builder.difficulty;
this.type = builder.type; this.type = builder.type;
} }
public static class Builder { public static class Builder {
private final int amount; private final int amount;
private TriviaCategory category; private TriviaCategory category;
private TriviaDifficulty difficulty; private TriviaDifficulty difficulty;
private TriviaType type; private TriviaType type;
public Builder() { public Builder() {
this.amount = DEFAULT_AMOUNT; this.amount = DEFAULT_AMOUNT;
} }
public Builder(int amount) { public Builder(int amount) {
if (amount > 50) { if (amount > 50) {
this.amount = 50; this.amount = 50;
} else { } else {
this.amount = amount; this.amount = amount;
} }
} }
public Builder category(TriviaCategory category) { public Builder category(TriviaCategory category) {
this.category = category; this.category = category;
return this; return this;
} }
public Builder difficulty(TriviaDifficulty difficulty) { public Builder difficulty(TriviaDifficulty difficulty) {
this.difficulty = difficulty; this.difficulty = difficulty;
return this; return this;
} }
public Builder type(TriviaType type) { public Builder type(TriviaType type) {
this.type = type; this.type = type;
return this; return this;
} }
public TriviaQuery build() { public TriviaQuery build() {
return new TriviaQuery(this); return new TriviaQuery(this);
} }
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
url.append(BASE); // Load custom server URL.
url.append("amount=").append(this.amount); 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);
if (this.category != null & this.category != TriviaCategory.ANY) { String base = sp.getString(key, defaultServer) + "?"; // append "?" to the end of the URL so we can specify GET parameters.
url.append("&category=").append(this.category.getID());
}
if (this.difficulty != null & this.difficulty != TriviaDifficulty.ANY) {
url.append("&difficulty=").append(this.difficulty.getName());
}
if (this.type != null & this.type != TriviaType.ANY) {
url.append("&type=").append(this.type.getName());
}
return url.toString(); url.append(base);
} url.append("amount=").append(this.amount);
if (this.category != null & this.category != TriviaCategory.ANY) {
url.append("&category=").append(this.category.getID());
}
if (this.difficulty != null & this.difficulty != TriviaDifficulty.ANY) {
url.append("&difficulty=").append(this.difficulty.getName());
}
if (this.type != null & this.type != TriviaType.ANY) {
url.append("&type=").append(this.type.getName());
}
return url.toString();
}
} }

View file

@ -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>

View file

@ -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>

View file

@ -24,23 +24,28 @@ Contact us at <joguitos+pluck@luca0n.com>.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory <PreferenceCategory
android:key="@string/pref_category_sound" android:key="@string/pref_category_sound"
android:title="@string/pref_category_sound_title"> android:title="@string/pref_category_sound_title">
<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
android:title="@string/pref_category_network_title">
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_network_tor"
android:title="@string/pref_network_tor_title"
android:summary="@string/pref_network_tor_summary" />
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory
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
android:defaultValue="false"
android:key="@string/pref_network_tor"
android:title="@string/pref_network_tor_title"
android:summary="@string/pref_network_tor_summary" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>