Browse Source

Miscellaneous Java lint cleanup

pull/559/head
TacoTheDank 4 years ago
parent
commit
9d2e11a8df
  1. 3
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  2. 12
      app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java
  3. 5
      app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java
  4. 4
      app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java
  5. 2
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java
  6. 4
      app/src/main/java/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java
  7. 4
      app/src/main/java/org/transdroid/core/gui/lists/TorrentStatusLayout.java
  8. 2
      app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java
  9. 2
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java
  10. 2
      app/src/main/java/org/transdroid/core/gui/navigation/SelectionModificationSpinner.java
  11. 4
      app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java
  12. 5
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedLoader.java
  13. 4
      app/src/main/java/org/transdroid/core/gui/rss/RssitemStatusLayout.java
  14. 2
      app/src/main/java/org/transdroid/core/gui/search/SearchSettingsDropDownAdapter.java
  15. 25
      app/src/main/java/org/transdroid/core/gui/settings/MainSettingsActivity.java
  16. 16
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java
  17. 19
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  18. 16
      app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java
  19. 19
      app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  20. 16
      app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java
  21. 19
      app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java
  22. 16
      app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java
  23. 5
      app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java
  24. 4
      app/src/main/java/org/transdroid/daemon/DaemonSettings.java
  25. 7
      app/src/main/java/org/transdroid/daemon/DummyAdapter.java
  26. 12
      app/src/main/java/org/transdroid/daemon/TorrentDetails.java
  27. 8
      app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java
  28. 28
      app/src/main/java/org/transdroid/daemon/TorrentsComparator.java
  29. 10
      app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
  30. 8
      app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java
  31. 41
      app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java
  32. 16
      app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java
  33. 9
      app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java
  34. 12
      app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java
  35. 3
      app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java
  36. 18
      app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
  37. 19
      app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java
  38. 6
      app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java
  39. 6
      app/src/main/java/org/transdroid/daemon/util/Collections2.java
  40. 4
      app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java

3
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 * @return A list of all stored server settings objects
*/ */
public List<ServerSetting> getAllServerSettings() { public List<ServerSetting> getAllServerSettings() {
List<ServerSetting> all = new ArrayList<>(); List<ServerSetting> all = new ArrayList<>(getNormalServerSettings());
all.addAll(getNormalServerSettings());
for (SeedboxProvider provider : SeedboxProvider.values()) { for (SeedboxProvider provider : SeedboxProvider.values()) {
all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size())); all.addAll(provider.getSettings().getAllServerSettings(prefs, all.size()));
} }

12
app/src/main/java/org/transdroid/core/gui/lists/LocalTorrent.java

