diff --git a/app/build.gradle b/app/build.gradle index 08bd5674..3500932f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 15 targetSdkVersion 30 - versionCode 239 - versionName '2.5.19' + versionCode 240 + versionName '2.5.20' javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7aebc26c..56ab952e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -230,7 +230,7 @@ android:name="org.transdroid.core.seedbox.DediseedboxSettingsActivity_" android:theme="@style/TransdroidTheme.Settings" /> 0) { + try { + Integer.parseInt(givenAddress.substring(dot)); + // Last bit is numeric: looks like an IP, so better use the default fallback name + } catch (NumberFormatException e) { + // Not numeric, looks like a domain name we can use + return givenAddress; + } + } } return DEFAULT_NAME; } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java index 662524fc..9f92ba46 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java @@ -57,8 +57,8 @@ import org.transdroid.core.seedbox.SeedboxProvider; import org.transdroid.core.seedbox.XirvikDediSettings; import org.transdroid.core.seedbox.XirvikSemiSettings; +import org.transdroid.core.seedbox.XirvikSettingsActivity; import org.transdroid.core.seedbox.XirvikSharedSettings; -import org.transdroid.core.seedbox.XirvikSharedSettingsActivity; import java.util.ArrayList; import java.util.List; @@ -128,7 +128,7 @@ public boolean onPreferenceClick(Preference preference) { // Start the configuration activity for this specific chosen seedbox if (which == 0) ServerSettingsActivity_.intent(MainSettingsActivity.this).start(); - else if (which == SeedboxProvider.values().length + 1) + else if (which == SeedboxProvider.activeProviders().length + 1) BarcodeHelper.startBarcodeScanner(this, BarcodeHelper.ACTIVITY_BARCODE_ADDSERVER); else startActivity(SeedboxProvider.values()[which - 1].getSettings().getSettingsActivityIntent(MainSettingsActivity.this)); @@ -266,10 +266,10 @@ protected void navigateUp() { protected Dialog onCreateDialog(int id) { if (id == DIALOG_ADDSEEDBOX) { // Open dialog to pick one of the supported seedbox providers (or a normal server) - String[] seedboxes = new String[SeedboxProvider.values().length + 2]; + String[] seedboxes = new String[SeedboxProvider.activeProviders().length + 2]; seedboxes[0] = getString(R.string.pref_addserver_normal); for (int i = 0; i < seedboxes.length - 2; i++) { - seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.values()[i].getSettings().getName()); + seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.activeProviders()[i].getSettings().getName()); } seedboxes[seedboxes.length - 1] = getString(R.string.pref_seedbox_xirvikviaqr); return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create(); @@ -296,7 +296,7 @@ protected void onServerBarcodeScanHandled(String[] qrResult) { final String token = qrResult[2]; final String name = server.replace(".xirvik.com", ""); - new XirvikSharedSettingsActivity.RetrieveXirvikAutoConfTask(server, "", "", token) { + new XirvikSettingsActivity.RetrieveXirvikAutoConfTask(server, "", "", token) { @Override protected void onPostExecute(String result) { if (result == null) { diff --git a/app/src/main/java/org/transdroid/core/seedbox/SeedboxProvider.java b/app/src/main/java/org/transdroid/core/seedbox/SeedboxProvider.java index 8043eb30..10a1a9a6 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/SeedboxProvider.java +++ b/app/src/main/java/org/transdroid/core/seedbox/SeedboxProvider.java @@ -32,7 +32,7 @@ public SeedboxSettings getSettings() { return new DediseedboxSettings(); } }, - XirvikShared { + Xirvik { @Override public SeedboxSettings getSettings() { return new XirvikSharedSettings(); @@ -51,6 +51,10 @@ public SeedboxSettings getSettings() { } }; + public static SeedboxProvider[] activeProviders() { + return new SeedboxProvider[]{SeedboxProvider.Dediseedbox, SeedboxProvider.Xirvik}; + } + public abstract SeedboxSettings getSettings(); } diff --git a/app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java b/app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java index 55877e8d..ae92eb4a 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java +++ b/app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java @@ -45,7 +45,7 @@ public ServerSetting getServerSetting(SharedPreferences prefs, int orderOffset, if (server == null) { return null; } - Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikdedi_client_" + order, null)); + Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikdedi_client_" + order, Daemon.toCode(Daemon.rTorrent))); String user = prefs.getString("seedbox_xirvikdedi_user_" + order, null); String pass = prefs.getString("seedbox_xirvikdedi_pass_" + order, null); String authToken = prefs.getString("seedbox_xirvikdedi_token_" + order, null); @@ -62,7 +62,7 @@ public ServerSetting getServerSetting(SharedPreferences prefs, int orderOffset, type != Daemon.uTorrent, false, null, - type == Daemon.Deluge ? "/deluge" : "/RPC2-aAoWTED8ngLqZyKnZ7FFEAgfz5lejcof", + type == Daemon.Deluge ? "/deluge" : null, true, user, pass, @@ -106,21 +106,21 @@ public void saveServerSetting(Context context, String server, String token, Stri SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Check server already exists to replace token - for(int i = 0 ; i <= SeedboxProvider.XirvikDedi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) ; i++) { - if(prefs.getString("seedbox_xirvikdedi_server_" + i, "").equals(server)) { + for (int i = 0; i <= SeedboxProvider.XirvikDedi.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)); i++) { + if (prefs.getString("seedbox_xirvikdedi_server_" + i, "").equals(server)) { key = i; } } // Store new seedbox pref prefs.edit() - .putString("seedbox_xirvikdedi_client_" + key, Daemon.toCode(Daemon.rTorrent)) - .putString("seedbox_xirvikdedi_name_" + key, name) - .putString("seedbox_xirvikdedi_server_" + key, server) - .putString("seedbox_xirvikdedi_user_" + key, "") - .putString("seedbox_xirvikdedi_pass_" + key, "") - .putString("seedbox_xirvikdedi_token_" + key, token) - .apply(); + .putString("seedbox_xirvikdedi_client_" + key, Daemon.toCode(Daemon.rTorrent)) + .putString("seedbox_xirvikdedi_name_" + key, name) + .putString("seedbox_xirvikdedi_server_" + key, server) + .putString("seedbox_xirvikdedi_user_" + key, "") + .putString("seedbox_xirvikdedi_pass_" + key, "") + .putString("seedbox_xirvikdedi_token_" + key, token) + .apply(); } diff --git a/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java b/app/src/main/java/org/transdroid/core/seedbox/XirvikSettingsActivity.java similarity index 85% rename from app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java rename to app/src/main/java/org/transdroid/core/seedbox/XirvikSettingsActivity.java index ea0c3cbc..ca7593b2 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/seedbox/XirvikSettingsActivity.java @@ -53,7 +53,7 @@ */ @EActivity @OptionsMenu(resName = "activity_deleteableprefs") -public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { +public class XirvikSettingsActivity extends KeyBoundPreferencesActivity { @Bean protected Log log; @@ -67,12 +67,11 @@ public void onCreate(Bundle savedInstanceState) { // Load the raw preferences to show in this screen init(R.xml.pref_seedbox_xirvikshared, - SeedboxProvider.XirvikShared.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(this))); + SeedboxProvider.Xirvik.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(this))); initTextPreference("seedbox_xirvikshared_name"); initTextPreference("seedbox_xirvikshared_server"); initTextPreference("seedbox_xirvikshared_user"); initTextPreference("seedbox_xirvikshared_pass"); - initTextPreference("seedbox_xirvikshared_rpc"); initBooleanPreference("seedbox_xirvikshared_alarmfinished", true); initBooleanPreference("seedbox_xirvikshared_alarmnew", true); excludeFilter = initTextPreference("seedbox_xirvikshared_alarmexclude"); @@ -82,7 +81,6 @@ public void onCreate(Bundle savedInstanceState) { @Override protected void onPreferencesChanged() { - // Show the exclude and the include filters if notifying SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean alarmFinished = prefs.getBoolean("seedbox_xirvikshared_alarmfinished_" + key, true); @@ -96,26 +94,28 @@ protected void onPreferencesChanged() { String pass = prefs.getString("seedbox_xirvikshared_pass_" + key, null); String token = prefs.getString("seedbox_xirvikshared_token_" + key, null); - new RetrieveXirvikAutoConfTask(server, user, pass, token) { - @Override - protected void onPostExecute(String result) { - storeScgiMountFolder(result); - } - }.execute(); + boolean enteredServerName = server != null && !server.isEmpty(); + boolean enteredUserCredentials = user != null && !user.isEmpty() && pass != null && !pass.isEmpty(); + boolean hasToken = token != null && !token.isEmpty(); + if (enteredServerName && (enteredUserCredentials || hasToken)) { + new RetrieveXirvikAutoConfTask(server, user, pass, token) { + @Override + protected void onPostExecute(String result) { + storeScgiMountFolder(result); + } + }.execute(); + } } protected void storeScgiMountFolder(String result) { - Editor edit = PreferenceManager.getDefaultSharedPreferences(XirvikSharedSettingsActivity.this).edit(); - EditTextPreference pref = (EditTextPreference) findPreference("seedbox_xirvikshared_rpc_" + key); + Editor edit = PreferenceManager.getDefaultSharedPreferences(XirvikSettingsActivity.this).edit(); if (result == null) { log.d(this, "Could not retrieve the Xirvik shared seedbox RPC mount point setting"); - SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirviknofolder).colorResource(R.color.red)); - edit.remove("seedbox_xirvikshared_rpc_" + key); - pref.setSummary(""); + SnackbarManager.show(Snackbar.with(this).text(R.string.pref_seedbox_xirvikfolderfallback).colorResource(R.color.red)); + edit.putString("seedbox_xirvikshared_rpc_" + key, null); } else { edit.putString("seedbox_xirvikshared_rpc_" + key, result); - pref.setSummary(result); } edit.apply(); } @@ -129,7 +129,7 @@ protected void navigateUp() { @OptionsItem(resName = "action_removesettings") protected void removeSettings() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - SeedboxProvider.XirvikShared.getSettings().removeServerSetting(prefs, key); + SeedboxProvider.Xirvik.getSettings().removeServerSetting(prefs, key); finish(); } diff --git a/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java b/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java index 3c92d18e..b2b66fe4 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java +++ b/app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java @@ -35,7 +35,7 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox @Override public String getName() { - return "Xirvik shared"; + return "Xirvik"; } @Override @@ -45,7 +45,7 @@ public ServerSetting getServerSetting(SharedPreferences prefs, int orderOffset, if (server == null) { return null; } - Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikshared_client_" + order, null)); + Daemon type = Daemon.fromCode(prefs.getString("seedbox_xirvikshared_client_" + order, Daemon.toCode(Daemon.rTorrent))); String user = prefs.getString("seedbox_xirvikshared_user_" + order, null); String pass = prefs.getString("seedbox_xirvikshared_pass_" + order, null); String rpc = prefs.getString("seedbox_xirvikshared_rpc_" + order, null); @@ -84,7 +84,7 @@ public ServerSetting getServerSetting(SharedPreferences prefs, int orderOffset, @Override public Intent getSettingsActivityIntent(Context context) { - return XirvikSharedSettingsActivity_.intent(context).get(); + return XirvikSettingsActivity_.intent(context).get(); } @Override @@ -101,13 +101,13 @@ public void removeServerSetting(SharedPreferences prefs, int order) { public void saveServerSetting(final Context context, String server, String token, String rcp, String name) { // Get server order - int key = SeedboxProvider.XirvikShared.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) + 1; + int key = SeedboxProvider.Xirvik.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)) + 1; // Shared preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Check server already exists to replace token - for (int i = 0; i <= SeedboxProvider.XirvikShared.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)); i++) { + for (int i = 0; i <= SeedboxProvider.Xirvik.getSettings().getMaxSeedboxOrder(PreferenceManager.getDefaultSharedPreferences(context)); i++) { if (prefs.getString("seedbox_xirvikshared_server_" + i, "").equals(server)) { key = i; } diff --git a/app/src/main/java/org/transdroid/daemon/DaemonSettings.java b/app/src/main/java/org/transdroid/daemon/DaemonSettings.java index f7fbdad3..7b7f226f 100644 --- a/app/src/main/java/org/transdroid/daemon/DaemonSettings.java +++ b/app/src/main/java/org/transdroid/daemon/DaemonSettings.java @@ -17,6 +17,8 @@ */ package org.transdroid.daemon; +import org.transdroid.core.app.settings.ServerSetting; + /** * A class that contains all the settings for a server daemon to connect. * @@ -24,8 +26,6 @@ */ public final class DaemonSettings { - private static final String DEFAULT_NAME = "Default"; - final private String name; final private Daemon type; final private String address; @@ -102,7 +102,7 @@ public DaemonSettings(String name, Daemon type, String address, int port, boolea } public String getName() { - return (name == null || name.equals("") ? DEFAULT_NAME : name); + return ServerSetting.getServerName(name, address); } public Daemon getType() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d2ffffe4..ca12c464 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -379,12 +379,12 @@ Torrent client Client to connect to Server address - Add Xirvik server via QR - Not a valid Xirvik server QR code + Add Xirvik seedbox via QR + Not a valid Xirvik seedbox QR code Like eplus001.xirvik.com Like semixl001a.xirvik.com Like desharedgbit001.xirvik.com - Cannot retrieve the Xirvik SCGI folder setting; please try again later or correct your server address setting + Cannot retrieve the Xirvik SCGI folder setting; using /RPC2 as default Like abcd123.dediseedbox.com rTorrent diff --git a/app/src/main/res/xml/pref_seedbox_xirvikshared.xml b/app/src/main/res/xml/pref_seedbox_xirvikshared.xml index b59e21f4..e0db0d9c 100644 --- a/app/src/main/res/xml/pref_seedbox_xirvikshared.xml +++ b/app/src/main/res/xml/pref_seedbox_xirvikshared.xml @@ -1,16 +1,16 @@ @@ -39,11 +39,6 @@ android:key="seedbox_xirvikshared_pass" android:title="@string/pref_pass" app:iconSpaceReserved="false" /> -