Browse Source

Added removing and fixed updating of settings.

pull/11/head
Eric Kok 12 years ago
parent
commit
bebf5e3d2e
  1. 0
      core/res/drawable-xhdpi/ic_action_sort_by_size.png
  2. 5
      core/res/drawable-xhdpi/loading_progress.xml
  3. 2
      core/res/menu/activity_deleteableprefs.xml
  4. 7
      core/res/values/strings.xml
  5. 13
      core/res/xml/pref_server.xml
  6. 3
      core/res/xml/pref_system.xml
  7. 172
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  8. 16
      core/src/org/transdroid/core/app/settings/RssfeedSetting.java
  9. 9
      core/src/org/transdroid/core/app/settings/ServerSetting.java
  10. 14
      core/src/org/transdroid/core/app/settings/WebsearchSetting.java
  11. 191
      core/src/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java
  12. 9
      core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java
  13. 1
      core/src/org/transdroid/core/gui/settings/RssfeedPreference.java
  14. 40
      core/src/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  15. 3
      core/src/org/transdroid/core/gui/settings/ServerPreference.java
  16. 112
      core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  17. 1
      core/src/org/transdroid/core/gui/settings/WebsearchPreference.java
  18. 38
      core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

0
core/res/drawable-xhdpi/action_sort_by_size.png → core/res/drawable-xhdpi/ic_action_sort_by_size.png

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

5
core/res/drawable-xhdpi/loading_progress.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_empty_details"
android:pivotX="50%"
android:pivotY="50%" />

2
core/res/menu/activity_deleteableprefs.xml

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item <item
android:id="@+id/action_remove" android:id="@+id/action_removesettings"
android:icon="@drawable/ic_action_discard" android:icon="@drawable/ic_action_discard"
android:showAsAction="always" android:showAsAction="always"
android:title="@string/action_removesettings"/> android:title="@string/action_removesettings"/>

7
core/res/values/strings.xml

@ -131,7 +131,7 @@
<string name="pref_localaddress">Local IP or host</string> <string name="pref_localaddress">Local IP or host</string>
<string name="pref_localaddress_info">When connected to the specified local network</string> <string name="pref_localaddress_info">When connected to the specified local network</string>
<string name="pref_localnetwork">Local network</string> <string name="pref_localnetwork">Local network</string>
<string name="pref_localnetwork_info">The server\'s local (wifi) network</string> <string name="pref_localnetwork_info">The server\'s local network SSID</string>
<string name="pref_folder">Folder</string> <string name="pref_folder">Folder</string>
<string name="pref_folder_info">Usually empty</string> <string name="pref_folder_info">Usually empty</string>
<string name="pref_scgifolder">SCGI mount point</string> <string name="pref_scgifolder">SCGI mount point</string>
@ -169,14 +169,15 @@
<string name="pref_system">System</string> <string name="pref_system">System</string>
<string name="pref_checkupdates">Check for updates</string> <string name="pref_checkupdates">Check for updates</string>
<string name="pref_checkupdates_info">Check transdroidorg for latest app version</string> <string name="pref_checkupdates_info">Check transdroid.org for latest app version</string>
<string name="pref_import">Import settings</string> <string name="pref_import">Import settings</string>
<string name="pref_export">Export settings</string> <string name="pref_export">Export settings</string>
<string name="pref_sendlog">Send error log</string> <string name="pref_sendlog">Send error log</string>
<string name="pref_sendlog_info">Get support or report a bug</string> <string name="pref_sendlog_info">Get support or report a bug</string>
<string name="pref_installhelp">View install guides</string> <string name="pref_installhelp">View install guides</string>
<string name="pref_installhelp_info">Available at transdroid.org/download</string>
<string name="pref_changelog">Recent changes</string> <string name="pref_changelog">Recent changes</string>
<string name="pref_about">About</string> <string name="pref_about">About Transdroid</string>
<string-array name="pref_daemon_types" translatable="false"> <string-array name="pref_daemon_types" translatable="false">
<item>BitComet</item> <item>BitComet</item>
<item>Bitflu 1.2+</item> <item>Bitflu 1.2+</item>

13
core/res/xml/pref_server.xml