@ -63,8 +63,6 @@ public class LocalTorrent {
switch (e.getType()) { switch (e.getType()) {
case MethodUnsupported: case MethodUnsupported:
return R.string.error_unsupported; return R.string.error_unsupported;
case ConnectionError:
return R.string.error_httperror;
case UnexpectedResponse: case UnexpectedResponse:
return R.string.error_jsonresponseerror; return R.string.error_jsonresponseerror;
case ParsingFailed: case ParsingFailed:
@ -75,6 +73,7 @@ public class LocalTorrent {
return R.string.error_401; return R.string.error_401;
case FileAccessError: case FileAccessError:
return R.string.error_torrentfile; return R.string.error_torrentfile;
case ConnectionError:
default: default:
return R.string.error_httperror; return R.string.error_httperror;
} }
@ -201,16 +200,15 @@ public class LocalTorrent {
public String getProgressSpeedText(Resources r) { public String getProgressSpeedText(Resources r) {
switch (t.getStatusCode()) { switch (t.getStatusCode()) {
case Waiting:
case Checking:
case Paused:
case Queued:
return "";
case Downloading: case Downloading:
return r.getString(R.string.status_speed_down, FileSizeConverter.getSize(t.getRateDownload()) + "/s") + " " 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"); + r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s");
case Seeding: case Seeding:
return r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s"); return r.getString(R.string.status_speed_up, FileSizeConverter.getSize(t.getRateUpload()) + "/s");
case Waiting:
case Checking:
case Paused:
case Queued:
default: default:
return ""; return "";
} }

5
app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java

@ -26,6 +26,7 @@ import android.widget.SectionIndexer;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
/** /**
* An adapter that can contain many other adapters and shows them in sequence. Taken from * 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(); Object[] curSections = ((SectionIndexer) piece).getSections();
if (curSections != null) { if (curSections != null) {
for (Object section : curSections) { sections.addAll(Arrays.asList(curSections));
sections.add(section);
}
} }
} }
} }

4
app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java

@ -111,9 +111,9 @@ class PiecesMapView extends View {
piecesScaled.add(state); piecesScaled.add(state);
} }
String scaledPiecesString = ""; StringBuilder scaledPiecesString = new StringBuilder();
for (int s : piecesScaled) { for (int s : piecesScaled) {
scaledPiecesString += s; scaledPiecesString.append(s);
} }
// Draw downscaled peices // Draw downscaled peices

2
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java

@ -67,7 +67,7 @@ public class SimpleListItemAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
SimpleListItemView filterItemView; SimpleListItemView filterItemView;
if (convertView == null || !(convertView instanceof SimpleListItemView)) { if (!(convertView instanceof SimpleListItemView)) {
filterItemView = SimpleListItemView_.build(context); filterItemView = SimpleListItemView_.build(context);
} else { } else {
filterItemView = (SimpleListItemView) convertView; filterItemView = (SimpleListItemView) convertView;

4
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) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
int height = getHeight(); fullRect.set(0, 0, WIDTH, getHeight());
int width = WIDTH;
fullRect.set(0, 0, width, height);
if (priority == null) { if (priority == null) {
return; return;

4
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) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
int height = getHeight(); fullRect.set(0, 0, WIDTH, getHeight());
int width = WIDTH;
fullRect.set(0, 0, width, height);
if (status == null) { if (status == null) {
return; return;

2
app/src/main/java/org/transdroid/core/gui/log/DatabaseHelper.java

@ -59,7 +59,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
switch (oldVersion) { switch (oldVersion) {
case 1: case 1:
TableUtils.createTable(connectionSource, ErrorLogEntry.class); TableUtils.createTable(connectionSource, ErrorLogEntry.class);
/*case 1: /*case 2:
etc...*/ etc...*/
} }

2
app/src/main/java/org/transdroid/core/gui/navigation/FilterListItemAdapter.java

@ -64,7 +64,7 @@ public class FilterListItemAdapter extends BaseAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
FilterListItemView filterItemView; FilterListItemView filterItemView;
if (convertView == null || !(convertView instanceof SimpleListItemView)) { if (!(convertView instanceof SimpleListItemView)) {
filterItemView = FilterListItemView_.build(context); filterItemView = FilterListItemView_.build(context);
} else { } else {
filterItemView = (FilterListItemView) convertView; filterItemView = (FilterListItemView) convertView;

2
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 * 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. * list item as in a normal spinner.
*/ */
private class SelectionDropDownAdapter extends ArrayAdapter<String> { private static class SelectionDropDownAdapter extends ArrayAdapter<String> {
protected TextView titleView = null; protected TextView titleView = null;

4
app/src/main/java/org/transdroid/core/gui/rss/RssFeedsActivity.java

@ -139,7 +139,7 @@ public class RssFeedsActivity extends AppCompatActivity {
try { try {
hasRemoteFeeds = remoteConnection.getRemoteRssChannels(log).size() > 0; hasRemoteFeeds = remoteConnection.getRemoteRssChannels(log).size() > 0;
} catch (DaemonException e) { } catch (DaemonException ignored) {
} }
if (hasRemoteFeeds) { if (hasRemoteFeeds) {
@ -279,7 +279,7 @@ public class RssFeedsActivity extends AppCompatActivity {
IDaemonAdapter currentConnection = this.getCurrentConnection(); IDaemonAdapter currentConnection = this.getCurrentConnection();
// remote rss not supported for this connection type // remote rss not supported for this connection type
if (currentConnection instanceof RemoteRssSupplier == false) { if (!(currentConnection instanceof RemoteRssSupplier)) {
return; return;
} }

5
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(); Date pubDate = channel.getItems().get(0).getPubdate();
usePublishDate = pubDate != null && pubDate.getTime() > 0; usePublishDate = pubDate != null && pubDate.getTime() > 0;
} }
newCount = 0;
if (usePublishDate) { if (usePublishDate) {
// Count the number of new items, based on the date that this RSS feed was last viewed by the user // Count the number of new items, based on the date that this RSS feed was last viewed by the user
newCount = 0;
List<Item> items = channel.getItems(); List<Item> items = channel.getItems();
// Reverse-order sort the items on their published date // Reverse-order sort the items on their published date
Collections.sort(items, new Comparator<Item>() { Collections.sort(items, new Comparator<Item>() {
@Override @Override
public int compare(Item lhs, Item rhs) { public int compare(Item lhs, Item rhs) {
return 0 - lhs.getPubdate().compareTo(rhs.getPubdate()); return -lhs.getPubdate().compareTo(rhs.getPubdate());
} }
}); });
for (Item item : items) { for (Item item : items) {
@ -77,7 +77,6 @@ public class RssfeedLoader {
} }
} else { } else {
// Use the url of the last RSS item the last time the feed was viewed by the user to count new items // 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; boolean isNew = true;
for (Item item : channel.getItems()) { for (Item item : channel.getItems()) {
if (item.getTheLink() != null && setting.getLastViewedItemUrl() != null && item.getTheLink().equals(setting.getLastViewedItemUrl())) { if (item.getTheLink() != null && setting.getLastViewedItemUrl() != null && item.getTheLink().equals(setting.getLastViewedItemUrl())) {

4
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) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
int height = getHeight(); fullRect.set(0, 0, WIDTH, getHeight());
int width = WIDTH;
fullRect.set(0, 0, width, height);
if (isNew == null) { if (isNew == null) {
return; return;

2
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) { public View getView(int position, View convertView, ViewGroup parent) {
// This returns the item to show in the action bar spinner // This returns the item to show in the action bar spinner
SearchSettingSelectionView filterItemView; SearchSettingSelectionView filterItemView;
if (convertView == null || !(convertView instanceof SearchSettingSelectionView)) { if (!(convertView instanceof SearchSettingSelectionView)) {
filterItemView = SearchSettingSelectionView_.build(context); filterItemView = SearchSettingSelectionView_.build(context);
} else { } else {
filterItemView = (SearchSettingSelectionView) convertView; filterItemView = (SearchSettingSelectionView) convertView;

25
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 // Allow selection of the default server
ListPreference defaultServerPreference = (ListPreference) findPreference("header_defaultserver"); ListPreference defaultServerPreference = (ListPreference) findPreference("header_defaultserver");
defaultServerPreference.setEntries(serverNames.toArray(new String[serverNames.size()])); defaultServerPreference.setEntries(serverNames.toArray(new String[0]));
defaultServerPreference.setEntryValues(serverCodes.toArray(new String[serverCodes.size()])); defaultServerPreference.setEntryValues(serverCodes.toArray(new String[0]));
// Add existing RSS feeds // Add existing RSS feeds
if (!enableRssUi) { if (!enableRssUi) {
@ -276,8 +276,8 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
siteValues.add(websearch.getKey()); siteValues.add(websearch.getKey());
} }
// Supply the Preference list names and values // Supply the Preference list names and values
setSite.setEntries(siteNames.toArray(new String[siteNames.size()])); setSite.setEntries(siteNames.toArray(new String[0]));
setSite.setEntryValues(siteValues.toArray(new String[siteValues.size()])); setSite.setEntryValues(siteValues.toArray(new String[0]));
} }
@ -289,15 +289,14 @@ public class MainSettingsActivity extends PreferenceCompatActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { if (id == DIALOG_ADDSEEDBOX) {
case DIALOG_ADDSEEDBOX: // Open dialog to pick one of the supported seedbox providers (or a normal server)
// Open dialog to pick one of the supported seedbox providers (or a normal server) String[] seedboxes = new String[SeedboxProvider.values().length + 1];
String[] seedboxes = new String[SeedboxProvider.values().length + 1]; seedboxes[0] = getString(R.string.pref_addserver_normal);
seedboxes[0] = getString(R.string.pref_addserver_normal); for (int i = 0; i < seedboxes.length - 1; i++) {
for (int i = 0; i < seedboxes.length - 1; 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.values()[i].getSettings().getName()); }
} return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create();
return new AlertDialog.Builder(this).setItems(seedboxes, onAddSeedbox).create();
} }
return null; return null;
} }

16
app/src/main/java/org/transdroid/core/gui/settings/RssfeedPreference.java

@ -33,17 +33,17 @@ public class RssfeedPreference extends Preference {
private RssfeedSetting rssfeedSetting; private RssfeedSetting rssfeedSetting;
private OnRssfeedClickedListener onRssfeedClickedListener = null; 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) { public RssfeedPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (onRssfeedClickedListener != null)
onRssfeedClickedListener.onRssfeedClicked(rssfeedSetting);
return true;
}
};
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);
} }

19
app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -74,16 +74,15 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { if (id == DIALOG_CONFIRMREMOVE) {
case DIALOG_CONFIRMREMOVE: return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) .setPositiveButton(android.R.string.ok, new OnClickListener() {
.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override
@Override public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key); finish();
finish(); }
} }).setNegativeButton(android.R.string.cancel, null).create();
}).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;
} }

16
app/src/main/java/org/transdroid/core/gui/settings/ServerPreference.java

@ -33,17 +33,17 @@ public class ServerPreference extends Preference {
protected ServerSetting serverSetting; protected ServerSetting serverSetting;
private OnServerClickedListener onServerClickedListener = null; 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) { public ServerPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (onServerClickedListener != null)
onServerClickedListener.onServerClicked(serverSetting);
return true;
}
};
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);
} }

