Browse Source

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.

pull/82/head
Eric Kok 11 years ago
parent
commit
4cee1802ae
  1. 2
      core/res/values/strings.xml
  2. 6
      core/res/xml/pref_system.xml
  3. 4
      core/src/org/transdroid/core/app/settings/SystemSettings.java
  4. 11
      core/src/org/transdroid/core/gui/ServerStatusView.java
  5. 4
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 5
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  7. 4
      core/src/org/transdroid/core/gui/navigation/Label.java
  8. 4
      core/src/org/transdroid/core/gui/navigation/NavigationFilter.java
  9. 21
      core/src/org/transdroid/core/gui/navigation/StatusType.java
  10. 5
      core/src/org/transdroid/core/widget/ListWidgetConfigActivity.java
  11. 3
      core/src/org/transdroid/core/widget/ListWidgetViewsService.java
  12. 20
      lib/src/org/transdroid/daemon/Torrent.java

2
core/res/values/strings.xml

@ -275,6 +275,8 @@ @@ -275,6 +275,8 @@
<string name="pref_adw_info">Show torrent counter in ADW Launcher</string>
<string name="pref_system">System</string>
<string name="pref_dormantasinactive">Treat dormant torrents as inactive</string>
<string name="pref_dormantasinactive_info">Torrents at 0KB/s (no data transfer) will be filtered as being inactive</string>
<string name="pref_checkupdates">Check for updates</string>
<string name="pref_checkupdates_info">Check transdroid.org for latest app version</string>
<string name="pref_usedarktheme">Use dark UI theme</string>

6
core/res/xml/pref_system.xml

@ -17,6 +17,12 @@ @@ -17,6 +17,12 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="system_dormantasinactive"
android:title="@string/pref_dormantasinactive"
android:summary="@string/pref_dormantasinactive_info"
android:defaultValue="false" />
<CheckBoxPreference
android:key="system_checkupdates"
android:title="@string/pref_checkupdates"

4
core/src/org/transdroid/core/app/settings/SystemSettings.java