@ -15,10 +15,6 @@
android:key="server_address" android:key="server_address"
android:title="@string/pref_address" android:title="@string/pref_address"
android:inputType="textUri" /> android:inputType="textUri" />
<EditTextPreference
android:key="server_port"
android:title="@string/pref_port"
android:inputType="numberSigned" />
<EditTextPreference <EditTextPreference
android:key="server_user" android:key="server_user"
android:title="@string/pref_user" android:title="@string/pref_user"
@ -33,12 +29,16 @@
android:inputType="textPassword" /> android:inputType="textPassword" />
<PreferenceScreen android:title="@string/pref_advanced" > <PreferenceScreen android:title="@string/pref_advanced" >
<EditTextPreference
android:key="server_port"
android:title="@string/pref_port"
android:inputType="numberSigned" />
<EditTextPreference <EditTextPreference
android:key="server_localaddress" android:key="server_localaddress"
android:title="@string/pref_localaddress" android:title="@string/pref_localaddress"
android:summary="@string/pref_localaddress_info" android:summary="@string/pref_localaddress_info"
android:inputType="textUri" /> android:inputType="textUri" />
<ListPreference <EditTextPreference
android:key="server_localnetwork" android:key="server_localnetwork"
android:title="@string/pref_localnetwork" android:title="@string/pref_localnetwork"
android:summary="@string/pref_localnetwork_info" /> android:summary="@string/pref_localnetwork_info" />
@ -87,7 +87,8 @@
android:key="server_os" android:key="server_os"
android:title="@string/pref_os" android:title="@string/pref_os"
android:entries="@array/pref_os_types" android:entries="@array/pref_os_types"
android:entryValues="@array/pref_os_values" /> android:entryValues="@array/pref_os_values"
android:defaultValue="type_linux" />
<EditTextPreference <EditTextPreference
android:key="server_downloaddir" android:key="server_downloaddir"
android:title="@string/pref_downdir" android:title="@string/pref_downdir"

3
core/res/xml/pref_system.xml

@ -14,7 +14,8 @@
<Preference <Preference
android:key="system_installhelp" android:key="system_installhelp"
android:title="@string/pref_installhelp" /> android:title="@string/pref_installhelp"
android:summary="@string/pref_installhelp_info" />
<Preference <Preference
android:key="system_importsettings" android:key="system_importsettings"

172
core/src/org/transdroid/core/app/settings/ApplicationSettings.java