19
app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -114,16 +114,15 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { if (id == DIALOG_CONFIRMREMOVE) {
case DIALOG_CONFIRMREMOVE: return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) .setPositiveButton(android.R.string.ok, new OnClickListener() {
.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override
@Override public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key);
ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key); finish();
finish(); }
} }).setNegativeButton(android.R.string.cancel, null).create();
}).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;
} }

16
app/src/main/java/org/transdroid/core/gui/settings/WebsearchPreference.java

@ -33,17 +33,17 @@ public class WebsearchPreference extends Preference {
private WebsearchSetting websearchSetting; private WebsearchSetting websearchSetting;
private OnWebsearchClickedListener onWebsearchClickedListener = null; 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) { public WebsearchPreference(Context context) {
super(context); super(context);
OnPreferenceClickListener onPreferenceClicked = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (onWebsearchClickedListener != null)
onWebsearchClickedListener.onWebsearchClicked(websearchSetting);
return true;
}
};
setOnPreferenceClickListener(onPreferenceClicked); setOnPreferenceClickListener(onPreferenceClicked);
setIconSpaceReserved(false); setIconSpaceReserved(false);
} }

19
app/src/main/java/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

@ -70,16 +70,15 @@ public class WebsearchSettingsActivity extends KeyBoundPreferencesActivity {
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
switch (id) { if (id == DIALOG_CONFIRMREMOVE) {
case DIALOG_CONFIRMREMOVE: return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove) .setPositiveButton(android.R.string.ok, new OnClickListener() {
.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override
@Override public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key);
ApplicationSettings_.getInstance_(WebsearchSettingsActivity.this).removeWebsearchSettings(key); finish();
finish(); }
} }).setNegativeButton(android.R.string.cancel, null).create();
}).setNegativeButton(android.R.string.cancel, null).create();
} }
return null; return null;
} }

