Added UI proxy preferences
This commit is contained in:
parent
0a0b8011c4
commit
7ed43c5491
|
@ -28,6 +28,8 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.EditTextPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.luca0n.joguitos.pluck.R;
|
||||
|
@ -44,12 +46,56 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
addPreferencesFromResource(R.xml.preferences);
|
||||
// Listen for theme preference changes
|
||||
ListPreference preferenceTheme = (ListPreference) findPreference(getString(R.string.pref_ui_theme));
|
||||
preferenceTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
|
||||
CheckBoxPreference preferenceTor = (CheckBoxPreference) findPreference(getString(R.string.pref_network_tor)),
|
||||
preferenceProxy = (CheckBoxPreference) findPreference(getString(R.string.pref_network_proxy));
|
||||
EditTextPreference preferenceProxyAddress = (EditTextPreference)
|
||||
findPreference(getString(R.string.pref_network_proxy_address));
|
||||
|
||||
// A few preferences override others, so let's go ahead and disable some of them based on the user preferences.
|
||||
// For more info, please check the comments on the OnPreferenceChangeListener below.
|
||||
if (preferenceTor.isChecked()){
|
||||
preferenceProxy.setEnabled(false);
|
||||
preferenceProxyAddress.setEnabled(false);
|
||||
} else if (preferenceProxy.isChecked()){
|
||||
preferenceTor.setEnabled(false);
|
||||
}
|
||||
|
||||
Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener(){
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue){
|
||||
// Because we are using this listener on multiple preferences, we need to check which one we are currently
|
||||
// dealing with.
|
||||
if (preference == preferenceTheme){
|
||||
// The user changed the app theme. In order to apply changes to this activity, we need to recreate it.
|
||||
// This will cause the screen to go black for a brief moment, but will apply the selected theme.
|
||||
getActivity().recreate();
|
||||
} else if (preference == preferenceTor){
|
||||
// Get the new value as a boolean since this is a CheckBoxPreference.
|
||||
boolean newBoolean = (boolean) newValue;
|
||||
// The user wants the app to use Tor.
|
||||
// This option is not compatible with a custom proxy, so let's go ahead and disable custom proxy preferences.
|
||||
preferenceProxy.setEnabled(!newBoolean);
|
||||
preferenceProxyAddress.setEnabled(!newBoolean);
|
||||
// Also uncheck the proxy preference in case it was previously checked.
|
||||
if (newBoolean)
|
||||
preferenceProxy.setChecked(false);
|
||||
} else if (preference == preferenceProxy){
|
||||
// Get the new value as a boolean since this is a CheckBoxPreference.
|
||||
boolean newBoolean = (boolean) newValue;
|
||||
// The user wants the app to use a custom proxy.
|
||||
// This option overrides the Tor preference, so let's go ahead and disable the Tor preference.
|
||||
preferenceTor.setEnabled(!newBoolean);
|
||||
// Also go ahead and uncheck the Tor preference in case it was previously checked.
|
||||
if (newBoolean)
|
||||
preferenceTor.setChecked(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Set the same listener for these preferences.
|
||||
preferenceTor.setOnPreferenceChangeListener(listener);
|
||||
preferenceProxy.setOnPreferenceChangeListener(listener);
|
||||
preferenceTheme.setOnPreferenceChangeListener(listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
<string name="pref_category_sound">pref_key_category_sound</string>
|
||||
<string name="pref_sound_answer">pref_sound_answer</string>
|
||||
<string name="pref_network_tor">pref_network_tor</string>
|
||||
<string name="pref_network_proxy">pref_network_proxy</string>
|
||||
<string name="pref_network_proxy_address">pref_network_proxy_address</string>
|
||||
<string name="pref_network_server">pref_network_server</string>
|
||||
<string name="pref_network_server_default">https://opentdb.com/api.php</string>
|
||||
<string name="pref_ui_theme">pref_ui_theme</string>
|
||||
|
|
|
@ -114,6 +114,10 @@ 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_proxy_title">Use Proxy</string>
|
||||
<string name="pref_network_proxy_summary">Uses a proxy of your choice when connecting to a trivia server.</string>
|
||||
<string name="pref_network_proxy_address_title">Proxy Address</string>
|
||||
<string name="pref_network_proxy_address_summary">Defines the proxy address that Pluck should use when connecting to a trivia server with a custom proxy. This will override the Tor proxy, if enabled. Pluck supports the HTTP and SOCKS protocols. Specify the proxy protocol.</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 when using a server as the trivia source. Leave this setting empty to use the default server.</string>
|
||||
|
||||
|
|
|
@ -47,6 +47,15 @@ Contact us at <joguitos+pluck@luca0n.com>.
|
|||
android:key="@string/pref_network_tor"
|
||||
android:title="@string/pref_network_tor_title"
|
||||
android:summary="@string/pref_network_tor_summary" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_network_proxy"
|
||||
android:title="@string/pref_network_proxy_title"
|
||||
android:summary="@string/pref_network_proxy_summary" />
|
||||
<EditTextPreference
|
||||
android:key="@string/pref_network_proxy_address"
|
||||
android:title="@string/pref_network_proxy_address_title"
|
||||
android:summary="@string/pref_network_proxy_address_summary" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_category_ui_title">
|
||||
|
|
Loading…
Reference in New Issue