Browse Source

Added option to show the server status stats (up and down count and speeds) in the widget action bar. Partially solves #42, although it doesn't look great when reducd to 1 cell high and 2 cells width.

pull/82/head
Eric Kok 11 years ago
parent
commit
5cba741216
  1. 7
      core/res/layout-v11/activity_widgetconfig.xml
  2. 83
      core/res/layout-v11/widget_torrents_dark.xml
  3. 84
      core/res/layout-v11/widget_torrents_light.xml
  4. 4
      core/res/values-land/dimens.xml
  5. 4
      core/res/values-sw600dp/dimens.xml
  6. 4
      core/res/values/dimens.xml
  7. 1
      core/res/values/strings.xml
  8. 2
      core/res/xml/listwidget_info.xml
  9. 13
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  10. 8
      core/src/org/transdroid/core/widget/ListWidgetConfig.java
  11. 40
      core/src/org/transdroid/core/widget/ListWidgetConfigActivity.java
  12. 7
      core/src/org/transdroid/core/widget/ListWidgetProvider.java
  13. 33
      core/src/org/transdroid/core/widget/ListWidgetViewsService.java

7
core/res/layout-v11/activity_widgetconfig.xml

@ -93,6 +93,13 @@
android:text="@string/widget_lookfeel" android:text="@string/widget_lookfeel"
android:textIsSelectable="false" /> android:textIsSelectable="false" />
<CheckBox
android:id="@+id/showstatus_check_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half"
android:text="@string/widget_showstatusview" />
<CheckBox <CheckBox
android:id="@+id/darktheme_check_box" android:id="@+id/darktheme_check_box"
android:layout_width="match_parent" android:layout_width="match_parent"

83
core/res/layout-v11/widget_torrents_dark.xml

@ -16,6 +16,7 @@
along with Transdroid. If not, see <http://www.gnu.org/licenses/>. along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background_dark" android:background="@color/background_dark"
@ -100,6 +101,88 @@
android:textSize="@dimen/ui_navigation_server" /> android:textSize="@dimen/ui_navigation_server" />
</LinearLayout> </LinearLayout>
<RelativeLayout
android:id="@+id/serverstatus_view"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_header_height"
android:layout_toLeftOf="@id/resumeall_button"
android:layout_toRightOf="@id/icon_image"
android:background="@drawable/selectable_background_transdroid"
android:clickable="true"
android:paddingTop="@dimen/ui_serverstatus_margin"
android:visibility="gone" >
<TextView
android:id="@+id/upcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↑"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_sign"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/upcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/downcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_text"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↓"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_sign"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/downcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/downcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/upspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/upcount_text"
android:layout_alignParentRight="true"
android:layout_below="@id/upcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
<TextView
android:id="@+id/downspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/downcount_text"
android:layout_alignRight="@id/downcount_sign"
android:layout_below="@id/downcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_dark"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/topline_view" android:id="@+id/topline_view"
android:layout_width="match_parent" android:layout_width="match_parent"

84
core/res/layout-v11/widget_torrents_light.xml

@ -16,6 +16,7 @@
along with Transdroid. If not, see <http://www.gnu.org/licenses/>. along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background_light" android:background="@color/background_light"
@ -100,6 +101,88 @@
android:textSize="@dimen/ui_navigation_server" /> android:textSize="@dimen/ui_navigation_server" />
</LinearLayout> </LinearLayout>
<RelativeLayout
android:id="@+id/serverstatus_view"
android:layout_width="match_parent"
android:layout_height="@dimen/widget_header_height"
android:layout_toLeftOf="@id/resumeall_button"
android:layout_toRightOf="@id/icon_image"
android:background="@drawable/selectable_background_transdroid2"
android:clickable="true"
android:paddingTop="@dimen/ui_serverstatus_margin"
android:visibility="gone" >
<TextView
android:id="@+id/upcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↑"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_sign"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/upcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/downcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_text"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↓"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_sign"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/downcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/downcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/upspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/upcount_text"
android:layout_alignParentRight="true"
android:layout_below="@id/upcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
<TextView
android:id="@+id/downspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/downcount_text"
android:layout_alignRight="@id/downcount_sign"
android:layout_below="@id/downcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="@color/text_bright_light"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/topline_view" android:id="@+id/topline_view"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -130,6 +213,7 @@
android:layout_below="@id/topline_view" android:layout_below="@id/topline_view"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default" android:padding="@dimen/margin_default"
android:textIsSelectable="false" android:textIsSelectable="false"
android:visibility="gone" /> android:visibility="gone" />

