@ -111,6 +111,7 @@ import android.net.Uri;
import android.os.AsyncTask ;
import android.os.AsyncTask ;
import android.os.Build ;
import android.os.Build ;
import android.os.Bundle ;
import android.os.Bundle ;
import android.text.TextUtils ;
import android.view.Menu ;
import android.view.Menu ;
import android.view.MenuItem ;
import android.view.MenuItem ;
import android.view.MenuItem.OnActionExpandListener ;
import android.view.MenuItem.OnActionExpandListener ;
@ -135,7 +136,8 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
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
public boolean stopRefresh = false ;
// Navigation components
// Navigation components
@Bean
@Bean
protected Log log ;
protected Log log ;
@ -150,19 +152,12 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
protected ServerStatusView serverStatusView ;
protected ServerStatusView serverStatusView ;
@SystemService
@SystemService
protected SearchManager searchManager ;
protected SearchManager searchManager ;
private MenuItem searchMenu = null ;
private PullToRefreshAttacher pullToRefreshAttacher = null ;
// Settings
// Settings
@Bean
@Bean
protected ApplicationSettings applicationSettings ;
protected ApplicationSettings applicationSettings ;
@Bean
@Bean
protected SystemSettings systemSettings ;
protected SystemSettings systemSettings ;
@InstanceState
@InstanceState
boolean firstStart = true ;
int skipNextOnNavigationItemSelectedCalls = 2 ;
private IDaemonAdapter currentConnection = null ;
@InstanceState
protected NavigationFilter currentFilter = null ;
protected NavigationFilter currentFilter = null ;
@InstanceState
@InstanceState
protected String preselectNavigationFilter = null ;
protected String preselectNavigationFilter = null ;
@ -170,17 +165,29 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
protected boolean turleModeEnabled = false ;
protected boolean turleModeEnabled = false ;
@InstanceState
@InstanceState
protected ArrayList < Label > lastNavigationLabels ;
protected ArrayList < Label > lastNavigationLabels ;
// Contained torrent and details fragments
// Contained torrent and details fragments
@FragmentById ( resName = "torrents_fragment" )
@FragmentById ( resName = "torrents_fragment" )
protected TorrentsFragment fragmentTorrents ;
protected TorrentsFragment fragmentTorrents ;
@FragmentById ( resName = "torrentdetails_fragment" )
@FragmentById ( resName = "torrentdetails_fragment" )
protected DetailsFragment fragmentDetails ;
protected DetailsFragment fragmentDetails ;
@InstanceState
boolean firstStart = true ;
int skipNextOnNavigationItemSelectedCalls = 2 ;
private MenuItem searchMenu = null ;
private PullToRefreshAttacher pullToRefreshAttacher = null ;
private IDaemonAdapter currentConnection = null ;
// Auto refresh task
// Auto refresh task
private AsyncTask < Void , Void , Void > autoRefreshTask ;
private AsyncTask < Void , Void , Void > autoRefreshTask ;
// Fragment uses this to pause the refresh across restarts
// Handles item selections on the dedicated list of filter items
public boolean stopRefresh = false ;
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 )
filterSelected ( ( SimpleListItem ) item , false ) ;
}
} ;
@Override
@Override
public void onCreate ( Bundle savedInstanceState ) {
public void onCreate ( Bundle savedInstanceState ) {
@ -466,17 +473,6 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
return false ;
return false ;
}
}
// 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 )
filterSelected ( ( SimpleListItem ) item , false ) ;
}
} ;
/ * *
/ * *
* A new filter was selected ; update the view over the current data
* A new filter was selected ; update the view over the current data
* @param item The touched filter item
* @param item The touched filter item
@ -719,11 +715,20 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
@OnActivityResult ( BarcodeHelper . ACTIVITY_BARCODE_ADDTORRENT )
@OnActivityResult ( BarcodeHelper . ACTIVITY_BARCODE_ADDTORRENT )
public void onBarcodeScanned ( int resultCode , Intent data ) {
public void onBarcodeScanned ( int resultCode , Intent data ) {
// We receive from the helper either a URL (as string) or a query we can start a search for
// We receive from the helper either a URL (as string) or a query we can start a search for
String query = BarcodeHelper . handleScanResult ( resultCode , data ) ;
String query = BarcodeHelper . handleScanResult ( resultCode , data , navigationHelper . enableSearchUi ( ) ) ;
if ( query . startsWith ( "http" ) | | query . startsWith ( "https" ) )
onBarcodeScanHandled ( data . getStringExtra ( "SCAN_RESULT" ) , query ) ;
addTorrentByUrl ( query , "QR code result" ) ; // No torrent title known
}
else
startSearch ( query , false , null , false ) ;
@UiThread
protected void onBarcodeScanHandled ( String barcode , String result ) {
log . d ( this , "Scanned barcode " + barcode + " and got " + result ) ;
if ( TextUtils . isEmpty ( result ) ) {
Crouton . showText ( this , R . string . error_noproductforcode , NavigationHelper . CROUTON_ERROR_STYLE ) ;
} else if ( result . startsWith ( "http" ) | | result . startsWith ( "https" ) ) {
addTorrentByUrl ( result , "QR code result" ) ; // No torrent title known
} else if ( navigationHelper . enableSearchUi ( ) ) {
startSearch ( result , false , null , false ) ;
}
}
}
/ * *
/ * *