From 85c2263f85bf3d85f45c3e78898218838a303454 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 8 Oct 2013 20:00:40 +0200 Subject: [PATCH] Added new widget config acitivity (the actual wisget is to follow). --- .../res/drawable-hdpi/ic_action_done_dark.png | Bin 0 -> 1335 bytes .../drawable-hdpi/ic_action_done_light.png | Bin 0 -> 1320 bytes .../res/drawable-mdpi/ic_action_done_dark.png | Bin 0 -> 1191 bytes .../drawable-mdpi/ic_action_done_light.png | Bin 0 -> 1197 bytes .../drawable-xhdpi/ic_action_done_dark.png | Bin 0 -> 1599 bytes .../drawable-xhdpi/ic_action_done_light.png | Bin 0 -> 1546 bytes core/res/layout/actionbar_donebutton.xml | 37 +++ core/res/layout/activity_widgetconfig.xml | 91 ++++++ core/res/layout/widget_torrents_dark.xml | 69 +++++ core/res/layout/widget_torrents_light.xml | 69 +++++ core/res/values-sw600dp/dimens.xml | 11 +- core/res/values-v14/dimens.xml | 21 ++ core/res/values/attrs.xml | 1 + core/res/values/dimens.xml | 7 + core/res/values/strings.xml | 7 + core/res/values/styles.xml | 2 + core/res/xml/appwidget_info.xml | 29 ++ .../app/settings/ApplicationSettings.java | 40 ++- .../core/gui/lists/SortByListItem.java | 46 +++ .../core/gui/navigation/StatusType.java | 4 + .../core/widget/WidgetConfigActivity.java | 265 ++++++++++++++++++ .../core/widget/WidgetProvider.java | 34 +++ .../core/widget/WidgetSettings.java | 63 +++++ full/AndroidManifest.xml | 20 +- lite/AndroidManifest.xml | 3 +- 25 files changed, 807 insertions(+), 12 deletions(-) create mode 100644 core/res/drawable-hdpi/ic_action_done_dark.png create mode 100644 core/res/drawable-hdpi/ic_action_done_light.png create mode 100644 core/res/drawable-mdpi/ic_action_done_dark.png create mode 100644 core/res/drawable-mdpi/ic_action_done_light.png create mode 100644 core/res/drawable-xhdpi/ic_action_done_dark.png create mode 100644 core/res/drawable-xhdpi/ic_action_done_light.png create mode 100644 core/res/layout/actionbar_donebutton.xml create mode 100644 core/res/layout/activity_widgetconfig.xml create mode 100644 core/res/layout/widget_torrents_dark.xml create mode 100644 core/res/layout/widget_torrents_light.xml create mode 100644 core/res/values-v14/dimens.xml create mode 100644 core/res/xml/appwidget_info.xml create mode 100644 core/src/org/transdroid/core/gui/lists/SortByListItem.java create mode 100644 core/src/org/transdroid/core/widget/WidgetConfigActivity.java create mode 100644 core/src/org/transdroid/core/widget/WidgetProvider.java create mode 100644 core/src/org/transdroid/core/widget/WidgetSettings.java diff --git a/core/res/drawable-hdpi/ic_action_done_dark.png b/core/res/drawable-hdpi/ic_action_done_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..53cf6877eb72ad70368fd9e61fb780d42633a407 GIT binary patch literal 1335 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%qp275hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8hm3bwJ6}oxF$}kgLQj3#|G7CyF^YauyCMG83 zmzLNn0bL65LT&-v*t}wBFaZNhzap_f-%!s00+w{G(#^lGsViu)xy!q!qCao$-vFf(ACh=#L&{!#L3yw z&D7A`#K{n**Cju>G&eP`1g19yq1PFwUQlAlEdbi=l3J8mmYU*Ll%J~r_Ow+d7Ppw0 zo0vEnx>*3tbHVNwh~5<3ZgIrv7JZ;&^g&UJ6xA>xVEO?u;RzSWfhYacJYae+0w!$c zeGexvFfgw4ba4!+xb|0uSaiB=&gzz|) zeHIPOP;}su6zlHbXs5?qvn2gF-PGqjm8BsheUo&jAzoFWWRjvlfM$7PiGfCjb)cOy_?6w^l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8hm3bwJ6}oxF$}kgLQj3#|G7CyF^YauyCMG83 zmzLNn0bL65LT&-v*t}wBFaZNhzap_f-%!s00+w{G(#^lGsVi#&Ct}+$imdr$-u?X(ACh=#L&{!#L3yw z&D7A`#K{n**Cju>G&eP`1g19yq1OzjUQlAlEdbi=l3J8mmYU*Ll%J~r_Ow+d7PlC? zn3-5OIXVK(v%u~ah~5<3ZZW~>7JZ;&^g&UJ6xA>xVEO?u;RzSWfhYacJYae+0w(OB zPunsW7#L@Hx;TbZ+F}XRH$BVJ_~tbB>ux&w{i&Jpl6k3-y`NvKHk21q zV1%GG?pIzqOj6l*_t-(U9qjp;vo`HwN=}ep)5vUa_N7?Rr}hN4ng+Fwoh&_BpW+wD z&uL8OV?3O|erD1ih8>LjGWVRk>cn-L{3q>ay)F~Cc;}xn`8m#J@(k z@^-_wj*fK>KI!`&dhL6Y6 literal 0 HcmV?d00001 diff --git a/core/res/drawable-mdpi/ic_action_done_dark.png b/core/res/drawable-mdpi/ic_action_done_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..35cda8e1121385b8a83038311dcecd8a3d6622e5 GIT binary patch literal 1191 zcmaJ>Uu@e%9KIxLsV26jAO!7NINXVs5!)A%wJ}ZOCQfK1TtXVLsC%j7TwBxnPwfkF z143a#kWEwBVA^;<8Xe*Rfp{1b2r)6l`Y;&M1nSe+11d})!88@|fV7Em?wY^@!IFJ< zzx%%L_g6lYn|NZ!_P*@^fF0R!DNk4Ey(pw0(5088i)7NAAyvi3V61GGFwE-8 zEY4%4ytMcg9swY*TPqYvQGQZTO`TOd4D0F^Wdksha4kih#{`z}tY*ZS8=swLpjM7E z`=T;0TPZxJjn`~ES(_-RwRtsGW)h=t#1*K3j)?+YeZg=9H_mM83Uu$8IRnbK!7^B0|oRK@>M+ID<_E2|KE-Swu4p=qV~C zvqItwjr2|my48|3oUJm^f^n{5afs!;l$thx6lsB%Vi6QeN0Owy~geTP{a~;k?%VtJO^togZ)88eDp4jXpN$yxVlJ z-Cv(t1HjjtmBtG0mC~)-w-Xmc|0A#XI^Ws(K;?_ZB1i;ps&7oM9K80Hcy(u`J{-J! zdbY~~i`~KJeH#OC^tBa#;hyihJ_3vP2NPiZM{(hZJP-=q5YJropPZW7|DylYwX+t; zo|ydJw|oEcCEo{PfA{L?vmf`L4A}KQJA$0Q7k=X2m4k|oa!j;vhU>{?)YW-hl7Xr1vcVv^sZI*_)iaJn7(%p zizD|nDs^{PFwwE@!oRkyV)5LouYY~u*u`hiH$Bgax4IkWa~JIVp1~aX&A)!>c<1Bq zJzc+h?WLl>(Vc()^O^qZZyph**L;ENpbi4y=WoC4yxco}%=>j@(-YE%$>{@s18j_l Aq5uE@ literal 0 HcmV?d00001 diff --git a/core/res/drawable-mdpi/ic_action_done_light.png b/core/res/drawable-mdpi/ic_action_done_light.png new file mode 100644 index 0000000000000000000000000000000000000000..cf5fab3adf243318d11ec95448c6deae3f52d9b1 GIT binary patch literal 1197 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 literal 0 HcmV?d00001 diff --git a/core/res/drawable-xhdpi/ic_action_done_light.png b/core/res/drawable-xhdpi/ic_action_done_light.png new file mode 100644 index 0000000000000000000000000000000000000000..b8915716e06792d926f397a7b17346f656c86aa1 GIT binary patch literal 1546 zcmaJ>eM}Q~7(NOZ>jx?|Mx7)_1qW{Q?n+DPg;FVn(PM_rcwjwgk7z zaExq;FcCM$1T(WNW-4=WI(1VrnIo~NbIM>M*htY0#}vP^FxeFW{X=%i-TV8!d7tO~ zdUEwS*{>~}w{ji;01FLSdXr$+1>d=Igzo{O;<{i~@EK-4moDL57>fgGHrj%N1`;d9 zO*m%rRCM7f01z5Ogb|R~a#dE8&^Q=`4tJ)^jrh+MMR3IR69s}KEImMxFjdYS170y97Bn2l! zc!x&%v?#MN2TZ3~98}8S1S_0`fJq7&qJY&3^{b#9Mqmh$L$E3Vfl;Ljg%NP-kqX&Z zTM25?XHMl3ZW^hb=NS}&TrQW)l_;axQV3D2)etO)%@DX$DNsRmu?1h*=3L=$S+q zji`a*c#N{*2E9fqaL5S4h9>Hh6v?`@WTg&HMvx3dtw7Wn3SD|yrV>#pbjUPTPg|WN zPVv)N+cT_sR%}oVBqLvOnw4(~Yn#0m)vQ=ZC?~O*G{jdJEH8vU^=Avr+i|X?`*2LY9 z7jHvHE29PrBH!kINN(*uSt$Oev6h7iu1N7t^Bcq8%eH4kerw;l_*m?|A2AK`y6?34 zP`@{J#lYB+FlJ}1sp{bG{!_iCO_Q1c_7CzZkyMzhv`>@qo7TfY@Gmt3uSG*tgxNWQc=v|JYQSD*fn7li5 z#PB$#i7UEVf00h?$hp1uLQj2zQtZFGsWX7jD_#?wJrFj3Z4#6Vd{fyGdK_MQaQVc! gtQRZb>M + + + + + + \ No newline at end of file diff --git a/core/res/layout/activity_widgetconfig.xml b/core/res/layout/activity_widgetconfig.xml new file mode 100644 index 00000000..1153afe2 --- /dev/null +++ b/core/res/layout/activity_widgetconfig.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/res/layout/widget_torrents_dark.xml b/core/res/layout/widget_torrents_dark.xml new file mode 100644 index 00000000..8b606768 --- /dev/null +++ b/core/res/layout/widget_torrents_dark.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/res/layout/widget_torrents_light.xml b/core/res/layout/widget_torrents_light.xml new file mode 100644 index 00000000..8b606768 --- /dev/null +++ b/core/res/layout/widget_torrents_light.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/res/values-sw600dp/dimens.xml b/core/res/values-sw600dp/dimens.xml index 268734c6..2a8dc8ce 100644 --- a/core/res/values-sw600dp/dimens.xml +++ b/core/res/values-sw600dp/dimens.xml @@ -16,11 +16,6 @@ --> - - 16dp - 8dp - 16dp - 14sp 17sp @@ -40,4 +35,10 @@ 14sp 63dp + + 0 + 15dp + -1dp + 300dp + diff --git a/core/res/values-v14/dimens.xml b/core/res/values-v14/dimens.xml new file mode 100644 index 00000000..54dfd51f --- /dev/null +++ b/core/res/values-v14/dimens.xml @@ -0,0 +1,21 @@ + + + + 0dp + + diff --git a/core/res/values/attrs.xml b/core/res/values/attrs.xml index 5bd9fc95..64c2f81e 100644 --- a/core/res/values/attrs.xml +++ b/core/res/values/attrs.xml @@ -42,6 +42,7 @@ + diff --git a/core/res/values/dimens.xml b/core/res/values/dimens.xml index 21633559..3dec83c5 100644 --- a/core/res/values/dimens.xml +++ b/core/res/values/dimens.xml @@ -20,6 +20,7 @@ 16dp 8dp 16dp + 8dp 12sp @@ -40,4 +41,10 @@ 13sp 53dp + + 1 + 10dp + 150dp + -1dp + diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index 92e97c81..b5856e1e 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -190,6 +190,13 @@ New torrents for %1$s + Open Transdroid + SERVER VIEW + LOOK & FEEL + Reverse sort order + Use dark theme + DONE + Servers Add new server Search sites diff --git a/core/res/values/styles.xml b/core/res/values/styles.xml index bf67e11f..85579153 100644 --- a/core/res/values/styles.xml +++ b/core/res/values/styles.xml @@ -22,6 +22,7 @@ @color/background_light @drawable/ic_action_discard_light + @drawable/ic_action_done_light @drawable/ic_action_filter_light @drawable/ic_action_labels_light @drawable/ic_action_new_light @@ -53,6 +54,7 @@ @color/background_dark @drawable/ic_action_discard_dark + @drawable/ic_action_done_dark @drawable/ic_action_filter_dark @drawable/ic_action_labels_dark @drawable/ic_action_new_dark diff --git a/core/res/xml/appwidget_info.xml b/core/res/xml/appwidget_info.xml new file mode 100644 index 00000000..57d66929 --- /dev/null +++ b/core/res/xml/appwidget_info.xml @@ -0,0 +1,29 @@ + + + diff --git a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java index 5946714e..ec13a23e 100644 --- a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java @@ -29,7 +29,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchSite; +import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.search.SearchSetting; +import org.transdroid.core.widget.WidgetSettings; import org.transdroid.daemon.Daemon; import org.transdroid.daemon.OS; import org.transdroid.daemon.TorrentsSortBy; @@ -408,7 +410,7 @@ public class ApplicationSettings { all.addAll(getWebsearchSettings()); return Collections.unmodifiableList(all); } - + /** * Returns the settings of the search site that was last used by the user or was selected by the user as default * site in the main settings. As opposed to getLastUsedSearchSiteKey(int), this method checks whether a site was @@ -434,7 +436,7 @@ public class ApplicationSettings { } return null; } - + if (lastWebsearch >= 0) { // The last used site should be a user-configured web search site int max = getMaxWebsearch(); // Zero-based index, so with max == 0 there is 1 server @@ -444,7 +446,7 @@ public class ApplicationSettings { } return getWebsearchSetting(lastWebsearch); } - + // Should be an in-app search key if (allsites != null) { for (SearchSite searchSite : allsites) { @@ -455,7 +457,7 @@ public class ApplicationSettings { // Not found at all; probably a no longer existing web search; return the first in-app one return allsites.get(0); } - + return null; } @@ -503,5 +505,33 @@ public class ApplicationSettings { public void setServerLastStats(ServerSetting server, JSONArray lastStats) { prefs.edit().putString(server.getUniqueIdentifier(), lastStats.toString()).commit(); } - + + /** + * Returns the user configuration for some specific app widget, if the widget is known at all. + * @param appWidgetId The unique ID of the app widget to retrieve settings for, as supplied by the AppWidgetManager + * @return A widget configuration object, or null if no settings were stored for the widget ID + */ + public WidgetSettings getWidgetConfig(int appWidgetId) { + if (!prefs.contains("widget_server_" + appWidgetId)) + return null; + // @formatter:off + return new WidgetSettings( + prefs.getInt("widget_server_" + appWidgetId, -1), + StatusType.valueOf(prefs.getString("widget_status_" + appWidgetId, StatusType.ShowAll.name())), + TorrentsSortBy.valueOf(prefs.getString("widget_sortby_" + appWidgetId, TorrentsSortBy.Alphanumeric.name())), + prefs.getBoolean("widget_reverse_" + appWidgetId, false), + prefs.getBoolean("widget_darktheme_" + appWidgetId, false)); + // @formatter:on + } + + public void setWidgetConfig(int appWidgetId, WidgetSettings settings) { + Editor edit = prefs.edit(); + edit.putInt("widget_server_" + appWidgetId, settings.getServerId()); + edit.putString("widget_status_" + appWidgetId, settings.getStatusType().name()); + edit.putString("widget_sortby_" + appWidgetId, settings.getSortBy().name()); + edit.putBoolean("widget_reverse_" + appWidgetId, settings.shouldReserveSort()); + edit.putBoolean("widget_darktheme_" + appWidgetId, settings.shouldUseDarkTheme()); + edit.commit(); + } + } diff --git a/core/src/org/transdroid/core/gui/lists/SortByListItem.java b/core/src/org/transdroid/core/gui/lists/SortByListItem.java new file mode 100644 index 00000000..d05c6aef --- /dev/null +++ b/core/src/org/transdroid/core/gui/lists/SortByListItem.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-2013 Eric Kok et al. + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + */ +package org.transdroid.core.gui.lists; + +import org.transdroid.daemon.TorrentsSortBy; + +/** + * Represents a way in which a torrents list can be sorted. + * @author Eric Kok + */ +public class SortByListItem implements SimpleListItem { + + private TorrentsSortBy sortBy; + + public SortByListItem(TorrentsSortBy sortBy) { + this.sortBy = sortBy; + } + + /** + * Returns the contained represented sort order. + * @return The sort by order as its enumeration value + */ + public TorrentsSortBy getSortBy() { + return sortBy; + } + + @Override + public String getName() { + return sortBy.name(); + } + +} diff --git a/core/src/org/transdroid/core/gui/navigation/StatusType.java b/core/src/org/transdroid/core/gui/navigation/StatusType.java index 74b26190..08c74e58 100644 --- a/core/src/org/transdroid/core/gui/navigation/StatusType.java +++ b/core/src/org/transdroid/core/gui/navigation/StatusType.java @@ -97,6 +97,10 @@ public enum StatusType { this.name = name; } + public StatusType getStatusType() { + return statusType; + } + @Override public String getName() { return name; diff --git a/core/src/org/transdroid/core/widget/WidgetConfigActivity.java b/core/src/org/transdroid/core/widget/WidgetConfigActivity.java new file mode 100644 index 00000000..abaa2f2e --- /dev/null +++ b/core/src/org/transdroid/core/widget/WidgetConfigActivity.java @@ -0,0 +1,265 @@ +/* + * Copyright 2010-2013 Eric Kok et al. + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + */ +package org.transdroid.core.widget; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Background; +import org.androidannotations.annotations.Bean; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.ItemSelect; +import org.androidannotations.annotations.SystemService; +import org.androidannotations.annotations.UiThread; +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.SimpleListItem; +import org.transdroid.core.gui.lists.SortByListItem; +import org.transdroid.core.gui.lists.TorrentsAdapter; +import org.transdroid.core.gui.navigation.FilterListItemAdapter; +import org.transdroid.core.gui.navigation.StatusType; +import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter; +import org.transdroid.core.service.ConnectivityHelper; +import org.transdroid.daemon.Daemon; +import org.transdroid.daemon.IDaemonAdapter; +import org.transdroid.daemon.Label; +import org.transdroid.daemon.Torrent; +import org.transdroid.daemon.TorrentsComparator; +import org.transdroid.daemon.TorrentsSortBy; +import org.transdroid.daemon.task.DaemonTaskResult; +import org.transdroid.daemon.task.RetrieveTask; +import org.transdroid.daemon.task.RetrieveTaskSuccessResult; + +import android.appwidget.AppWidgetManager; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.Spinner; +import android.widget.TextView; + +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.view.SherlockListView; + +@EActivity(resName = "activity_widgetconfig") +public class WidgetConfigActivity extends SherlockActivity { + + // Views and adapters + @ViewById + protected Spinner serverSpinner, filterSpinner, sortSpinner; + @ViewById + protected CheckBox reverseorderCheckBox, darkthemeCheckBox; + @ViewById + protected TextView filterText, serverText, errorText; + @ViewById + protected SherlockListView torrentsList; + @Bean + protected TorrentsAdapter previewTorrentsAdapter; + private List previewTorrents = null; + + // Settings and helpers + @SystemService + protected AppWidgetManager appWidgetManager; + @SystemService + protected LayoutInflater layoutInflater; + @Bean + protected ConnectivityHelper connectivityHelper; + @Bean + protected ApplicationSettings applicationSettings; + private int appWidgetId; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + // Set the theme according to the user preference + if (SystemSettings_.getInstance_(this).useDarkTheme()) { + setTheme(R.style.TransdroidTheme_Dark); + getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); + } + super.onCreate(savedInstanceState); + + if (getIntent() != null && getIntent().getExtras() != null) { + // Get the appwidget ID we are configuring + appWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + // Set preliminary canceled result and continue with the initialisation + setResult(RESULT_CANCELED, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)); + } + + // Invalid configuration; return canceled result + setResult(RESULT_CANCELED, + new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)); + finish(); + + } + + @AfterViews + protected void init() { + + // Populate the selection spinners + List sortOrders = new ArrayList(); + for (TorrentsSortBy order : TorrentsSortBy.values()) { + sortOrders.add(new SortByListItem(order)); + } + serverSpinner.setAdapter(new FilterListItemAdapter(this, applicationSettings.getServerSettings())); + filterSpinner.setAdapter(new FilterListItemAdapter(this, StatusType.getAllStatusTypes(this))); + sortSpinner.setAdapter(new FilterListItemAdapter(this, sortOrders)); + // TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged + reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged); + torrentsList.setAdapter(previewTorrentsAdapter); + + // Set up action bar with a done button + // Inspired by NoNonsenseNotes's ListWidgetConfig.java (Apache License, Version 2.0) + getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, + ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); + View doneButtonFrame = layoutInflater.inflate(R.layout.actionbar_donebutton, null); + doneButtonFrame.findViewById(R.id.actionbar_done).setOnClickListener(doneClicked); + getSupportActionBar().setCustomView(doneButtonFrame); + + } + + @ItemSelect + protected void serverSpinnerItemSelected(boolean selected, ServerSetting server) { + serverText.setText(server.getName()); + loadTorrents(); + } + + @ItemSelect + protected void filterSpinnerItemSelected(boolean selected, StatusTypeFilter statusTypeFilter) { + filterText.setText(statusTypeFilter.getName()); + filterTorrents(); + } + + @ItemSelect + protected void sortSpinnerItemSelected(boolean selected, SortByListItem sortByListItem) { + filterTorrents(); + } + + protected OnCheckedChangeListener reverseorderCheckedChanged = new OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + filterTorrents(); + } + }; + + @Background + protected void loadTorrents() { + + if (serverSpinner.getSelectedItem() == null) + return; + + // Create a connection object and retrieve the live torrents + IDaemonAdapter connection = ((ServerSetting) serverSpinner.getSelectedItem()) + .createServerAdapter(connectivityHelper.getConnectedNetworkName()); + DaemonTaskResult result = RetrieveTask.create(connection).execute(); + if (result instanceof RetrieveTaskSuccessResult) { + // Success; show the active torrents in the widget preview + onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), + ((RetrieveTaskSuccessResult) result).getLabels()); + } else { + // Can't connect right now; provide a nice error message + showError(false); + } + + } + + @UiThread + protected void onTorrentsRetrieved(List torrents, List