From f99bed2da2eb529e4c8a90961f8c791aa2a8a58d Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 18 Jun 2013 14:02:44 +0200 Subject: [PATCH] Added server status (counts and speeds) in the action bar. --- core/project.properties | 2 +- core/res/layout/actionbar_serverstatus.xml | 84 +++++++++++++++++++ core/res/values-land/dimens.xml | 27 ++++++ .../dimens.xml | 6 ++ core/res/values/dimens.xml | 6 ++ core/res/values/strings.xml | 4 +- .../transdroid/core/gui/ServerStatusView.java | 65 ++++++++++++++ .../transdroid/core/gui/TorrentsActivity.java | 14 +++- lite/AndroidManifest.xml | 19 ++--- 9 files changed, 213 insertions(+), 14 deletions(-) create mode 100644 core/res/layout/actionbar_serverstatus.xml create mode 100644 core/res/values-land/dimens.xml rename core/res/{values-sw500dp => values-sw600dp}/dimens.xml (65%) create mode 100644 core/src/org/transdroid/core/gui/ServerStatusView.java diff --git a/core/project.properties b/core/project.properties index 2c3a9595..0a043162 100644 --- a/core/project.properties +++ b/core/project.properties @@ -11,7 +11,7 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-16 +target=android-17 android.library.reference.1=../external/JakeWharton-ActionBarSherlock/library android.library.reference.2=../external/ColorPickerPreference android.library=true diff --git a/core/res/layout/actionbar_serverstatus.xml b/core/res/layout/actionbar_serverstatus.xml new file mode 100644 index 00000000..1a8d4baa --- /dev/null +++ b/core/res/layout/actionbar_serverstatus.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/res/values-land/dimens.xml b/core/res/values-land/dimens.xml new file mode 100644 index 00000000..c8a1d911 --- /dev/null +++ b/core/res/values-land/dimens.xml @@ -0,0 +1,27 @@ + + + + 16dp + 8dp + 16dp + + + 12sp + 15sp + 15sp + 22sp + 33sp + 12sp + + + 15sp + 12sp + 110dp + 1dp + 2dp + 19sp + 12sp + 12sp + 53dp + + \ No newline at end of file diff --git a/core/res/values-sw500dp/dimens.xml b/core/res/values-sw600dp/dimens.xml similarity index 65% rename from core/res/values-sw500dp/dimens.xml rename to core/res/values-sw600dp/dimens.xml index ce641b92..f4926c5c 100644 --- a/core/res/values-sw500dp/dimens.xml +++ b/core/res/values-sw600dp/dimens.xml @@ -17,5 +17,11 @@ 18sp 15sp 125dp + 2dp + 5dp + 25sp + 17sp + 14sp + 63dp \ No newline at end of file diff --git a/core/res/values/dimens.xml b/core/res/values/dimens.xml index 518bbae0..46d7ea75 100644 --- a/core/res/values/dimens.xml +++ b/core/res/values/dimens.xml @@ -17,5 +17,11 @@ 17sp 14sp 110dp + 2dp + 3dp + 21sp + 15sp + 13sp + 53dp \ No newline at end of file diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index d846679c..870ba5ca 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -73,8 +73,8 @@ UNKNOWN ETA RATIO %1$s %1$s OF %2$s PEERS - ↑ %1$s - ↓ %1$s + ↑ %1$s + ↓ %1$s Downloading Seeding Paused diff --git a/core/src/org/transdroid/core/gui/ServerStatusView.java b/core/src/org/transdroid/core/gui/ServerStatusView.java new file mode 100644 index 00000000..8bbda367 --- /dev/null +++ b/core/src/org/transdroid/core/gui/ServerStatusView.java @@ -0,0 +1,65 @@ +package org.transdroid.core.gui; + +import java.util.List; + +import org.androidannotations.annotations.EViewGroup; +import org.androidannotations.annotations.ViewById; +import org.transdroid.daemon.Torrent; +import org.transdroid.daemon.TorrentStatus; +import org.transdroid.daemon.util.FileSizeConverter; + +import android.content.Context; +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.TextView; + +@EViewGroup(resName="actionbar_serverstatus") +public class ServerStatusView extends RelativeLayout { + + @ViewById + protected TextView downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText; + + public ServerStatusView(Context context) { + super(context); + } + + /** + * Updates the statistics as shown in the action bar through this server status view. + * @param torrents The most recently received list of torrents + */ + public void update(List torrents) { + + if (torrents == null) { + downcountText.setText(null); + upcountText.setText(null); + downspeedText.setText(null); + upspeedText.setText(null); + downcountSign.setVisibility(View.INVISIBLE); + upcountSign.setVisibility(View.INVISIBLE); + } + + int downcount = 0, upcount = 0, downspeed = 0, upspeed = 0; + for (Torrent torrent : torrents) { + + // Downloading torrents count towards downloads and uploads, seeding torrents towards uploads + if (torrent.getStatusCode() == TorrentStatus.Downloading) { + downcount++; + upcount++; + } else if (torrent.getStatusCode() == TorrentStatus.Seeding) { + upcount++; + } + downspeed += torrent.getRateDownload(); + upspeed += torrent.getRateUpload(); + + } + + downcountText.setText(Integer.toString(downcount)); + upcountText.setText(Integer.toString(upcount)); + downspeedText.setText(FileSizeConverter.getSize(downspeed)); + upspeedText.setText(FileSizeConverter.getSize(upspeed)); + downcountSign.setVisibility(View.VISIBLE); + upcountSign.setVisibility(View.VISIBLE); + + } + +} diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index ae218244..0019add9 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/core/src/org/transdroid/core/gui/TorrentsActivity.java @@ -101,6 +101,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi protected SherlockListView filtersList; protected FilterListAdapter navigationListAdapter = null; protected FilterListDropDownAdapter navigationSpinnerAdapter = null; + protected ServerStatusView serverStatusView; @SystemService protected SearchManager searchManager; @@ -135,10 +136,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @AfterViews protected void init() { - // Set up navigation, with an action bar spinner and possibly (if room) with a filter list + // Set up navigation, with an action bar spinner, server status indicator and possibly (if room) with a filter + // list + serverStatusView = ServerStatusView_.build(this); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setHomeButtonEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); + getSupportActionBar().setDisplayShowCustomEnabled(true); + getSupportActionBar().setCustomView(serverStatusView); navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this); // Servers are always added to the action bar spinner navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings()); @@ -780,13 +785,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @UiThread protected void onTorrentsRetrieved(List torrents, List labels) { + // Report the newly retrieved list of torrents to the torrents fragment fragmentTorrents.updateIsLoading(false); fragmentTorrents.updateTorrents(new ArrayList(torrents)); + // Update the details fragment if the currently shown torrent is in the newly retrieved list if (fragmentDetails != null) { fragmentDetails.perhapsUpdateTorrent(torrents); } + // Update local list of labels in the navigation List