@ -11,6 +11,7 @@ import org.transdroid.daemon.OS;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
/** /**
@ -58,19 +59,95 @@ public class ApplicationSettings {
* @return The server settings object, loaded from shared preferences * @return The server settings object, loaded from shared preferences
*/ */
public ServerSetting getServerSetting(int order) { public ServerSetting getServerSetting(int order) {
return new ServerSetting(order, prefs.getString("server_name_" + order, null), Daemon.fromCode(prefs.getString( // @formatter:off
"server_type_" + order, null)), prefs.getString("server_address_" + order, null), prefs.getString( Daemon type = Daemon.fromCode(prefs.getString("server_type_" + order, null));
"server_localaddress_" + order, null), prefs.getString("server_localnetwork_" + order, null), boolean ssl = prefs.getBoolean("server_sslenabled_" + order, false);
Integer.parseInt(prefs.getString("server_port_" + order, "-1")), prefs.getBoolean("server_sslenabled_" String defaultPort = Integer.toString(Daemon.getDefaultPortNumber(type, ssl));
+ order, false), prefs.getBoolean("server_ssltrustall_" + order, false), prefs.getString( return new ServerSetting(order,
"server_ssltrustkey_" + order, null), prefs.getString("server_folder_" + order, null), prefs.getString("server_name_" + order, null),
prefs.getBoolean("server_useauth_" + order, true), prefs.getString("server_user_" + order, null), type,
prefs.getString("server_pass_" + order, null), prefs.getString("server_extrapass_" + order, null), prefs.getString("server_address_" + order, null),
OS.fromCode(prefs.getString("server_os_" + order, null)), prefs.getString( prefs.getString("server_localaddress_" + order, null),
"server_downloaddir_" + order, null), prefs.getString("server_ftpurl_" + order, null), prefs.getString("server_localnetwork_" + order, null),
prefs.getString("server_ftppass_" + order, null), Integer.parseInt(prefs.getString("server_timeout_" Integer.parseInt(prefs.getString("server_port_" + order, defaultPort)),
+ order, "8")), prefs.getBoolean("server_alarmfinished_" + order, true), prefs.getBoolean( ssl,
"server_alarmnew_" + order, false), false); prefs.getBoolean("server_ssltrustall_" + order, false),
prefs.getString("server_ssltrustkey_" + order, null),
prefs.getString("server_folder_" + order, null),
prefs.getBoolean("server_useauth_" + order, true),
prefs.getString("server_user_" + order, null),
prefs.getString("server_pass_" + order, null),
prefs.getString("server_extrapass_" + order, null),
OS.fromCode(prefs.getString("server_os_" + order, "type_linux")),
prefs.getString("server_downloaddir_" + order, null),
prefs.getString("server_ftpurl_" + order, null),
prefs.getString("server_ftppass_" + order, null),
Integer.parseInt(prefs.getString("server_timeout_"+ order, "8")),
prefs.getBoolean("server_alarmfinished_" + order, true),
prefs.getBoolean("server_alarmnew_" + order, false), false);
// @formatter:on
}
/**
* Removes all settings related to a configured server. Since servers are ordered, the order of the remaining
* servers will be updated accordingly.
* @param order The identifying order number/key of the settings to remove
*/
public void removeServerSettings(int order) {
if (prefs.getString("server_type_" + order, null) == null)
return; // The settings that were requested to be removed do not exist
// Copy all settings higher than the supplied order number to the previous spot
Editor edit = prefs.edit();
int max = getMaxWebsearch();
for (int i = order; i < max; i++) {
edit.putString("server_name_" + i, prefs.getString("server_name_" + (i + 1), null));
edit.putString("server_type_" + i, prefs.getString("server_type_" + (i + 1), null));
edit.putString("server_address_" + i, prefs.getString("server_address_" + (i + 1), null));
edit.putString("server_localaddress_" + i, prefs.getString("server_localaddress_" + (i + 1), null));
edit.putString("server_localnetwork_" + i, prefs.getString("server_localnetwork_" + (i + 1), null));
edit.putString("server_port_" + i, prefs.getString("server_port_" + (i + 1), null));
edit.putBoolean("server_sslenabled_" + i, prefs.getBoolean("server_sslenabled_" + (i + 1), false));
edit.putBoolean("server_ssltrustall_" + i, prefs.getBoolean("server_ssltrustall_" + (i + 1), false));
edit.putString("server_ssltrustkey_" + i, prefs.getString("server_ssltrustkey_" + (i + 1), null));
edit.putString("server_folder_" + i, prefs.getString("server_folder_" + (i + 1), null));
edit.putBoolean("server_useauth_" + i, prefs.getBoolean("server_useauth_" + (i + 1), false));
edit.putString("server_user_" + i, prefs.getString("server_user_" + (i + 1), null));
edit.putString("server_pass_" + i, prefs.getString("server_pass_" + (i + 1), null));
edit.putString("server_extrapass_" + i, prefs.getString("server_extrapass_" + (i + 1), null));
edit.putString("server_os_" + i, prefs.getString("server_os_" + (i + 1), null));
edit.putString("server_downloaddir_" + i, prefs.getString("server_downloaddir_" + (i + 1), null));
edit.putString("server_ftpurl_" + i, prefs.getString("server_ftpurl_" + (i + 1), null));
edit.putString("server_ftppass_" + i, prefs.getString("server_ftppass_" + (i + 1), null));
edit.putString("server_timeout_" + i, prefs.getString("server_timeout_" + (i + 1), null));
edit.putBoolean("server_alarmfinished_" + i, prefs.getBoolean("server_alarmfinished_" + (i + 1), false));
edit.putBoolean("server_alarmfinished_" + i, prefs.getBoolean("server_alarmfinished_" + (i + 1), false));
}
// Remove the last settings, of which we are now sure are no longer required
edit.remove("server_name_" + max);
edit.remove("server_type_" + max);
edit.remove("server_address_" + max);
edit.remove("server_localaddress_" + max);
edit.remove("server_localnetwork_" + max);
edit.remove("server_port_" + max);
edit.remove("server_sslenabled_" + max);
edit.remove("server_ssltrustall_" + max);
edit.remove("server_ssltrustkey_" + max);
edit.remove("server_folder_" + max);
edit.remove("server_useauth_" + max);
edit.remove("server_user_" + max);
edit.remove("server_pass_" + max);
edit.remove("server_extrapass_" + max);
edit.remove("server_os_" + max);
edit.remove("server_downloaddir_" + max);
edit.remove("server_ftpurl_" + max);
edit.remove("server_ftppass_" + max);
edit.remove("server_timeout_" + max);
edit.remove("server_alarmfinished_" + max);
edit.remove("server_alarmfinished_" + max);
edit.commit();
} }
/** /**
@ -138,7 +215,7 @@ public class ApplicationSettings {
*/ */
public int getMaxWebsearch() { public int getMaxWebsearch() {
for (int i = 0; true; i++) { for (int i = 0; true; i++) {
if (prefs.getString("websearch_url_" + i, null) == null) if (prefs.getString("websearch_baseurl_" + i, null) == null)
return i - 1; return i - 1;
} }
} }
@ -149,8 +226,35 @@ public class ApplicationSettings {
* @return The web search site settings object, loaded from shared preferences * @return The web search site settings object, loaded from shared preferences
*/ */
public WebsearchSetting getWebsearchSetting(int order) { public WebsearchSetting getWebsearchSetting(int order) {
return new WebsearchSetting(order, prefs.getString("websearch_name_" + order, null), prefs.getString( // @formatter:off
"websearch_url_" + order, null)); return new WebsearchSetting(order,
prefs.getString("websearch_name_" + order, null),
prefs.getString("websearch_baseurl_" + order, null));
// @formatter:on
}
/**
* Removes all settings related to a configured web-based search site. Since sites are ordered, the order of the
* remaining sites will be updated accordingly.
* @param order The identifying order number/key of the settings to remove
*/
public void removeWebsearchSettings(int order) {
if (prefs.getString("websearch_baseurl_" + order, null) == null)
return; // The settings that were requested to be removed do not exist
// Copy all settings higher than the supplied order number to the previous spot
Editor edit = prefs.edit();
int max = getMaxWebsearch();
for (int i = order; i < max; i++) {
edit.putString("websearch_name_" + i, prefs.getString("websearch_name_" + (i + 1), null));
edit.putString("websearch_baseurl_" + i, prefs.getString("websearch_baseurl_" + (i + 1), null));
}
// Remove the last settings, of which we are now sure are no longer required
edit.remove("websearch_name_" + max);
edit.remove("websearch_baseurl_" + max);
edit.commit();
} }
/** /**
@ -171,7 +275,7 @@ public class ApplicationSettings {
*/ */
public int getMaxRssfeed() { public int getMaxRssfeed() {
for (int i = 0; true; i++) { for (int i = 0; true; i++) {
if (prefs.getString("rssfeed_feedurl_" + i, null) == null) if (prefs.getString("rssfeed_url_" + i, null) == null)
return i - 1; return i - 1;
} }
} }
@ -182,8 +286,38 @@ public class ApplicationSettings {
* @return The RSS feed settings object, loaded from shared preferences * @return The RSS feed settings object, loaded from shared preferences
*/ */
public RssfeedSetting getRssfeedSetting(int order) { public RssfeedSetting getRssfeedSetting(int order) {
return new RssfeedSetting(order, prefs.getString("rssfeed_name_" + order, null), prefs.getString( // @formatter:off
"rssfeed_feedurl_" + order, null), prefs.getBoolean("rssfeed_reqauth_" + order, false)); return new RssfeedSetting(order,
prefs.getString("rssfeed_name_" + order, null),
prefs.getString("rssfeed_url_" + order, null),
prefs.getBoolean("rssfeed_reqauth_" + order, false));
// @formatter:on
}
/**
* Removes all settings related to a configured RSS feed. Since feeds are ordered, the order of the remaining feeds
* will be updated accordingly.
* @param order The identifying order number/key of the settings to remove
*/
public void removeRssfeedSettings(int order) {
if (prefs.getString("rssfeed_url_" + order, null) == null)
return; // The settings that were requested to be removed do not exist
// Copy all settings higher than the supplied order number to the previous spot
Editor edit = prefs.edit();
int max = getMaxWebsearch();
for (int i = order; i < max; i++) {
edit.putString("rssfeed_name_" + i, prefs.getString("rssfeed_name_" + (i + 1), null));
edit.putString("rssfeed_url_" + i, prefs.getString("rssfeed_url_" + (i + 1), null));
edit.putBoolean("rssfeed_reqauth_" + i, prefs.getBoolean("rssfeed_reqauth_" + (i + 1), false));
}
// Remove the last settings, of which we are now sure are no longer required
edit.remove("rssfeed_name_" + max);
edit.remove("rssfeed_url_" + max);
edit.remove("rssfeed_reqauth_" + max);
edit.commit();
} }
} }

