@ -16,17 +16,28 @@
* /
* /
package org.transdroid.core.gui ;
package org.transdroid.core.gui ;
import java.io.File ;
import android.annotation.TargetApi ;
import java.io.FileNotFoundException ;
import android.app.SearchManager ;
import java.io.FileOutputStream ;
import android.content.ContentResolver ;
import java.io.IOException ;
import android.content.Intent ;
import java.io.InputStream ;
import android.net.Uri ;
import java.io.UnsupportedEncodingException ;
import android.os.AsyncTask ;
import java.net.URLDecoder ;
import android.os.Build ;
import java.util.ArrayList ;
import android.os.Bundle ;
import java.util.List ;
import android.support.v4.view.MenuItemCompat ;
import java.util.Map ;
import android.support.v4.widget.DrawerLayout ;
import java.util.Map.Entry ;
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.AfterViews ;
import org.androidannotations.annotations.Background ;
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.client.DefaultHttpClient ;
import org.apache.http.impl.cookie.BasicClientCookie ;
import org.apache.http.impl.cookie.BasicClientCookie ;
import org.transdroid.R ;
import org.transdroid.R ;
import org.transdroid.core.app.search.* ;
import org.transdroid.core.app.search.SearchHelper_ ;
import org.transdroid.core.app.settings.* ;
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.LocalTorrent ;
import org.transdroid.core.gui.lists.SimpleListItem ;
import org.transdroid.core.gui.lists.SimpleListItem ;
import org.transdroid.core.gui.log.* ;
import org.transdroid.core.gui.log.Log ;
import org.transdroid.core.gui.navigation.* ;
import org.transdroid.core.gui.log.LogUncaughtExceptionHandler ;
import org.transdroid.core.gui.rss.* ;
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.BarcodeHelper ;
import org.transdroid.core.gui.search.FilePickerHelper ;
import org.transdroid.core.gui.search.FilePickerHelper ;
import org.transdroid.core.gui.search.UrlEntryDialog ;
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.BootReceiver ;
import org.transdroid.core.service.ConnectivityHelper ;
import org.transdroid.core.service.ConnectivityHelper ;
import org.transdroid.core.widget.ListWidgetProvider ;
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.task.StopTask ;
import org.transdroid.daemon.util.HttpHelper ;
import org.transdroid.daemon.util.HttpHelper ;
import android.annotation.TargetApi ;
import java.io.File ;
import android.app.SearchManager ;
import java.io.FileNotFoundException ;
import android.content.ContentResolver ;
import java.io.FileOutputStream ;
import android.content.Intent ;
import java.io.IOException ;
import android.net.Uri ;
import java.io.InputStream ;
import android.os.AsyncTask ;
import java.io.UnsupportedEncodingException ;
import android.os.Build ;
import java.net.URLDecoder ;
import android.os.Bundle ;
import java.util.ArrayList ;
import android.support.v4.view.MenuItemCompat ;
import java.util.List ;
import android.support.v7.app.ActionBar ;
import java.util.Map ;
import android.support.v7.app.ActionBarActivity ;
import java.util.Map.Entry ;
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 de.keyboardsurfer.android.widget.crouton.Crouton ;
import de.keyboardsurfer.android.widget.crouton.Crouton ;
/ * *
/ * *
@ -127,13 +141,16 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
* /
* /
@EActivity ( resName = "activity_torrents" )
@EActivity ( resName = "activity_torrents" )
@OptionsMenu ( resName = "activity_torrents" )
@OptionsMenu ( resName = "activity_torrents" )
public class TorrentsActivity extends ActionBarActivity implements ActionBar . OnNavigationListener , TorrentTasksExecutor ,
public class TorrentsActivity extends ActionBarActivity implements TorrentTasksExecutor , RefreshableActivity {
RefreshableActivity {
private static final int RESULT_DETAILS = 0 ;
private static final int RESULT_DETAILS = 0 ;
// Fragment uses this to pause the refresh across restarts
// Fragment uses this to pause the refresh across restarts
public boolean stopRefresh = false ;
public boolean stopRefresh = false ;
// Navigation components
// Navigation components
@SystemService
protected SearchManager searchManager ;
@Bean
@Bean
protected Log log ;
protected Log log ;
@Bean
@Bean
@ -141,12 +158,18 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Bean
@Bean
protected ConnectivityHelper connectivityHelper ;
protected ConnectivityHelper connectivityHelper ;
@ViewById
@ViewById
protected Toolbar torrentsToolbar ;
@ViewById
protected DrawerLayout drawerLayout ;
@ViewById
protected ListView drawerList ;
@ViewById
protected ListView filtersList ;
protected ListView filtersList ;
protected FilterListAdapter navigationListAdapter = null ;
protected ListView navigationList ;
protected FilterListDropDownAdapter navigationSpinnerAdapter = null ;
protected FilterListAdapter navigationListAdapter ;
protected ServerStatusView serverStatusView ;
protected ServerStatusView serverStatusView ;
@SystemService
protected ActionBarDrawerToggle drawerToggle ;
protected SearchManager searchManager ;
// Settings
// Settings
@Bean
@Bean
protected ApplicationSettings applicationSettings ;
protected ApplicationSettings applicationSettings ;
@ -167,19 +190,23 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
protected DetailsFragment fragmentDetails ;
protected DetailsFragment fragmentDetails ;
@InstanceState
@InstanceState
boolean firstStart = true ;
boolean firstStart = true ;
int skipNextOnNavigationItemSelectedCalls = 2 ;
private MenuItem searchMenu = null ;
private MenuItem searchMenu = null ;
private IDaemonAdapter currentConnection = null ;
private IDaemonAdapter currentConnection = null ;
// Auto refresh task
// Auto refresh task
private AsyncTask < Void , Void , Void > autoRefreshTask ;
private AsyncTask < Void , Void , Void > 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 ( ) {
private OnItemClickListener onFilterListItemClicked = new OnItemClickListener ( ) {
@Override
@Override
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
filters List. setItemChecked ( position , true ) ;
navigation List. setItemChecked ( position , true ) ;
Object item = filters List. getAdapter ( ) . getItem ( position ) ;
Object item = navigation List. getAdapter ( ) . getItem ( position ) ;
if ( item instanceof SimpleListItem )
if ( item instanceof SimpleListItem ) {
filterSelected ( ( SimpleListItem ) item , false ) ;
filterSelected ( ( SimpleListItem ) item , false ) ;
}
drawerLayout . closeDrawer ( drawerList ) ;
}
}
} ;
} ;
@ -190,50 +217,43 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
setTheme ( R . style . TransdroidTheme_Dark ) ;
setTheme ( R . style . TransdroidTheme_Dark ) ;
}
}
// Catch any uncaught exception to log it
// Catch any uncaught exception to log it
Thread . setDefaultUncaughtExceptionHandler ( new LogUncaughtExceptionHandler ( this ,
Thread . setDefaultUncaughtExceptionHandler (
Thread . getDefaultUncaughtExceptionHandler ( ) ) ) ;
new LogUncaughtExceptionHandler ( this , Thread . getDefaultUncaughtExceptionHandler ( ) ) ) ;
super . onCreate ( savedInstanceState ) ;
super . onCreate ( savedInstanceState ) ;
}
}
@AfterViews
@AfterViews
protected void init ( ) {
protected void init ( ) {
// Set up navigation, with an action bar spinner, server status indicator and possibly (if room) with a filter
// Use a custom view as action bar content, showing filter selection and current torrent counts/speeds
// list
setSupportActionBar ( torrentsToolbar ) ;
serverStatusView = ServerStatusView_ . build ( this ) ;
serverStatusView = ServerStatusView_ . build ( this ) ;
ActionBar actionBar = getSupportActionBar ( ) ;
torrentsToolbar . addView ( serverStatusView ) ;
actionBar . setNavigationMode ( ActionBar . NAVIGATION_MODE_LIST ) ;
actionBar . setHomeButtonEnabled ( false ) ;
// Construct the filters list, i.e. the list of servers, status types and labels
actionBar . setDisplayShowTitleEnabled ( false ) ;
navigationListAdapter = FilterListAdapter_ . getInstance_ ( this ) ;
actionBar . setDisplayShowCustomEnabled ( true ) ;
navigationListAdapter . updateServers ( applicationSettings . getAllServerSettings ( ) ) ;
actionBar . setCustomView ( serverStatusView ) ;
navigationListAdapter . updateStatusTypes ( StatusType . getAllStatusTypes ( this ) ) ;
navigationSpinnerAdapter = FilterListDropDownAdapter_ . getInstance_ ( getSupportActionBar ( ) . getThemedContext ( ) ) ;
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
// Servers are always added to the action bar spinner
navigationListAdapter . updateLabels ( new ArrayList < Label > ( ) ) ;
navigationSpinnerAdapter . updateServers ( applicationSettings . getAllServerSettings ( ) ) ;
// Apply the filters list to the navigation drawer (on phones) or the dedicated side bar (i.e. on tablets)
// Check if there was room for a dedicated filter list (i.e. on tablets)
if ( filtersList ! = null ) {
if ( filtersList ! = null ) {
// The action bar spinner doesn't have to show the 'servers' label, as it will only contain servers
navigationList = filtersList ;
navigationSpinnerAdapter . hideServersLabel ( ) ;
// Create dedicated side list adapter and add the status types
navigationListAdapter = FilterListAdapter_ . getInstance_ ( this ) ;
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 < Label > ( ) ) ;
filtersList . setAdapter ( navigationListAdapter ) ;
filtersList . setOnItemClickListener ( onFilterListItemClicked ) ;
} else {
} else {
// Add status types directly to the action bar spinner
navigationList = drawerList ;
navigationSpinnerAdapter . updateStatusTypes ( StatusType . getAllStatusTypes ( this ) ) ;
drawerToggle = new ActionBarDrawerToggle ( this , drawerLayout , R . string . navigation_opendrawer ,
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
R . string . navigation_closedrawer ) ;
navigationSpinnerAdapter . updateLabels ( new ArrayList < Label > ( ) ) ;
drawerToggle . setDrawerIndicatorEnabled ( true ) ;
drawerLayout . setDrawerListener ( drawerToggle ) ;
}
}
navigationList . setAdapter ( navigationListAdapter ) ;
navigationList . setOnItemClickListener ( onFilterListItemClicked ) ;
// Now that all items (or at least their adapters) have been added, ensure a filter is selected
// Now that all items (or at least their adapters) have been added, ensure a filter is selected
// NOTE When this is a fresh start, it might override the filter later (based on the last user selection)
// NOTE When this is a fresh start, it might override the filter later (based on the last user selection)
if ( currentFilter = = null ) {
if ( currentFilter = = null ) {
currentFilter = StatusType . getShowAllType ( this ) ;
currentFilter = StatusType . getShowAllType ( this ) ;
}
}
actionBar . setListNavigationCallbacks ( navigationSpinnerAdapter , this ) ;
// Load the default server or a server that was explicitly supplied in the starting intent
// Load the default server or a server that was explicitly supplied in the starting intent
ServerSetting defaultServer = applicationSettings . getDefaultServer ( ) ;
ServerSetting defaultServer = applicationSettings . getDefaultServer ( ) ;
@ -242,24 +262,21 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
return ;
return ;
}
}
Torrent openTorrent = null ;
Torrent openTorrent = null ;
if ( getIntent ( ) . getAction ( ) ! = null & & getIntent ( ) . getAction ( ) . equals ( ListWidgetProvider . INTENT_STARTSERVER )
if ( getIntent ( ) . getAction ( ) ! = null & & getIntent ( ) . getAction ( ) . equals ( ListWidgetProvider . INTENT_STARTSERVER ) & &
& & getIntent ( ) . getExtras ( ) = = null & & getIntent ( ) . hasExtra ( ListWidgetProvider . EXTRA_SERVER ) ) {
getIntent ( ) . getExtras ( ) = = null & & getIntent ( ) . hasExtra ( ListWidgetProvider . EXTRA_SERVER ) ) {
// A server settings order ID was provided in this org.transdroid.START_SERVER action intent
// A server settings order ID was provided in this org.transdroid.START_SERVER action intent
int serverId = getIntent ( ) . getExtras ( ) . getInt ( ListWidgetProvider . EXTRA_SERVER ) ;
int serverId = getIntent ( ) . getExtras ( ) . getInt ( ListWidgetProvider . EXTRA_SERVER ) ;
if ( serverId < 0 | | serverId > applicationSettings . getMaxOfAllServers ( ) ) {
if ( serverId < 0 | | serverId > applicationSettings . getMaxOfAllServers ( ) ) {
log . e ( this , "Tried to start with " + ListWidgetProvider . EXTRA_SERVER + " intent but " + serverId
log . e ( this , "Tried to start with " + ListWidgetProvider . EXTRA_SERVER + " intent but " + serverId +
+ " is not an existing server order id" ) ;
" is not an existing server order id" ) ;
} else {
} else {
defaultServer = applicationSettings . getServerSetting ( serverId ) ;
defaultServer = applicationSettings . getServerSetting ( serverId ) ;
if ( getIntent ( ) . hasExtra ( ListWidgetProvider . EXTRA_TORRENT ) )
if ( getIntent ( ) . hasExtra ( ListWidgetProvider . EXTRA_TORRENT ) ) {
openTorrent = getIntent ( ) . getParcelableExtra ( ListWidgetProvider . EXTRA_TORRENT ) ;
openTorrent = getIntent ( ) . getParcelableExtra ( ListWidgetProvider . EXTRA_TORRENT ) ;
}
}
}
}
}
// Set this as selection in the action bar spinner; we can use the server setting key since we have stable ids
// Note: skipNextOnNavigationItemSelectedCalls is used to prevent this event from triggering filterSelected
actionBar . setSelectedNavigationItem ( defaultServer . getOrder ( ) + 1 ) ;
// Connect to the last used server or a server that was explicitly supplied in the starting intent
// Connect to the last used server or a server that was explicitly supplied in the starting intent
if ( firstStart ) {
if ( firstStart ) {
// Force first torrents refresh
// Force first torrents refresh
@ -276,8 +293,8 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
// Resume after instead of fully loading the torrents list; create connection and set action bar title
// Resume after instead of fully loading the torrents list; create connection and set action bar title
ServerSetting lastUsed = applicationSettings . getLastUsedServer ( ) ;
ServerSetting lastUsed = applicationSettings . getLastUsedServer ( ) ;
currentConnection = lastUsed . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
currentConnection = lastUsed . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
navigationSpinnerAdapter . updateCurrentServer ( currentConnection ) ;
serverStatusView . updateCurrentServer ( currentConnection ) ;
navigationSpinnerAdapter . updateCurrentFilter ( currentFilter ) ;
serverStatusView . updateCurrentFilter ( currentFilter ) ;
}
}
firstStart = false ;
firstStart = false ;
@ -287,12 +304,21 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
}
}
@Override
protected void onPostCreate ( Bundle savedInstanceState ) {
super . onPostCreate ( savedInstanceState ) ;
// Sync the toggle state after onRestoreInstanceState has occurred
if ( drawerToggle ! = null ) {
drawerToggle . syncState ( ) ;
}
}
@Override
@Override
protected void onResume ( ) {
protected void onResume ( ) {
super . onResume ( ) ;
super . onResume ( ) ;
// Refresh server settings
// Refresh server settings
navigationSpinnerAdapter . updateServers ( applicationSettings . getAllServerSettings ( ) ) ;
navigationList Adapter . updateServers ( applicationSettings . getAllServerSettings ( ) ) ;
ServerSetting lastUsed = applicationSettings . getLastUsedServer ( ) ;
ServerSetting lastUsed = applicationSettings . getLastUsedServer ( ) ;
if ( lastUsed = = null ) {
if ( lastUsed = = null ) {
// Still no settings
// Still no settings
@ -301,10 +327,11 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
}
}
// If we had no connection before, establish it now; otherwise just reload the settings
// If we had no connection before, establish it now; otherwise just reload the settings
if ( currentConnection = = null )
if ( currentConnection = = null ) {
filterSelected ( lastUsed , true ) ;
filterSelected ( lastUsed , true ) ;
else
} else {
currentConnection = lastUsed . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
currentConnection = lastUsed . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
}
// Start auto refresh
// Start auto refresh
startAutoRefresh ( ) ;
startAutoRefresh ( ) ;
@ -324,8 +351,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@TargetApi ( Build . VERSION_CODES . HONEYCOMB )
@TargetApi ( Build . VERSION_CODES . HONEYCOMB )
public void startAutoRefresh ( ) {
public void startAutoRefresh ( ) {
// Check if already running
// Check if already running
if ( autoRefreshTask ! = null | | stopRefresh | | systemSettings . getRefreshIntervalMilliseconds ( ) = = 0 )
if ( autoRefreshTask ! = null | | stopRefresh | | systemSettings . getRefreshIntervalMilliseconds ( ) = = 0 ) {
return ;
return ;
}
autoRefreshTask = new AsyncTask < Void , Void , Void > ( ) {
autoRefreshTask = new AsyncTask < Void , Void , Void > ( ) {
@Override
@Override
@ -337,27 +365,27 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
// Ignore
// Ignore
}
}
// Just in case it was cancelled during sleep
// Just in case it was cancelled during sleep
if ( isCancelled ( ) )
if ( isCancelled ( ) ) {
return null ;
return null ;
}
refreshTorrents ( ) ;
refreshTorrents ( ) ;
if ( Daemon . supportsStats ( currentConnection . getType ( ) ) )
if ( Daemon . supportsStats ( currentConnection . getType ( ) ) ) {
getAdditionalStats ( ) ;
getAdditionalStats ( ) ;
}
}
}
return null ;
return null ;
}
}
} ;
} ;
// Executes serially by default on Honeycomb, was parallel before
// Executes serially by default on Honeycomb, was parallel before
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . HONEYCOMB )
autoRefreshTask . executeOnExecutor ( AsyncTask . THREAD_POOL_EXECUTOR ) ;
autoRefreshTask . executeOnExecutor ( AsyncTask . THREAD_POOL_EXECUTOR ) ;
else
autoRefreshTask . execute ( ) ;
}
}
public void stopAutoRefresh ( ) {
public void stopAutoRefresh ( ) {
if ( autoRefreshTask ! = null )
if ( autoRefreshTask ! = null ) {
autoRefreshTask . cancel ( true ) ;
autoRefreshTask . cancel ( true ) ;
}
autoRefreshTask = null ;
autoRefreshTask = null ;
}
}
@ -419,9 +447,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
menu . findItem ( R . id . action_filter ) . setVisible ( false ) ;
menu . findItem ( R . id . action_filter ) . setVisible ( false ) ;
menu . findItem ( R . id . action_settings ) . setShowAsAction ( MenuItem . SHOW_AS_ACTION_ALWAYS ) ;
menu . findItem ( R . id . action_settings ) . setShowAsAction ( MenuItem . SHOW_AS_ACTION_ALWAYS ) ;
menu . findItem ( R . id . action_help ) . setVisible ( true ) ;
menu . findItem ( R . id . action_help ) . setVisible ( true ) ;
if ( fragmentTorrents ! = null )
if ( fragmentTorrents ! = null ) {
fragmentTorrents . updateConnectionStatus ( false , null ) ;
fragmentTorrents . updateConnectionStatus ( false , null ) ;
getSupportActionBar ( ) . setNavigationMode ( ActionBar . NAVIGATION_MODE_STANDARD ) ;
}
return true ;
return true ;
}
}
@ -440,30 +468,17 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
menu . findItem ( R . id . action_filter ) . setVisible ( true ) ;
menu . findItem ( R . id . action_filter ) . setVisible ( true ) ;
menu . findItem ( R . id . action_settings ) . setShowAsAction ( MenuItem . SHOW_AS_ACTION_NEVER ) ;
menu . findItem ( R . id . action_settings ) . setShowAsAction ( MenuItem . SHOW_AS_ACTION_NEVER ) ;
menu . findItem ( R . id . action_help ) . setVisible ( false ) ;
menu . findItem ( R . id . action_help ) . setVisible ( false ) ;
if ( fragmentTorrents ! = null )
if ( fragmentTorrents ! = null ) {
fragmentTorrents . updateConnectionStatus ( true , currentConnection . getType ( ) ) ;
fragmentTorrents . updateConnectionStatus ( true , currentConnection . getType ( ) ) ;
getSupportActionBar ( ) . setNavigationMode ( ActionBar . NAVIGATION_MODE_LIST ) ;
}
return true ;
return true ;
}
}
/ * *
* Called when an item in the action bar navigation spinner was selected
* /
@Override
@Override
public boolean onNavigationItemSelected ( int itemPosition , long itemId ) {
public boolean onOptionsItemSelected ( MenuItem item ) {
if ( skipNextOnNavigationItemSelectedCalls > 0 ) {
// Handle only if this is the drawer toggle; otherwise the AndroidAnnotations will be used
skipNextOnNavigationItemSelectedCalls - - ;
return drawerToggle ! = null & & drawerToggle . onOptionsItemSelected ( item ) ;
return false ;
}
Object item = navigationSpinnerAdapter . getItem ( itemPosition ) ;
if ( item instanceof SimpleListItem ) {
// A filter item was selected form the navigation spinner
filterSelected ( ( SimpleListItem ) item , false ) ;
return true ;
}
// A header was selected; no action
return false ;
}
}
/ * *
/ * *
@ -490,9 +505,10 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
// Update connection to the newly selected server and refresh
// Update connection to the newly selected server and refresh
currentConnection = server . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
currentConnection = server . createServerAdapter ( connectivityHelper . getConnectedNetworkName ( ) , this ) ;
applicationSettings . setLastUsedServer ( server ) ;
applicationSettings . setLastUsedServer ( server ) ;
navigationSpinnerAdapter . updateCurrentServer ( currentConnection ) ;
serverStatusView . updateCurrentServer ( currentConnection ) ;
if ( forceNewConnection )
if ( forceNewConnection ) {
navigationSpinnerAdapter . updateCurrentFilter ( currentFilter ) ;
serverStatusView . updateCurrentFilter ( currentFilter ) ;
}
// Clear the currently shown list of torrents and perhaps the details
// Clear the currently shown list of torrents and perhaps the details
fragmentTorrents . clear ( true , true ) ;
fragmentTorrents . clear ( true , true ) ;
@ -512,7 +528,7 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
// Set new filter
// Set new filter
currentFilter = ( NavigationFilter ) item ;
currentFilter = ( NavigationFilter ) item ;
fragmentTorrents . applyNavigationFilter ( currentFilter ) ;
fragmentTorrents . applyNavigationFilter ( currentFilter ) ;
navigationSpinnerAdapter . updateCurrentFilter ( currentFilter ) ;
serverStatusView . updateCurrentFilter ( currentFilter ) ;
// Remember that the user last selected this
// Remember that the user last selected this
applicationSettings . setLastUsedNavigationFilter ( currentFilter ) ;
applicationSettings . setLastUsedNavigationFilter ( currentFilter ) ;
// Clear the details view
// Clear the details view
@ -529,13 +545,13 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
* @param hasServerSettings Whether there are server settings available , so we can continue to connect
* @param hasServerSettings Whether there are server settings available , so we can continue to connect
* /
* /
private void updateFragmentVisibility ( boolean hasServerSettings ) {
private void updateFragmentVisibility ( boolean hasServerSettings ) {
if ( filtersList ! = null )
// TODO Hide hamburger icon?
filtersList . setVisibility ( hasServerSettings ? View . VISIBLE : View . GONE ) ;
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
if ( hasServerSettings )
if ( hasServerSettings ) {
getFragmentManager ( ) . beginTransaction ( ) . show ( fragmentDetails ) . commit ( ) ;
getFragmentManager ( ) . beginTransaction ( ) . show ( fragmentDetails ) . commit ( ) ;
else
} else {
getFragmentManager ( ) . beginTransaction ( ) . hide ( fragmentDetails ) . commit ( ) ;
getFragmentManager ( ) . beginTransaction ( ) . hide ( fragmentDetails ) . commit ( ) ;
}
}
}
invalidateOptionsMenu ( ) ;
invalidateOptionsMenu ( ) ;
}
}
@ -548,8 +564,8 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
protected void handleStartIntent ( ) {
protected void handleStartIntent ( ) {
// For intents that come from out of the application, perhaps we can not directly add them
// For intents that come from out of the application, perhaps we can not directly add them
if ( applicationSettings . getDefaultServerKey ( ) = = ApplicationSettings . DEFAULTSERVER_ASKONADD
if ( applicationSettings . getDefaultServerKey ( ) = = ApplicationSettings . DEFAULTSERVER_ASKONADD & &
& & getIntent ( ) . getData ( ) ! = null ) {
getIntent ( ) . getData ( ) ! = null ) {
// First ask which server to use before adding any intent from the extras
// First ask which server to use before adding any intent from the extras
ServerPickerDialog . startServerPicker ( this , applicationSettings . getAllServerSettings ( ) ) ;
ServerPickerDialog . startServerPicker ( this , applicationSettings . getAllServerSettings ( ) ) ;
return ;
return ;
@ -563,8 +579,6 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
ServerSetting selectedServer = applicationSettings . getAllServerSettings ( ) . get ( position ) ;
ServerSetting selectedServer = applicationSettings . getAllServerSettings ( ) . get ( position ) ;
filterSelected ( selectedServer , false ) ;
filterSelected ( selectedServer , false ) ;
addFromIntent ( ) ;
addFromIntent ( ) ;
skipNextOnNavigationItemSelectedCalls + + ; // Prevent this selection from launching filterSelected() again
getSupportActionBar ( ) . setSelectedNavigationItem ( position + 1 ) ;
}
}
/ * *
/ * *
@ -583,8 +597,8 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
String [ ] titles = intent . getStringArrayExtra ( "TORRENT_TITLES" ) ;
String [ ] titles = intent . getStringArrayExtra ( "TORRENT_TITLES" ) ;
if ( urls ! = null ) {
if ( urls ! = null ) {
for ( int i = 0 ; i < urls . length ; i + + ) {
for ( int i = 0 ; i < urls . length ; i + + ) {
String title = ( titles ! = null & & titles . length > = i ? titles [ i ] : NavigationHelper
String title = ( titles ! = null & & titles . length > = i ? titles [ i ] :
. extractNameFromUri ( Uri . parse ( urls [ i ] ) ) ) ;
NavigationHelper . extractNameFromUri ( Uri . parse ( urls [ i ] ) ) ) ;
if ( intent . hasExtra ( "PRIVATE_SOURCE" ) ) {
if ( intent . hasExtra ( "PRIVATE_SOURCE" ) ) {
// This is marked by the Search Module as being a private source site; get the url locally first
// This is marked by the Search Module as being a private source site; get the url locally first
addTorrentFromPrivateSource ( urls [ i ] , title , intent . getStringExtra ( "PRIVATE_SOURCE" ) ) ;
addTorrentFromPrivateSource ( urls [ i ] , title , intent . getStringExtra ( "PRIVATE_SOURCE" ) ) ;
@ -597,8 +611,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
}
}
// Add a torrent from a local or remote data URI?
// Add a torrent from a local or remote data URI?
if ( dataUri = = null )
if ( dataUri = = null ) {
return ;
return ;
}
if ( dataUri . getScheme ( ) = = null ) {
if ( dataUri . getScheme ( ) = = null ) {
Crouton . showText ( this , R . string . error_invalid_url_form , NavigationHelper . CROUTON_ERROR_STYLE ) ;
Crouton . showText ( this , R . string . error_invalid_url_form , NavigationHelper . CROUTON_ERROR_STYLE ) ;
return ;
return ;
@ -664,8 +679,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Override
@Override
protected void onPause ( ) {
protected void onPause ( ) {
if ( searchMenu ! = null )
if ( searchMenu ! = null ) {
searchMenu . collapseActionView ( ) ;
searchMenu . collapseActionView ( ) ;
}
stopAutoRefresh ( ) ;
stopAutoRefresh ( ) ;
super . onPause ( ) ;
super . onPause ( ) ;
}
}
@ -729,15 +745,16 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
* /
* /
@Override
@Override
public void addRefreshableView ( View view ) {
public void addRefreshableView ( View view ) {
// TODO Add new style pull to refresh library
// TODO Add new style pull to refresh library (using SwipeRefreshLayout?)
}
}
@OptionsItem ( resName = "action_refresh" )
@OptionsItem ( resName = "action_refresh" )
public void refreshScreen ( ) {
public void refreshScreen ( ) {
fragmentTorrents . updateIsLoading ( true ) ;
fragmentTorrents . updateIsLoading ( true ) ;
refreshTorrents ( ) ;
refreshTorrents ( ) ;
if ( Daemon . supportsStats ( currentConnection . getType ( ) ) )
if ( Daemon . supportsStats ( currentConnection . getType ( ) ) ) {
getAdditionalStats ( ) ;
getAdditionalStats ( ) ;
}
}
}
@OptionsItem ( resName = "action_enableturtle" )
@OptionsItem ( resName = "action_enableturtle" )
@ -855,8 +872,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Background
@Background
public void refreshTorrentDetails ( Torrent torrent ) {
public void refreshTorrentDetails ( Torrent torrent ) {
if ( ! Daemon . supportsFineDetails ( currentConnection . getType ( ) ) )
if ( ! Daemon . supportsFineDetails ( currentConnection . getType ( ) ) ) {
return ;
return ;
}
String startConnectionId = currentConnection . getSettings ( ) . getIdString ( ) ;
String startConnectionId = currentConnection . getSettings ( ) . getIdString ( ) ;
DaemonTaskResult result = GetTorrentDetailsTask . create ( currentConnection , torrent ) . execute ( log ) ;
DaemonTaskResult result = GetTorrentDetailsTask . create ( currentConnection , torrent ) . execute ( log ) ;
if ( ! startConnectionId . equals ( currentConnection . getSettings ( ) . getIdString ( ) ) ) {
if ( ! startConnectionId . equals ( currentConnection . getSettings ( ) . getIdString ( ) ) ) {
@ -872,8 +890,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Background
@Background
public void refreshTorrentFiles ( Torrent torrent ) {
public void refreshTorrentFiles ( Torrent torrent ) {
if ( ! Daemon . supportsFileListing ( currentConnection . getType ( ) ) )
if ( ! Daemon . supportsFileListing ( currentConnection . getType ( ) ) ) {
return ;
return ;
}
String startConnectionId = currentConnection . getSettings ( ) . getIdString ( ) ;
String startConnectionId = currentConnection . getSettings ( ) . getIdString ( ) ;
DaemonTaskResult result = GetFileListTask . create ( currentConnection , torrent ) . execute ( log ) ;
DaemonTaskResult result = GetFileListTask . create ( currentConnection , torrent ) . execute ( log ) ;
if ( ! startConnectionId . equals ( currentConnection . getSettings ( ) . getIdString ( ) ) ) {
if ( ! startConnectionId . equals ( currentConnection . getSettings ( ) . getIdString ( ) ) ) {
@ -1002,8 +1021,8 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
try {
try {
// Cookies are taken from the websearchSetting that we already matched against this target URL
// Cookies are taken from the websearchSetting that we already matched against this target URL
DefaultHttpClient httpclient = HttpHelper . createStandardHttpClient ( false , null , null , true , null , 10000 ,
DefaultHttpClient httpclient =
null , - 1 ) ;
HttpHelper . createStandardHttpClient ( false , null , null , true , null , 10000 , null , - 1 ) ;
Map < String , String > cookies = HttpHelper . parseCookiePairs ( websearchSetting . getCookies ( ) ) ;
Map < String , String > cookies = HttpHelper . parseCookiePairs ( websearchSetting . getCookies ( ) ) ;
String domain = Uri . parse ( url ) . getHost ( ) ;
String domain = Uri . parse ( url ) . getHost ( ) ;
for ( Entry < String , String > pair : cookies . entrySet ( ) ) {
for ( Entry < String , String > pair : cookies . entrySet ( ) ) {
@ -1016,11 +1035,11 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
// Download the torrent at the specified URL (which will first be written to a temporary file)
// Download the torrent at the specified URL (which will first be written to a temporary file)
// If we get an HTTP 401, 403 or 404 response, show an error to the user
// If we get an HTTP 401, 403 or 404 response, show an error to the user
HttpResponse response = httpclient . execute ( new HttpGet ( url ) ) ;
HttpResponse response = httpclient . execute ( new HttpGet ( url ) ) ;
if ( response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_UNAUTHORIZED
if ( response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_UNAUTHORIZED | |
| | response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_FORBIDDEN
response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_FORBIDDEN | |
| | response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_NOT_FOUND ) {
response . getStatusLine ( ) . getStatusCode ( ) = = HttpStatus . SC_NOT_FOUND ) {
log . e ( this , "Can't retrieve web torrent " + url + ": Unexpected HTTP response status code "
log . e ( this , "Can't retrieve web torrent " + url + ": Unexpected HTTP response status code " +
+ response . getStatusLine ( ) . toString ( ) ) ;
response . getStatusLine ( ) . toString ( ) ) ;
Crouton . showText ( this , R . string . error_401 , NavigationHelper . CROUTON_ERROR_STYLE ) ;
Crouton . showText ( this , R . string . error_401 , NavigationHelper . CROUTON_ERROR_STYLE ) ;
return ;
return ;
}
}
@ -1043,8 +1062,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
try {
try {
final byte [ ] buffer = new byte [ 1024 ] ;
final byte [ ] buffer = new byte [ 1024 ] ;
int read ;
int read ;
while ( ( read = input . read ( buffer ) ) ! = - 1 )
while ( ( read = input . read ( buffer ) ) ! = - 1 ) {
output . write ( buffer , 0 , read ) ;
output . write ( buffer , 0 , read ) ;
}
output . flush ( ) ;
output . flush ( ) ;
String fileName = Uri . fromFile ( tempFile ) . toString ( ) ;
String fileName = Uri . fromFile ( tempFile ) . toString ( ) ;
addTorrentByFile ( fileName , title ) ;
addTorrentByFile ( fileName , title ) ;
@ -1056,8 +1076,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
Crouton . showText ( this , R . string . error_torrentfile , NavigationHelper . CROUTON_ERROR_STYLE ) ;
Crouton . showText ( this , R . string . error_torrentfile , NavigationHelper . CROUTON_ERROR_STYLE ) ;
} finally {
} finally {
try {
try {
if ( input ! = null )
if ( input ! = null ) {
input . close ( ) ;
input . close ( ) ;
}
} catch ( IOException e ) {
} catch ( IOException e ) {
log . e ( this , "Error closing the input stream " + tempFile . toString ( ) + ": " + e . toString ( ) ) ;
log . e ( this , "Error closing the input stream " + tempFile . toString ( ) + ": " + e . toString ( ) ) ;
Crouton . showText ( this , R . string . error_torrentfile , NavigationHelper . CROUTON_ERROR_STYLE ) ;
Crouton . showText ( this , R . string . error_torrentfile , NavigationHelper . CROUTON_ERROR_STYLE ) ;
@ -1118,9 +1139,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
public void removeTorrent ( Torrent torrent , boolean withData ) {
public void removeTorrent ( Torrent torrent , boolean withData ) {
DaemonTaskResult result = RemoveTask . create ( currentConnection , torrent , withData ) . execute ( log ) ;
DaemonTaskResult result = RemoveTask . create ( currentConnection , torrent , withData ) . execute ( log ) ;
if ( result instanceof DaemonTaskSuccessResult ) {
if ( result instanceof DaemonTaskSuccessResult ) {
onTaskSucceeded (
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result ,
( DaemonTaskSuccessResult ) result ,
getString ( withData ? R . string . result_removed_with_data : R . string . result_removed ,
getString ( withData ? R . string . result_removed_with_data : R . string . result_removed , torrent . getName ( ) ) ) ;
torrent . getName ( ) ) ) ;
} else {
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result , false ) ;
onCommunicationError ( ( DaemonTaskFailureResult ) result , false ) ;
}
}
@ -1130,13 +1151,12 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Override
@Override
public void updateLabel ( Torrent torrent , String newLabel ) {
public void updateLabel ( Torrent torrent , String newLabel ) {
torrent . mimicNewLabel ( newLabel ) ;
torrent . mimicNewLabel ( newLabel ) ;
DaemonTaskResult result = SetLabelTask . create ( currentConnection , torrent , newLabel = = null ? "" : newLabel )
DaemonTaskResult result =
. execute ( log ) ;
SetLabelTask . create ( currentConnection , torrent , newLabel = = null ? "" : newLabel ) . execute ( log ) ;
if ( result instanceof DaemonTaskSuccessResult ) {
if ( result instanceof DaemonTaskSuccessResult ) {
onTaskSucceeded (
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result ,
( DaemonTaskSuccessResult ) result ,
newLabel = = null ? getString ( R . string . result_labelremoved ) :
newLabel = = null ? getString ( R . string . result_labelremoved ) : getString ( R . string . result_labelset ,
getString ( R . string . result_labelset , newLabel ) ) ;
newLabel ) ) ;
} else {
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result , false ) ;
onCommunicationError ( ( DaemonTaskFailureResult ) result , false ) ;
}
}
@ -1180,8 +1200,9 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Background
@Background
@Override
@Override
public void updatePriority ( Torrent torrent , List < TorrentFile > files , Priority priority ) {
public void updatePriority ( Torrent torrent , List < TorrentFile > files , Priority priority ) {
DaemonTaskResult result = SetFilePriorityTask . create ( currentConnection , torrent , priority ,
DaemonTaskResult result =
new ArrayList < TorrentFile > ( files ) ) . execute ( log ) ;
SetFilePriorityTask . create ( currentConnection , torrent , priority , new ArrayList < TorrentFile > ( files ) )
. execute ( log ) ;
if ( result instanceof DaemonTaskSuccessResult ) {
if ( result instanceof DaemonTaskSuccessResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , getString ( R . string . result_priotitiesset ) ) ;
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , getString ( R . string . result_priotitiesset ) ) ;
} else {
} else {
@ -1191,8 +1212,8 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@Background
@Background
public void updateMaxSpeeds ( Integer maxDownloadSpeed , Integer maxUploadSpeed ) {
public void updateMaxSpeeds ( Integer maxDownloadSpeed , Integer maxUploadSpeed ) {
DaemonTaskResult result = SetTransferRatesTask . create ( currentConnection , maxUploadSpeed , maxDownloadSpeed )
DaemonTaskResult result =
. execute ( log ) ;
SetTransferRatesTask . create ( currentConnection , maxUploadSpeed , maxDownloadSpeed ) . execute ( log ) ;
if ( result instanceof DaemonTaskSuccessResult ) {
if ( result instanceof DaemonTaskSuccessResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , getString ( R . string . result_maxspeedsset ) ) ;
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , getString ( R . string . result_maxspeedsset ) ) ;
} else {
} else {
@ -1209,22 +1230,24 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@UiThread
@UiThread
protected void onCommunicationError ( DaemonTaskFailureResult result , boolean isCritical ) {
protected void onCommunicationError ( DaemonTaskFailureResult result , boolean isCritical ) {
//noinspection ThrowableResultOfMethodCallIgnored
log . i ( this , result . getException ( ) . toString ( ) ) ;
log . i ( this , result . getException ( ) . toString ( ) ) ;
String error = getString ( LocalTorrent . getResourceForDaemonException ( result . getException ( ) ) ) ;
String error = getString ( LocalTorrent . getResourceForDaemonException ( result . getException ( ) ) ) ;
Crouton . showText ( this , error , NavigationHelper . CROUTON_ERROR_STYLE ) ;
Crouton . showText ( this , error , NavigationHelper . CROUTON_ERROR_STYLE ) ;
fragmentTorrents . updateIsLoading ( false ) ;
fragmentTorrents . updateIsLoading ( false ) ;
if ( isCritical ) {
if ( isCritical ) {
fragmentTorrents . updateError ( error ) ;
fragmentTorrents . updateError ( error ) ;
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) )
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
fragmentDetails . updateIsLoading ( false , error ) ;
fragmentDetails . updateIsLoading ( false , error ) ;
}
}
}
}
}
@UiThread
@UiThread
protected void onTorrentsRetrieved ( List < Torrent > torrents , List < org . transdroid . daemon . Label > labels ) {
protected void onTorrentsRetrieved ( List < Torrent > torrents , List < org . transdroid . daemon . Label > labels ) {
lastNavigationLabels = Label . convertToNavigationLabels ( labels ,
lastNavigationLabels =
getResources ( ) . getString ( R . string . labels_unlabeled ) ) ;
Label . convertToNavigationLabels ( labels , getResources ( ) . getString ( R . string . labels_unlabeled ) ) ;
// Report the newly retrieved list of torrents to the torrents fragment
// Report the newly retrieved list of torrents to the torrents fragment
fragmentTorrents . updateIsLoading ( false ) ;
fragmentTorrents . updateIsLoading ( false ) ;
@ -1236,27 +1259,19 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
}
}
// Update local list of labels in the navigation
// Update local list of labels in the navigation
if ( navigationListAdapter ! = null ) {
navigationListAdapter . updateLabels ( lastNavigationLabels ) ;
// Labels are shown in the dedicated side navigation
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
navigationListAdapter . updateLabels ( lastNavigationLabels ) ;
} else {
// Labels are shown in the action bar spinner
navigationSpinnerAdapter . updateLabels ( lastNavigationLabels ) ;
}
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) )
fragmentDetails . updateLabels ( lastNavigationLabels ) ;
fragmentDetails . updateLabels ( lastNavigationLabels ) ;
}
// Perhaps we were still waiting to preselect the last used filter (on a fresh application start)
// Perhaps we were still waiting to preselect the last used filter (on a fresh application start)
if ( preselectNavigationFilter ! = null ) {
if ( preselectNavigationFilter ! = null & & navigationListAdapter ! = null ) {
FilterListAdapter adapter = navigationListAdapter ! = null ? navigationListAdapter
for ( int i = 0 ; i < navigationListAdapter . getCount ( ) ; i + + ) {
: navigationSpinnerAdapter ;
// Look up the navigation filter item, which is represented as simple list item (and might not exist any
for ( int i = 0 ; i < adapter . getCount ( ) ; i + + ) {
// more, such as with a label that is deleted on the server)
// Regardless of the navigation style (side list or action bar spinner), we can look up the navigation
Object item = navigationListAdapter . getItem ( i ) ;
// filter item, which is represented as simple list item (and might not exist any more, such as with a
if ( item instanceof SimpleListItem & & item instanceof NavigationFilter & &
// label that is deleted on the server)
( ( NavigationFilter ) item ) . getCode ( ) . equals ( preselectNavigationFilter ) ) {
Object item = adapter . getItem ( i ) ;
if ( item instanceof SimpleListItem & & item instanceof NavigationFilter
& & ( ( NavigationFilter ) item ) . getCode ( ) . equals ( preselectNavigationFilter ) ) {
filterSelected ( ( SimpleListItem ) item , false ) ;
filterSelected ( ( SimpleListItem ) item , false ) ;
break ;
break ;
}
}
@ -1266,7 +1281,7 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
}
}
// Update the server status (counts and speeds) in the action bar
// Update the server status (counts and speeds) in the action bar
serverStatusView . update ( torrents , systemSettings . treatDormantAsInactive ( ) ,
serverStatusView . updateStatus ( torrents , systemSettings . treatDormantAsInactive ( ) ,
Daemon . supportsSetTransferRates ( currentConnection . getType ( ) ) ) ;
Daemon . supportsSetTransferRates ( currentConnection . getType ( ) ) ) ;
}
}
@ -1274,15 +1289,17 @@ public class TorrentsActivity extends ActionBarActivity implements ActionBar.OnN
@UiThread
@UiThread
protected void onTorrentDetailsRetrieved ( Torrent torrent , TorrentDetails torrentDetails ) {
protected void onTorrentDetailsRetrieved ( Torrent torrent , TorrentDetails torrentDetails ) {
// Update the details fragment with the new fine details for the shown torrent
// Update the details fragment with the new fine details for the shown torrent
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) )
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
fragmentDetails . updateTorrentDetails ( torrent , torrentDetails ) ;
fragmentDetails . updateTorrentDetails ( torrent , torrentDetails ) ;
}
}
}
@UiThread
@UiThread
protected void onTorrentFilesRetrieved ( Torrent torrent , List < TorrentFile > torrentFiles ) {
protected void onTorrentFilesRetrieved ( Torrent torrent , List < TorrentFile > torrentFiles ) {
// Update the details fragment with the newly retrieved list of files
// Update the details fragment with the newly retrieved list of files
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) )
if ( fragmentDetails ! = null & & fragmentDetails . isAdded ( ) ) {
fragmentDetails . updateTorrentFiles ( torrent , new ArrayList < TorrentFile > ( torrentFiles ) ) ;
fragmentDetails . updateTorrentFiles ( torrent , new ArrayList < TorrentFile > ( torrentFiles ) ) ;
}
}
}
@UiThread
@UiThread