16
app/src/main/java/org/transdroid/core/seedbox/SeedboxPreference.java

@ -33,17 +33,17 @@ public class SeedboxPreference extends ServerPreference {
private SeedboxProvider provider = null; private SeedboxProvider provider = null;
private OnSeedboxClickedListener onSeedboxClickedListener = null; private OnSeedboxClickedListener onSeedboxClickedListener = null;
private int onSeedboxClickedListenerOffset = 0; 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) { public SeedboxPreference(Context context) {
super(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); setOnPreferenceClickListener(onSeedboxPreferenceClicked);
} }

5
app/src/main/java/org/transdroid/core/service/ServerCheckerJobRunner.java

@ -171,10 +171,11 @@ public class ServerCheckerJobRunner {
// No notification to show // No notification to show
continue; continue;
} }
String forString = ""; StringBuilder forStringBuilder = new StringBuilder();
for (Torrent affected : affectedTorrents) { for (Torrent affected : affectedTorrents) {
forString += affected.getName() + ", "; forStringBuilder.append(affected.getName()).append(", ");
} }
String forString = forStringBuilder.toString();
forString = forString.substring(0, forString.length() - 2); forString = forString.substring(0, forString.length() - 2);
// Build the basic notification // Build the basic notification

4
app/src/main/java/org/transdroid/daemon/DaemonSettings.java

@ -191,11 +191,11 @@ public final class DaemonSettings {
public String getHumanReadableIdentifier() { public String getHumanReadableIdentifier() {
if (isAutoGenerated) { if (isAutoGenerated) {
// Hide the 'implementation details'; just give the username and server // 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(); .getUsername() + "@" : "") + getAddress();
} }
return (this.ssl ? "https://" : "http://") 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() .getUsername() + "@" : "") + getAddress() + ":" + getPort()
+ (Daemon.supportsCustomFolder(getType()) && getFolder() != null ? getFolder() : ""); + (Daemon.supportsCustomFolder(getType()) && getFolder() != null ? getFolder() : "");
} }

7
app/src/main/java/org/transdroid/daemon/DummyAdapter.java