4
core/res/values-land/dimens.xml

@ -22,8 +22,8 @@
<dimen name="ui_serverstatus_margin">1dp</dimen> <dimen name="ui_serverstatus_margin">1dp</dimen>
<dimen name="ui_serverstatus_signmargin">2dp</dimen> <dimen name="ui_serverstatus_signmargin">2dp</dimen>
<dimen name="ui_serverstatus_bignumber">19sp</dimen> <dimen name="ui_serverstatus_bignumber">19sp</dimen>
<dimen name="ui_serverstatus_sign">12sp</dimen> <dimen name="ui_serverstatus_sign">12dp</dimen>
<dimen name="ui_serverstatus_smallnumber">12sp</dimen> <dimen name="ui_serverstatus_smallnumber">12dp</dimen>
<dimen name="ui_serverstatus_width">53dp</dimen> <dimen name="ui_serverstatus_width">53dp</dimen>
</resources> </resources>

4
core/res/values-sw600dp/dimens.xml

@ -31,8 +31,8 @@
<dimen name="ui_serverstatus_margin">2dp</dimen> <dimen name="ui_serverstatus_margin">2dp</dimen>
<dimen name="ui_serverstatus_signmargin">5dp</dimen> <dimen name="ui_serverstatus_signmargin">5dp</dimen>
<dimen name="ui_serverstatus_bignumber">25sp</dimen> <dimen name="ui_serverstatus_bignumber">25sp</dimen>
<dimen name="ui_serverstatus_sign">17sp</dimen> <dimen name="ui_serverstatus_sign">17dp</dimen>
<dimen name="ui_serverstatus_smallnumber">14sp</dimen> <dimen name="ui_serverstatus_smallnumber">14dp</dimen>
<dimen name="ui_serverstatus_width">63dp</dimen> <dimen name="ui_serverstatus_width">63dp</dimen>
<!-- Widget configuration --> <!-- Widget configuration -->

4
core/res/values/dimens.xml

@ -37,8 +37,8 @@
<dimen name="ui_serverstatus_margin">2dp</dimen> <dimen name="ui_serverstatus_margin">2dp</dimen>
<dimen name="ui_serverstatus_signmargin">3dp</dimen> <dimen name="ui_serverstatus_signmargin">3dp</dimen>
<dimen name="ui_serverstatus_bignumber">21sp</dimen> <dimen name="ui_serverstatus_bignumber">21sp</dimen>
<dimen name="ui_serverstatus_sign">15sp</dimen> <dimen name="ui_serverstatus_sign">15dp</dimen>
<dimen name="ui_serverstatus_smallnumber">13sp</dimen> <dimen name="ui_serverstatus_smallnumber">13dp</dimen>
<dimen name="ui_serverstatus_width">53dp</dimen> <dimen name="ui_serverstatus_width">53dp</dimen>
<!-- Widget configuration --> <!-- Widget configuration -->

1
core/res/values/strings.xml

@ -204,6 +204,7 @@
<string name="widget_lookfeel">LOOK &amp; FEEL</string> <string name="widget_lookfeel">LOOK &amp; FEEL</string>
<string name="widget_sortby">SORT ORDER</string> <string name="widget_sortby">SORT ORDER</string>
<string name="widget_reversesortorder">Reversed sort order</string> <string name="widget_reversesortorder">Reversed sort order</string>
<string name="widget_showstatusview">Server status instead of title</string>
<string name="widget_usedarktheme">Use dark theme (no preview)</string> <string name="widget_usedarktheme">Use dark theme (no preview)</string>
<string name="widget_done">DONE</string> <string name="widget_done">DONE</string>

