From ad8c0f39ac7cca0224ed6dbe619cf31aa8828a70 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 4 Dec 2014 17:50:06 +0100 Subject: [PATCH] Replaced action bar with Toolbar and replaced spinner navigation with nav drawer. --- .../app/settings/ApplicationSettings.java | 8 +- .../core/app/settings/ServerSetting.java | 5 + .../transdroid/core/gui/ServerStatusView.java | 24 +- .../transdroid/core/gui/TorrentsActivity.java | 387 +++++++++--------- .../gui/navigation/FilterListAdapter.java | 5 - .../navigation/FilterListDropDownAdapter.java | 70 ---- .../core/gui/navigation/NavigationHelper.java | 155 ++++--- .../navigation/NavigationSelectionView.java | 52 --- .../core/service/ConnectivityHelper.java | 10 +- .../main/res/drawable/elevation_shadow.xml | 8 + .../res/layout-w600dp/activity_torrents.xml | 56 ++- .../res/layout-w900dp/activity_torrents.xml | 72 ++-- .../main/res/layout/actionbar_navigation.xml | 44 -- .../res/layout/actionbar_serverstatus.xml | 114 ++++-- app/src/main/res/layout/activity_torrents.xml | 47 ++- app/src/main/res/layout/list_item_filter.xml | 2 +- app/src/main/res/values-v16/styles.xml | 2 +- app/src/main/res/values-v21/styles.xml | 17 +- app/src/main/res/values/strings.xml | 4 +- app/src/main/res/values/styles.xml | 14 +- .../res/values/styles_transdroid_dark.xml | 2 +- .../res/values/styles_transdroid_light.xml | 2 +- 22 files changed, 547 insertions(+), 553 deletions(-) delete mode 100644 app/src/main/java/org/transdroid/core/gui/navigation/FilterListDropDownAdapter.java delete mode 100644 app/src/main/java/org/transdroid/core/gui/navigation/NavigationSelectionView.java create mode 100644 app/src/main/res/drawable/elevation_shadow.xml delete mode 100644 app/src/main/res/layout/actionbar_navigation.xml diff --git a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java index 830539d2..f9e83af9 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java @@ -97,15 +97,15 @@ public class ApplicationSettings { * @return The server settings object, loaded from shared preferences */ public ServerSetting getServerSetting(int order) { - int max = getMaxNormalServer(); - if (order <= max) { + int max = getMaxNormalServer() + 1; + if (order < max) { return getNormalServerSetting(order); } for (SeedboxProvider provider : SeedboxProvider.values()) { int offset = max; max += provider.getSettings().getMaxSeedboxOrder(prefs) + 1; - if (order <= max) { - return provider.getSettings().getServerSetting(prefs, offset, order - offset - 1); + if (order < max) { + return provider.getSettings().getServerSetting(prefs, offset, order - offset); } } return null; diff --git a/app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java b/app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java index 57329fc4..bac0163c 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java +++ b/app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java @@ -259,6 +259,11 @@ public class ServerSetting implements SimpleListItem { return false; } + @Override + public String toString() { + return getUniqueIdentifier(); + } + /** * Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not diff --git a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java index 41ff0ee0..265b7703 100644 --- a/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java +++ b/app/src/main/java/org/transdroid/core/gui/ServerStatusView.java @@ -21,9 +21,11 @@ import java.util.List; import org.androidannotations.annotations.EViewGroup; import org.androidannotations.annotations.ViewById; import org.transdroid.R; +import org.transdroid.core.gui.navigation.NavigationFilter; 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.IDaemonAdapter; import org.transdroid.daemon.Torrent; import org.transdroid.daemon.util.FileSizeConverter; @@ -37,7 +39,7 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; public class ServerStatusView extends RelativeLayout implements OnRatesPickedListener { @ViewById - protected TextView downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText; + protected TextView filterText, serverText, downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText; @ViewById protected View speedswrapperLayout; private TorrentsActivity activity; @@ -47,17 +49,33 @@ public class ServerStatusView extends RelativeLayout implements OnRatesPickedLis } public ServerStatusView(TorrentsActivity activity) { - super(activity); + super(activity.getSupportActionBar().getThemedContext()); this.activity = activity; } + /** + * Updates the name of the current connected server. + * @param currentServer The server currently connected to + */ + public void updateCurrentServer(IDaemonAdapter currentServer) { + serverText.setText(currentServer.getSettings().getName()); + } + + /** + * Updates the name of the selected filter. + * @param currentFilter The filter that is currently selected + */ + public void updateCurrentFilter(NavigationFilter currentFilter) { + filterText.setText(currentFilter.getName()); + } + /** * 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 Whether to treat dormant (0KB/s) torrent as inactive state torrents * @param supportsSetTransferRates Whether the connected torrent client supports setting of max transfer speeds */ - public void update(List torrents, boolean dormantAsInactive, boolean supportsSetTransferRates) { + public void updateStatus(List torrents, boolean dormantAsInactive, boolean supportsSetTransferRates) { if (torrents == null) { downcountText.setText(null); diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 4a4e9bab..c4b368f1 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -16,17 +16,28 @@ */ package org.transdroid.core.gui; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; +import android.annotation.TargetApi; +import android.app.SearchManager; +import android.content.ContentResolver; +import android.content.Intent; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.widget.Toolbar; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ListView; +import android.widget.SearchView; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Background; @@ -46,17 +57,28 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.cookie.BasicClientCookie; import org.transdroid.R; -import org.transdroid.core.app.search.*; -import org.transdroid.core.app.settings.*; +import org.transdroid.core.app.search.SearchHelper_; +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.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.WebsearchSetting; import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.SimpleListItem; -import org.transdroid.core.gui.log.*; -import org.transdroid.core.gui.navigation.*; -import org.transdroid.core.gui.rss.*; +import org.transdroid.core.gui.log.Log; +import org.transdroid.core.gui.log.LogUncaughtExceptionHandler; +import org.transdroid.core.gui.navigation.FilterListAdapter; +import org.transdroid.core.gui.navigation.FilterListAdapter_; +import org.transdroid.core.gui.navigation.Label; +import org.transdroid.core.gui.navigation.NavigationFilter; +import org.transdroid.core.gui.navigation.NavigationHelper; +import org.transdroid.core.gui.navigation.RefreshableActivity; +import org.transdroid.core.gui.navigation.StatusType; +import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.UrlEntryDialog; -import org.transdroid.core.gui.settings.*; +import org.transdroid.core.gui.settings.MainSettingsActivity_; import org.transdroid.core.service.BootReceiver; import org.transdroid.core.service.ConnectivityHelper; import org.transdroid.core.widget.ListWidgetProvider; @@ -96,26 +118,18 @@ import org.transdroid.daemon.task.StartTask; import org.transdroid.daemon.task.StopTask; import org.transdroid.daemon.util.HttpHelper; -import android.annotation.TargetApi; -import android.app.SearchManager; -import android.content.ContentResolver; -import android.content.Intent; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; -import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.ListView; -import android.widget.SearchView; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import de.keyboardsurfer.android.widget.crouton.Crouton; /** @@ -127,13 +141,16 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; */ @EActivity(resName = "activity_torrents") @OptionsMenu(resName = "activity_torrents") -public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnNavigationListener, TorrentTasksExecutor, - RefreshableActivity { +public class TorrentsActivity extends ActionBarActivity implements TorrentTasksExecutor, RefreshableActivity { private static final int RESULT_DETAILS = 0; + // Fragment uses this to pause the refresh across restarts public boolean stopRefresh = false; + // Navigation components + @SystemService + protected SearchManager searchManager; @Bean protected Log log; @Bean @@ -141,12 +158,18 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN @Bean protected ConnectivityHelper connectivityHelper; @ViewById + protected Toolbar torrentsToolbar; + @ViewById + protected DrawerLayout drawerLayout; + @ViewById + protected ListView drawerList; + @ViewById protected ListView filtersList; - protected FilterListAdapter navigationListAdapter = null; - protected FilterListDropDownAdapter navigationSpinnerAdapter = null; + protected ListView navigationList; + protected FilterListAdapter navigationListAdapter; protected ServerStatusView serverStatusView; - @SystemService - protected SearchManager searchManager; + protected ActionBarDrawerToggle drawerToggle; + // Settings @Bean protected ApplicationSettings applicationSettings; @@ -167,19 +190,23 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN protected DetailsFragment fragmentDetails; @InstanceState boolean firstStart = true; - int skipNextOnNavigationItemSelectedCalls = 2; private MenuItem searchMenu = null; private IDaemonAdapter currentConnection = null; + // Auto refresh task private AsyncTask autoRefreshTask; - // Handles item selections on the dedicated list of filter items + /** + * Handles item selections on the dedicated list of filter items + */ private OnItemClickListener onFilterListItemClicked = new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - filtersList.setItemChecked(position, true); - Object item = filtersList.getAdapter().getItem(position); - if (item instanceof SimpleListItem) + navigationList.setItemChecked(position, true); + Object item = navigationList.getAdapter().getItem(position); + if (item instanceof SimpleListItem) { filterSelected((SimpleListItem) item, false); + } + drawerLayout.closeDrawer(drawerList); } }; @@ -190,50 +217,43 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN setTheme(R.style.TransdroidTheme_Dark); } // Catch any uncaught exception to log it - Thread.setDefaultUncaughtExceptionHandler(new LogUncaughtExceptionHandler(this, - Thread.getDefaultUncaughtExceptionHandler())); + Thread.setDefaultUncaughtExceptionHandler( + new LogUncaughtExceptionHandler(this, Thread.getDefaultUncaughtExceptionHandler())); super.onCreate(savedInstanceState); } @AfterViews protected void init() { - // Set up navigation, with an action bar spinner, server status indicator and possibly (if room) with a filter - // list + // Use a custom view as action bar content, showing filter selection and current torrent counts/speeds + setSupportActionBar(torrentsToolbar); serverStatusView = ServerStatusView_.build(this); - ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - actionBar.setHomeButtonEnabled(false); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setCustomView(serverStatusView); - navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(getSupportActionBar().getThemedContext()); - // Servers are always added to the action bar spinner - navigationSpinnerAdapter.updateServers(applicationSettings.getAllServerSettings()); - - // Check if there was room for a dedicated filter list (i.e. on tablets) + torrentsToolbar.addView(serverStatusView); + + // Construct the filters list, i.e. the list of servers, status types and labels + navigationListAdapter = FilterListAdapter_.getInstance_(this); + navigationListAdapter.updateServers(applicationSettings.getAllServerSettings()); + navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this)); + // Add an empty labels list (which will be updated later, but the adapter needs to be created now) + navigationListAdapter.updateLabels(new ArrayList