@ -201,6 +201,8 @@ public class DummyAdapter implements IDaemonAdapter {
case Pause: case Pause:
case Resume:
task.getTargetTorrent().mimicPause(); task.getTargetTorrent().mimicPause();
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
@ -211,11 +213,6 @@ public class DummyAdapter implements IDaemonAdapter {
} }
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case Resume:
task.getTargetTorrent().mimicPause();
return new DaemonTaskSuccessResult(task);
case ResumeAll: case ResumeAll:
for (Torrent torrent : dummyTorrents) { for (Torrent torrent : dummyTorrents) {

12
app/src/main/java/org/transdroid/daemon/TorrentDetails.java

@ -81,11 +81,11 @@ public final class TorrentDetails implements Parcelable {
*/ */
public String getTrackersText() { public String getTrackersText() {
// Build a string with one tracker URL per line // Build a string with one tracker URL per line
String trackersText = ""; StringBuilder trackersText = new StringBuilder();
for (String tracker : trackers) { 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() { public String getErrorsText() {
// Build a string with one tracker error per line // Build a string with one tracker error per line
String errorsText = ""; StringBuilder errorsText = new StringBuilder();
for (String error : errors) { 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<Integer> getPieces() { public List<Integer> getPieces() {

8
app/src/main/java/org/transdroid/daemon/TorrentFilesComparator.java

@ -49,18 +49,18 @@ public class TorrentFilesComparator implements Comparator<TorrentFile> {
case PartDone: case PartDone:
return Float.compare(file1.getPartDone(), file2.getPartDone()); return Float.compare(file1.getPartDone(), file2.getPartDone());
case TotalSize: case TotalSize:
return Long.valueOf(file1.getTotalSize()).compareTo(file2.getTotalSize()); return Long.compare(file1.getTotalSize(), file2.getTotalSize());
default: default:
return alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase()); return alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase());
} }
} else { } else {
switch (sortBy) { switch (sortBy) {
case PartDone: case PartDone:
return 0 - Float.compare(file1.getPartDone(), file2.getPartDone()); return -Float.compare(file1.getPartDone(), file2.getPartDone());
case TotalSize: case TotalSize:
return 0 - Long.valueOf(file1.getTotalSize()).compareTo(file2.getTotalSize()); return -Long.compare(file1.getTotalSize(), file2.getTotalSize());
default: default:
return 0 - alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase()); return -alphanumComparator.compare(file1.getName().toLowerCase(), file2.getName().toLowerCase());
} }
} }
} }

28
app/src/main/java/org/transdroid/daemon/TorrentsComparator.java

@ -67,42 +67,42 @@ public class TorrentsComparator implements Comparator<Torrent> {
case DateDone: case DateDone:
return tor1.getDateDone().compareTo(tor2.getDateDone()); return tor1.getDateDone().compareTo(tor2.getDateDone());
case Percent: case Percent:
return Float.valueOf(tor1.getDownloadedPercentage()).compareTo(tor2.getDownloadedPercentage()); return Float.compare(tor1.getDownloadedPercentage(), tor2.getDownloadedPercentage());
case DownloadSpeed: case DownloadSpeed:
return Integer.valueOf(tor1.getRateDownload()).compareTo(tor2.getRateDownload()); return Integer.compare(tor1.getRateDownload(), tor2.getRateDownload());
case UploadSpeed: case UploadSpeed:
return Integer.valueOf(tor1.getRateUpload()).compareTo(tor2.getRateUpload()); return Integer.compare(tor1.getRateUpload(), tor2.getRateUpload());
case Ratio: case Ratio:
return Double.valueOf(tor1.getRatio()).compareTo(tor2.getRatio()); return Double.compare(tor1.getRatio(), tor2.getRatio());
case Size: case Size:
return Double.valueOf(tor1.getTotalSize()).compareTo((double) tor2.getTotalSize()); return Double.compare(tor1.getTotalSize(), (double) tor2.getTotalSize());
default: default:
return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); return alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }
} else { } else {
switch (sortBy) { switch (sortBy) {
case Status: case Status:
return 0 - tor1.getStatusCode().compareStatusCodeTo(tor2.getStatusCode()); return -tor1.getStatusCode().compareStatusCodeTo(tor2.getStatusCode());
case DateAdded: case DateAdded:
if (tor1.getDateAdded() == null) if (tor1.getDateAdded() == null)
return 1; return 1;
if (tor2.getDateAdded() == null) if (tor2.getDateAdded() == null)
return -1; return -1;
return 0 - tor1.getDateAdded().compareTo(tor2.getDateAdded()); return -tor1.getDateAdded().compareTo(tor2.getDateAdded());
case DateDone: case DateDone:
return 0 - tor1.getDateDone().compareTo(tor2.getDateDone()); return -tor1.getDateDone().compareTo(tor2.getDateDone());
case Percent: case Percent:
return 0 - (Float.valueOf(tor1.getDownloadedPercentage()).compareTo(tor2.getDownloadedPercentage())); return -(Float.compare(tor1.getDownloadedPercentage(), tor2.getDownloadedPercentage()));
case DownloadSpeed: case DownloadSpeed:
return 0 - (Integer.valueOf(tor1.getRateDownload()).compareTo(tor2.getRateDownload())); return -(Integer.compare(tor1.getRateDownload(), tor2.getRateDownload()));
case UploadSpeed: case UploadSpeed:
return 0 - (Integer.valueOf(tor1.getRateUpload()).compareTo(tor2.getRateUpload())); return -(Integer.compare(tor1.getRateUpload(), tor2.getRateUpload()));
case Ratio: case Ratio:
return 0 - Double.valueOf(tor1.getRatio()).compareTo(tor2.getRatio()); return -Double.compare(tor1.getRatio(), tor2.getRatio());
case Size: case Size:
return 0 - Double.valueOf(tor1.getTotalSize()).compareTo((double) tor2.getTotalSize()); return -Double.compare(tor1.getTotalSize(), (double) tor2.getTotalSize());
default: default:
return 0 - alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase()); return -alphanumComparator.compare(tor1.getName().toLowerCase(), tor2.getName().toLowerCase());
} }
} }
} }

