From 403c2ee3d0acf8f8c7fe1d00f561fcff1bab9938 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 5 Mar 2012 14:35:21 +0100 Subject: [PATCH] Added support for Seedstuff. --- android/AndroidManifest.xml | 1 + android/res/drawable/seedstuff.png | Bin 0 -> 5437 bytes android/res/drawable/seedstuff_icon.png | Bin 0 -> 2148 bytes android/res/layout/dialog_seedstuff_info.xml | 23 +++ android/res/values/strings.xml | 7 + .../PreferencesSeedstuffServer.java | 187 ++++++++++++++++++ .../preferences/SeedstuffSettings.java | 90 +++++++++ .../transdroid/preferences/Preferences.java | 95 +++++++++ .../preferences/PreferencesAdapter.java | 93 ++++++++- .../preferences/PreferencesMain.java | 51 ++++- 10 files changed, 540 insertions(+), 7 deletions(-) create mode 100644 android/res/drawable/seedstuff.png create mode 100644 android/res/drawable/seedstuff_icon.png create mode 100644 android/res/layout/dialog_seedstuff_info.xml create mode 100644 android/src/ca/seedstuff/transdroid/preferences/PreferencesSeedstuffServer.java create mode 100644 android/src/ca/seedstuff/transdroid/preferences/SeedstuffSettings.java 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 0000000000000000000000000000000000000000..49409f4cdaf127d5040218ed53f67397a0fdeb08 GIT binary patch literal 5437 zcmWldcRX9)8^=R!s%UDIqNqJu)ZRj^8bwK|9ecGgV->Zc_AXIUwSv^1Rjal4mk^`W zUbXl7-QOSQo_k++oO7S?dEV#5=)jc(t$Z4A0P`{ti@Ii_~Rw!-XUgxd*zfkuE$UEQ)ZOFY^C1z(>!5= z8qp=k#ukS0^4(KYlFGpa&ngCgpZ<5aKxQ|+J#5oBbS{5-gBrfMX~q7bZ~H)ShlGmp zsTFVnYQmCye(o~4Q~$@}?OV69lF%=pq@<+F(_Is=nn7wsRT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({&-Sk-CJCMq_I zu2ZIIqsYCKS5b^IRL`@!#`ltm5(=o2^ly8{&b^5SXc}UZK%wn#!i83!umYq?iIb2l$R#;`zQ+3S$kuwY7D% z{b1ASd;ljWClEHBi^b*TLIMJ^foFSwq+aXESa*D!nle?UIXF1LAJk5U(WZD`}*5h*o`RKSU=X0o%h zb96;kMuzY4rm@WzfCXR<4hgLCO~CX}zVp*R0wh7E<&(!-IK9lL1hfe((#a_))j+ub z*w7K41R`K9*bp6Bw&5$!+XS0DdR_f-VL8*}<+c?ht$pfzmo_(rKmo>te!)RV{4^>b zGtlzsk;9Hx6Z`a$T9*Jz_0WJ>TiZ{0ngz{yqwZ%_3>-d?s2D=rz@auT@~7@fxQMhN zDJ21c6;<14-d34CHbj@gmz4BwXh=1~1mj+U)d!s4kg@@~h_J|;lrX1;B1I;GgAkmp zBihCz=tAtrBh{m8_@pg4(LK?V9~NQnEarkp*3^ za*o*NyVIaE;GWCub`_;hf`|+T%?#Shs+F)ROlSA4mnfIc@22E9ZI&O}OWsj5tBkG$ zS-uf;=NfXOAqZmn$>Ed9E=*C8nF$lrW~Ow^!z$g8(=cEN6XNhO7=&kY2h@y1Zc%Hh zamHeMwrv!90r$tbG9gFm%0yXV3I2wHu;LFS!FC@xSNFNIVBk3VV)iSxVR<{7Psh(Z z4--F{4jj@&P$=E$m+OR+5Zs*&{7MY6de-SmPR-F9{aeCyfg4T(nrI;j4<-qwPZbAt f7DLTwZtq3r6AQT(S?vN_pdd{(T}XwBRoMRka+;p) literal 0 HcmV?d00001 diff --git a/android/res/drawable/seedstuff_icon.png b/android/res/drawable/seedstuff_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..135c4f8fe100815623cae89313d2389146626187 GIT binary patch literal 2148 zcmV-q2%GnbP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L04^f{04^f|c%?sf000N~NklHuFWLRw;~&`#yV(SgN6Jj^A3M9h zx#yhE{ho8r-n|QamBxw{E4l&ba4)i%O`A5ocKY<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fGxp# z1g;U}?KAq)vr4UwJM#n6YPI5WDJmZzJORKr)iKNd<(NPvMHWs?s>Q%r2KbawywK<) zBZU}w!*o9?#GH*Rvw~{}&V;4y2J~MuelKYQK87*>a;{ljks2kmE(K;(ulGkgs zE5k9P?#fm12q9B4w4SiR=uo{B2|LlYD1m63a+TzDMmPRk%86r?cG}|}^S%tDKRoVe zw}HUnL`AI!a7e)V9qmm}ddHV?2kavZf6r%%zR + + + + + \ 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