2
core/res/xml/listwidget_info.xml

@ -20,7 +20,7 @@
android:initialKeyguardLayout="@layout/widget_torrents_light" android:initialKeyguardLayout="@layout/widget_torrents_light"
android:initialLayout="@layout/widget_torrents_light" android:initialLayout="@layout/widget_torrents_light"
android:minHeight="110dip" android:minHeight="110dip"
android:minResizeHeight="110dip" android:minResizeHeight="40dip"
android:minResizeWidth="110dp" android:minResizeWidth="110dp"
android:minWidth="180dp" android:minWidth="180dp"
android:previewImage="@drawable/widget_preview" android:previewImage="@drawable/widget_preview"

13
core/src/org/transdroid/core/app/settings/ApplicationSettings.java

@ -527,10 +527,13 @@ public class ApplicationSettings {
if (!prefs.contains("widget_server_" + appWidgetId)) if (!prefs.contains("widget_server_" + appWidgetId))
return null; return null;
// @formatter:off // @formatter:off
return new ListWidgetConfig(prefs.getInt("widget_server_" + appWidgetId, -1), StatusType.valueOf(prefs.getString( return new ListWidgetConfig(
"widget_status_" + appWidgetId, StatusType.ShowAll.name())), TorrentsSortBy.valueOf(prefs.getString( prefs.getInt("widget_server_" + appWidgetId, -1),
"widget_sortby_" + appWidgetId, TorrentsSortBy.Alphanumeric.name())), prefs.getBoolean( StatusType.valueOf(prefs.getString("widget_status_" + appWidgetId, StatusType.ShowAll.name())),
"widget_reverse_" + appWidgetId, false), prefs.getBoolean("widget_darktheme_" + appWidgetId, false)); TorrentsSortBy.valueOf(prefs.getString("widget_sortby_" + appWidgetId, TorrentsSortBy.Alphanumeric.name())),
prefs.getBoolean("widget_reverse_" + appWidgetId, false),
prefs.getBoolean("widget_showstatus_" + appWidgetId, false),
prefs.getBoolean("widget_darktheme_" + appWidgetId, false));
// @formatter:on // @formatter:on
} }
@ -549,6 +552,7 @@ public class ApplicationSettings {
edit.putString("widget_status_" + appWidgetId, settings.getStatusType().name()); edit.putString("widget_status_" + appWidgetId, settings.getStatusType().name());
edit.putString("widget_sortby_" + appWidgetId, settings.getSortBy().name()); edit.putString("widget_sortby_" + appWidgetId, settings.getSortBy().name());
edit.putBoolean("widget_reverse_" + appWidgetId, settings.shouldReserveSort()); edit.putBoolean("widget_reverse_" + appWidgetId, settings.shouldReserveSort());
edit.putBoolean("widget_showstatus_" + appWidgetId, settings.shouldShowStatusView());
edit.putBoolean("widget_darktheme_" + appWidgetId, settings.shouldUseDarkTheme()); edit.putBoolean("widget_darktheme_" + appWidgetId, settings.shouldUseDarkTheme());
edit.commit(); edit.commit();
} }
@ -563,6 +567,7 @@ public class ApplicationSettings {
edit.remove("widget_status_" + appWidgetId); edit.remove("widget_status_" + appWidgetId);
edit.remove("widget_sortby_" + appWidgetId); edit.remove("widget_sortby_" + appWidgetId);
edit.remove("widget_reverse_" + appWidgetId); edit.remove("widget_reverse_" + appWidgetId);
edit.remove("widget_showstatus_" + appWidgetId);
edit.remove("widget_darktheme_" + appWidgetId); edit.remove("widget_darktheme_" + appWidgetId);
edit.commit(); edit.commit();
} }