10
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")) { } else if (size.endsWith("B")) {
return (long) (Float.parseFloat(size.substring(0, size.indexOf("B")))); return (long) (Float.parseFloat(size.substring(0, size.indexOf("B"))));
} }
} catch (Exception e) { } catch (Exception ignored) {
} }
return 0; return 0;
} }
@ -277,15 +277,17 @@ public class BitCometAdapter implements IDaemonAdapter {
// Add the parameters to the query string // Add the parameters to the query string
boolean first = true; boolean first = true;
StringBuilder urlBuilder = new StringBuilder(url);
for (NameValuePair param : params) { for (NameValuePair param : params) {
if (first) { if (first) {
url += "?"; urlBuilder.append("?");
first = false; first = false;
} else { } else {
url += "&"; urlBuilder.append("&");
} }
url += param.getName() + "=" + param.getValue(); urlBuilder.append(param.getName()).append("=").append(param.getValue());
} }
url = urlBuilder.toString();
// Make the request // Make the request
HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url))); HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url)));

8
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 // Add the parameters to the query string
boolean first = true; boolean first = true;
StringBuilder urlBuilder = new StringBuilder(url);
for (NameValuePair param : params) { for (NameValuePair param : params) {
if (first) { if (first) {
url += "?"; urlBuilder.append("?");
first = false; first = false;
} else { } else {
url += "&"; urlBuilder.append("&");
} }
url += param.getName() + "=" + param.getValue(); urlBuilder.append(param.getName()).append("=").append(param.getValue());
} }
url = urlBuilder.toString();
// Make the request // Make the request
HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url))); HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url)));