16
core/src/org/transdroid/core/app/settings/RssfeedSetting.java

@ -35,8 +35,10 @@ public class RssfeedSetting implements SimpleListItem {
public String getName() { public String getName() {
if (!TextUtils.isEmpty(name)) if (!TextUtils.isEmpty(name))
return name; return name;
if (!TextUtils.isEmpty(url)) if (!TextUtils.isEmpty(url)) {
return Uri.parse(url).getHost(); String host = Uri.parse(url).getHost();
return host == null? DEFAULT_NAME: host;
}
return DEFAULT_NAME; return DEFAULT_NAME;
} }
@ -64,4 +66,14 @@ public class RssfeedSetting implements SimpleListItem {
this.lastNew = lastNew; this.lastNew = lastNew;
} }
/**
* Returns a nicely formatted identifier containing (a portion of) the feed URL
* @return A string to identify this feed's URL
*/
public String getHumanReadableIdentifier() {
String host = Uri.parse(url).getHost();
String path = Uri.parse(url).getPath();
return (host == null? null: host + (path == null? "": path));
}
} }

9
core/src/org/transdroid/core/app/settings/ServerSetting.java

@ -6,6 +6,7 @@ import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.OS; import org.transdroid.daemon.OS;
import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
/** /**
@ -91,7 +92,13 @@ public class ServerSetting implements SimpleListItem {
@Override @Override
public String getName() { public String getName() {
return (name == null || name.equals("") ? DEFAULT_NAME : name); if (!TextUtils.isEmpty(name))
return name;
if (!TextUtils.isEmpty(address)) {
String host = Uri.parse(address).getHost();
return host == null? DEFAULT_NAME: host;
}
return DEFAULT_NAME;
} }
public Daemon getType() { public Daemon getType() {

14
core/src/org/transdroid/core/app/settings/WebsearchSetting.java

@ -32,8 +32,10 @@ public class WebsearchSetting implements SimpleListItem {
public String getName() { public String getName() {
if (!TextUtils.isEmpty(name)) if (!TextUtils.isEmpty(name))
return name; return name;
if (!TextUtils.isEmpty(baseUrl)) if (!TextUtils.isEmpty(baseUrl)) {
return Uri.parse(baseUrl).getHost(); String host = Uri.parse(baseUrl).getHost();
return host == null? DEFAULT_NAME: host;
}
return DEFAULT_NAME; return DEFAULT_NAME;
} }
@ -45,4 +47,12 @@ public class WebsearchSetting implements SimpleListItem {
return KEY_PREFIX + getOrder(); return KEY_PREFIX + getOrder();
} }
/**
* Returns a nicely formatted identifier containing (a portion of) the search base URL
* @return A string to identify this site's search URL
*/
public String getHumanReadableIdentifier() {
return Uri.parse(baseUrl).getHost();
}
} }

