From 4cee1802ae058803e6cc2885cd1fda532ada04b0 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 15 Nov 2013 13:23:09 +0100 Subject: [PATCH] Fixes #22. Adds an option (in System settings) to treat all dormant (0KB/s, no data transfer going on) torrents as inactive so that they do not show in the Downloading or Seeding lists. --- core/res/values/strings.xml | 2 ++ core/res/xml/pref_system.xml | 6 ++++++ .../core/app/settings/SystemSettings.java | 4 ++++ .../transdroid/core/gui/ServerStatusView.java | 11 +++++----- .../transdroid/core/gui/TorrentsActivity.java | 4 +++- .../transdroid/core/gui/TorrentsFragment.java | 5 ++++- .../transdroid/core/gui/navigation/Label.java | 4 +++- .../core/gui/navigation/NavigationFilter.java | 6 ++++-- .../core/gui/navigation/StatusType.java | 21 ++++++++----------- .../core/widget/ListWidgetConfigActivity.java | 5 ++++- .../core/widget/ListWidgetViewsService.java | 3 ++- lib/src/org/transdroid/daemon/Torrent.java | 20 ++++++++++++++++++ 12 files changed, 66 insertions(+), 25 deletions(-) diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index b03014c9..16349f53 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -275,6 +275,8 @@ Show torrent counter in ADW Launcher System + Treat dormant torrents as inactive + Torrents at 0KB/s (no data transfer) will be filtered as being inactive Check for updates Check transdroid.org for latest app version Use dark UI theme diff --git a/core/res/xml/pref_system.xml b/core/res/xml/pref_system.xml index 7060eb10..ef65d994 100644 --- a/core/res/xml/pref_system.xml +++ b/core/res/xml/pref_system.xml @@ -17,6 +17,12 @@ --> + + torrents) { + public void update(List torrents, boolean dormantAsInactive) { if (torrents == null) { downcountText.setText(null); @@ -71,10 +70,10 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis for (Torrent torrent : torrents) { // Downloading torrents count towards downloads and uploads, seeding torrents towards uploads - if (torrent.getStatusCode() == TorrentStatus.Downloading) { + if (torrent.isDownloading(dormantAsInactive)) { downcount++; upcount++; - } else if (torrent.getStatusCode() == TorrentStatus.Seeding) { + } else if (torrent.isSeeding(dormantAsInactive)) { upcount++; } downspeed += torrent.getRateDownload(); diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 69c17cf3..f49cdde5 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -160,6 +160,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi // Settings @Bean protected ApplicationSettings applicationSettings; + @Bean + protected SystemSettings systemSettings; @InstanceState boolean firstStart = true; int skipNextOnNavigationItemSelectedCalls = 2; @@ -1072,7 +1074,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi fragmentDetails.updateLabels(lastNavigationLabels); // Update the server status (counts and speeds) in the action bar - serverStatusView.update(torrents); + serverStatusView.update(torrents, systemSettings.treatDormantAsInactive()); } diff --git a/core/src/org/transdroid/core/gui/TorrentsFragment.java b/core/src/org/transdroid/core/gui/TorrentsFragment.java index 02bff444..4d929556 100644 --- a/core/src/org/transdroid/core/gui/TorrentsFragment.java +++ b/core/src/org/transdroid/core/gui/TorrentsFragment.java @@ -30,6 +30,7 @@ import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ViewById; import org.transdroid.core.R; import org.transdroid.core.app.settings.ApplicationSettings; +import org.transdroid.core.app.settings.SystemSettings; import org.transdroid.core.gui.lists.TorrentsAdapter; import org.transdroid.core.gui.lists.TorrentsAdapter_; import org.transdroid.core.gui.navigation.Label; @@ -66,6 +67,8 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL // Local data @Bean protected ApplicationSettings applicationSettings; + @Bean + protected SystemSettings systemSettings; @InstanceState protected ArrayList torrents = null; @InstanceState @@ -214,7 +217,7 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL if (filteredTorrents != null && currentNavigationFilter != null) { // Remove torrents that do not match the selected navigation filter for (Iterator torrentIter = filteredTorrents.iterator(); torrentIter.hasNext();) { - if (!currentNavigationFilter.matches(torrentIter.next())) + if (!currentNavigationFilter.matches(torrentIter.next(), systemSettings.treatDormantAsInactive())) torrentIter.remove(); } } diff --git a/core/src/org/transdroid/core/gui/navigation/Label.java b/core/src/org/transdroid/core/gui/navigation/Label.java index 76ad2495..9d8ae96c 100644 --- a/core/src/org/transdroid/core/gui/navigation/Label.java +++ b/core/src/org/transdroid/core/gui/navigation/Label.java @@ -66,9 +66,11 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable