diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 8db98970..7c97b5c9 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -148,6 +148,7 @@ + diff --git a/android/res/drawable/seedstuff.png b/android/res/drawable/seedstuff.png new file mode 100644 index 00000000..49409f4c Binary files /dev/null and b/android/res/drawable/seedstuff.png differ diff --git a/android/res/drawable/seedstuff_icon.png b/android/res/drawable/seedstuff_icon.png new file mode 100644 index 00000000..135c4f8f Binary files /dev/null and b/android/res/drawable/seedstuff_icon.png differ diff --git a/android/res/layout/dialog_seedstuff_info.xml b/android/res/layout/dialog_seedstuff_info.xml new file mode 100644 index 00000000..7630c56a --- /dev/null +++ b/android/res/layout/dialog_seedstuff_info.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index ced567cc..98741ac9 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -372,6 +372,13 @@ Like alpha.seedm8.com Invalid server (use the full host name, like alpha.seedm8.com) +Seedstuff offers seedboxes where customer service is priority #1. Transdroid provides easy setup for Seedstuff servers.\n\nRead more at www.seedstuff.ca +Add Seedstuff server +Seedstuff server settings +Server name +Like 100.seedstuff.ca +Invalid server (use the full host name, like 100.seedstuff.ca) + Combined ordering Number of seeders/leechers diff --git a/android/src/ca/seedstuff/transdroid/preferences/PreferencesSeedstuffServer.java b/android/src/ca/seedstuff/transdroid/preferences/PreferencesSeedstuffServer.java new file mode 100644 index 00000000..2bcdfd7f --- /dev/null +++ b/android/src/ca/seedstuff/transdroid/preferences/PreferencesSeedstuffServer.java @@ -0,0 +1,187 @@ +/* + * This file is part of Transdroid + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + * + */ + package ca.seedstuff.transdroid.preferences; + +import org.transdroid.R; +import org.transdroid.preferences.Preferences; +import org.transdroid.preferences.TransdroidCheckBoxPreference; +import org.transdroid.preferences.TransdroidEditTextPreference; +import org.transdroid.preferences.TransdroidListPreference; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.text.InputType; +import android.text.method.PasswordTransformationMethod; +import android.view.View; +import android.view.inputmethod.EditorInfo; +import android.widget.ListView; +import android.widget.Toast; + +public class PreferencesSeedstuffServer extends PreferenceActivity { + + public static final String PREFERENCES_SSERVER_KEY = "PREFERENCES_SSERVER_POSTFIX"; + public static final String[] validAddressEnding = { ".seedstuff.ca" }; + + private String serverPostfix; + // These preferences are members so they can be accessed by the updateOptionAvailibility event + private TransdroidEditTextPreference name; + private TransdroidEditTextPreference server; + private TransdroidEditTextPreference user; + private TransdroidEditTextPreference pass; + private TransdroidCheckBoxPreference alarmFinished; + private TransdroidCheckBoxPreference alarmNew; + + private String nameValue = null; + private String serverValue = null; + private String userValue = null; + //private String passValue = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // For which server? + serverPostfix = getIntent().getStringExtra(PREFERENCES_SSERVER_KEY); + // Create the preferences screen here: this takes care of saving/loading, but also contains the ListView adapter, etc. + setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this)); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + + nameValue = prefs.getString(Preferences.KEY_PREF_SNAME + serverPostfix, null); + serverValue = prefs.getString(Preferences.KEY_PREF_SSERVER + serverPostfix, null); + userValue = prefs.getString(Preferences.KEY_PREF_SUSER + serverPostfix, null); + //passValue = prefs.getString(Preferences.KEY_PREF_SPASS + serverPostfix, null); + + // Create preference objects + getPreferenceScreen().setTitle(R.string.seedstuff_pref_title); + // Name + name = new TransdroidEditTextPreference(this); + name.setTitle(R.string.pref_name); + name.setKey(Preferences.KEY_PREF_SNAME + serverPostfix); + name.getEditText().setSingleLine(); + name.setDialogTitle(R.string.pref_name); + name.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(name); + // Server + server = new TransdroidEditTextPreference(this); + server.setTitle(R.string.seedstuff_pref_server); + server.setKey(Preferences.KEY_PREF_SSERVER + serverPostfix); + server.getEditText().setSingleLine(); + server.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); + server.setDialogTitle(R.string.seedstuff_pref_server); + server.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(server); + // User + user = new TransdroidEditTextPreference(this); + user.setTitle(R.string.pref_user); + user.setKey(Preferences.KEY_PREF_SUSER + serverPostfix); + user.getEditText().setSingleLine(); + user.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER); + user.setDialogTitle(R.string.pref_user); + user.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(user); + // Pass + pass = new TransdroidEditTextPreference(this); + pass.setTitle(R.string.pref_pass); + pass.setKey(Preferences.KEY_PREF_SPASS + serverPostfix); + pass.getEditText().setSingleLine(); + pass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); + pass.getEditText().setTransformationMethod(new PasswordTransformationMethod()); + pass.setDialogTitle(R.string.pref_pass); + pass.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(pass); + + // AlertFinished + alarmFinished = new TransdroidCheckBoxPreference(this); + alarmFinished.setDefaultValue(true); + alarmFinished.setTitle(R.string.pref_alarmfinished); + alarmFinished.setSummary(R.string.pref_alarmfinished_info); + alarmFinished.setKey(Preferences.KEY_PREF_SALARMFINISHED + serverPostfix); + alarmFinished.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(alarmFinished); + // AlertNew + alarmNew = new TransdroidCheckBoxPreference(this); + alarmNew.setTitle(R.string.pref_alarmnew); + alarmNew.setSummary(R.string.pref_alarmnew_info); + alarmNew.setKey(Preferences.KEY_PREF_SALARMNEW + serverPostfix); + alarmNew.setOnPreferenceChangeListener(updateHandler); + getPreferenceScreen().addItemFromInflater(alarmNew); + + updateDescriptionTexts(); + + } + + private OnPreferenceChangeListener updateHandler = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference == name) { + nameValue = (String) newValue; + } else if (preference == server) { + String newServer = (String) newValue; + // Validate seedstuff server address + boolean valid = newServer != null && !newServer.equals("") && !(newServer.indexOf(" ") >= 0); + boolean validEnd = false; + for (int i = 0; i < validAddressEnding.length && valid; i++) { + validEnd |= newServer.endsWith(validAddressEnding[i]); + } + if (!valid || !validEnd) { + Toast.makeText(getApplicationContext(), R.string.seedstuff_error_invalid_servername, Toast.LENGTH_LONG).show(); + return false; + } + serverValue = newServer; + } else if (preference == user) { + userValue = (String) newValue; + } else if (preference == pass) { + //passValue = (String) newValue; + } + updateDescriptionTexts(); + // Set the value as usual + return true; + } + }; + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + + // Perform click action, which always is a Preference + Preference item = (Preference) getListAdapter().getItem(position); + + // Let the Preference open the right dialog + if (item instanceof TransdroidListPreference) { + ((TransdroidListPreference)item).click(); + } else if (item instanceof TransdroidCheckBoxPreference) { + ((TransdroidCheckBoxPreference)item).click(); + } else if (item instanceof TransdroidEditTextPreference) { + ((TransdroidEditTextPreference)item).click(); + } + + } + + private void updateDescriptionTexts() { + + // Update the 'summary' labels of all preferences to show their current value + name.setSummary(nameValue == null? getText(R.string.pref_name_info): nameValue); + server.setSummary(serverValue == null? getText(R.string.seedstuff_pref_server_info): serverValue); + user.setSummary(userValue == null? "": userValue); + + } + +} diff --git a/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java b/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java new file mode 100644 index 00000000..d8e813cd --- /dev/null +++ b/android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java @@ -0,0 +1,90 @@ +package ca.seedstuff.transdroid.preferences; + +import java.util.ArrayList; +import java.util.List; + +import org.transdroid.daemon.Daemon; +import org.transdroid.daemon.DaemonSettings; +import org.transdroid.daemon.OS; +import org.transdroid.daemon.util.HttpHelper; + +public class SeedstuffSettings { + + private static final String DEFAULT_NAME = "Seedstuff"; + + private static final int RTORRENT_PORT = 443; + private static final String RTORRENT_FOLDER_PART = "/user/"; + private static final int FTP_PORT = 32001; + + final private String name; + final private String server; + final private String username; + final private String password; + final private boolean alarmOnFinishedDownload; + final private boolean alarmOnNewTorrent; + final private String idString; + + public SeedstuffSettings(String name, String server, String username, String password, boolean alarmOnFinishedDownload, + boolean alarmOnNewTorrent, String idString) { + this.name = name; + this.server = server; + this.username = username; + this.password = password; + this.alarmOnFinishedDownload = alarmOnFinishedDownload; + this.alarmOnNewTorrent = alarmOnNewTorrent; + this.idString = idString; + } + + public String getName() { + return (name == null || name.equals("") ? DEFAULT_NAME : name); + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public boolean shouldAlarmOnFinishedDownload() { + return alarmOnFinishedDownload; + } + + public boolean shouldAlarmOnNewTorrent() { + return alarmOnNewTorrent; + } + + public String getIdString() { + return idString; + } + + /** + * Builds a text that can be used by a human reader to identify this daemon settings + * @return A concatenation of username, address, port and folder, where applicable + */ + public String getHumanReadableIdentifier() { + return getServer(); + } + + public String getServer() { + return server; + } + + @Override + public String toString() { + return getHumanReadableIdentifier(); + } + + public List createDaemonSettings(int startID) { + List daemons = new ArrayList(); + // rTorrent + daemons.add(new DaemonSettings(getName(), Daemon.rTorrent, getServer(), RTORRENT_PORT, true, true, null, + RTORRENT_FOLDER_PART + getUsername(), true, getUsername(), getPassword(), OS.Linux, + "/rtorrent/downloads/", "ftp://" + getName() + "@" + getServer() + FTP_PORT + "/rtorrents/downloads/", + getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), + shouldAlarmOnNewTorrent(), "" + startID++, true)); + return daemons; + } + +} diff --git a/android/src/org/transdroid/preferences/Preferences.java b/android/src/org/transdroid/preferences/Preferences.java index d9bf79bd..d645a615 100644 --- a/android/src/org/transdroid/preferences/Preferences.java +++ b/android/src/org/transdroid/preferences/Preferences.java @@ -42,6 +42,8 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; +import ca.seedstuff.transdroid.preferences.SeedstuffSettings; + import com.seedm8.transdroid.preferences.SeedM8Settings; import com.xirvik.transdroid.preferences.XirvikServerType; import com.xirvik.transdroid.preferences.XirvikSettings; @@ -78,6 +80,13 @@ public class Preferences { public static final String KEY_PREF_8SPASS = "transdroid_8server_spass"; public static final String KEY_PREF_8ALARMFINISHED = "transdroid_8server_alarmfinished"; public static final String KEY_PREF_8ALARMNEW = "transdroid_8server_alarmnew"; + + public static final String KEY_PREF_SNAME = "transdroid_sserver_name"; + public static final String KEY_PREF_SSERVER = "transdroid_sserver_server"; + public static final String KEY_PREF_SUSER = "transdroid_sserver_user"; + public static final String KEY_PREF_SPASS = "transdroid_sserver_pass"; + public static final String KEY_PREF_SALARMFINISHED = "transdroid_sserver_alarmfinished"; + public static final String KEY_PREF_SALARMNEW = "transdroid_sserver_alarmnew"; public static final String KEY_PREF_NAME = "transdroid_server_name"; public static final String KEY_PREF_DAEMON = "transdroid_server_daemon"; @@ -314,6 +323,48 @@ public class Preferences { editor.commit(); } + public static void removeSeedstuffSettings(SharedPreferences prefs, SeedstuffSettings toRemove) { + + Editor editor = prefs.edit(); + + // Move all seedstuff server settings 'up' 1 spot (by saving the preferences to an order id number 1 lower) + int id = (toRemove.getIdString() == ""? 0: Integer.parseInt(toRemove.getIdString())); + while (prefs.contains(KEY_PREF_SUSER + Integer.toString(id + 1))) { + + // Copy the preferences + String fromId = Integer.toString(id + 1); + String toId = (id == 0? "": Integer.toString(id)); + editor.putString(KEY_PREF_SNAME + toId, prefs.getString(KEY_PREF_SNAME + fromId, null)); + editor.putString(KEY_PREF_SSERVER + toId, prefs.getString(KEY_PREF_SSERVER + fromId, null)); + editor.putString(KEY_PREF_SUSER + toId, prefs.getString(KEY_PREF_SUSER + fromId, null)); + editor.putString(KEY_PREF_SPASS + toId, prefs.getString(KEY_PREF_SPASS + fromId, null)); + editor.putString(KEY_PREF_SALARMFINISHED + toId, prefs.getString(KEY_PREF_SALARMFINISHED + fromId, null)); + editor.putString(KEY_PREF_SALARMNEW + toId, prefs.getString(KEY_PREF_SALARMNEW + fromId, null)); + id++; + + } + + // Remove the last server preferences configuration + String delId = (id == 0? "": Integer.toString(id)); + editor.remove(KEY_PREF_SNAME + delId); + editor.remove(KEY_PREF_SSERVER + delId); + editor.remove(KEY_PREF_SUSER + delId); + editor.remove(KEY_PREF_SPASS + delId); + editor.remove(KEY_PREF_SALARMNEW + delId); + editor.remove(KEY_PREF_SALARMFINISHED + delId); + + // If the last used daemon... + String lastUsed = prefs.getString(KEY_PREF_LASTUSED, ""); + + // no longer exists... + if (!prefs.contains(KEY_PREF_ADDRESS + lastUsed)) { + // Just reset the last used number + editor.putString(KEY_PREF_LASTUSED, ""); + } + + editor.commit(); + } + public static void removeSiteSettings(SharedPreferences prefs, SiteSettings toRemove) { Editor editor = prefs.edit(); @@ -471,6 +522,33 @@ public class Preferences { return s8servers; } + /** + * Build a list of seedstuff server setting objects, available in the stored preferences + * @param prefs The application's shared preferences + * @return A list of all seedstuff server configurations available + */ + public static List readAllSeedstuffSettings(SharedPreferences prefs) { + + // Build a list of seedstuff server setting objects, available in the stored preferences + List sservers = new ArrayList(); + int i = 0; + String nextName = KEY_PREF_SUSER; + while (prefs.contains(nextName)) { + + // The first server is stored without number, subsequent ones have an order number after the regular pref key + String postfix = (i == 0? "": Integer.toString(i)); + + // Add an entry for this server + sservers.add(readSeedstuffSettings(prefs, postfix)); + + // Search for more + i++; + nextName = KEY_PREF_SUSER + Integer.toString(i); + } + + return sservers; + } + /** * Build a list of server setting objects, available in the stored preferences * @param prefs The application's shared preferences @@ -517,6 +595,9 @@ public class Preferences { for (SeedM8Settings seedm8 : readAllSeedM8Settings(prefs)) { daemons.addAll(seedm8.createDaemonSettings(max + 1)); } + for (SeedstuffSettings seedstuff : readAllSeedstuffSettings(prefs)) { + daemons.addAll(seedstuff.createDaemonSettings(max + 1)); + } return daemons; } @@ -783,6 +864,20 @@ public class Preferences { } + private static SeedstuffSettings readSeedstuffSettings(SharedPreferences prefs, String postfix) { + + // Return daemon settings + return new SeedstuffSettings( + prefs.getString(KEY_PREF_SNAME + postfix, null), + prefs.getString(KEY_PREF_SSERVER + postfix, null), + prefs.getString(KEY_PREF_SUSER + postfix, null), + prefs.getString(KEY_PREF_SPASS + postfix, null), + prefs.getBoolean(KEY_PREF_SALARMFINISHED + postfix, true), + prefs.getBoolean(KEY_PREF_SALARMNEW + postfix, false), + postfix); + + } + private static DaemonSettings readDaemonSettings(SharedPreferences prefs, String postfix) { // Read saved preferences diff --git a/android/src/org/transdroid/preferences/PreferencesAdapter.java b/android/src/org/transdroid/preferences/PreferencesAdapter.java index c279fe8e..19f412fc 100644 --- a/android/src/org/transdroid/preferences/PreferencesAdapter.java +++ b/android/src/org/transdroid/preferences/PreferencesAdapter.java @@ -25,6 +25,8 @@ import org.transdroid.daemon.DaemonSettings; import org.transdroid.gui.search.SiteSettings; import org.transdroid.rss.RssFeedSettings; +import ca.seedstuff.transdroid.preferences.SeedstuffSettings; + import com.seedm8.transdroid.preferences.SeedM8Settings; import com.xirvik.transdroid.preferences.XirvikSettings; @@ -48,11 +50,11 @@ public class PreferencesAdapter extends BaseAdapter { public static final String ADD_NEW_XSERVER = "add_new_xserver"; public static final String ADD_NEW_8SERVER = "add_new_8server"; + public static final String ADD_NEW_SSERVER = "add_new_sserver"; public static final String ADD_NEW_DAEMON = "add_new_daemon"; public static final String ADD_NEW_WEBSITE = "add_new_website"; public static final String ADD_NEW_RSSFEED = "add_new_rssfeed"; public static final String ADD_EZRSS_FEED = "add_ezrss_feed"; - public static final String XIRVIK_INFO = "xirvik_info"; public static final String RSS_SETTINGS = "rss_settings"; public static final String INTERFACE_SETTINGS = "interface_settings"; public static final String CLEAN_SEARCH_HISTORY = "clear_search_history"; @@ -70,7 +72,7 @@ public class PreferencesAdapter extends BaseAdapter { * @param daemons List of existing servers */ public PreferencesAdapter(Context context, List daemons) { - this(context, null, null, null, daemons, null, null, true, false, false); + this(context, null, null, null, null, daemons, null, null, true, false, false); } /** @@ -80,7 +82,7 @@ public class PreferencesAdapter extends BaseAdapter { * @param foo Dummy (unused) parameter to make this constructor's signature unique */ public PreferencesAdapter(Context context, List feeds, int foo) { - this(context, null, null, null, null, feeds, null, false, false, true); + this(context, null, null, null, null, null, feeds, null, false, false, true); } /** @@ -91,11 +93,11 @@ public class PreferencesAdapter extends BaseAdapter { * @param daemons All regular server settings * @param websites All web-search site settings */ - public PreferencesAdapter(ListActivity preferencesActivity, List xservers, List s8servers, List daemons, List websites) { - this(preferencesActivity, preferencesActivity, xservers, s8servers, daemons, null, websites, true, true, false); + public PreferencesAdapter(ListActivity preferencesActivity, List xservers, List s8servers, List sservers, List daemons, List websites) { + this(preferencesActivity, preferencesActivity, xservers, s8servers, sservers, daemons, null, websites, true, true, false); } - private PreferencesAdapter(Context context, ListActivity preferencesActivity, List xservers, List s8servers, List daemons, List feeds, List websites, boolean withDaemons, boolean withOthers, boolean withRssFeeds) { + private PreferencesAdapter(Context context, ListActivity preferencesActivity, List xservers, List s8servers, List sservers, List daemons, List feeds, List websites, boolean withDaemons, boolean withOthers, boolean withRssFeeds) { this.context = context; @@ -107,9 +109,11 @@ public class PreferencesAdapter extends BaseAdapter { if (withOthers) { this.items.addAll(xservers); this.items.addAll(s8servers); + this.items.addAll(sservers); this.items.add(new PreferencesListButton(context, ADD_NEW_DAEMON, R.string.add_new_server)); this.items.add(new XirvikListButton(preferencesActivity, ADD_NEW_XSERVER, R.string.xirvik_add_new_xserver)); this.items.add(new SeedM8ListButton(preferencesActivity, ADD_NEW_8SERVER, R.string.seedm8_add_new_xserver)); + this.items.add(new SeedstuffListButton(preferencesActivity, ADD_NEW_SSERVER, R.string.seedstuff_add_new_xserver)); this.items.add(new Divider(context, R.string.pref_search)); this.items.add(new PreferencesListButton(context, SET_DEFAULT_SITE, R.string.pref_setdefault)); this.items.addAll(websites); @@ -190,6 +194,18 @@ public class PreferencesAdapter extends BaseAdapter { setView.SetData(s8server); return setView; + } else if (item instanceof SeedstuffSettings) { + + // return a Seedstuff list view + SeedstuffSettings sserver = (SeedstuffSettings) item; + if (convertView == null || !(convertView instanceof SeedstuffSettingsView)) { + return new SeedstuffSettingsView(context, sserver); + } + // Reuse view + SeedstuffSettingsView setView = (SeedstuffSettingsView) convertView; + setView.SetData(sserver); + return setView; + } else if (item instanceof DaemonSettings) { // return a DaemonSettings list view @@ -290,6 +306,33 @@ public class PreferencesAdapter extends BaseAdapter { } + /** + * A list item representing a Seedstuff settings object (by showing its name and an identifier text) + */ + public class SeedstuffSettingsView extends LinearLayout { + + SeedstuffSettings settings; + + public SeedstuffSettingsView(Context context, SeedstuffSettings settings) { + super(context); + addView(inflate(context, R.layout.list_item_seedbox_settings, null)); + ImageView icon = (ImageView) findViewById(R.id.icon); + icon.setImageResource(R.drawable.seedstuff_icon); + + this.settings = settings; + SetData(settings); + } + + /** + * Sets the actual texts and images to the visible widgets (fields) + */ + public void SetData(SeedstuffSettings settings) { + ((TextView)findViewById(R.id.title)).setText(settings.getName()); + ((TextView)findViewById(R.id.summary)).setText(settings.getHumanReadableIdentifier()); + } + + } + /** * A list item representing a daemon settings object (by showing its name and an identifier text) */ @@ -470,6 +513,44 @@ public class PreferencesAdapter extends BaseAdapter { return key; } } + + /** + * An button to show inside the list, that allows adding of a new seedstuff server as well as to click a '?' button + */ + public class SeedstuffListButton extends LinearLayout { + + private String key; + + /** + * Create a static action button instance, that can be shown in the list screen + * @param preferencesActivity The application context + * @param key The button-unique string to identify clicks + * @param textResourceID The resource of the text to show as the buttons title text + */ + public SeedstuffListButton(final ListActivity preferencesActivity, String key, int textResourceID) { + super(preferencesActivity); + addView(inflate(preferencesActivity, R.layout.list_item_seedbox_pref, null)); + + this.key = key; + ((TextView)findViewById(R.id.add_server)).setText(textResourceID); + ImageButton helpButton = (ImageButton)findViewById(R.id.info); + helpButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + preferencesActivity.showDialog(PreferencesMain.DIALOG_SEEDSTUFF_INFO); + } + }); + helpButton.setFocusable(false); + } + + /** + * Returns the string identifier that can be used on clicks + * @return The identifier key + */ + public String getKey() { + return key; + } + } /** * A list divider (with the same look as a PreferenceCategory), showing a simple text * diff --git a/android/src/org/transdroid/preferences/PreferencesMain.java b/android/src/org/transdroid/preferences/PreferencesMain.java index 7371878a..0af93f6d 100644 --- a/android/src/org/transdroid/preferences/PreferencesMain.java +++ b/android/src/org/transdroid/preferences/PreferencesMain.java @@ -30,6 +30,7 @@ import org.transdroid.gui.search.TorrentSearchHistoryProvider; import org.transdroid.gui.util.ActivityUtil; import org.transdroid.preferences.PreferencesAdapter.PreferencesListButton; import org.transdroid.preferences.PreferencesAdapter.SeedM8ListButton; +import org.transdroid.preferences.PreferencesAdapter.SeedstuffListButton; import org.transdroid.preferences.PreferencesAdapter.XirvikListButton; import android.app.AlertDialog; @@ -53,6 +54,9 @@ import android.widget.ListView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; +import ca.seedstuff.transdroid.preferences.PreferencesSeedstuffServer; +import ca.seedstuff.transdroid.preferences.SeedstuffSettings; + import com.seedm8.transdroid.preferences.PreferencesSeedM8Server; import com.seedm8.transdroid.preferences.SeedM8Settings; import com.xirvik.transdroid.preferences.PreferencesXirvikServer; @@ -74,6 +78,7 @@ public class PreferencesMain extends ListActivity { private static final int DIALOG_IMPORT_SETTINGS = 3; private static final int DIALOG_EXPORT_SETTINGS = 4; private static final int DIALOG_INSTALL_FILE_MANAGER = 5; + static final int DIALOG_SEEDSTUFF_INFO = 6; private final static String PICK_DIRECTORY_INTENT = "org.openintents.action.PICK_DIRECTORY"; private final static String PICK_FILE_INTENT = "org.openintents.action.PICK_FILE"; private final static Uri OIFM_MARKET_URI = Uri.parse("market://search?q=pname:org.openintents.filemanager"); @@ -103,13 +108,14 @@ public class PreferencesMain extends ListActivity { // Build a list of server and search site settings objects to show List xservers = Preferences.readAllXirvikSettings(prefs); List s8servers = Preferences.readAllSeedM8Settings(prefs); + List sservers = Preferences.readAllSeedstuffSettings(prefs); List daemons = Preferences.readAllNormalDaemonSettings(prefs); List websites = Preferences.readAllWebSearchSiteSettings(prefs); currentdefaultsite = Preferences.readDefaultSearchSiteSettings(prefs); // Set the list items - adapter = new PreferencesAdapter(this, xservers, s8servers, daemons, websites); + adapter = new PreferencesAdapter(this, xservers, s8servers, sservers, daemons, websites); setListAdapter(adapter); } @@ -147,6 +153,19 @@ public class PreferencesMain extends ListActivity { i.putExtra(PreferencesSeedM8Server.PREFERENCES_8SERVER_KEY, (max == 0? "": Integer.toString(max))); startActivityForResult(i, 0); + } else if (item instanceof SeedstuffListButton) { + + // What is the max current seedstuff settings ID number? + int max = 0; + while (prefs.contains(Preferences.KEY_PREF_SUSER + (max == 0? "": Integer.toString(max)))) { + max++; + } + + // Start a new seedstuff server settings screen + Intent i = new Intent(this, PreferencesSeedstuffServer.class); + i.putExtra(PreferencesSeedstuffServer.PREFERENCES_SSERVER_KEY, (max == 0? "": Integer.toString(max))); + startActivityForResult(i, 0); + } else if (item instanceof PreferencesListButton) { PreferencesListButton button = (PreferencesListButton) item; @@ -217,6 +236,14 @@ public class PreferencesMain extends ListActivity { i.putExtra(PreferencesSeedM8Server.PREFERENCES_8SERVER_KEY, s8server.getIdString()); startActivityForResult(i, 0); + } else if (item instanceof SeedstuffSettings) { + + // Open the seedstuff server settings edit activity for the clicked server + Intent i = new Intent(this, PreferencesSeedstuffServer.class); + SeedstuffSettings sserver = (SeedstuffSettings) item; + i.putExtra(PreferencesSeedstuffServer.PREFERENCES_SSERVER_KEY, sserver.getIdString()); + startActivityForResult(i, 0); + } else if (item instanceof DaemonSettings) { // Open the daemon settings edit activity for the clicked server @@ -309,6 +336,16 @@ public class PreferencesMain extends ListActivity { return true; } } + if (selected instanceof SeedstuffSettings) { + + if (item.getItemId() == MENU_REMOVE_ID) { + + // Remove this Seedstuff server configuration and reload this screen + Preferences.removeSeedstuffSettings(prefs, (SeedstuffSettings)selected); + buildAdapter(); + return true; + } + } if (selected instanceof SiteSettings) { if (item.getItemId() == MENU_REMOVE_ID) { @@ -348,6 +385,11 @@ public class PreferencesMain extends ListActivity { menu.add(0, MENU_REMOVE_ID, 0, R.string.menu_remove); } + // For SeedstuffSettings, allow removing of the config + if (item instanceof SeedstuffSettings) { + menu.add(0, MENU_REMOVE_ID, 0, R.string.menu_remove); + } + // For DeamonSettings, allow removing of the config if (item instanceof DaemonSettings) { menu.add(0, MENU_REMOVE_ID, 0, R.string.menu_remove); @@ -382,6 +424,13 @@ public class PreferencesMain extends ListActivity { s8infoDialog.setView(getLayoutInflater().inflate(R.layout.dialog_seedm8_info, null)); return s8infoDialog.create(); + case DIALOG_SEEDSTUFF_INFO: + + // Build a dialog with the seedstuff info message (with logo and link) + AlertDialog.Builder sinfoDialog = new AlertDialog.Builder(this); + sinfoDialog.setView(getLayoutInflater().inflate(R.layout.dialog_seedstuff_info, null)); + return sinfoDialog.create(); + case DIALOG_SET_DEFAULT_SITE: // Build a dialog with a radio box per available search site