From 2773d27a15827dd342a1e954a32ad14aa5b67561 Mon Sep 17 00:00:00 2001 From: Alon Albert Date: Wed, 3 Jan 2018 09:05:34 +0200 Subject: [PATCH] use field arrays --- .../daemon/Deluge/DelugeAdapter.java | 135 +++++++++--------- .../daemon/Deluge/DelugeCommon.java | 2 +- .../daemon/Deluge/DelugeRpcAdapter.java | 4 +- 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java index 84871177..5eee5d8f 100644 --- a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java @@ -17,72 +17,14 @@ */ package org.transdroid.daemon.Deluge; -import com.android.internalcopy.http.multipart.FilePart; -import com.android.internalcopy.http.multipart.MultipartEntity; -import com.android.internalcopy.http.multipart.Part; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.cookie.Cookie; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.protocol.HTTP; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.transdroid.core.gui.log.Log; -import org.transdroid.daemon.Daemon; -import org.transdroid.daemon.DaemonException; -import org.transdroid.daemon.DaemonException.ExceptionType; -import org.transdroid.daemon.DaemonSettings; -import org.transdroid.daemon.IDaemonAdapter; -import org.transdroid.daemon.Label; -import org.transdroid.daemon.Priority; -import org.transdroid.daemon.Torrent; -import org.transdroid.daemon.TorrentDetails; -import org.transdroid.daemon.TorrentFile; -import org.transdroid.daemon.TorrentStatus; -import org.transdroid.daemon.task.AddByFileTask; -import org.transdroid.daemon.task.AddByMagnetUrlTask; -import org.transdroid.daemon.task.AddByUrlTask; -import org.transdroid.daemon.task.DaemonTask; -import org.transdroid.daemon.task.DaemonTaskFailureResult; -import org.transdroid.daemon.task.DaemonTaskResult; -import org.transdroid.daemon.task.DaemonTaskSuccessResult; -import org.transdroid.daemon.task.GetFileListTask; -import org.transdroid.daemon.task.GetFileListTaskSuccessResult; -import org.transdroid.daemon.task.GetTorrentDetailsTask; -import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; -import org.transdroid.daemon.task.PauseTask; -import org.transdroid.daemon.task.RemoveTask; -import org.transdroid.daemon.task.ResumeTask; -import org.transdroid.daemon.task.RetrieveTask; -import org.transdroid.daemon.task.RetrieveTaskSuccessResult; -import org.transdroid.daemon.task.SetDownloadLocationTask; -import org.transdroid.daemon.task.SetFilePriorityTask; -import org.transdroid.daemon.task.SetLabelTask; -import org.transdroid.daemon.task.SetTrackersTask; -import org.transdroid.daemon.task.SetTransferRatesTask; -import org.transdroid.daemon.util.HttpHelper; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DOWNLOADEDEVER; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_ETA; -import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS; -import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY; +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPRIORITIES; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPROGRESS; +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE_FIELDS_ARRAY; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_INDEX; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_LABEL; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXDOWNLOAD; @@ -92,9 +34,9 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_FILE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_MAGNET; +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_AUTH_LOGIN; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_FORCERECHECK; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET; -import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_AUTH_LOGIN; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_MOVESTORAGE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE_ALL; @@ -119,6 +61,7 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SESSION_ID; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS_FIELDS_ARRAY; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TORRENTS; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS; @@ -130,6 +73,63 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER; +import com.android.internalcopy.http.multipart.FilePart; +import com.android.internalcopy.http.multipart.MultipartEntity; +import com.android.internalcopy.http.multipart.Part; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.cookie.Cookie; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.protocol.HTTP; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.transdroid.core.gui.log.Log; +import org.transdroid.daemon.Daemon; +import org.transdroid.daemon.DaemonException; +import org.transdroid.daemon.DaemonException.ExceptionType; +import org.transdroid.daemon.DaemonSettings; +import org.transdroid.daemon.IDaemonAdapter; +import org.transdroid.daemon.Label; +import org.transdroid.daemon.Priority; +import org.transdroid.daemon.Torrent; +import org.transdroid.daemon.TorrentDetails; +import org.transdroid.daemon.TorrentFile; +import org.transdroid.daemon.TorrentStatus; +import org.transdroid.daemon.task.AddByFileTask; +import org.transdroid.daemon.task.AddByMagnetUrlTask; +import org.transdroid.daemon.task.AddByUrlTask; +import org.transdroid.daemon.task.DaemonTask; +import org.transdroid.daemon.task.DaemonTaskFailureResult; +import org.transdroid.daemon.task.DaemonTaskResult; +import org.transdroid.daemon.task.DaemonTaskSuccessResult; +import org.transdroid.daemon.task.GetFileListTask; +import org.transdroid.daemon.task.GetFileListTaskSuccessResult; +import org.transdroid.daemon.task.GetTorrentDetailsTask; +import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; +import org.transdroid.daemon.task.PauseTask; +import org.transdroid.daemon.task.RemoveTask; +import org.transdroid.daemon.task.ResumeTask; +import org.transdroid.daemon.task.RetrieveTask; +import org.transdroid.daemon.task.RetrieveTaskSuccessResult; +import org.transdroid.daemon.task.SetDownloadLocationTask; +import org.transdroid.daemon.task.SetFilePriorityTask; +import org.transdroid.daemon.task.SetLabelTask; +import org.transdroid.daemon.task.SetTrackersTask; +import org.transdroid.daemon.task.SetTransferRatesTask; +import org.transdroid.daemon.util.HttpHelper; + /** * The daemon adapter from the Deluge torrent client. @@ -203,9 +203,9 @@ public class DelugeAdapter implements IDaemonAdapter { // Array of the fields needed for files listing calls JSONArray ffields = new JSONArray(); - ffields.put(RPC_DETAILS); - ffields.put(RPC_FILEPROGRESS); - ffields.put(RPC_FILEPRIORITIES); + for (String field : RPC_FILE_FIELDS_ARRAY) { + ffields.put(field); + } switch (task.getMethod()) { case Retrieve: @@ -228,8 +228,9 @@ public class DelugeAdapter implements IDaemonAdapter { // Array of the fields needed for files listing calls JSONArray dfields = new JSONArray(); - dfields.put(RPC_TRACKERS); - dfields.put(RPC_TRACKER_STATUS); + for (String field : RPC_DETAILS_FIELDS_ARRAY) { + dfields.put(field); + } // Request file listing of a torrent params.put(task.getTargetTorrent().getUniqueID()); // torrent_id diff --git a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java index 34cf3771..3a50e963 100644 --- a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java +++ b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java @@ -88,7 +88,7 @@ class DelugeCommon { static final String RPC_TRACKER_URL = "url"; static final String RPC_UPLOADEDEVER = "total_uploaded"; - static final String[] RPC_STATUS_FIELDS_ARRAY = { + static final String[] RPC_DETAILS_FIELDS_ARRAY = { RPC_TRACKERS, RPC_TRACKER_STATUS, }; diff --git a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java index 1119e909..a3b38d55 100644 --- a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java @@ -59,7 +59,7 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEUPLOAD; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; -import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS_FIELDS_ARRAY; +import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS_FIELDS_ARRAY; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS; import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS; @@ -232,7 +232,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { final Map response = (Map) client.sendRequest( RPC_METHOD_STATUS, task.getTargetTorrent().getUniqueID(), - RPC_STATUS_FIELDS_ARRAY); + RPC_DETAILS_FIELDS_ARRAY); //noinspection unchecked final List> trackerResponses = (List>) response