8
core/src/org/transdroid/core/widget/ListWidgetConfig.java

@ -29,14 +29,16 @@ public class ListWidgetConfig {
private final StatusType statusType; private final StatusType statusType;
private final TorrentsSortBy sortBy; private final TorrentsSortBy sortBy;
private final boolean reserveSort; private final boolean reserveSort;
private final boolean showStatusView;
private final boolean useDarkTheme; private final boolean useDarkTheme;
public ListWidgetConfig(int serverId, StatusType statusType, TorrentsSortBy sortBy, boolean reverseSort, public ListWidgetConfig(int serverId, StatusType statusType, TorrentsSortBy sortBy, boolean reverseSort,
boolean useDarkTheme) { boolean showStatusView, boolean useDarkTheme) {
this.serverId = serverId; this.serverId = serverId;
this.statusType = statusType; this.statusType = statusType;
this.sortBy = sortBy; this.sortBy = sortBy;
this.reserveSort = reverseSort; this.reserveSort = reverseSort;
this.showStatusView = showStatusView;
this.useDarkTheme = useDarkTheme; this.useDarkTheme = useDarkTheme;
} }
@ -56,6 +58,10 @@ public class ListWidgetConfig {
return reserveSort; return reserveSort;
} }
public boolean shouldShowStatusView() {
return showStatusView;
}
public boolean shouldUseDarkTheme() { public boolean shouldUseDarkTheme() {
return useDarkTheme; return useDarkTheme;
} }

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

