@ -17,16 +17,14 @@ import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R ;
import org.transdroid.core.R ;
import org.transdroid.core.app.settings.ApplicationSettings ;
import org.transdroid.core.app.settings.ApplicationSettings ;
import org.transdroid.core.app.settings.ServerSetting ;
import org.transdroid.core.app.settings.ServerSetting ;
import org.transdroid.core.gui.DetailsFragment.DetailsTasksExecutor ;
import org.transdroid.core.gui.TorrentsFragment.TorrentsTasksExecutor ;
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.navigation.FilterListAdapter ;
import org.transdroid.core.gui.navigation.FilterListAdapter ;
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.NavigationHelper ;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager ;
import org.transdroid.core.gui.navigation.StatusType ;
import org.transdroid.core.gui.navigation.StatusType ;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter ;
import org.transdroid.core.gui.settings.MainSettingsActivity_ ;
import org.transdroid.core.gui.settings.MainSettingsActivity_ ;
import org.transdroid.daemon.Daemon ;
import org.transdroid.daemon.Daemon ;
import org.transdroid.daemon.IDaemonAdapter ;
import org.transdroid.daemon.IDaemonAdapter ;
@ -34,9 +32,19 @@ import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.task.DaemonTaskFailureResult ;
import org.transdroid.daemon.task.DaemonTaskFailureResult ;
import org.transdroid.daemon.task.DaemonTaskResult ;
import org.transdroid.daemon.task.DaemonTaskResult ;
import org.transdroid.daemon.task.DaemonTaskSuccessResult ;
import org.transdroid.daemon.task.DaemonTaskSuccessResult ;
import org.transdroid.daemon.task.GetStatsTask ;
import org.transdroid.daemon.task.GetStatsTaskSuccessResult ;
import org.transdroid.daemon.task.PauseTask ;
import org.transdroid.daemon.task.RemoveTask ;
import org.transdroid.daemon.task.ResumeTask ;
import org.transdroid.daemon.task.ResumeTask ;
import org.transdroid.daemon.task.RetrieveTask ;
import org.transdroid.daemon.task.RetrieveTask ;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult ;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult ;
import org.transdroid.daemon.task.SetAlternativeModeTask ;
import org.transdroid.daemon.task.SetDownloadLocationTask ;
import org.transdroid.daemon.task.SetLabelTask ;
import org.transdroid.daemon.task.SetTrackersTask ;
import org.transdroid.daemon.task.StartTask ;
import org.transdroid.daemon.task.StopTask ;
import android.annotation.TargetApi ;
import android.annotation.TargetApi ;
import android.app.SearchManager ;
import android.app.SearchManager ;
@ -56,7 +64,7 @@ import com.actionbarsherlock.widget.SearchView;
@EActivity ( R . layout . activity_torrents )
@EActivity ( R . layout . activity_torrents )
@OptionsMenu ( R . menu . activity_torrents )
@OptionsMenu ( R . menu . activity_torrents )
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener , DetailsTasksExecutor , TorrentsTasksExecuto r {
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener , TorrentTasksExecutor , NavigationFilterManage r {
// Navigation components
// Navigation components
@Bean
@Bean
@ -75,6 +83,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
boolean firstStart = true ;
boolean firstStart = true ;
private IDaemonAdapter currentConnection = null ;
private IDaemonAdapter currentConnection = null ;
@InstanceState
@InstanceState
protected NavigationFilter currentFilter = null ;
@InstanceState
protected boolean turleModeEnabled = false ;
protected boolean turleModeEnabled = false ;
// Torrents list components
// Torrents list components
@ -91,7 +101,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Set up navigation, with an action bar spinner and possibly (if room) with a filter list
// Set up navigation, with an action bar spinner and possibly (if room) with a filter list
getSupportActionBar ( ) . setNavigationMode ( ActionBar . NAVIGATION_MODE_LIST ) ;
getSupportActionBar ( ) . setNavigationMode ( ActionBar . NAVIGATION_MODE_LIST ) ;
getSupportActionBar ( ) . setHomeButtonEnabled ( false ) ;
getSupportActionBar ( ) . setHomeButtonEnabled ( false ) ;
navigationSpinnerAdapter = FilterListAdapter_ . getInstance_ ( this ) ;
navigationSpinnerAdapter = FilterListAdapter_ . getInstance_ ( this ) . setNavigationFilterManager ( this ) ;
// Servers are always added to the action bar spinner
// Servers are always added to the action bar spinner
navigationSpinnerAdapter . updateServers ( applicationSettings . getServerSettings ( ) ) ;
navigationSpinnerAdapter . updateServers ( applicationSettings . getServerSettings ( ) ) ;
getSupportActionBar ( ) . setListNavigationCallbacks ( navigationSpinnerAdapter , this ) ;
getSupportActionBar ( ) . setListNavigationCallbacks ( navigationSpinnerAdapter , this ) ;
@ -240,21 +250,35 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Update connection to the newly selected server and refresh
// Update connection to the newly selected server and refresh
currentConnection = server . createServerAdapter ( ) ;
currentConnection = server . createServerAdapter ( ) ;
applicationSettings . setLastUsedServer ( server ) ;
clearScreens ( ) ;
clearScreens ( ) ;
refreshTorrents ( ) ;
refreshTorrents ( ) ;
return ;
}
}
if ( item instanceof StatusTypeFilter ) {
// Status type or label selection - both of which are navigation filters
// TODO: Update the torrent list view
if ( item instanceof NavigationFilter ) {
}
currentFilter = ( NavigationFilter ) item ;
fragmentTorrents . applyFilter ( currentFilter ) ;
if ( item instanceof Label ) {
// Clear the details view
// TODO: Update the torrent list view
if ( fragmentDetails ! = null ) {
fragmentDetails . clear ( ) ;
}
}
}
}
}
@Override
public String getActiveFilterText ( ) {
return currentFilter . getName ( ) ;
}
@Override
public String getActiveServerText ( ) {
return currentConnection . getSettings ( ) . getName ( ) ;
}
/ * *
/ * *
* If required , add torrents , switch to a specific server , etc .
* If required , add torrents , switch to a specific server , etc .
* /
* /
@ -265,7 +289,17 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@OptionsItem ( R . id . action_refresh )
@OptionsItem ( R . id . action_refresh )
protected void refreshScreen ( ) {
protected void refreshScreen ( ) {
refreshTorrents ( ) ;
refreshTorrents ( ) ;
// TODO: Retrieve turtle mode status
getAdditionalStats ( ) ;
}
@OptionsItem ( R . id . action_enableturtle )
protected void enableTurtleMode ( ) {
updateTurtleMode ( true ) ;
}
@OptionsItem ( R . id . action_disableturtle )
protected void disableTurtleMode ( ) {
updateTurtleMode ( false ) ;
}
}
@OptionsItem ( R . id . action_settings )
@OptionsItem ( R . id . action_settings )
@ -291,28 +325,25 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
}
}
}
@UiThrea d
@Backgroun d
protected void onTorrentsRetrieved ( List < Torrent > torrents , List < org . transdroid . daemon . Label > labels ) {
protected void getAdditionalStats ( ) {
// Report the newly retrieved list of torrents to the torrents fragment
DaemonTaskResult result = GetStatsTask . create ( currentConnection ) . execute ( ) ;
fragmentTorrents . updateTorrents ( new ArrayList < Torrent > ( torrents ) ) ;
if ( result instanceof GetStatsTaskSuccessResult ) {
// Update the details fragment if the currently shown torrent is in the newly retrieved list
onTurtleModeRetrieved ( ( ( GetStatsTaskSuccessResult ) result ) . isAlternativeModeEnabled ( ) ) ;
if ( fragmentDetails ! = null ) {
} else {
fragmentDetails . perhapsUpdateTorrent ( torrents ) ;
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
// TODO: Update local list of labels
}
@UiThread
protected void onTaskSucceeded ( DaemonTaskSuccessResult result , int successMessageId , Torrent target ) {
// TODO: Properly report this success
Toast . makeText ( this , getString ( successMessageId , target . getName ( ) ) , Toast . LENGTH_LONG ) . show ( ) ;
}
}
@UiThread
@Background
protected void onCommunicationError ( DaemonTaskFailureResult result ) {
protected void updateTurtleMode ( boolean enable ) {
// TODO: Properly report this error
DaemonTaskResult result = SetAlternativeModeTask . create ( currentConnection , enable ) . execute ( ) ;
Toast . makeText ( this , getString ( LocalTorrent . getResourceForDaemonException ( result . getException ( ) ) ) ,
if ( result instanceof GetStatsTaskSuccessResult ) {
Toast . LENGTH_LONG ) . show ( ) ;
// Success; no need to retrieve it again - just update the visual indicator
onTurtleModeRetrieved ( enable ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Background
@ -321,70 +352,122 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent . mimicResume ( ) ;
torrent . mimicResume ( ) ;
DaemonTaskResult result = ResumeTask . create ( currentConnection , torrent ) . execute ( ) ;
DaemonTaskResult result = ResumeTask . create ( currentConnection , torrent ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_resumed , torrent ) ;
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_resumed ) ;
} else {
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
}
@Background
@Override
@Override
public void pauseTorrent ( Torrent torrent ) {
public void pauseTorrent ( Torrent torrent ) {
// TODO Auto-generated method stub
torrent . mimicPause ( ) ;
DaemonTaskResult result = PauseTask . create ( currentConnection , torrent ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_paused ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void startTorrent ( Torrent torrent ) {
public void startTorrent ( Torrent torrent , boolean forced ) {
// TODO Auto-generated method stub
torrent . mimicStart ( ) ;
DaemonTaskResult result = StartTask . create ( currentConnection , torrent , forced ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_started ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void stopTorrent ( Torrent torrent ) {
public void stopTorrent ( Torrent torrent ) {
// TODO Auto-generated method stub
torrent . mimicStop ( ) ;
DaemonTaskResult result = StopTask . create ( currentConnection , torrent ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_stopped ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void removeTorrent ( Torrent torrent , boolean withData ) {
public void removeTorrent ( Torrent torrent , boolean withData ) {
// TODO Auto-generated method stub
DaemonTaskResult result = RemoveTask . create ( currentConnection , torrent , withData ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , withData ? R . string . result_removed_with_data
: R . string . result_removed ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void setLabel ( Torrent torrent ) {
public void updateLabel ( Torrent torrent , String newLabel ) {
// TODO Auto-generated method stub
torrent . mimicNewLabel ( newLabel ) ;
DaemonTaskResult result = SetLabelTask . create ( currentConnection , torrent , newLabel ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_labelset , newLabel ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void updateTrackers ( Torrent torrent ) {
public void updateTrackers ( Torrent torrent , List < String > newTrackers ) {
// TODO Auto-generated method stub
DaemonTaskResult result = SetTrackersTask . create ( currentConnection , torrent , newTrackers ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_trackersupdated ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Background
@Override
@Override
public void resumeTorrents ( List < Torrent > torrents ) {
public void updateLocation ( Torrent torrent , String newLocation ) {
// TODO Auto-generated method stub
DaemonTaskResult result = SetDownloadLocationTask . create ( currentConnection , torrent , newLocation ) . execute ( ) ;
if ( result instanceof DaemonTaskResult ) {
onTaskSucceeded ( ( DaemonTaskSuccessResult ) result , R . string . result_locationset , newLocation ) ;
} else {
onCommunicationError ( ( DaemonTaskFailureResult ) result ) ;
}
}
}
@Override
@UiThread
public void pauseTorrents ( List < Torrent > torrents ) {
protected void onTaskSucceeded ( DaemonTaskSuccessResult result , int successMessageId , String . . . messageParam s ) {
// TODO Auto-generated method stub
// TODO: Properly report this success
Toast . makeText ( this , getString ( successMessageId , ( Object [ ] ) messageParams ) , Toast . LENGTH_LONG ) . show ( ) ;
}
}
@Override
@UiThread
public void removeTorrents ( List < Torrent > torrents , boolean withData ) {
protected void onCommunicationError ( DaemonTaskFailureResult result ) {
// TODO Auto-generated method stub
// TODO: Properly report this error
Toast . makeText ( this , getString ( LocalTorrent . getResourceForDaemonException ( result . getException ( ) ) ) ,
Toast . LENGTH_LONG ) . show ( ) ;
}
}
@Override
@UiThread
public void setLabels ( List < Torrent > torrents ) {
protected void onTorrentsRetrieved ( List < Torrent > torrents , List < org . transdroid . daemon . Label > labels ) {
// TODO Auto-generated method stub
// Report the newly retrieved list of torrents to the torrents fragment
fragmentTorrents . updateTorrents ( new ArrayList < Torrent > ( torrents ) ) ;
// Update the details fragment if the currently shown torrent is in the newly retrieved list
if ( fragmentDetails ! = null ) {
fragmentDetails . perhapsUpdateTorrent ( torrents ) ;
}
// TODO: Update local list of labels
}
@UiThread
protected void onTurtleModeRetrieved ( boolean turtleModeEnabled ) {
turleModeEnabled = turtleModeEnabled ;
supportInvalidateOptionsMenu ( ) ;
}
}
}
}