41
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 * @return The size in number of kB
*/ */
public static long convertSize(String size) { public static long convertSize(String size) {
String s = size.substring(0, size.length() - 4);
if (size.endsWith("GiB")) { 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")) { } 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")) { } 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")) { } else if (size.endsWith("B")) {
return convertStringToFloat(size.substring(0, size.length() - 2)).longValue(); return convertStringToFloat(size.substring(0, size.length() - 2)).longValue();
} }
@ -228,10 +229,11 @@ public class StatsParser {
* @return The rate (or speed) in KiB/s * @return The rate (or speed) in KiB/s
*/ */
public static int convertRate(String rate) { public static int convertRate(String rate) {
String s = rate.substring(0, rate.length() - 6);
if (rate.endsWith("MiB/s")) { 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")) { } 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")) { } else if (rate.endsWith("B/s")) {
return convertStringToFloat(rate.substring(0, rate.length() - 4)).intValue(); 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 * @return The status as TorrentStatus or Unknown if it could not been parsed
*/ */
private static TorrentStatus convertStatus(String status) { private static TorrentStatus convertStatus(String status) {
if (status.equals("Downloading")) { switch (status) {
return TorrentStatus.Downloading; case "Downloading":
} else if (status.equals("Seeding")) { return TorrentStatus.Downloading;
return TorrentStatus.Seeding; case "Seeding":
} else if (status.equals("Stopped")) { return TorrentStatus.Seeding;
return TorrentStatus.Paused; case "Stopped":
} else if (status.equals("Stalled")) { case "Download completed":
return TorrentStatus.Paused; case "Not started":
} else if (status.equals("Download completed")) { return TorrentStatus.Paused;
return TorrentStatus.Paused; case "Stalled":
} else if (status.equals("Not started")) { return TorrentStatus.Waiting;
return TorrentStatus.Paused; case "Checking data":
} else if (status.equals("Stalled")) { return TorrentStatus.Checking;
return TorrentStatus.Waiting;
} else if (status.equals("Checking data")) {
return TorrentStatus.Checking;
} }
return TorrentStatus.Unknown; return TorrentStatus.Unknown;
} }

16
app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java

@ -332,13 +332,15 @@ public class RTorrentAdapter implements IDaemonAdapter {
initialise(); initialise();
} }
String params = ""; StringBuilder paramsBuilder = new StringBuilder();
for (Object arg : arguments) { 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 { try {
log.d(LOG_NAME, "Calling " + serverMethod + " with params [" + log.d(LOG_NAME, "Calling " + serverMethod + " with params [" +
(params.length() > 100 ? params.substring(0, 100) + "..." : params) + " ]"); s + " ]");
return rpcclient.call(serverMethod, arguments); return rpcclient.call(serverMethod, arguments);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.d(LOG_NAME, "Using " + buildWebUIUrl() + ": " + e.toString()); log.d(LOG_NAME, "Using " + buildWebUIUrl() + ": " + e.toString());
@ -353,7 +355,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
} }
throw new DaemonException(ExceptionType.ConnectionError, throw new DaemonException(ExceptionType.ConnectionError,
"Error making call to " + serverMethod + " with params [" + "Error making call to " + serverMethod + " with params [" +
(params.length() > 100 ? params.substring(0, 100) + "..." : params) + " ]: " + s + " ]: " +
e.toString()); e.toString());
} }
@ -386,7 +388,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
private List<Torrent> onTorrentsRetrieved(Object response) throws DaemonException { private List<Torrent> onTorrentsRetrieved(Object response) throws DaemonException {
if (response == null || !(response instanceof Object[])) { if (!(response instanceof Object[])) {
throw new DaemonException(ExceptionType.ParsingFailed, throw new DaemonException(ExceptionType.ParsingFailed,
"Response on retrieveing torrents did not return a list of objects"); "Response on retrieveing torrents did not return a list of objects");
@ -532,7 +534,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
private List<TorrentFile> onTorrentFilesRetrieved(Object response, Torrent torrent) throws DaemonException { private List<TorrentFile> onTorrentFilesRetrieved(Object response, Torrent torrent) throws DaemonException {
if (response == null || !(response instanceof Object[])) { if (!(response instanceof Object[])) {
throw new DaemonException(ExceptionType.ParsingFailed, throw new DaemonException(ExceptionType.ParsingFailed,
"Response on retrieveing torrent files did not return a list of objects"); "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 { private TorrentDetails onTorrentDetailsRetrieved(Log log, Object response) throws DaemonException {
if (response == null || !(response instanceof Object[])) { if (!(response instanceof Object[])) {
throw new DaemonException(ExceptionType.ParsingFailed, throw new DaemonException(ExceptionType.ParsingFailed,
"Response on retrieveing trackers did not return a list of objects"); "Response on retrieveing trackers did not return a list of objects");

9
app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java

@ -91,8 +91,6 @@ public class SynologyAdapter implements IDaemonAdapter {
switch (task.getMethod()) { switch (task.getMethod()) {
case Retrieve: case Retrieve:
return new RetrieveTaskSuccessResult((RetrieveTask) task, tasksList(log), null); return new RetrieveTaskSuccessResult((RetrieveTask) task, tasksList(log), null);
case GetStats:
return null;
case GetTorrentDetails: case GetTorrentDetails:
tid = task.getTargetTorrent().getUniqueID(); tid = task.getTargetTorrent().getUniqueID();
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task,
@ -129,10 +127,6 @@ public class SynologyAdapter implements IDaemonAdapter {
case ResumeAll: case ResumeAll:
resumeAllTasks(log); resumeAllTasks(log);
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case SetDownloadLocation:
return null;
case SetFilePriorities:
return null;
case SetTransferRates: case SetTransferRates:
SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; SetTransferRatesTask ratesTask = (SetTransferRatesTask) task;
int uploadRate = ratesTask.getUploadRate() == null ? 0 : ratesTask.getUploadRate(); int uploadRate = ratesTask.getUploadRate() == null ? 0 : ratesTask.getUploadRate();
@ -140,6 +134,9 @@ public class SynologyAdapter implements IDaemonAdapter {
setTransferRates(log, uploadRate, downloadRate); setTransferRates(log, uploadRate, downloadRate);
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case SetAlternativeMode: case SetAlternativeMode:
case GetStats:
case SetDownloadLocation:
case SetFilePriorities:
default: default:
return null; return null;
} }

12
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 * @return The size in number of kB
*/ */
private static long convertSize(String size) { private static long convertSize(String size) {
float v = Float.parseFloat(size.substring(0, size.length() - 3));
if (size.endsWith("GB")) { 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")) { } 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")) { } 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")) { } else if (size.endsWith("B")) {
return (long) (Float.parseFloat(size.substring(0, size.length() - 2))); 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 * @return The rate (or speed) in kB/s
*/ */
private static int convertRate(String rate) { private static int convertRate(String rate) {
float v = Float.parseFloat(rate.substring(0, rate.length() - 5));
if (rate.endsWith("MB/s")) { 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")) { } 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")) { } else if (rate.endsWith("B/s")) {
return (int) Float.parseFloat(rate.substring(0, rate.length() - 4)); return (int) Float.parseFloat(rate.substring(0, rate.length() - 4));
} }

3
app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java

@ -567,11 +567,10 @@ public class TransmissionAdapter implements IDaemonAdapter {
case 2: case 2:
return TorrentStatus.Checking; return TorrentStatus.Checking;
case 3: case 3:
case 5:
return TorrentStatus.Queued; return TorrentStatus.Queued;
case 4: case 4:
return TorrentStatus.Downloading; return TorrentStatus.Downloading;
case 5:
return TorrentStatus.Queued;
case 6: case 6:
return TorrentStatus.Seeding; return TorrentStatus.Seeding;
} }

18
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 // Set priorities of the files of some torrent
SetFilePriorityTask prioTask = (SetFilePriorityTask) task; SetFilePriorityTask prioTask = (SetFilePriorityTask) task;
String prioUrl = "&p=" + convertPriority(prioTask.getNewPriority()); StringBuilder prioUrl = new StringBuilder("&p=" + convertPriority(prioTask.getNewPriority()));
for (TorrentFile forFile : prioTask.getForFiles()) { for (TorrentFile forFile : prioTask.getForFiles()) {
prioUrl += "&f=" + forFile.getKey(); prioUrl.append("&f=").append(forFile.getKey());
} }
makeUtorrentRequest(log, makeUtorrentRequest(log,
"&action=setprio" + RPC_URL_HASH + task.getTargetTorrent().getUniqueID() + prioUrl); "&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 // Set the trackers of some torrent
SetTrackersTask trackersTask = (SetTrackersTask) task; SetTrackersTask trackersTask = (SetTrackersTask) task;
// Build list of tracker lines, separated by a \r\n // Build list of tracker lines, separated by a \r\n
String newTrackersText = ""; StringBuilder newTrackersText = new StringBuilder();
for (String tracker : trackersTask.getNewTrackers()) { for (String tracker : trackersTask.getNewTrackers()) {
newTrackersText += (newTrackersText.length() == 0 ? "" : "\r\n") + tracker; newTrackersText.append(newTrackersText.length() == 0 ? "" : "\r\n").append(tracker);
} }
makeUtorrentRequest(log, makeUtorrentRequest(log,
"&action=setprops" + RPC_URL_HASH + trackersTask.getTargetTorrent().getUniqueID() + "&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); return new DaemonTaskSuccessResult(task);
case ForceRecheck: case ForceRecheck:
@ -552,7 +552,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
for (int i = 0; i < results.length(); i++) { for (int i = 0; i < results.length(); i++) {
JSONArray tor = results.getJSONArray(i); JSONArray tor = results.getJSONArray(i);
String name = tor.getString(RPC_NAME_IDX); 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 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 // 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 // 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<Torrent> torrents = parseJsonRetrieveTorrents(result.getJSONArray("torrents")); ArrayList<Torrent> torrents = parseJsonRetrieveTorrents(result.getJSONArray("torrents"));
// Build a string of hashes of all the torrents // Build a string of hashes of all the torrents
String hashes = ""; StringBuilder hashes = new StringBuilder();
for (Torrent torrent : torrents) { for (Torrent torrent : torrents) {
hashes += RPC_URL_HASH + torrent.getUniqueID(); hashes.append(RPC_URL_HASH).append(torrent.getUniqueID());
} }
return hashes; return hashes.toString();
} }

19
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"); throw new DaemonException(ExceptionType.UnexpectedResponse, "No plugin config ID returned on getPluginconfig");
} }
savedPluginConfigID = (Long) config.get("_object_id"); 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[]]")) { } 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"); throw new DaemonException(ExceptionType.UnexpectedResponse, "No torrent manager ID returned on getTorrentManager");
} }
savedTorrentManagerID = (Long) manager.get("_object_id"); 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) // And we will need the download manager as well later on (for addDownload after createFromBEncodedData)
if (savedDownloadManagerID == null) { if (savedDownloadManagerID == null) {
// Download manager needed, but we don't know it's ID yet // 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"); throw new DaemonException(ExceptionType.UnexpectedResponse, "No download manager ID returned on getDownloadManager");
} }
savedDownloadManagerID = (Long) manager.get("_object_id"); 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 { } else {

6
app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java

@ -172,16 +172,14 @@ public class VuzeXmlOverHttpClient {
// Long? // Long?
try { try {
Long longnum = Long.parseLong(rawText); return Long.parseLong(rawText);
return longnum;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// Just continue trying the next type // Just continue trying the next type
} }
// Double? // Double?
try { try {
Double doublenum = Double.parseDouble(rawText); return Double.parseDouble(rawText);
return doublenum;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// Just continue trying the next type // Just continue trying the next type
} }

6
app/src/main/java/org/transdroid/daemon/util/Collections2.java

@ -10,12 +10,12 @@ public class Collections2 {
*/ */
public static <T> String joinString(Iterable<T> iterable, String separator) { public static <T> String joinString(Iterable<T> iterable, String separator) {
boolean first = true; boolean first = true;
String result = ""; StringBuilder result = new StringBuilder();
for (T anIterable : iterable) { for (T anIterable : iterable) {
result += (first ? "" : separator) + anIterable.toString(); result.append(first ? "" : separator).append(anIterable.toString());
first = false; first = false;
} }
return result; return result.toString();
} }
} }

4
app/src/main/java/org/transdroid/daemon/util/SelfSignedTrustManager.java

@ -78,10 +78,8 @@ public class SelfSignedTrustManager implements X509TrustManager {
return; return;
} }
CertificateException certificateException =
new CertificateException("Certificate key [" + thumbprint + "] doesn't match expected value.");
//Log.e(SelfSignedTrustManager.class.getSimpleName(), certificateException.toString()); //Log.e(SelfSignedTrustManager.class.getSimpleName(), certificateException.toString());
throw certificateException; throw new CertificateException("Certificate key [" + thumbprint + "] doesn't match expected value.");
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new CertificateException("Unable to check self-signed cert, unknown algorithm. " + e.toString()); throw new CertificateException("Unable to check self-signed cert, unknown algorithm. " + e.toString());

Loading…
Cancel
Save