@ -45,6 +45,7 @@ import org.transdroid.daemon.TorrentsSortBy;
import org.transdroid.daemon.task.DaemonTaskResult; import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.RetrieveTask; import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.util.FileSizeConverter;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
@ -71,11 +72,15 @@ public class ListWidgetConfigActivity extends SherlockActivity {
@ViewById @ViewById
protected Spinner serverSpinner, filterSpinner, sortSpinner; protected Spinner serverSpinner, filterSpinner, sortSpinner;
@ViewById @ViewById
protected CheckBox reverseorderCheckBox, darkthemeCheckBox; protected CheckBox reverseorderCheckBox, showstatusCheckBox, darkthemeCheckBox;
@ViewById @ViewById
protected TextView filterText, serverText, errorText; protected TextView filterText, serverText, errorText;
@ViewById @ViewById
protected TextView downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText;
@ViewById
protected ListView torrentsList; protected ListView torrentsList;
@ViewById
protected View navigationView, serverstatusView;
private List<Torrent> previewTorrents = null; private List<Torrent> previewTorrents = null;
// Settings and helpers // Settings and helpers
@ -122,6 +127,7 @@ public class ListWidgetConfigActivity extends SherlockActivity {
sortSpinner.setAdapter(new SimpleListItemSpinnerAdapter<SortByListItem>(this, 0, sortOrders)); sortSpinner.setAdapter(new SimpleListItemSpinnerAdapter<SortByListItem>(this, 0, sortOrders));
// TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged // TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged
reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged); reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged);
showstatusCheckBox.setOnCheckedChangeListener(showstatusCheckChanged);
torrentsList.setEmptyView(errorText); torrentsList.setEmptyView(errorText);
// Set up action bar with a done button // Set up action bar with a done button
@ -158,6 +164,14 @@ public class ListWidgetConfigActivity extends SherlockActivity {
} }
}; };
protected OnCheckedChangeListener showstatusCheckChanged = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
navigationView.setVisibility(showstatusCheckBox.isChecked()? View.GONE: View.VISIBLE);
serverstatusView.setVisibility(showstatusCheckBox.isChecked()? View.VISIBLE: View.GONE);
}
};
@Background @Background
protected void loadTorrents() { protected void loadTorrents() {
@ -200,8 +214,9 @@ public class ListWidgetConfigActivity extends SherlockActivity {
// Get the already loaded torrents and filter and sort them // Get the already loaded torrents and filter and sort them
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>(previewTorrents.size()); ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>(previewTorrents.size());
StatusTypeFilter statusTypeFilter = (StatusTypeFilter) filterSpinner.getSelectedItem(); StatusTypeFilter statusTypeFilter = (StatusTypeFilter) filterSpinner.getSelectedItem();
boolean dormantAsInactive = systemSettings.treatDormantAsInactive();
for (Torrent torrent : previewTorrents) { for (Torrent torrent : previewTorrents) {
if (statusTypeFilter.matches(torrent, systemSettings.treatDormantAsInactive())) if (statusTypeFilter.matches(torrent, dormantAsInactive))
filteredTorrents.add(torrent); filteredTorrents.add(torrent);
} }
if (filteredTorrents.size() == 0) { if (filteredTorrents.size() == 0) {
@ -213,6 +228,23 @@ public class ListWidgetConfigActivity extends SherlockActivity {
Collections Collections
.sort(filteredTorrents, new TorrentsComparator(serverType, sortBy, reverseorderCheckBox.isChecked())); .sort(filteredTorrents, new TorrentsComparator(serverType, sortBy, reverseorderCheckBox.isChecked()));
// Update the server status count and speeds
int downcount = 0, upcount = 0, downspeed = 0, upspeed = 0;
for (Torrent torrent : previewTorrents) {
if (torrent.isDownloading(dormantAsInactive)) {
downcount++;
upcount++;
} else if (torrent.isSeeding(dormantAsInactive)) {
upcount++;
}
downspeed += torrent.getRateDownload();
upspeed += torrent.getRateUpload();
}
downcountText.setText(Integer.toString(downcount));
upcountText.setText(Integer.toString(upcount));
downspeedText.setText(FileSizeConverter.getSize(downspeed) + "/s");
upspeedText.setText(FileSizeConverter.getSize(upspeed) + "/s");
// Finally update the widget preview with the live, filtered and sorted torrents list // Finally update the widget preview with the live, filtered and sorted torrents list
torrentsList.setAdapter(new ListWidgetPreviewAdapter(this, 0, filteredTorrents)); torrentsList.setAdapter(new ListWidgetPreviewAdapter(this, 0, filteredTorrents));
torrentsList.setVisibility(View.VISIBLE); torrentsList.setVisibility(View.VISIBLE);
@ -243,8 +275,10 @@ public class ListWidgetConfigActivity extends SherlockActivity {
StatusType statusType = ((StatusTypeFilter) filterSpinner.getSelectedItem()).getStatusType(); StatusType statusType = ((StatusTypeFilter) filterSpinner.getSelectedItem()).getStatusType();
TorrentsSortBy sortBy = ((SortByListItem) sortSpinner.getSelectedItem()).getSortBy(); TorrentsSortBy sortBy = ((SortByListItem) sortSpinner.getSelectedItem()).getSortBy();
boolean reverseSort = reverseorderCheckBox.isChecked(); boolean reverseSort = reverseorderCheckBox.isChecked();
boolean showstatus = showstatusCheckBox.isChecked();
boolean useDarkTheme = darkthemeCheckBox.isChecked(); boolean useDarkTheme = darkthemeCheckBox.isChecked();
ListWidgetConfig config = new ListWidgetConfig(server, statusType, sortBy, reverseSort, useDarkTheme); ListWidgetConfig config = new ListWidgetConfig(server, statusType, sortBy, reverseSort, showstatus,
useDarkTheme);
applicationSettings.setWidgetConfig(appWidgetId, config); applicationSettings.setWidgetConfig(appWidgetId, config);
// Return the widget configuration result // Return the widget configuration result

7
core/src/org/transdroid/core/widget/ListWidgetProvider.java

@ -19,8 +19,10 @@ package org.transdroid.core.widget;
import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EReceiver; import org.androidannotations.annotations.EReceiver;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.*; import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.gui.*; import org.transdroid.core.app.settings.ApplicationSettings_;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.service.ControlService; import org.transdroid.core.service.ControlService;
@ -132,6 +134,7 @@ public class ListWidgetProvider extends AppWidgetProvider {
rv.setTextViewText(R.id.error_text, context.getString(R.string.widget_loading)); rv.setTextViewText(R.id.error_text, context.getString(R.string.widget_loading));
// Show the server and status type filter from the widget configuration in the 'action bar' // Show the server and status type filter from the widget configuration in the 'action bar'
// NOTE: The ListWidgetViewsService will eventually decide to show these labels or the server status statistics
ServerSetting server = appSettings.getServerSetting(config.getServerId()); ServerSetting server = appSettings.getServerSetting(config.getServerId());
rv.setTextViewText(R.id.server_text, server.getName()); rv.setTextViewText(R.id.server_text, server.getName());
rv.setTextViewText(R.id.filter_text, config.getStatusType().getFilterItem(context).getName()); rv.setTextViewText(R.id.filter_text, config.getStatusType().getFilterItem(context).getName());

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

@ -23,7 +23,6 @@ import java.util.List;
import org.androidannotations.annotations.EService; import org.androidannotations.annotations.EService;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.*; import org.transdroid.core.app.settings.*;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.service.*; import org.transdroid.core.service.*;
@ -34,12 +33,14 @@ import org.transdroid.daemon.TorrentsComparator;
import org.transdroid.daemon.task.DaemonTaskResult; import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.RetrieveTask; import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.util.FileSizeConverter;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
@ -112,7 +113,8 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
// We have data; filter, sort and store it to use later when getViewAt gets called // We have data; filter, sort and store it to use later when getViewAt gets called
SystemSettings systemSettings = SystemSettings_.getInstance_(context); SystemSettings systemSettings = SystemSettings_.getInstance_(context);
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>(); ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>();
for (Torrent torrent : ((RetrieveTaskSuccessResult) result).getTorrents()) { List<Torrent> allTorrents = ((RetrieveTaskSuccessResult) result).getTorrents();
for (Torrent torrent : allTorrents) {
if (config.getStatusType().getFilterItem(context).matches(torrent, systemSettings.treatDormantAsInactive())) if (config.getStatusType().getFilterItem(context).matches(torrent, systemSettings.treatDormantAsInactive()))
filteredTorrents.add(torrent); filteredTorrents.add(torrent);
} }
@ -124,6 +126,33 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
} }
torrents = filteredTorrents; torrents = filteredTorrents;
// If the user asked to show the server status statistics, we need to update the widget remote views again
RemoteViews rv = ListWidgetProvider.buildRemoteViews(context, appWidgetId, config);
if (config.shouldShowStatusView()) {
// Update the server status count and speeds in the 'action bar'
int downcount = 0, upcount = 0, downspeed = 0, upspeed = 0;
for (Torrent torrent : torrents) {
if (torrent.isDownloading(systemSettings.treatDormantAsInactive())) {
downcount++;
upcount++;
} else if (torrent.isSeeding(systemSettings.treatDormantAsInactive())) {
upcount++;
}
downspeed += torrent.getRateDownload();
upspeed += torrent.getRateUpload();
}
rv.setViewVisibility(R.id.navigation_view, View.GONE);
rv.setViewVisibility(R.id.serverstatus_view, View.VISIBLE);
rv.setTextViewText(R.id.downcount_text, Integer.toString(downcount));
rv.setTextViewText(R.id.upcount_text, Integer.toString(upcount));
rv.setTextViewText(R.id.downspeed_text, FileSizeConverter.getSize(downspeed) + "/s");
rv.setTextViewText(R.id.upspeed_text, FileSizeConverter.getSize(upspeed) + "/s");
AppWidgetManager.getInstance(context.getApplicationContext()).updateAppWidget(appWidgetId, rv);
}
} }
@Override @Override

Loading…
Cancel
Save