191
core/src/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java

@ -0,0 +1,191 @@
package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
/**
* Abstract activity that helps implement a preference screen for key-bound settings, i.e. settings of which there can
* be multiple and which are identified by an ascending order number/unique key. A typical implementation calls
* {@link #init(int, int)} during the {@link #onCreate(android.os.Bundle)} (but after calling super.onCreate(Bundle))
* and then call initXPreference for each contained preference. {@link #onPreferencesChanged()} can be overridden to
* react to preference changes, e.g. when field availability should be updated (and where preference dependency isn't
* enough).
* @author Eric Kok
*/
@EActivity
public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActivity {
@Extra
protected int key = -1;
private SharedPreferences sharedPrefs;
/**
* Should be called during the activity {@link #onCreate(android.os.Bundle)} (but after super.onCreate(Bundle)) to
* load the preferences for this screen from an XML resource.
* @param preferencesResId The XML resource to read preferences from, which may contain embedded
* {@link PreferenceScreen} objects
* @param currentMaxKey The value of what is currently the last defined settings object, or -1 of no settings were
* defined so far at all
*/
@SuppressWarnings("deprecation")
protected final void init(int preferencesResId, int currentMaxKey) {
// Load the raw preferences to show in this screen
addPreferencesFromResource(preferencesResId);
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
// If no key was supplied (in the extra bundle) then use a new key instead
if (key < 0) {
key = currentMaxKey + 1;
}
}
protected void onResume() {
super.onResume();
// Monitor preference changes
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(
onPreferenceChangeListener);
};
protected void onPause() {
super.onPause();
// Stop monitoring preference changes
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(
onPreferenceChangeListener);
};
private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
onPreferencesChanged();
}
};
/**
* Key-bound preference activities may override this method if they want to react to preference changes.
*/
protected void onPreferencesChanged() {
}
/**
* Updates a preference that allows for text entry via a dialog. This is used for both string and integer values. No
* default value will be shown.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link EditTextPreference} that is bound to this preference
*/
protected final EditTextPreference initTextPreference(String baseName) {
return initTextPreference(baseName, null);
}
/**
* Updates a preference that allows for text entry via a dialog. This is used for both string and integer values.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
* @return The concrete {@link EditTextPreference} that is bound to this preference
*/
protected final EditTextPreference initTextPreference(String baseName, String defValue) {
return initTextPreference(baseName, defValue, null);
}
/**
* Updates a preference (including dependency) that allows for text entry via a dialog. This is used for both string
* and integer values.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
* @param dependency The base name of the preference to which this preference depends
* @return The concrete {@link EditTextPreference} that is bound to this preference
*/
@SuppressWarnings("deprecation")
protected final EditTextPreference initTextPreference(String baseName, String defValue, String dependency) {
// Update the loaded Preference with the actual preference key to load/store with
EditTextPreference pref = (EditTextPreference) findPreference(baseName);
pref.setKey(baseName + "_" + key);
pref.setDependency(dependency == null? null: dependency + "_" + key);
// Update the Preference by loading the current stored value into the EditText, if it exists
pref.setText(sharedPrefs.getString(baseName + "_" + key, defValue));
return pref;
}
/**
* Updates a preference that simply shows a check box. No default value will be shown.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link CheckBoxPreference} that is bound to this preference
*/
protected final CheckBoxPreference initBooleanPreference(String baseName) {
return initBooleanPreference(baseName, false);
}
/**
* Updates a preference that simply shows a check box.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
* @return The concrete {@link CheckBoxPreference} that is bound to this preference
*/
protected final CheckBoxPreference initBooleanPreference(String baseName, boolean defValue) {
return initBooleanPreference(baseName, defValue, null);
}
/**
* Updates a preference (including dependency) that simply shows a check box.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
* @param dependency The base name of the preference to which this preference depends
* @return The concrete {@link CheckBoxPreference} that is bound to this preference
*/
@SuppressWarnings("deprecation")
protected final CheckBoxPreference initBooleanPreference(String baseName, boolean defValue, String dependency) {
// Update the loaded Preference with the actual preference key to load/store with
CheckBoxPreference pref = (CheckBoxPreference) findPreference(baseName);
pref.setKey(baseName + "_" + key);
pref.setDependency(dependency == null? null: dependency + "_" + key);
// Update the Preference by loading the current stored value into the Checkbox, if it exists
pref.setChecked(sharedPrefs.getBoolean(baseName + "_" + key, defValue));
return pref;
}
/**
* Updates a preference that allows picking an item from a list. No default value will be shown.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @return The concrete {@link ListPreference} that is bound to this preference
*/
protected final ListPreference initListPreference(String baseName) {
return initListPreference(baseName, null);
}
/**
* Updates a preference that allows picking an item from a list.
* @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under
* item_name_[key]
* @param defValue The default value for this preference, as shown when no value was yet stored
* @return The concrete {@link ListPreference} that is bound to this preference
*/
@SuppressWarnings("deprecation")
protected final ListPreference initListPreference(String baseName, String defValue) {
// Update the loaded Preference with the actual preference key to load/store with
ListPreference pref = (ListPreference) findPreference(baseName);
pref.setKey(baseName + "_" + key);
// Update the Preference by selecting the current stored value in the list, if it exists
pref.setValue(sharedPrefs.getString(baseName + "_" + key, defValue));
return pref;
}
}

