From 9d2e11a8dff151e7f0cebfa0419c30422e501864 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Fri, 10 Jul 2020 18:30:34 -0400 Subject: [PATCH] Miscellaneous Java lint cleanup --- .../app/settings/ApplicationSettings.java | 3 +- .../core/gui/lists/LocalTorrent.java | 12 +++--- .../core/gui/lists/MergeAdapter.java | 5 +-- .../core/gui/lists/PiecesMapView.java | 4 +- .../core/gui/lists/SimpleListItemAdapter.java | 2 +- .../gui/lists/TorrentFilePriorityLayout.java | 4 +- .../core/gui/lists/TorrentStatusLayout.java | 4 +- .../core/gui/log/DatabaseHelper.java | 2 +- .../gui/navigation/FilterListItemAdapter.java | 2 +- .../SelectionModificationSpinner.java | 2 +- .../core/gui/rss/RssFeedsActivity.java | 4 +- .../core/gui/rss/RssfeedLoader.java | 5 +-- .../core/gui/rss/RssitemStatusLayout.java | 4 +- .../search/SearchSettingsDropDownAdapter.java | 2 +- .../gui/settings/MainSettingsActivity.java | 25 ++++++----- .../core/gui/settings/RssfeedPreference.java | 16 ++++---- .../gui/settings/RssfeedSettingsActivity.java | 19 ++++----- .../core/gui/settings/ServerPreference.java | 16 ++++---- .../gui/settings/ServerSettingsActivity.java | 19 ++++----- .../gui/settings/WebsearchPreference.java | 16 ++++---- .../settings/WebsearchSettingsActivity.java | 19 ++++----- .../core/seedbox/SeedboxPreference.java | 16 ++++---- .../core/service/ServerCheckerJobRunner.java | 5 ++- .../org/transdroid/daemon/DaemonSettings.java | 4 +- .../org/transdroid/daemon/DummyAdapter.java | 7 +--- .../org/transdroid/daemon/TorrentDetails.java | 12 +++--- .../daemon/TorrentFilesComparator.java | 8 ++-- .../transdroid/daemon/TorrentsComparator.java | 28 ++++++------- .../adapters/bitComet/BitCometAdapter.java | 10 +++-- .../buffaloNas/BuffaloNasAdapter.java | 8 ++-- .../daemon/adapters/kTorrent/StatsParser.java | 41 +++++++++---------- .../adapters/rTorrent/RTorrentAdapter.java | 16 ++++---- .../adapters/synology/SynologyAdapter.java | 9 ++-- .../daemon/adapters/tfb4rt/StatsParser.java | 12 +++--- .../transmission/TransmissionAdapter.java | 3 +- .../adapters/uTorrent/UTorrentAdapter.java | 18 ++++---- .../daemon/adapters/vuze/VuzeAdapter.java | 19 ++++----- .../adapters/vuze/VuzeXmlOverHttpClient.java | 6 +-- .../transdroid/daemon/util/Collections2.java | 6 +-- .../daemon/util/SelfSignedTrustManager.java | 4 +- 40 files changed, 197 insertions(+), 220 deletions(-) diff --git a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java index da867be5..7c0bc0a0 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java @@ -74,8 +74,7 @@ public class ApplicationSettings { * @return A list of all stored server settings objects */ public List getAllServerSettings() { - List all = new ArrayList<>(); - all.addAll(getNormalServerSettings()); + List all = new ArrayList<>(getNormalServerSettings()); for (SeedboxProvider provider : SeedboxProvider.values()) { all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size())); } diff --git a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java index 8a89ec5d..9ab09507 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java @@ -63,8 +63,6 @@ public class LocalTorrent { switch (e.getType()) { case MethodUnsupported: return R.string.error_unsupported; - case ConnectionError: - return R.string.error_httperror; case UnexpectedResponse: return R.string.error_jsonresponseerror; case ParsingFailed: @@ -75,6 +73,7 @@ public class LocalTorrent { return R.string.error_401; case FileAccessError: return R.string.error_torrentfile; + case ConnectionError: default: return R.string.error_httperror; } @@ -201,16 +200,15 @@ public class LocalTorrent { public String getProgressSpeedText(Resources r) { switch (t.getStatusCode()) { - case Waiting: - case Checking: - case Paused: - case Queued: - return ""; case Downloading: return r.getString(R.string.status_speed_down, FileSizeConverter.getSize(t.getRateDownload()) + "/s") + " " + r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s"); case Seeding: return r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s"); + case Waiting: + case Checking: + case Paused: + case Queued: default: return ""; } diff --git a/app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java b/app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java index 37349792..fd0f1c87 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java @@ -26,6 +26,7 @@ import android.widget.SectionIndexer; import android.widget.TextView; import java.util.ArrayList; +import java.util.Arrays; /** * An adapter that can contain many other adapters and shows them in sequence. Taken from @@ -293,9 +294,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer { Object[] curSections = ((SectionIndexer) piece).getSections(); if (curSections != null) { - for (Object section : curSections) { - sections.add(section); - } + sections.addAll(Arrays.asList(curSections)); } } } diff --git a/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java b/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java index 18c27b5b..771e78fc 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java @@ -111,9 +111,9 @@ class PiecesMapView extends View { piecesScaled.add(state); } - String scaledPiecesString = ""; + StringBuilder scaledPiecesString = new StringBuilder(); for (int s : piecesScaled) { - scaledPiecesString += s; + scaledPiecesString.append(s); } // Draw downscaled peices diff --git a/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java b/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java index 24d58a6c..a84c93a6 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java @@ -67,7 +67,7 @@ public class SimpleListItemAdapter extends BaseAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { SimpleListItemView filterItemView; - if (convertView == null || !(convertView instanceof SimpleListItemView)) { + if (!(convertView instanceof SimpleListItemView)) { filterItemView = SimpleListItemView_.build(context); } else { filterItemView = (SimpleListItemView) convertView; diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java index 456d39db..a87e75e7 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java @@ -72,9 +72,7 @@ public class TorrentFilePriorityLayout extends RelativeLayout { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - int height = getHeight(); - int width = WIDTH; - fullRect.set(0, 0, width, height); + fullRect.set(0, 0, WIDTH, getHeight()); if (priority == null) { return; diff --git a/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java b/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java index 04dace96..340cfe6b 100644 --- a/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java +++ b/app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java @@ -80,9 +80,7 @@ public class TorrentStatusLayout extends RelativeLayout { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - int height = getHeight(); - int width = WIDTH; - fullRect.set(0, 0, width, height); + fullRect.set(0, 0, WIDTH, getHeight()); if (status == null) { return; diff --git a/app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java b/app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java index 987fbba3..6bd7e965 100644 --- a/app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java @@ -59,7 +59,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { switch (oldVersion) { case 1: TableUtils.createTable(connectionSource, ErrorLogEntry.class); - /*case 1: + /*case 2: etc...*/ } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java index 91b4ac83..6ba17f95 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java @@ -64,7 +64,7 @@ public class FilterListItemAdapter extends BaseAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { FilterListItemView filterItemView; - if (convertView == null || !(convertView instanceof SimpleListItemView)) { + if (!(convertView instanceof SimpleListItemView)) { filterItemView = FilterListItemView_.build(context); } else { filterItemView = (FilterListItemView) convertView; diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java b/app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java index c14cf00f..b96588f9 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java @@ -95,7 +95,7 @@ public class SelectionModificationSpinner extends AppCompatSpinner { * Local adapter that holds the actions which can be performed and a title text view that always shows instead of a * list item as in a normal spinner. */ - private class SelectionDropDownAdapter extends ArrayAdapter { + private static class SelectionDropDownAdapter extends ArrayAdapter { protected TextView titleView = null; diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java index 4dc23707..317cc715 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java @@ -139,7 +139,7 @@ public class RssFeedsActivity extends AppCompatActivity { try { hasRemoteFeeds = remoteConnection.getRemoteRssChannels(log).size() > 0; - } catch (DaemonException e) { + } catch (DaemonException ignored) { } if (hasRemoteFeeds) { @@ -279,7 +279,7 @@ public class RssFeedsActivity extends AppCompatActivity { IDaemonAdapter currentConnection = this.getCurrentConnection(); // remote rss not supported for this connection type - if (currentConnection instanceof RemoteRssSupplier == false) { + if (!(currentConnection instanceof RemoteRssSupplier)) { return; } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java index d4137e22..d39503da 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java @@ -56,15 +56,15 @@ public class RssfeedLoader { Date pubDate = channel.getItems().get(0).getPubdate(); usePublishDate = pubDate != null && pubDate.getTime() > 0; } + newCount = 0; if (usePublishDate) { // Count the number of new items, based on the date that this RSS feed was last viewed by the user - newCount = 0; List items = channel.getItems(); // Reverse-order sort the items on their published date Collections.sort(items, new Comparator() { @Override public int compare(Item lhs, Item rhs) { - return 0 - lhs.getPubdate().compareTo(rhs.getPubdate()); + return -lhs.getPubdate().compareTo(rhs.getPubdate()); } }); for (Item item : items) { @@ -77,7 +77,6 @@ public class RssfeedLoader { } } else { // Use the url of the last RSS item the last time the feed was viewed by the user to count new items - newCount = 0; boolean isNew = true; for (Item item : channel.getItems()) { if (item.getTheLink() != null && setting.getLastViewedItemUrl() != null && item.getTheLink().equals(setting.getLastViewedItemUrl())) { diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java b/app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java index b9a31ae3..c26cc11a 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java @@ -66,9 +66,7 @@ public class RssitemStatusLayout extends RelativeLayout { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - int height = getHeight(); - int width = WIDTH; - fullRect.set(0, 0, width, height); + fullRect.set(0, 0, WIDTH, getHeight()); if (isNew == null) { return; diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java b/app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java index ef53bb89..d4646725 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java @@ -43,7 +43,7 @@ public class SearchSettingsDropDownAdapter extends FilterListItemAdapter { public View getView(int position, View convertView, ViewGroup parent) { // This returns the item to show in the action bar spinner SearchSettingSelectionView filterItemView; - if (convertView == null || !(convertView instanceof SearchSettingSelectionView)) { + if (!(convertView instanceof SearchSettingSelectionView)) { filterItemView = SearchSettingSelectionView_.build(context); } else { filterItemView = (SearchSettingSelectionView) convertView; 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 862cd6e2..24fafbce 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 @@ -230,8 +230,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { } // Allow selection of the default server ListPreference defaultServerPreference = (ListPreference) findPreference("header_defaultserver"); - defaultServerPreference.setEntries(serverNames.toArray(new String[serverNames.size()])); - defaultServerPreference.setEntryValues(serverCodes.toArray(new String[serverCodes.size()])); + defaultServerPreference.setEntries(serverNames.toArray(new String[0])); + defaultServerPreference.setEntryValues(serverCodes.toArray(new String[0])); // Add existing RSS feeds if (!enableRssUi) { @@ -276,8 +276,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity { siteValues.add(websearch.getKey()); } // Supply the Preference list names and values - setSite.setEntries(siteNames.toArray(new String[siteNames.size()])); - setSite.setEntryValues(siteValues.toArray(new String[siteValues.size()])); + setSite.setEntries(siteNames.toArray(new String[0])); + setSite.setEntryValues(siteValues.toArray(new String[0])); } @@ -289,15 +289,14 @@ public class MainSettingsActivity extends PreferenceCompatActivity { @Override protected Dialog onCreateDialog(int id) { - switch (id) { - case DIALOG_ADDSEEDBOX: - // Open dialog to pick one of the supported seedbox providers (or a normal server) - String[] seedboxes = new String[SeedboxProvider.values().length + 1]; - seedboxes[0] = getString(R.string.pref_addserver_normal); - for (int i = 0; i < seedboxes.length - 1; i++) { - seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.values()[i].getSettings().getName()); - } - return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create(); + 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 + 1]; + seedboxes[0] = getString(R.string.pref_addserver_normal); + for (int i = 0; i < seedboxes.length - 1; i++) { + seedboxes[i + 1] = getString(R.string.pref_seedbox_addseedbox, SeedboxProvider.values()[i].getSettings().getName()); + } + return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create(); } return null; } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java index 9cc64812..9049c021 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java @@ -33,17 +33,17 @@ public class RssfeedPreference extends Preference { private RssfeedSetting rssfeedSetting; private OnRssfeedClickedListener onRssfeedClickedListener = null; - private OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onRssfeedClickedListener != null) - onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting); - return true; - } - }; public RssfeedPreference(Context context) { super(context); + OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + if (onRssfeedClickedListener != null) + onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting); + return true; + } + }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java index a9db25ca..b58d59a3 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java @@ -74,16 +74,15 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { @Override protected Dialog onCreateDialog(int id) { - switch (id) { - case DIALOG_CONFIRMREMOVE: - return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); - finish(); - } - }).setNegativeButton(android.R.string.cancel, null).create(); + if (id == DIALOG_CONFIRMREMOVE) { + return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) + .setPositiveButton(android.R.string.ok, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); + finish(); + } + }).setNegativeButton(android.R.string.cancel, null).create(); } return null; } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java index 17054034..418bdbd9 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java @@ -33,17 +33,17 @@ public class ServerPreference extends Preference { protected ServerSetting serverSetting; private OnServerClickedListener onServerClickedListener = null; - private OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onServerClickedListener != null) - onServerClickedListener.onServerClicked(serverSetting); - return true; - } - }; public ServerPreference(Context context) { super(context); + OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + if (onServerClickedListener != null) + onServerClickedListener.onServerClicked(serverSetting); + return true; + } + }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java index fa4cf585..acfddb1c 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java @@ -114,16 +114,15 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { @Override protected Dialog onCreateDialog(int id) { - switch (id) { - case DIALOG_CONFIRMREMOVE: - return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); - finish(); - } - }).setNegativeButton(android.R.string.cancel, null).create(); + if (id == DIALOG_CONFIRMREMOVE) { + return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) + .setPositiveButton(android.R.string.ok, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); + finish(); + } + }).setNegativeButton(android.R.string.cancel, null).create(); } return null; } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java index 4d989ac8..a1ccea1d 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java @@ -33,17 +33,17 @@ public class WebsearchPreference extends Preference { private WebsearchSetting websearchSetting; private OnWebsearchClickedListener onWebsearchClickedListener = null; - private OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onWebsearchClickedListener != null) - onWebsearchClickedListener.onWebsearchClicked(websearchSetting); - return true; - } - }; public WebsearchPreference(Context context) { super(context); + OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + if (onWebsearchClickedListener != null) + onWebsearchClickedListener.onWebsearchClicked(websearchSetting); + return true; + } + }; setOnPreferenceClickListener(onPreferenceClicked); setIconSpaceReserved(false); } diff --git a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java index 923042bb..4ddc1f50 100644 --- a/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java @@ -70,16 +70,15 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity { @Override protected Dialog onCreateDialog(int id) { - switch (id) { - case DIALOG_CONFIRMREMOVE: - return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) - .setPositiveButton(android.R.string.ok, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); - finish(); - } - }).setNegativeButton(android.R.string.cancel, null).create(); + if (id == DIALOG_CONFIRMREMOVE) { + return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) + .setPositiveButton(android.R.string.ok, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); + finish(); + } + }).setNegativeButton(android.R.string.cancel, null).create(); } return null; } diff --git a/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java b/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java index 8211443e..bca53a03 100644 --- a/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java +++ b/app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java @@ -33,17 +33,17 @@ public class SeedboxPreference extends ServerPreference { private SeedboxProvider provider = null; private OnSeedboxClickedListener onSeedboxClickedListener = null; private int onSeedboxClickedListenerOffset = 0; - private OnPreferenceClickListener onSeedboxPreferenceClicked = new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - if (onSeedboxClickedListener != null) - onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset); - return true; - } - }; public SeedboxPreference(Context context) { super(context); + OnPreferenceClickListener onSeedboxPreferenceClicked = new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + if (onSeedboxClickedListener != null) + onSeedboxClickedListener.onSeedboxClicked(serverSetting, provider, onSeedboxClickedListenerOffset); + return true; + } + }; setOnPreferenceClickListener(onSeedboxPreferenceClicked); } diff --git a/app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java b/app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java index d86922ca..42b9a384 100644 --- a/app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java +++ b/app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java @@ -171,10 +171,11 @@ public class ServerCheckerJobRunner { // No notification to show continue; } - String forString = ""; + StringBuilder forStringBuilder = new StringBuilder(); for (Torrent affected : affectedTorrents) { - forString += affected.getName() + ", "; + forStringBuilder.append(affected.getName()).append(", "); } + String forString = forStringBuilder.toString(); forString = forString.substring(0, forString.length() - 2); // Build the basic notification diff --git a/app/src/main/java/org/transdroid/daemon/DaemonSettings.java b/app/src/main/java/org/transdroid/daemon/DaemonSettings.java index 4620024e..a9574670 100644 --- a/app/src/main/java/org/transdroid/daemon/DaemonSettings.java +++ b/app/src/main/java/org/transdroid/daemon/DaemonSettings.java @@ -191,11 +191,11 @@ public final class DaemonSettings { public String getHumanReadableIdentifier() { if (isAutoGenerated) { // Hide the 'implementation details'; just give the username and server - return (this.shouldUseAuthentication() && this.getUsername() != null && this.getUsername() != "" ? this + return (this.shouldUseAuthentication() && this.getUsername() != null && !this.getUsername().equals("") ? this .getUsername() + "@" : "") + getAddress(); } return (this.ssl ? "https://" : "http://") - + (this.shouldUseAuthentication() && this.getUsername() != null && this.getUsername() != "" ? this + + (this.shouldUseAuthentication() && this.getUsername() != null && !this.getUsername().equals("") ? this .getUsername() + "@" : "") + getAddress() + ":" + getPort() + (Daemon.supportsCustomFolder(getType()) && getFolder() != null ? getFolder() : ""); } diff --git a/app/src/main/java/org/transdroid/daemon/DummyAdapter.java b/app/src/main/java/org/transdroid/daemon/DummyAdapter.java index aa5354d7..f2facb3a 100644 --- a/app/src/main/java/org/transdroid/daemon/DummyAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/DummyAdapter.java @@ -201,6 +201,8 @@ public class DummyAdapter implements IDaemonAdapter { case Pause: + case Resume: + task.getTargetTorrent().mimicPause(); return new DaemonTaskSuccessResult(task); @@ -211,11 +213,6 @@ public class DummyAdapter implements IDaemonAdapter { } return new DaemonTaskSuccessResult(task); - case Resume: - - task.getTargetTorrent().mimicPause(); - return new DaemonTaskSuccessResult(task); - case ResumeAll: for (Torrent torrent : dummyTorrents) { diff --git a/app/src/main/java/org/transdroid/daemon/TorrentDetails.java b/app/src/main/java/org/transdroid/daemon/TorrentDetails.java index b5a6947c..6c6a32a0 100644 --- a/app/src/main/java/org/transdroid/daemon/TorrentDetails.java +++ b/app/src/main/java/org/transdroid/daemon/TorrentDetails.java @@ -81,11 +81,11 @@ public final class TorrentDetails implements Parcelable { */ public String getTrackersText() { // Build a string with one tracker URL per line - String trackersText = ""; + StringBuilder trackersText = new StringBuilder(); for (String tracker : trackers) { - trackersText += (trackersText.length() == 0 ? "" : "\n") + tracker; + trackersText.append(trackersText.length() == 0 ? "" : "\n").append(tracker); } - return trackersText; + return trackersText.toString(); } /** @@ -95,11 +95,11 @@ public final class TorrentDetails implements Parcelable { */ public String getErrorsText() { // Build a string with one tracker error per line - String errorsText = ""; + StringBuilder errorsText = new StringBuilder(); for (String error : errors) { - errorsText += (errorsText.length() == 0 ? "" : "\n") + error; + errorsText.append(errorsText.length() == 0 ? "" : "\n").append(error); } - return errorsText; + return errorsText.toString(); } public List getPieces() { diff --git a/app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java b/app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java index 331c3bff..6b024fec 100644 --- a/app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java +++ b/app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java @@ -49,18 +49,18 @@ public class TorrentFilesComparator implements Comparator { case PartDone: return Float.compare(file1.getPartDone(), file2.getPartDone()); case TotalSize: - return Long.valueOf(file1.getTotalSize()).compareTo(file2.getTotalSize()); + return Long.compare(file1.getTotalSize(), file2.getTotalSize()); default: return alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase()); } } else { switch (sortBy) { case PartDone: - return 0 - Float.compare(file1.getPartDone(), file2.getPartDone()); + return -Float.compare(file1.getPartDone(), file2.getPartDone()); case TotalSize: - return 0 - Long.valueOf(file1.getTotalSize()).compareTo(file2.getTotalSize()); + return -Long.compare(file1.getTotalSize(), file2.getTotalSize()); default: - return 0 - alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase()); + return -alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase()); } } } diff --git a/app/src/main/java/org/transdroid/daemon/TorrentsComparator.java b/app/src/main/java/org/transdroid/daemon/TorrentsComparator.java index ba0cba2a..ffd4c2d8 100644 --- a/app/src/main/java/org/transdroid/daemon/TorrentsComparator.java +++ b/app/src/main/java/org/transdroid/daemon/TorrentsComparator.java @@ -67,42 +67,42 @@ public class TorrentsComparator implements Comparator { case DateDone: return tor1.getDateDone().compareTo(tor2.getDateDone()); case Percent: - return Float.valueOf(tor1.getDownloadedPercentage()).compareTo(tor2.getDownloadedPercentage()); + return Float.compare(tor1.getDownloadedPercentage(), tor2.getDownloadedPercentage()); case DownloadSpeed: - return Integer.valueOf(tor1.getRateDownload()).compareTo(tor2.getRateDownload()); + return Integer.compare(tor1.getRateDownload(), tor2.getRateDownload()); case UploadSpeed: - return Integer.valueOf(tor1.getRateUpload()).compareTo(tor2.getRateUpload()); + return Integer.compare(tor1.getRateUpload(), tor2.getRateUpload()); case Ratio: - return Double.valueOf(tor1.getRatio()).compareTo(tor2.getRatio()); + return Double.compare(tor1.getRatio(), tor2.getRatio()); case Size: - return Double.valueOf(tor1.getTotalSize()).compareTo((double) tor2.getTotalSize()); + return Double.compare(tor1.getTotalSize(), (double) tor2.getTotalSize()); default: return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); } } else { switch (sortBy) { case Status: - return 0 - tor1.getStatusCode().compareStatusCodeTo(tor2.getStatusCode()); + return -tor1.getStatusCode().compareStatusCodeTo(tor2.getStatusCode()); case DateAdded: if (tor1.getDateAdded() == null) return 1; if (tor2.getDateAdded() == null) return -1; - return 0 - tor1.getDateAdded().compareTo(tor2.getDateAdded()); + return -tor1.getDateAdded().compareTo(tor2.getDateAdded()); case DateDone: - return 0 - tor1.getDateDone().compareTo(tor2.getDateDone()); + return -tor1.getDateDone().compareTo(tor2.getDateDone()); case Percent: - return 0 - (Float.valueOf(tor1.getDownloadedPercentage()).compareTo(tor2.getDownloadedPercentage())); + return -(Float.compare(tor1.getDownloadedPercentage(), tor2.getDownloadedPercentage())); case DownloadSpeed: - return 0 - (Integer.valueOf(tor1.getRateDownload()).compareTo(tor2.getRateDownload())); + return -(Integer.compare(tor1.getRateDownload(), tor2.getRateDownload())); case UploadSpeed: - return 0 - (Integer.valueOf(tor1.getRateUpload()).compareTo(tor2.getRateUpload())); + return -(Integer.compare(tor1.getRateUpload(), tor2.getRateUpload())); case Ratio: - return 0 - Double.valueOf(tor1.getRatio()).compareTo(tor2.getRatio()); + return -Double.compare(tor1.getRatio(), tor2.getRatio()); case Size: - return 0 - Double.valueOf(tor1.getTotalSize()).compareTo((double) tor2.getTotalSize()); + return -Double.compare(tor1.getTotalSize(), (double) tor2.getTotalSize()); default: - return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); + return -alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); } } } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java index 08f8267d..1dbce241 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java @@ -107,7 +107,7 @@ public class BitCometAdapter implements IDaemonAdapter { } else if (size.endsWith("B")) { return (long) (Float.parseFloat(size.substring(0, size.indexOf("B")))); } - } catch (Exception e) { + } catch (Exception ignored) { } return 0; } @@ -277,15 +277,17 @@ public class BitCometAdapter implements IDaemonAdapter { // Add the parameters to the query string boolean first = true; + StringBuilder urlBuilder = new StringBuilder(url); for (NameValuePair param : params) { if (first) { - url += "?"; + urlBuilder.append("?"); first = false; } else { - url += "&"; + urlBuilder.append("&"); } - url += param.getName() + "=" + param.getValue(); + urlBuilder.append(param.getName()).append("=").append(param.getValue()); } + url = urlBuilder.toString(); // Make the request HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url))); diff --git a/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java index 04de8c48..7adf75dc 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java @@ -180,15 +180,17 @@ public class BuffaloNasAdapter implements IDaemonAdapter { // Add the parameters to the query string boolean first = true; + StringBuilder urlBuilder = new StringBuilder(url); for (NameValuePair param : params) { if (first) { - url += "?"; + urlBuilder.append("?"); first = false; } else { - url += "&"; + urlBuilder.append("&"); } - url += param.getName() + "=" + param.getValue(); + urlBuilder.append(param.getName()).append("=").append(param.getValue()); } + url = urlBuilder.toString(); // Make the request HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url))); diff --git a/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java b/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java index a4c34916..f32e25d8 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java @@ -209,12 +209,13 @@ public class StatsParser { * @return The size in number of kB */ public static long convertSize(String size) { + String s = size.substring(0, size.length() - 4); if (size.endsWith("GiB")) { - return (long) (convertStringToFloat(size.substring(0, size.length() - 4)) * 1024 * 1024 * 1024); + return (long) (convertStringToFloat(s) * 1024 * 1024 * 1024); } else if (size.endsWith("MiB")) { - return (long) (convertStringToFloat(size.substring(0, size.length() - 4)) * 1024 * 1024); + return (long) (convertStringToFloat(s) * 1024 * 1024); } else if (size.endsWith("KiB")) { - return (long) (convertStringToFloat(size.substring(0, size.length() - 4)) * 1024); + return (long) (convertStringToFloat(s) * 1024); } else if (size.endsWith("B")) { return convertStringToFloat(size.substring(0, size.length() - 2)).longValue(); } @@ -228,10 +229,11 @@ public class StatsParser { * @return The rate (or speed) in KiB/s */ public static int convertRate(String rate) { + String s = rate.substring(0, rate.length() - 6); if (rate.endsWith("MiB/s")) { - return (int) (convertStringToFloat(rate.substring(0, rate.length() - 6)) * 1024 * 1024); + return (int) (convertStringToFloat(s) * 1024 * 1024); } else if (rate.endsWith("KiB/s")) { - return (int) (convertStringToFloat(rate.substring(0, rate.length() - 6)) * 1024); + return (int) (convertStringToFloat(s) * 1024); } else if (rate.endsWith("B/s")) { return convertStringToFloat(rate.substring(0, rate.length() - 4)).intValue(); } @@ -245,22 +247,19 @@ public class StatsParser { * @return The status as TorrentStatus or Unknown if it could not been parsed */ private static TorrentStatus convertStatus(String status) { - if (status.equals("Downloading")) { - return TorrentStatus.Downloading; - } else if (status.equals("Seeding")) { - return TorrentStatus.Seeding; - } else if (status.equals("Stopped")) { - return TorrentStatus.Paused; - } else if (status.equals("Stalled")) { - return TorrentStatus.Paused; - } else if (status.equals("Download completed")) { - return TorrentStatus.Paused; - } else if (status.equals("Not started")) { - return TorrentStatus.Paused; - } else if (status.equals("Stalled")) { - return TorrentStatus.Waiting; - } else if (status.equals("Checking data")) { - return TorrentStatus.Checking; + switch (status) { + case "Downloading": + return TorrentStatus.Downloading; + case "Seeding": + return TorrentStatus.Seeding; + case "Stopped": + case "Download completed": + case "Not started": + return TorrentStatus.Paused; + case "Stalled": + return TorrentStatus.Waiting; + case "Checking data": + return TorrentStatus.Checking; } return TorrentStatus.Unknown; } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java index 62a8c914..91f31a33 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java @@ -332,13 +332,15 @@ public class RTorrentAdapter implements IDaemonAdapter { initialise(); } - String params = ""; + StringBuilder paramsBuilder = new StringBuilder(); for (Object arg : arguments) { - params += " " + arg.toString(); + paramsBuilder.append(" ").append(arg.toString()); } + String params = paramsBuilder.toString(); + String s = params.length() > 100 ? params.substring(0, 100) + "..." : params; try { log.d(LOG_NAME, "Calling " + serverMethod + " with params [" + - (params.length() > 100 ? params.substring(0, 100) + "..." : params) + " ]"); + s + " ]"); return rpcclient.call(serverMethod, arguments); } catch (IllegalArgumentException e) { log.d(LOG_NAME, "Using " + buildWebUIUrl() + ": " + e.toString()); @@ -353,7 +355,7 @@ public class RTorrentAdapter implements IDaemonAdapter { } throw new DaemonException(ExceptionType.ConnectionError, "Error making call to " + serverMethod + " with params [" + - (params.length() > 100 ? params.substring(0, 100) + "..." : params) + " ]: " + + s + " ]: " + e.toString()); } @@ -386,7 +388,7 @@ public class RTorrentAdapter implements IDaemonAdapter { private List onTorrentsRetrieved(Object response) throws DaemonException { - if (response == null || !(response instanceof Object[])) { + if (!(response instanceof Object[])) { throw new DaemonException(ExceptionType.ParsingFailed, "Response on retrieveing torrents did not return a list of objects"); @@ -532,7 +534,7 @@ public class RTorrentAdapter implements IDaemonAdapter { private List onTorrentFilesRetrieved(Object response, Torrent torrent) throws DaemonException { - if (response == null || !(response instanceof Object[])) { + if (!(response instanceof Object[])) { throw new DaemonException(ExceptionType.ParsingFailed, "Response on retrieveing torrent files did not return a list of objects"); @@ -639,7 +641,7 @@ public class RTorrentAdapter implements IDaemonAdapter { private TorrentDetails onTorrentDetailsRetrieved(Log log, Object response) throws DaemonException { - if (response == null || !(response instanceof Object[])) { + if (!(response instanceof Object[])) { throw new DaemonException(ExceptionType.ParsingFailed, "Response on retrieveing trackers did not return a list of objects"); diff --git a/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java index c23da538..ea49facf 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java @@ -91,8 +91,6 @@ public class SynologyAdapter implements IDaemonAdapter { switch (task.getMethod()) { case Retrieve: return new RetrieveTaskSuccessResult((RetrieveTask) task, tasksList(log), null); - case GetStats: - return null; case GetTorrentDetails: tid = task.getTargetTorrent().getUniqueID(); return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, @@ -129,10 +127,6 @@ public class SynologyAdapter implements IDaemonAdapter { case ResumeAll: resumeAllTasks(log); return new DaemonTaskSuccessResult(task); - case SetDownloadLocation: - return null; - case SetFilePriorities: - return null; case SetTransferRates: SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; int uploadRate = ratesTask.getUploadRate() == null ? 0 : ratesTask.getUploadRate(); @@ -140,6 +134,9 @@ public class SynologyAdapter implements IDaemonAdapter { setTransferRates(log, uploadRate, downloadRate); return new DaemonTaskSuccessResult(task); case SetAlternativeMode: + case GetStats: + case SetDownloadLocation: + case SetFilePriorities: default: return null; } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java b/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java index 9ff6ab24..96d83c65 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java @@ -163,12 +163,13 @@ public class StatsParser { * @return The size in number of kB */ private static long convertSize(String size) { + float v = Float.parseFloat(size.substring(0, size.length() - 3)); if (size.endsWith("GB")) { - return (long) (Float.parseFloat(size.substring(0, size.length() - 3)) * 1024 * 1024 * 1024); + return (long) (v * 1024 * 1024 * 1024); } else if (size.endsWith("MB")) { - return (long) (Float.parseFloat(size.substring(0, size.length() - 3)) * 1024 * 1024); + return (long) (v * 1024 * 1024); } else if (size.endsWith("kB")) { - return (long) (Float.parseFloat(size.substring(0, size.length() - 3)) * 1024); + return (long) (v * 1024); } else if (size.endsWith("B")) { return (long) (Float.parseFloat(size.substring(0, size.length() - 2))); } @@ -216,10 +217,11 @@ public class StatsParser { * @return The rate (or speed) in kB/s */ private static int convertRate(String rate) { + float v = Float.parseFloat(rate.substring(0, rate.length() - 5)); if (rate.endsWith("MB/s")) { - return (int) (Float.parseFloat(rate.substring(0, rate.length() - 5)) * 1024 * 1024); + return (int) (v * 1024 * 1024); } else if (rate.endsWith("kB/s")) { - return (int) (Float.parseFloat(rate.substring(0, rate.length() - 5)) * 1024); + return (int) (v * 1024); } else if (rate.endsWith("B/s")) { return (int) Float.parseFloat(rate.substring(0, rate.length() - 4)); } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java index a21e0940..b03ef3d7 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java @@ -567,11 +567,10 @@ public class TransmissionAdapter implements IDaemonAdapter { case 2: return TorrentStatus.Checking; case 3: + case 5: return TorrentStatus.Queued; case 4: return TorrentStatus.Downloading; - case 5: - return TorrentStatus.Queued; case 6: return TorrentStatus.Seeding; } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java index 1d46fcba..ace7092b 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java @@ -259,9 +259,9 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { // Set priorities of the files of some torrent SetFilePriorityTask prioTask = (SetFilePriorityTask) task; - String prioUrl = "&p=" + convertPriority(prioTask.getNewPriority()); + StringBuilder prioUrl = new StringBuilder("&p=" + convertPriority(prioTask.getNewPriority())); for (TorrentFile forFile : prioTask.getForFiles()) { - prioUrl += "&f=" + forFile.getKey(); + prioUrl.append("&f=").append(forFile.getKey()); } makeUtorrentRequest(log, "&action=setprio" + RPC_URL_HASH + task.getTargetTorrent().getUniqueID() + prioUrl); @@ -291,13 +291,13 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { // Set the trackers of some torrent SetTrackersTask trackersTask = (SetTrackersTask) task; // Build list of tracker lines, separated by a \r\n - String newTrackersText = ""; + StringBuilder newTrackersText = new StringBuilder(); for (String tracker : trackersTask.getNewTrackers()) { - newTrackersText += (newTrackersText.length() == 0 ? "" : "\r\n") + tracker; + newTrackersText.append(newTrackersText.length() == 0 ? "" : "\r\n").append(tracker); } makeUtorrentRequest(log, "&action=setprops" + RPC_URL_HASH + trackersTask.getTargetTorrent().getUniqueID() + - "&s=trackers&v=" + URLEncoder.encode(newTrackersText, "UTF-8")); + "&s=trackers&v=" + URLEncoder.encode(newTrackersText.toString(), "UTF-8")); return new DaemonTaskSuccessResult(task); case ForceRecheck: @@ -552,7 +552,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { for (int i = 0; i < results.length(); i++) { JSONArray tor = results.getJSONArray(i); String name = tor.getString(RPC_NAME_IDX); - boolean downloaded = (tor.getLong(RPC_PARTDONE) == 1000l); + boolean downloaded = (tor.getLong(RPC_PARTDONE) == 1000L); float available = ((float) tor.getInt(RPC_AVAILABILITY_IDX)) / 65536f; // Integer in 1/65536ths // The full torrent path is not available in uTorrent web UI API // Guess the torrent's directory based on the user-specific default download dir and the torrent name @@ -641,11 +641,11 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { ArrayList torrents = parseJsonRetrieveTorrents(result.getJSONArray("torrents")); // Build a string of hashes of all the torrents - String hashes = ""; + StringBuilder hashes = new StringBuilder(); for (Torrent torrent : torrents) { - hashes += RPC_URL_HASH + torrent.getUniqueID(); + hashes.append(RPC_URL_HASH).append(torrent.getUniqueID()); } - return hashes; + return hashes.toString(); } diff --git a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java index 488c79d6..ba93a12c 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java @@ -256,11 +256,9 @@ public class VuzeAdapter implements IDaemonAdapter { throw new DaemonException(ExceptionType.UnexpectedResponse, "No plugin config ID returned on getPluginconfig"); } savedPluginConfigID = (Long) config.get("_object_id"); - vuzeObjectID = savedPluginConfigID; - } else { - // We stored the plugin config ID, so no need to ask for it again - vuzeObjectID = savedPluginConfigID; } + // We stored the plugin config ID, so no need to ask for it again + vuzeObjectID = savedPluginConfigID; } else if (serverMethod.equals("createFromBEncodedData[byte[]]")) { @@ -272,11 +270,10 @@ public class VuzeAdapter implements IDaemonAdapter { throw new DaemonException(ExceptionType.UnexpectedResponse, "No torrent manager ID returned on getTorrentManager"); } savedTorrentManagerID = (Long) manager.get("_object_id"); - vuzeObjectID = savedTorrentManagerID; - } else { - // We stored the torrent manager ID, so no need to ask for it again - vuzeObjectID = savedTorrentManagerID; } + // We stored the torrent manager ID, so no need to ask for it again + vuzeObjectID = savedTorrentManagerID; + // And we will need the download manager as well later on (for addDownload after createFromBEncodedData) if (savedDownloadManagerID == null) { // Download manager needed, but we don't know it's ID yet @@ -297,11 +294,9 @@ public class VuzeAdapter implements IDaemonAdapter { throw new DaemonException(ExceptionType.UnexpectedResponse, "No download manager ID returned on getDownloadManager"); } savedDownloadManagerID = (Long) manager.get("_object_id"); - vuzeObjectID = savedDownloadManagerID; - } else { - // We stored the download manager ID, so no need to ask for it again - vuzeObjectID = savedDownloadManagerID; } + // We stored the download manager ID, so no need to ask for it again + vuzeObjectID = savedDownloadManagerID; } } else { diff --git a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java index dfe909fc..3c61407c 100644 --- a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java +++ b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java @@ -172,16 +172,14 @@ public class VuzeXmlOverHttpClient { // Long? try { - Long longnum = Long.parseLong(rawText); - return longnum; + return Long.parseLong(rawText); } catch (NumberFormatException e) { // Just continue trying the next type } // Double? try { - Double doublenum = Double.parseDouble(rawText); - return doublenum; + return Double.parseDouble(rawText); } catch (NumberFormatException e) { // Just continue trying the next type } diff --git a/app/src/main/java/org/transdroid/daemon/util/Collections2.java b/app/src/main/java/org/transdroid/daemon/util/Collections2.java index a3a8dd53..531960c7 100644 --- a/app/src/main/java/org/transdroid/daemon/util/Collections2.java +++ b/app/src/main/java/org/transdroid/daemon/util/Collections2.java @@ -10,12 +10,12 @@ public class Collections2 { */ public static String joinString(Iterable iterable, String separator) { boolean first = true; - String result = ""; + StringBuilder result = new StringBuilder(); for (T anIterable : iterable) { - result += (first ? "" : separator) + anIterable.toString(); + result.append(first ? "" : separator).append(anIterable.toString()); first = false; } - return result; + return result.toString(); } } diff --git a/app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java b/app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java index 0a3442b3..d8fc8111 100644 --- a/app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java +++ b/app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java @@ -78,10 +78,8 @@ public class SelfSignedTrustManager implements X509TrustManager { return; } - CertificateException certificateException = - new CertificateException("Certificate key [" + thumbprint + "] doesn't match expected value."); //Log.e(SelfSignedTrustManager.class.getSimpleName(), certificateException.toString()); - throw certificateException; + throw new CertificateException("Certificate key [" + thumbprint + "] doesn't match expected value."); } catch (NoSuchAlgorithmException e) { throw new CertificateException("Unable to check self-signed cert, unknown algorithm. " + e.toString());