From ae665eabaf71ef378fcdf4a68dcb4bb6d353996d Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 17 Jun 2014 17:06:15 +0200 Subject: [PATCH] Support multiple network SSID specifiers by sparating them with a | symbol. Fixes #132. --- .../core/app/settings/ServerSetting.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/org/transdroid/core/app/settings/ServerSetting.java b/core/src/org/transdroid/core/app/settings/ServerSetting.java index 6c72cdab..fee29b07 100644 --- a/core/src/org/transdroid/core/app/settings/ServerSetting.java +++ b/core/src/org/transdroid/core/app/settings/ServerSetting.java @@ -272,7 +272,7 @@ public class ServerSetting implements SimpleListItem { * Converts local server settings into an old-style {@link DaemonSettings} object. * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not * be determined - * @param caller + * @param caller A context to access the logger * @return A {@link DaemonSettings} object to execute server commands against */ private DaemonSettings convertToDaemonSettings(String connectedToNetwork, Context caller) { @@ -282,12 +282,21 @@ public class ServerSetting implements SimpleListItem { if (!TextUtils.isEmpty(localNetwork)) Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to " + connectedToNetwork + " and configured local network is " + localNetwork); - return new DaemonSettings(name, type, - !TextUtils.isEmpty(connectedToNetwork) && !TextUtils.isEmpty(localAddress) - && connectedToNetwork.equals(localNetwork) ? localAddress : address, - !TextUtils.isEmpty(connectedToNetwork) && connectedToNetwork.equals(localNetwork) ? localPort : port, - ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os, - downloadDir, ftpUrl, ftpPassword, timeout, alarmOnFinishedDownload, alarmOnNewTorrent, - Integer.toString(key), isAutoGenerated); + String addressToUse = address; + int portToUse = port; + if (!TextUtils.isEmpty(localNetwork) && !TextUtils.isEmpty(localAddress) + && !TextUtils.isEmpty(connectedToNetwork)) { + String[] localNetworks = localNetwork.split("\\|"); + for (String network : localNetworks) { + if (connectedToNetwork.equals(network)) { + addressToUse = localAddress; + portToUse = localPort; + break; + } + } + } + return new DaemonSettings(name, type, addressToUse, portToUse, ssl, sslTrustAll, sslTrustKey, folder, + useAuthentication, username, password, extraPass, os, downloadDir, ftpUrl, ftpPassword, timeout, + alarmOnFinishedDownload, alarmOnNewTorrent, Integer.toString(key), isAutoGenerated); } }