@ -42,6 +42,10 @@ public class SystemSettings { @@ -42,6 +42,10 @@ public class SystemSettings {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
public boolean treatDormantAsInactive() {
return prefs.getBoolean("system_dormantasinactive", false);
}
public boolean checkForUpdates() {
return prefs.getBoolean("system_checkupdates", true);
}

11
core/src/org/transdroid/core/gui/ServerStatusView.java

@ -25,15 +25,13 @@ import org.transdroid.core.gui.navigation.NavigationHelper; @@ -25,15 +25,13 @@ import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.SetTransferRatesDialog;
import org.transdroid.core.gui.navigation.SetTransferRatesDialog.OnRatesPickedListener;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.util.FileSizeConverter;
import de.keyboardsurfer.android.widget.crouton.Crouton;
import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import de.keyboardsurfer.android.widget.crouton.Crouton;
@EViewGroup(resName = "actionbar_serverstatus")
public class ServerStatusView extends RelativeLayout implements OnRatesPickedListener {
@ -54,8 +52,9 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -54,8 +52,9 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis
/**
* Updates the statistics as shown in the action bar through this server status view.
* @param torrents The most recently received list of torrents
* @param dormantAsInactive
*/
public void update(List<Torrent> torrents) {
public void update(List<Torrent> torrents, boolean dormantAsInactive) {
if (torrents == null) {
downcountText.setText(null);
@ -71,10 +70,10 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis @@ -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();

4
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -160,6 +160,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -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 @@ -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());
}

5
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -30,6 +30,7 @@ import org.androidannotations.annotations.ItemClick; @@ -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 @@ -66,6 +67,8 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL
// Local data
@Bean
protected ApplicationSettings applicationSettings;
@Bean
protected SystemSettings systemSettings;
@InstanceState
protected ArrayList<Torrent> torrents = null;
@InstanceState
@ -214,7 +217,7 @@ public class TorrentsFragment extends SherlockFragment implements OnLabelPickedL @@ -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<Torrent> torrentIter = filteredTorrents.iterator(); torrentIter.hasNext();) {
if (!currentNavigationFilter.matches(torrentIter.next()))
if (!currentNavigationFilter.matches(torrentIter.next(), systemSettings.treatDormantAsInactive()))
torrentIter.remove();
}
}

4
core/src/org/transdroid/core/gui/navigation/Label.java

@ -66,9 +66,11 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label @@ -66,9 +66,11 @@ public class Label implements SimpleListItem, NavigationFilter, Comparable<Label
/**
* Returns true if the torrent label's name matches this (selected) label's name, false otherwise
* @param torrent The torrent to match against this label
* @param dormantAsInactive This property is ignored for label comparisons
*/
@Override
public boolean matches(Torrent torrent) {
public boolean matches(Torrent torrent, boolean dormantAsInactive) {
if (isEmptyLabel)
return TextUtils.isEmpty(torrent.getLabelName());
return torrent.getLabelName() != null && torrent.getLabelName().equals(name);

4
core/src/org/transdroid/core/gui/navigation/NavigationFilter.java

@ -30,9 +30,11 @@ public interface NavigationFilter extends Parcelable { @@ -30,9 +30,11 @@ public interface NavigationFilter extends Parcelable {
* Implementations should check if the supplied torrent matches the filter; for example a label filter should return
* true if the torrent's label equals this items label name.
* @param torrent The torrent to check for matches
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively downloading or
* seeding
* @return True if the torrent matches the filter and should be shown in the current screen, false otherwise
*/
boolean matches(Torrent torrent);
boolean matches(Torrent torrent, boolean dormantAsInactive);
/**
* Implementations should return a name that can be shown to indicate the active filter

21
core/src/org/transdroid/core/gui/navigation/StatusType.java

@ -22,7 +22,6 @@ import java.util.List; @@ -22,7 +22,6 @@ import java.util.List;
import org.transdroid.core.R;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentStatus;
import android.content.Context;
import android.os.Parcel;
@ -108,24 +107,22 @@ public enum StatusType { @@ -108,24 +107,22 @@ public enum StatusType {
/**
* Returns true if the torrent status matches this (selected) status type, false otherwise
* @param torrent The torrent to match against this status type
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively
* downloading or seeding
*/
@Override
public boolean matches(Torrent torrent) {
public boolean matches(Torrent torrent, boolean dormantAsInactive) {
switch (statusType) {
case OnlyDownloading:
return torrent.getStatusCode() == TorrentStatus.Downloading;
return torrent.isDownloading(dormantAsInactive);
case OnlyUploading:
return torrent.getStatusCode() == TorrentStatus.Seeding;
return torrent.isSeeding(dormantAsInactive);
case OnlyActive:
return torrent.getStatusCode() == TorrentStatus.Downloading
|| torrent.getStatusCode() == TorrentStatus.Seeding;
return torrent.isDownloading(dormantAsInactive)
|| torrent.isSeeding(dormantAsInactive);
case OnlyInactive:
return torrent.getStatusCode() == TorrentStatus.Checking
|| torrent.getStatusCode() == TorrentStatus.Error
|| torrent.getStatusCode() == TorrentStatus.Paused
|| torrent.getStatusCode() == TorrentStatus.Queued
|| torrent.getStatusCode() == TorrentStatus.Unknown
|| torrent.getStatusCode() == TorrentStatus.Waiting;
return !torrent.isDownloading(dormantAsInactive) && !torrent.isSeeding(dormantAsInactive);
default:
return true;
}

5
core/src/org/transdroid/core/widget/ListWidgetConfigActivity.java

@ -30,6 +30,7 @@ import org.androidannotations.annotations.ViewById; @@ -30,6 +30,7 @@ import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings;
import org.transdroid.core.gui.lists.SimpleListItemSpinnerAdapter;
import org.transdroid.core.gui.lists.SortByListItem;
import org.transdroid.core.gui.navigation.StatusType;
@ -82,6 +83,8 @@ public class ListWidgetConfigActivity extends SherlockActivity { @@ -82,6 +83,8 @@ public class ListWidgetConfigActivity extends SherlockActivity {
protected ConnectivityHelper connectivityHelper;
@Bean
protected ApplicationSettings applicationSettings;
@Bean
protected SystemSettings systemSettings;
private int appWidgetId;
@Override
@ -198,7 +201,7 @@ public class ListWidgetConfigActivity extends SherlockActivity { @@ -198,7 +201,7 @@ public class ListWidgetConfigActivity extends SherlockActivity {
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>(previewTorrents.size());
StatusTypeFilter statusTypeFilter = (StatusTypeFilter) filterSpinner.getSelectedItem();
for (Torrent torrent : previewTorrents) {
if (statusTypeFilter.matches(torrent))
if (statusTypeFilter.matches(torrent, systemSettings.treatDormantAsInactive()))
filteredTorrents.add(torrent);
}
if (filteredTorrents.size() == 0) {

3
core/src/org/transdroid/core/widget/ListWidgetViewsService.java

@ -110,9 +110,10 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory { @@ -110,9 +110,10 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
}
// We have data; filter, sort and store it to use later when getViewAt gets called
SystemSettings systemSettings = SystemSettings_.getInstance_(context);
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>();
for (Torrent torrent : ((RetrieveTaskSuccessResult) result).getTorrents()) {
if (config.getStatusType().getFilterItem(context).matches(torrent))
if (config.getStatusType().getFilterItem(context).matches(torrent, systemSettings.treatDormantAsInactive()))
filteredTorrents.add(torrent);
}
if (filteredTorrents.size() > 0) {

20
lib/src/org/transdroid/daemon/Torrent.java

@ -187,6 +187,26 @@ public final class Torrent implements Parcelable, Comparable<Torrent> { @@ -187,6 +187,26 @@ public final class Torrent implements Parcelable, Comparable<Torrent> {
return partDone;
}
/**
* Returns whether this torrents is actively downloading or not.
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively downloading
* @return True if this torrent is to be treated as being in a downloading state, that is, it is trying to finish a
* download
*/
public boolean isDownloading(boolean dormantAsInactive) {
return statusCode == TorrentStatus.Downloading && (!dormantAsInactive || rateDownload > 0);
}
/**
* Returns whether this torrents is actively seeding or not.
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are never actively seeding
* @return True if this torrent is to be treated as being in a seeding state, that is, it is sending data to
* leechers
*/
public boolean isSeeding(boolean dormantAsInactive) {
return statusCode == TorrentStatus.Seeding && (!dormantAsInactive || rateUpload > 0);
}
/**
* Indicates if the torrent can be paused at this moment
* @return If it can be paused

Loading…
Cancel
Save