9
core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java

@ -50,7 +50,7 @@ public class MainSettingsActivity extends SherlockPreferenceActivity {
if (getPreferenceScreen() != null) if (getPreferenceScreen() != null)
getPreferenceScreen().removeAll(); getPreferenceScreen().removeAll();
// Load the preference menu and attack actions // Load the preference menu and attach actions
addPreferencesFromResource(R.xml.pref_main); addPreferencesFromResource(R.xml.pref_main);
findPreference("header_addserver").setOnPreferenceClickListener(onAddServer); findPreference("header_addserver").setOnPreferenceClickListener(onAddServer);
findPreference("header_addwebsearch").setOnPreferenceClickListener(onAddWebsearch); findPreference("header_addwebsearch").setOnPreferenceClickListener(onAddWebsearch);
@ -58,13 +58,6 @@ public class MainSettingsActivity extends SherlockPreferenceActivity {
findPreference("header_background").setOnPreferenceClickListener(onBackgroundSettings); findPreference("header_background").setOnPreferenceClickListener(onBackgroundSettings);
findPreference("header_system").setOnPreferenceClickListener(onSystemSettings); findPreference("header_system").setOnPreferenceClickListener(onSystemSettings);
loadSettings();
}
@SuppressWarnings("deprecation")
private void loadSettings() {
// Add existing servers // Add existing servers
List<ServerSetting> servers = applicationSettings.getServerSettings(); List<ServerSetting> servers = applicationSettings.getServerSettings();
for (ServerSetting serverSetting : servers) { for (ServerSetting serverSetting : servers) {

1
core/src/org/transdroid/core/gui/settings/RssfeedPreference.java

@ -29,6 +29,7 @@ public class RssfeedPreference extends Preference {
public RssfeedPreference setRssfeedSetting(RssfeedSetting rssfeedSetting) { public RssfeedPreference setRssfeedSetting(RssfeedSetting rssfeedSetting) {
this.rssfeedSetting = rssfeedSetting; this.rssfeedSetting = rssfeedSetting;
setTitle(rssfeedSetting.getName()); setTitle(rssfeedSetting.getName());
setSummary(rssfeedSetting.getHumanReadableIdentifier());
setOrder(ORDER_START + rssfeedSetting.getOrder()); setOrder(ORDER_START + rssfeedSetting.getOrder());
return this; return this;
} }

40
core/src/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -1,16 +1,13 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ApplicationSettings_;
import android.os.Bundle; import android.os.Bundle;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
/** /**
* Activity that allows for a configuration of some RSS feed. The key can be supplied to update an * Activity that allows for a configuration of some RSS feed. The key can be supplied to update an
* existing RSS feed setting instead of creating a new one. * existing RSS feed setting instead of creating a new one.
@ -18,31 +15,24 @@ import com.actionbarsherlock.app.SherlockPreferenceActivity;
*/ */
@EActivity @EActivity
@OptionsMenu(resName="activity_deleteableprefs") @OptionsMenu(resName="activity_deleteableprefs")
public class RssfeedSettingsActivity extends SherlockPreferenceActivity { public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
@Extra
protected int key = -1;
@Bean @Override
protected ApplicationSettings applicationSettings; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the raw preferences to show in this screen // Load the raw preferences to show in this screen
addPreferencesFromResource(R.xml.pref_rssfeed); init(R.xml.pref_rssfeed, ApplicationSettings_.getInstance_(this).getMaxRssfeed());
initTextPreference("rssfeed_name");
initTextPreference("rssfeed_url");
initBooleanPreference("rssfeed_reqauth");
// Bind the preferences to the correct storage key, e.g. the first RSS feed setting stores its URL in the }
// 'rssfeed_url_0' shared preferences field
if (key < 0) {
key = applicationSettings.getMaxRssfeed() + 1;
}
findPreference("rssfeed_name").setKey("rssfeed_name_" + key);
findPreference("rssfeed_url").setKey("rssfeed_url_" + key);
findPreference("rssfeed_reqauth").setKey("rssfeed_reqauth_" + key);
@OptionsItem(resName = "action_removesettings")
protected void removeSettings() {
ApplicationSettings_.getInstance_(this).removeRssfeedSettings(key);
finish();
} }
} }

3
core/src/org/transdroid/core/gui/settings/ServerPreference.java

@ -28,7 +28,8 @@ public class ServerPreference extends Preference {
*/ */
public ServerPreference setServerSetting(ServerSetting serverSetting) { public ServerPreference setServerSetting(ServerSetting serverSetting) {
this.serverSetting = serverSetting; this.serverSetting = serverSetting;
setTitle(serverSetting.getHumanReadableIdentifier()); setTitle(serverSetting.getName());
setSummary(serverSetting.getHumanReadableIdentifier());
setOrder(ORDER_START + serverSetting.getOrder()); setOrder(ORDER_START + serverSetting.getOrder());
return this; return this;
} }

112
core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -1,99 +1,77 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.daemon.Daemon;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ApplicationSettings_;
import org.transdroid.daemon.Daemon;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.EditTextPreference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
/** /**
* Activity that allows for a configuration of a server. The key can be supplied to update an existing server setting * Activity that allows for a configuration of a server. The key can be supplied to update an existing server setting
* instead of creating a new one. * instead of creating a new one.
* @author Eric Kok * @author Eric Kok
*/ */
@EActivity @EActivity
@OptionsMenu(resName="activity_deleteableprefs") @OptionsMenu(resName = "activity_deleteableprefs")
public class ServerSettingsActivity extends SherlockPreferenceActivity { public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
@Extra
protected int key = -1;
@Bean private EditTextPreference extraPass, folder, downloadDir;
protected ApplicationSettings applicationSettings;
@SuppressWarnings("deprecation")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Load the raw preferences to show in this screen // Load the raw preferences to show in this screen
addPreferencesFromResource(R.xml.pref_server); init(R.xml.pref_server, ApplicationSettings_.getInstance_(this).getMaxServer());
initTextPreference("server_name");
initListPreference("server_type");
initTextPreference("server_address");
initTextPreference("server_port");
initTextPreference("server_user");
initTextPreference("server_pass");
extraPass = initTextPreference("server_extrapass");
initTextPreference("server_localaddress");
initTextPreference("server_localnetwork");
folder = initTextPreference("server_folder");
initTextPreference("server_timeout", "8");
initBooleanPreference("server_alarmfinished", true);
initBooleanPreference("server_alarmnew");
initListPreference("server_os", "type_linux");
downloadDir = initTextPreference("server_downloaddir");
initTextPreference("server_ftpurl");
initTextPreference("server_ftppass");
initBooleanPreference("server_sslenabled");
initBooleanPreference("server_ssltrustall", false, "server_sslenabled");
initTextPreference("server_ssltrustkey", null, "server_sslenabled");
// Bind the preferences to the correct storage key, e.g. the first server setting stores its address in the
// 'server_address_0' shared preferences field
if (key < 0) {
key = applicationSettings.getMaxWebsearch() + 1;
}
findPreference("server_name").setKey("server_name_" + key);
findPreference("server_type").setKey("server_type_" + key);
findPreference("server_address").setKey("server_address_" + key);
findPreference("server_port").setKey("server_port_" + key);
findPreference("server_user").setKey("server_user_" + key);
findPreference("server_pass").setKey("server_pass_" + key);
findPreference("server_extrapass").setKey("server_extrapass_" + key);
findPreference("server_localaddress").setKey("server_localaddress_" + key);
findPreference("server_localnetwork").setKey("server_localnetwork_" + key);
findPreference("server_folder").setKey("server_folder_" + key);
findPreference("server_timeout").setKey("server_timeout_" + key);
findPreference("server_alarmfinished").setKey("server_alarmfinished_" + key);
findPreference("server_alarmnew").setKey("server_alarmnew_" + key);
findPreference("server_os").setKey("server_os_" + key);
findPreference("server_downloaddir").setKey("server_downloaddir_" + key);
findPreference("server_ftpurl").setKey("server_ftpurl_" + key);
findPreference("server_ftppass").setKey("server_ftppass_" + key);
findPreference("server_sslenabled").setKey("server_sslenabled_" + key);
findPreference("server_ssltrustall").setKey("server_ssltrustall_" + key);
findPreference("server_ssltrustall_" + key).setDependency("server_sslenabled_" + key);
findPreference("server_ssltrustkey").setKey("server_ssltrustkey_" + key);
findPreference("server_ssltrustkey_" + key).setDependency("server_sslenabled_" + key);
// Monitor preference changes
getPreferenceScreen().setOnPreferenceChangeListener(onPreferenceChangeListener);
} }
private OnPreferenceChangeListener onPreferenceChangeListener = new OnPreferenceChangeListener() { @OptionsItem(resName = "action_removesettings")
@Override protected void removeSettings() {
public boolean onPreferenceChange(Preference preference, Object newValue) { ApplicationSettings_.getInstance_(this).removeServerSettings(key);
// TODO: This doesn't get called finish();
updatePreferenceAvailability(); }
return true;
}
};
@SuppressWarnings("deprecation") @Override
private void updatePreferenceAvailability() { protected void onPreferencesChanged() {
// Use daemon factory to see if the newly selected daemon supports the feature // Use daemon factory to see if the newly selected daemon supports the feature
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Daemon daemonType = Daemon.fromCode(prefs.getString("server_type_" + key, null)); Daemon daemonType = Daemon.fromCode(prefs.getString("server_type_" + key, null));
findPreference("server_extrapass_" + key).setEnabled(Daemon.supportsExtraPassword(daemonType)); extraPass.setEnabled(Daemon.supportsExtraPassword(daemonType));
findPreference("server_folder_" + key).setEnabled(daemonType == null? false: Daemon.supportsCustomFolder(daemonType)); folder.setEnabled(daemonType == null ? false : Daemon.supportsCustomFolder(daemonType));
findPreference("server_downloaddir_" + key).setEnabled(daemonType == null? false: Daemon.needsManualPathSpecified(daemonType)); downloadDir.setEnabled(daemonType == null ? false : Daemon.needsManualPathSpecified(daemonType));
//findPreference("server_ssltrustkey_" + key).setEnabled(sslValue && !sslTAValue); // sslTrustKey.setEnabled(sslValue && !sslTAValue);
// Adjust title texts accordingly // Adjust title texts accordingly
findPreference("server_folder_" + key).setTitle(daemonType == Daemon.rTorrent? R.string.pref_scgifolder: R.string.pref_folder); folder.setTitle(daemonType == Daemon.rTorrent ? R.string.pref_scgifolder : R.string.pref_folder);
} }
} }

1
core/src/org/transdroid/core/gui/settings/WebsearchPreference.java

@ -29,6 +29,7 @@ public class WebsearchPreference extends Preference {
public WebsearchPreference setWebsearchSetting(WebsearchSetting websearchSetting) { public WebsearchPreference setWebsearchSetting(WebsearchSetting websearchSetting) {
this.websearchSetting = websearchSetting; this.websearchSetting = websearchSetting;
setTitle(websearchSetting.getName()); setTitle(websearchSetting.getName());
setSummary(websearchSetting.getHumanReadableIdentifier());
setOrder(ORDER_START + websearchSetting.getOrder()); setOrder(ORDER_START + websearchSetting.getOrder());
return this; return this;
} }

38
core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

@ -1,16 +1,13 @@
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ApplicationSettings_;
import android.os.Bundle; import android.os.Bundle;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
/** /**
* Activity that allows for a configuration of a web search site. The key can be supplied to update an existing web * Activity that allows for a configuration of a web search site. The key can be supplied to update an existing web
* search site setting instead of creating a new one. * search site setting instead of creating a new one.
@ -18,30 +15,23 @@ import com.actionbarsherlock.app.SherlockPreferenceActivity;
*/ */
@EActivity @EActivity
@OptionsMenu(resName="activity_deleteableprefs") @OptionsMenu(resName="activity_deleteableprefs")
public class WebsearchSettingsActivity extends SherlockPreferenceActivity { public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity {
@Extra
protected int key = -1;
@Bean @Override
protected ApplicationSettings applicationSettings; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the raw preferences to show in this screen // Load the raw preferences to show in this screen
addPreferencesFromResource(R.xml.pref_websearch); init(R.xml.pref_websearch, ApplicationSettings_.getInstance_(this).getMaxWebsearch());
initTextPreference("websearch_name");
initTextPreference("websearch_baseurl");
// Bind the preferences to the correct storage key, e.g. the first site setting stores its URL in the }
// 'websearch_baseurl_0' shared preferences field
if (key < 0) {
key = applicationSettings.getMaxWebsearch() + 1;
}
findPreference("websearch_name").setKey("websearch_name_" + key);
findPreference("websearch_baseurl").setKey("websearch_baseurl_" + key);
@OptionsItem(resName = "action_removesettings")
protected void removeSettings() {
ApplicationSettings_.getInstance_(this).removeWebsearchSettings(key);
finish();
} }
} }

Loading…
Cancel
Save