You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1277 lines
48 KiB
1277 lines
48 KiB
11 years ago
|
/*
|
||
|
* Copyright 2010-2013 Eric Kok et al.
|
||
|
*
|
||
|
* Transdroid is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Transdroid is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
11 years ago
|
package org.transdroid.core.gui;
|
||
|
|
||
11 years ago
|
import java.io.File;
|
||
11 years ago
|
import java.io.FileNotFoundException;
|
||
11 years ago
|
import java.io.FileOutputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
11 years ago
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
11 years ago
|
import java.util.Map;
|
||
|
import java.util.Map.Entry;
|
||
11 years ago
|
|
||
|
import org.androidannotations.annotations.AfterViews;
|
||
|
import org.androidannotations.annotations.Background;
|
||
|
import org.androidannotations.annotations.Bean;
|
||
|
import org.androidannotations.annotations.EActivity;
|
||
|
import org.androidannotations.annotations.FragmentById;
|
||
|
import org.androidannotations.annotations.InstanceState;
|
||
11 years ago
|
import org.androidannotations.annotations.OnActivityResult;
|
||
11 years ago
|
import org.androidannotations.annotations.OptionsItem;
|
||
|
import org.androidannotations.annotations.OptionsMenu;
|
||
|
import org.androidannotations.annotations.SystemService;
|
||
|
import org.androidannotations.annotations.UiThread;
|
||
|
import org.androidannotations.annotations.ViewById;
|
||
11 years ago
|
import org.apache.http.HttpResponse;
|
||
|
import org.apache.http.HttpStatus;
|
||
|
import org.apache.http.client.methods.HttpGet;
|
||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
||
10 years ago
|
import org.transdroid.R;
|
||
10 years ago
|
import org.transdroid.core.app.search.*;
|
||
|
import org.transdroid.core.app.settings.*;
|
||
11 years ago
|
import org.transdroid.core.gui.lists.LocalTorrent;
|
||
11 years ago
|
import org.transdroid.core.gui.lists.NoProgressHeaderTransformer;
|
||
11 years ago
|
import org.transdroid.core.gui.lists.SimpleListItem;
|
||
10 years ago
|
import org.transdroid.core.gui.log.*;
|
||
|
import org.transdroid.core.gui.navigation.*;
|
||
|
import org.transdroid.core.gui.rss.*;
|
||
11 years ago
|
import org.transdroid.core.gui.search.BarcodeHelper;
|
||
|
import org.transdroid.core.gui.search.FilePickerHelper;
|
||
|
import org.transdroid.core.gui.search.UrlEntryDialog;
|
||
10 years ago
|
import org.transdroid.core.gui.settings.*;
|
||
11 years ago
|
import org.transdroid.core.service.BootReceiver;
|
||
11 years ago
|
import org.transdroid.core.service.ConnectivityHelper;
|
||
11 years ago
|
import org.transdroid.core.widget.ListWidgetProvider;
|
||
11 years ago
|
import org.transdroid.daemon.Daemon;
|
||
11 years ago
|
import org.transdroid.daemon.IDaemonAdapter;
|
||
11 years ago
|
import org.transdroid.daemon.Priority;
|
||
11 years ago
|
import org.transdroid.daemon.Torrent;
|
||
11 years ago
|
import org.transdroid.daemon.TorrentDetails;
|
||
|
import org.transdroid.daemon.TorrentFile;
|
||
11 years ago
|
import org.transdroid.daemon.TorrentsSortBy;
|
||
11 years ago
|
import org.transdroid.daemon.task.AddByFileTask;
|
||
|
import org.transdroid.daemon.task.AddByMagnetUrlTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.AddByUrlTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.DaemonTaskFailureResult;
|
||
|
import org.transdroid.daemon.task.DaemonTaskResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.ForceRecheckTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.GetFileListTask;
|
||
|
import org.transdroid.daemon.task.GetFileListTaskSuccessResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.GetStatsTask;
|
||
|
import org.transdroid.daemon.task.GetStatsTaskSuccessResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.GetTorrentDetailsTask;
|
||
|
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.PauseTask;
|
||
|
import org.transdroid.daemon.task.RemoveTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.ResumeTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.RetrieveTask;
|
||
|
import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
|
||
11 years ago
|
import org.transdroid.daemon.task.SetAlternativeModeTask;
|
||
|
import org.transdroid.daemon.task.SetDownloadLocationTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.SetFilePriorityTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.SetLabelTask;
|
||
|
import org.transdroid.daemon.task.SetTrackersTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.SetTransferRatesTask;
|
||
11 years ago
|
import org.transdroid.daemon.task.StartTask;
|
||
|
import org.transdroid.daemon.task.StopTask;
|
||
11 years ago
|
import org.transdroid.daemon.util.DLog;
|
||
11 years ago
|
import org.transdroid.daemon.util.HttpHelper;
|
||
11 years ago
|
|
||
10 years ago
|
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher;
|
||
11 years ago
|
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
|
||
|
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.Options;
|
||
11 years ago
|
import android.annotation.TargetApi;
|
||
10 years ago
|
import android.app.ActionBar;
|
||
|
import android.app.ActionBar.OnNavigationListener;
|
||
|
import android.app.Activity;
|
||
11 years ago
|
import android.app.SearchManager;
|
||
11 years ago
|
import android.content.ContentResolver;
|
||
11 years ago
|
import android.content.Intent;
|
||
|
import android.net.Uri;
|
||
11 years ago
|
import android.os.AsyncTask;
|
||
11 years ago
|
import android.os.Build;
|
||
11 years ago
|
import android.os.Bundle;
|
||
10 years ago
|
import android.view.Menu;
|
||
|
import android.view.MenuItem;
|
||
|
import android.view.MenuItem.OnActionExpandListener;
|
||
11 years ago
|
import android.view.View;
|
||
10 years ago
|
import android.view.View.OnClickListener;
|
||
11 years ago
|
import android.widget.AdapterView;
|
||
11 years ago
|
import android.widget.AdapterView.OnItemClickListener;
|
||
10 years ago
|
import android.widget.ListView;
|
||
|
import android.widget.SearchView;
|
||
11 years ago
|
import de.keyboardsurfer.android.widget.crouton.Crouton;
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Main activity that holds the fragment that shows the torrents list, presents a way to filter the list (via an action
|
||
|
* bar spinner or list side list) and potentially shows a torrent details fragment too, if there is room. Task execution
|
||
|
* such as loading of and adding torrents is performs in this activity, using background methods. Finally, the activity
|
||
|
* offers navigation elements such as access to settings and showing connection issues.
|
||
|
* @author Eric Kok
|
||
|
*/
|
||
11 years ago
|
@EActivity(resName = "activity_torrents")
|
||
|
@OptionsMenu(resName = "activity_torrents")
|
||
10 years ago
|
public class TorrentsActivity extends Activity implements OnNavigationListener, TorrentTasksExecutor,
|
||
11 years ago
|
RefreshableActivity {
|
||
11 years ago
|
|
||
11 years ago
|
private static final int RESULT_DETAILS = 0;
|
||
11 years ago
|
|
||
11 years ago
|
// Navigation components
|
||
|
@Bean
|
||
|
protected NavigationHelper navigationHelper;
|
||
11 years ago
|
@Bean
|
||
|
protected ConnectivityHelper connectivityHelper;
|
||
11 years ago
|
@ViewById
|
||
10 years ago
|
protected ListView filtersList;
|
||
11 years ago
|
protected FilterListAdapter navigationListAdapter = null;
|
||
11 years ago
|
protected FilterListDropDownAdapter navigationSpinnerAdapter = null;
|
||
11 years ago
|
protected ServerStatusView serverStatusView;
|
||
11 years ago
|
@SystemService
|
||
|
protected SearchManager searchManager;
|
||
11 years ago
|
private MenuItem searchMenu = null;
|
||
11 years ago
|
private PullToRefreshAttacher pullToRefreshAttacher = null;
|
||
11 years ago
|
|
||
|
// Settings
|
||
|
@Bean
|
||
|
protected ApplicationSettings applicationSettings;
|
||
11 years ago
|
@Bean
|
||
|
protected SystemSettings systemSettings;
|
||
11 years ago
|
@InstanceState
|
||
|
boolean firstStart = true;
|
||
11 years ago
|
int skipNextOnNavigationItemSelectedCalls = 2;
|
||
11 years ago
|
private IDaemonAdapter currentConnection = null;
|
||
11 years ago
|
@InstanceState
|
||
11 years ago
|
protected NavigationFilter currentFilter = null;
|
||
|
@InstanceState
|
||
10 years ago
|
protected String preselectNavigationFilter = null;
|
||
|
@InstanceState
|
||
11 years ago
|
protected boolean turleModeEnabled = false;
|
||
11 years ago
|
@InstanceState
|
||
|
protected ArrayList<Label> lastNavigationLabels;
|
||
11 years ago
|
|
||
11 years ago
|
// Contained torrent and details fragments
|
||
10 years ago
|
@FragmentById(resName = "torrents_fragment")
|
||
11 years ago
|
protected TorrentsFragment fragmentTorrents;
|
||
10 years ago
|
@FragmentById(resName = "torrentdetails_fragment")
|
||
11 years ago
|
protected DetailsFragment fragmentDetails;
|
||
10 years ago
|
|
||
10 years ago
|
// Auto refresh task
|
||
11 years ago
|
private AsyncTask<Void, Void, Void> autoRefreshTask;
|
||
|
// Fragment uses this to pause the refresh across restarts
|
||
|
public boolean stopRefresh = false;
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
public void onCreate(Bundle savedInstanceState) {
|
||
|
// Set the theme according to the user preference
|
||
|
if (SystemSettings_.getInstance_(this).useDarkTheme()) {
|
||
|
setTheme(R.style.TransdroidTheme_Dark);
|
||
10 years ago
|
getActionBar().setIcon(R.drawable.ic_activity_torrents);
|
||
11 years ago
|
}
|
||
|
super.onCreate(savedInstanceState);
|
||
|
}
|
||
|
|
||
11 years ago
|
@AfterViews
|
||
|
protected void init() {
|
||
|
|
||
11 years ago
|
// Set up navigation, with an action bar spinner, server status indicator and possibly (if room) with a filter
|
||
|
// list
|
||
|
serverStatusView = ServerStatusView_.build(this);
|
||
10 years ago
|
ActionBar actionBar = getActionBar();
|
||
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
||
|
actionBar.setHomeButtonEnabled(false);
|
||
|
actionBar.setDisplayShowTitleEnabled(false);
|
||
|
actionBar.setDisplayShowCustomEnabled(true);
|
||
|
actionBar.setCustomView(serverStatusView);
|
||
11 years ago
|
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this);
|
||
11 years ago
|
// Servers are always added to the action bar spinner
|
||
11 years ago
|
navigationSpinnerAdapter.updateServers(applicationSettings.getAllServerSettings());
|
||
11 years ago
|
|
||
|
// Check if there was room for a dedicated filter list (i.e. on tablets)
|
||
11 years ago
|
if (filtersList != null) {
|
||
11 years ago
|
// The action bar spinner doesn't have to show the 'servers' label, as it will only contain servers
|
||
|
navigationSpinnerAdapter.hideServersLabel();
|
||
11 years ago
|
// Create dedicated side list adapter and add the status types
|
||
11 years ago
|
navigationListAdapter = FilterListAdapter_.getInstance_(this);
|
||
|
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
|
||
11 years ago
|
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
|
||
11 years ago
|
navigationListAdapter.updateLabels(new ArrayList<Label>());
|
||
11 years ago
|
filtersList.setAdapter(navigationListAdapter);
|
||
11 years ago
|
filtersList.setOnItemClickListener(onFilterListItemClicked);
|
||
11 years ago
|
} else {
|
||
|
// Add status types directly to the action bar spinner
|
||
|
navigationSpinnerAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
|
||
11 years ago
|
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
|
||
11 years ago
|
navigationSpinnerAdapter.updateLabels(new ArrayList<Label>());
|
||
11 years ago
|
}
|
||
10 years ago
|
// 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)
|
||
11 years ago
|
if (currentFilter == null) {
|
||
|
currentFilter = StatusType.getShowAllType(this);
|
||
|
}
|
||
10 years ago
|
actionBar.setListNavigationCallbacks(navigationSpinnerAdapter, this);
|
||
11 years ago
|
|
||
11 years ago
|
// Log messages from the server daemons using our singleton logger
|
||
|
DLog.setLogger(Log_.getInstance_(this));
|
||
|
|
||
10 years ago
|
// Load the default server or a server that was explicitly supplied in the starting intent
|
||
|
ServerSetting defaultServer = applicationSettings.getDefaultServer();
|
||
|
if (defaultServer == null) {
|
||
|
// No server settings yet
|
||
11 years ago
|
return;
|
||
|
}
|
||
10 years ago
|
Torrent openTorrent = null;
|
||
11 years ago
|
if (getIntent().getAction() != null && getIntent().getAction().equals(ListWidgetProvider.INTENT_STARTSERVER)
|
||
|
&& getIntent().getExtras() == null && getIntent().hasExtra(ListWidgetProvider.EXTRA_SERVER)) {
|
||
11 years ago
|
// A server settings order ID was provided in this org.transdroid.START_SERVER action intent
|
||
11 years ago
|
int serverId = getIntent().getExtras().getInt(ListWidgetProvider.EXTRA_SERVER);
|
||
11 years ago
|
if (serverId < 0 || serverId > applicationSettings.getMaxOfAllServers()) {
|
||
11 years ago
|
Log.e(this, "Tried to start with " + ListWidgetProvider.EXTRA_SERVER + " intent but " + serverId
|
||
11 years ago
|
+ " is not an existing server order id");
|
||
|
} else {
|
||
10 years ago
|
defaultServer = applicationSettings.getServerSetting(serverId);
|
||
11 years ago
|
if (getIntent().hasExtra(ListWidgetProvider.EXTRA_TORRENT))
|
||
10 years ago
|
openTorrent = getIntent().getParcelableExtra(ListWidgetProvider.EXTRA_TORRENT);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
// Set this as selection in the action bar spinner; we can use the server setting key since we have stable ids
|
||
11 years ago
|
// Note: skipNextOnNavigationItemSelectedCalls is used to prevent this event from triggering filterSelected
|
||
10 years ago
|
actionBar.setSelectedNavigationItem(defaultServer.getOrder() + 1);
|
||
11 years ago
|
|
||
11 years ago
|
// Connect to the last used server or a server that was explicitly supplied in the starting intent
|
||
|
if (firstStart) {
|
||
|
// Force first torrents refresh
|
||
10 years ago
|
filterSelected(defaultServer, true);
|
||
10 years ago
|
// Perhaps we can select the last used navigation filter, but only after a first refresh was completed
|
||
|
preselectNavigationFilter = applicationSettings.getLastUsedNavigationFilter();
|
||
11 years ago
|
// Handle any start up intents
|
||
10 years ago
|
if (openTorrent != null) {
|
||
|
openDetails(openTorrent);
|
||
|
openTorrent = null;
|
||
|
} else if (getIntent() != null) {
|
||
11 years ago
|
handleStartIntent();
|
||
|
}
|
||
|
} else {
|
||
|
// Resume after instead of fully loading the torrents list; create connection and set action bar title
|
||
10 years ago
|
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
|
||
11 years ago
|
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
|
||
11 years ago
|
navigationSpinnerAdapter.updateCurrentServer(currentConnection);
|
||
|
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
|
||
11 years ago
|
}
|
||
11 years ago
|
firstStart = false;
|
||
11 years ago
|
|
||
11 years ago
|
// Start the alarms for the background services, if needed
|
||
|
BootReceiver.startBackgroundServices(getApplicationContext(), false);
|
||
|
BootReceiver.startAppUpdatesService(getApplicationContext());
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
protected void onResume() {
|
||
|
super.onResume();
|
||
11 years ago
|
|
||
11 years ago
|
// Refresh server settings
|
||
11 years ago
|
navigationSpinnerAdapter.updateServers(applicationSettings.getAllServerSettings());
|
||
11 years ago
|
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
|
||
|
if (lastUsed == null) {
|
||
|
// Still no settings
|
||
11 years ago
|
updateFragmentVisibility(false);
|
||
11 years ago
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
|
// If we had no connection before, establish it now; otherwise just reload the settings
|
||
11 years ago
|
if (currentConnection == null)
|
||
|
filterSelected(lastUsed, true);
|
||
11 years ago
|
else
|
||
11 years ago
|
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
|
||
10 years ago
|
|
||
10 years ago
|
// Start auto refresh
|
||
|
startAutoRefresh();
|
||
|
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@OnActivityResult(RESULT_DETAILS)
|
||
|
protected void onDetailsScreenResult(Intent result) {
|
||
11 years ago
|
// If the details activity returns whether the torrent was removed or updated, update the torrents list as well
|
||
|
// (the details fragment is the source, so no need to update that)
|
||
|
if (result != null && result.hasExtra("affected_torrent")) {
|
||
|
Torrent affected = result.getParcelableExtra("affected_torrent");
|
||
|
fragmentTorrents.quickUpdateTorrent(affected, result.getBooleanExtra("torrent_removed", false));
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||
|
public void startAutoRefresh() {
|
||
|
// Check if already running
|
||
10 years ago
|
if (autoRefreshTask != null || stopRefresh || systemSettings.getRefreshIntervalMilliseconds() == 0)
|
||
11 years ago
|
return;
|
||
10 years ago
|
|
||
11 years ago
|
autoRefreshTask = new AsyncTask<Void, Void, Void>() {
|
||
|
@Override
|
||
|
protected Void doInBackground(Void... params) {
|
||
|
while (!isCancelled()) {
|
||
|
try {
|
||
10 years ago
|
Thread.sleep(systemSettings.getRefreshIntervalMilliseconds());
|
||
11 years ago
|
} catch (InterruptedException e) {
|
||
|
// Ignore
|
||
|
}
|
||
|
// Just in case it was cancelled during sleep
|
||
|
if (isCancelled())
|
||
|
return null;
|
||
10 years ago
|
|
||
11 years ago
|
refreshTorrents();
|
||
|
if (Daemon.supportsStats(currentConnection.getType()))
|
||
|
getAdditionalStats();
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
10 years ago
|
|
||
11 years ago
|
};
|
||
|
// Executes serially by default on Honeycomb, was parallel before
|
||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||
10 years ago
|
autoRefreshTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||
11 years ago
|
else
|
||
|
autoRefreshTask.execute();
|
||
|
}
|
||
10 years ago
|
|
||
11 years ago
|
public void stopAutoRefresh() {
|
||
|
if (autoRefreshTask != null)
|
||
|
autoRefreshTask.cancel(true);
|
||
|
autoRefreshTask = null;
|
||
|
}
|
||
10 years ago
|
|
||
11 years ago
|
@Override
|
||
|
protected void onDestroy() {
|
||
|
Crouton.cancelAllCroutons();
|
||
|
super.onDestroy();
|
||
|
}
|
||
|
|
||
11 years ago
|
@Override
|
||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||
|
super.onCreateOptionsMenu(menu);
|
||
11 years ago
|
if (navigationHelper.enableSearchUi()) {
|
||
10 years ago
|
// Add an expandable SearchView to the action bar
|
||
11 years ago
|
MenuItem item = menu.findItem(R.id.action_search);
|
||
10 years ago
|
SearchView searchView = new SearchView(this);
|
||
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
||
|
searchView.setQueryRefinementEnabled(true);
|
||
|
searchView.setOnSearchClickListener(new OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
// Pause autorefresh
|
||
|
stopRefresh = true;
|
||
|
stopAutoRefresh();
|
||
|
}
|
||
|
});
|
||
|
item.setOnActionExpandListener(new OnActionExpandListener() {
|
||
|
@Override
|
||
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||
|
return true;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||
|
stopRefresh = false;
|
||
|
startAutoRefresh();
|
||
|
return true;
|
||
|
}
|
||
|
});
|
||
|
item.setActionView(searchView);
|
||
|
searchMenu = item;
|
||
11 years ago
|
}
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||
|
super.onPrepareOptionsMenu(menu);
|
||
11 years ago
|
|
||
11 years ago
|
// No connection yet; hide all menu options except settings
|
||
|
if (currentConnection == null) {
|
||
|
menu.findItem(R.id.action_add).setVisible(false);
|
||
|
menu.findItem(R.id.action_search).setVisible(false);
|
||
|
menu.findItem(R.id.action_rss).setVisible(false);
|
||
|
menu.findItem(R.id.action_enableturtle).setVisible(false);
|
||
|
menu.findItem(R.id.action_disableturtle).setVisible(false);
|
||
|
menu.findItem(R.id.action_refresh).setVisible(false);
|
||
|
menu.findItem(R.id.action_sort).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_help).setVisible(true);
|
||
11 years ago
|
if (fragmentTorrents != null)
|
||
11 years ago
|
fragmentTorrents.updateConnectionStatus(false, null);
|
||
10 years ago
|
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||
11 years ago
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
// There is a connection (read: settings to some server known)
|
||
|
menu.findItem(R.id.action_add).setVisible(true);
|
||
11 years ago
|
menu.findItem(R.id.action_search).setVisible(navigationHelper.enableSearchUi());
|
||
|
menu.findItem(R.id.action_rss).setVisible(navigationHelper.enableRssUi());
|
||
11 years ago
|
boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType());
|
||
|
menu.findItem(R.id.action_enableturtle).setVisible(hasAltMode && !turleModeEnabled);
|
||
|
menu.findItem(R.id.action_disableturtle).setVisible(hasAltMode && turleModeEnabled);
|
||
|
menu.findItem(R.id.action_refresh).setVisible(true);
|
||
|
menu.findItem(R.id.action_sort).setVisible(true);
|
||
11 years ago
|
menu.findItem(R.id.action_sort_added).setVisible(Daemon.supportsDateAdded(currentConnection.getType()));
|
||
11 years ago
|
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_help).setVisible(false);
|
||
11 years ago
|
if (fragmentTorrents != null)
|
||
11 years ago
|
fragmentTorrents.updateConnectionStatus(true, currentConnection.getType());
|
||
10 years ago
|
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
||
11 years ago
|
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Called when an item in the action bar navigation spinner was selected
|
||
|
*/
|
||
|
@Override
|
||
|
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
||
11 years ago
|
if (skipNextOnNavigationItemSelectedCalls > 0) {
|
||
|
skipNextOnNavigationItemSelectedCalls--;
|
||
11 years ago
|
return false;
|
||
|
}
|
||
11 years ago
|
Object item = navigationSpinnerAdapter.getItem(itemPosition);
|
||
|
if (item instanceof SimpleListItem) {
|
||
|
// A filter item was selected form the navigation spinner
|
||
11 years ago
|
filterSelected((SimpleListItem) item, false);
|
||
11 years ago
|
return true;
|
||
|
}
|
||
|
// A header was selected; no action
|
||
|
return false;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
// Handles item selections on the dedicated list of filter items
|
||
|
private OnItemClickListener onFilterListItemClicked = new OnItemClickListener() {
|
||
11 years ago
|
@Override
|
||
11 years ago
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||
|
filtersList.setItemChecked(position, true);
|
||
11 years ago
|
Object item = filtersList.getAdapter().getItem(position);
|
||
|
if (item instanceof SimpleListItem)
|
||
|
filterSelected((SimpleListItem) item, false);
|
||
11 years ago
|
}
|
||
|
};
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
|
* A new filter was selected; update the view over the current data
|
||
|
* @param item The touched filter item
|
||
11 years ago
|
* @param forceNewConnection Whether a new connection should be initialised regardless of the old server selection
|
||
11 years ago
|
*/
|
||
11 years ago
|
protected void filterSelected(SimpleListItem item, boolean forceNewConnection) {
|
||
11 years ago
|
|
||
10 years ago
|
// No longer apply the last used filter (on a fresh application start), if we still needed to
|
||
|
preselectNavigationFilter = null;
|
||
|
|
||
11 years ago
|
// Server selection
|
||
|
if (item instanceof ServerSetting) {
|
||
|
ServerSetting server = (ServerSetting) item;
|
||
11 years ago
|
|
||
11 years ago
|
if (!forceNewConnection && currentConnection != null && server.equals(currentConnection.getSettings())) {
|
||
11 years ago
|
// Already connected to this server; just ask for a refresh instead
|
||
11 years ago
|
fragmentTorrents.updateIsLoading(true);
|
||
11 years ago
|
refreshTorrents();
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
// Update connection to the newly selected server and refresh
|
||
11 years ago
|
currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
|
||
11 years ago
|
applicationSettings.setLastUsedServer(server);
|
||
11 years ago
|
navigationSpinnerAdapter.updateCurrentServer(currentConnection);
|
||
|
if (forceNewConnection)
|
||
|
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
|
||
|
|
||
|
// Clear the currently shown list of torrents and perhaps the details
|
||
11 years ago
|
fragmentTorrents.clear(true, true);
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded() && fragmentDetails.getActivity() != null) {
|
||
11 years ago
|
fragmentDetails.updateIsLoading(false, null);
|
||
11 years ago
|
fragmentDetails.clear();
|
||
11 years ago
|
fragmentDetails.setCurrentServerSettings(server);
|
||
11 years ago
|
}
|
||
11 years ago
|
updateFragmentVisibility(true);
|
||
11 years ago
|
refreshScreen();
|
||
11 years ago
|
return;
|
||
11 years ago
|
|
||
|
}
|
||
11 years ago
|
|
||
|
// Status type or label selection - both of which are navigation filters
|
||
11 years ago
|
if (item instanceof NavigationFilter) {
|
||
10 years ago
|
// Set new filter
|
||
11 years ago
|
currentFilter = (NavigationFilter) item;
|
||
11 years ago
|
fragmentTorrents.applyNavigationFilter(currentFilter);
|
||
11 years ago
|
navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
|
||
10 years ago
|
// Remember that the user last selected this
|
||
|
applicationSettings.setLastUsedNavigationFilter(currentFilter);
|
||
11 years ago
|
// Clear the details view
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded()) {
|
||
11 years ago
|
fragmentDetails.updateIsLoading(false, null);
|
||
11 years ago
|
fragmentDetails.clear();
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Hides the filter list and details fragment's full view if there is no configured connection
|
||
|
* @param hasServerSettings Whether there are server settings available, so we can continue to connect
|
||
|
*/
|
||
|
private void updateFragmentVisibility(boolean hasServerSettings) {
|
||
|
if (filtersList != null)
|
||
11 years ago
|
filtersList.setVisibility(hasServerSettings ? View.VISIBLE : View.GONE);
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded()) {
|
||
11 years ago
|
if (hasServerSettings)
|
||
10 years ago
|
getFragmentManager().beginTransaction().show(fragmentDetails).commit();
|
||
11 years ago
|
else
|
||
10 years ago
|
getFragmentManager().beginTransaction().hide(fragmentDetails).commit();
|
||
11 years ago
|
}
|
||
10 years ago
|
invalidateOptionsMenu();
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
protected void onNewIntent(Intent intent) {
|
||
|
setIntent(intent);
|
||
|
handleStartIntent();
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
protected void handleStartIntent() {
|
||
10 years ago
|
// For intents that come from out of the application, perhaps we can not directly add them
|
||
|
if (applicationSettings.getDefaultServerKey() == ApplicationSettings.DEFAULTSERVER_ASKONADD
|
||
|
&& getIntent().getData() != null) {
|
||
|
// First ask which server to use before adding any intent from the extras
|
||
|
ServerPickerDialog.startServerPicker(this, applicationSettings.getAllServerSettings());
|
||
|
return;
|
||
|
}
|
||
|
addFromIntent();
|
||
|
}
|
||
|
|
||
|
public void switchServerAndAddFromIntent(int position) {
|
||
|
// Callback from the ServerPickerDialog; force a connection before selecting it (in the navigation)
|
||
|
// Note: we can just use the list position as we have stable server setting ids
|
||
|
ServerSetting selectedServer = applicationSettings.getAllServerSettings().get(position);
|
||
|
filterSelected(selectedServer, false);
|
||
|
addFromIntent();
|
||
|
skipNextOnNavigationItemSelectedCalls++; // Prevent this selection from launching filterSelected() again
|
||
|
getActionBar().setSelectedNavigationItem(position + 1);
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
/**
|
||
|
* If required, add torrents from the supplied intent extras.
|
||
|
*/
|
||
|
protected void addFromIntent() {
|
||
11 years ago
|
Intent intent = getIntent();
|
||
|
Uri dataUri = intent.getData();
|
||
|
String data = intent.getDataString();
|
||
|
String action = intent.getAction();
|
||
11 years ago
|
|
||
|
// Adding multiple torrents at the same time (as found in the Intent extras Bundle)
|
||
|
if (action != null && action.equals("org.transdroid.ADD_MULTIPLE")) {
|
||
11 years ago
|
// Intent should have some extras pointing to possibly multiple torrents
|
||
11 years ago
|
String[] urls = intent.getStringArrayExtra("TORRENT_URLS");
|
||
|
String[] titles = intent.getStringArrayExtra("TORRENT_TITLES");
|
||
|
if (urls != null) {
|
||
|
for (int i = 0; i < urls.length; i++) {
|
||
10 years ago
|
String title = (titles != null && titles.length >= i ? titles[i] : NavigationHelper
|
||
|
.extractNameFromUri(Uri.parse(urls[i])));
|
||
10 years ago
|
if (intent.hasExtra("PRIVATE_SOURCE")) {
|
||
|
// 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"));
|
||
|
} else {
|
||
|
addTorrentByUrl(urls[i], title);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
return;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
// Add a torrent from a local or remote data URI?
|
||
|
if (dataUri == null)
|
||
|
return;
|
||
11 years ago
|
if (dataUri.getScheme() == null) {
|
||
|
Crouton.showText(this, R.string.error_invalid_url_form, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
// Get torrent title
|
||
|
String title = NavigationHelper.extractNameFromUri(dataUri);
|
||
|
if (intent.hasExtra("TORRENT_TITLE")) {
|
||
|
title = intent.getStringExtra("TORRENT_TITLE");
|
||
|
}
|
||
|
|
||
11 years ago
|
// Adding a torrent from the Android downloads manager
|
||
11 years ago
|
if (dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
|
||
10 years ago
|
addTorrentFromDownloads(dataUri, title);
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
// Adding a torrent from http or https URL
|
||
11 years ago
|
if (dataUri.getScheme().equals("http") || dataUri.getScheme().equals("https")) {
|
||
11 years ago
|
|
||
10 years ago
|
String privateSource = getIntent().getStringExtra("PRIVATE_SOURCE");
|
||
|
|
||
11 years ago
|
WebsearchSetting match = null;
|
||
10 years ago
|
if (privateSource == null) {
|
||
|
// Check if the target URL is also defined as a web search in the user's settings
|
||
|
List<WebsearchSetting> websearches = applicationSettings.getWebsearchSettings();
|
||
|
for (WebsearchSetting setting : websearches) {
|
||
|
Uri uri = Uri.parse(setting.getBaseUrl());
|
||
|
if (uri.getHost() != null && uri.getHost().equals(dataUri.getHost())) {
|
||
|
match = setting;
|
||
|
break;
|
||
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// If the URL is also a web search and it defines cookies, use the cookies by downloading the targeted
|
||
|
// torrent file (while supplies the cookies to the HTTP request) instead of sending the URL directly to the
|
||
10 years ago
|
// torrent client. If instead it is marked (by the Torrent Search module) as being form a private site, use
|
||
|
// the Search Module instead to download the url locally first.
|
||
11 years ago
|
if (match != null && match.getCookies() != null) {
|
||
10 years ago
|
addTorrentFromWeb(data, match, title);
|
||
|
} else if (privateSource != null) {
|
||
|
addTorrentFromPrivateSource(data.toString(), title, privateSource);
|
||
11 years ago
|
} else {
|
||
10 years ago
|
// Normally send the URL to the torrent client
|
||
|
addTorrentByUrl(data, title);
|
||
11 years ago
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
// Adding a torrent from magnet URL
|
||
11 years ago
|
if (dataUri.getScheme().equals("magnet")) {
|
||
10 years ago
|
addTorrentByMagnetUrl(data, title);
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
11 years ago
|
// Adding a local .torrent file; the title we show is just the file name
|
||
11 years ago
|
if (dataUri.getScheme().equals("file")) {
|
||
|
addTorrentByFile(data, title);
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Override
|
||
|
protected void onPause() {
|
||
|
if (searchMenu != null)
|
||
|
searchMenu.collapseActionView();
|
||
10 years ago
|
stopAutoRefresh();
|
||
11 years ago
|
super.onPause();
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
public boolean onSearchRequested() {
|
||
|
if (searchMenu != null) {
|
||
|
searchMenu.expandActionView();
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@OptionsItem(resName = "action_add_fromurl")
|
||
|
protected void startUrlEntryDialog() {
|
||
11 years ago
|
UrlEntryDialog.startUrlEntry(this);
|
||
11 years ago
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_add_fromfile")
|
||
|
protected void startFilePicker() {
|
||
11 years ago
|
FilePickerHelper.startFilePicker(this);
|
||
|
}
|
||
|
|
||
|
@Background
|
||
|
@OnActivityResult(FilePickerHelper.ACTIVITY_FILEPICKER)
|
||
|
public void onFilePicked(int resultCode, Intent data) {
|
||
|
// We should have received an Intent with a local torrent's Uri as data from the file picker
|
||
|
if (data != null && data.getData() != null && !data.getData().equals("")) {
|
||
|
String url = data.getData().getPath();
|
||
|
addTorrentByFile(data.getData().toString(), url.substring(url.lastIndexOf("/")));
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_add_frombarcode")
|
||
|
protected void startBarcodeScanner() {
|
||
|
BarcodeHelper.startBarcodeScanner(this);
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@OnActivityResult(BarcodeHelper.ACTIVITY_BARCODE)
|
||
|
public void onBarcodeScanned(int resultCode, Intent data) {
|
||
11 years ago
|
// 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);
|
||
11 years ago
|
if (query.startsWith("http"))
|
||
|
addTorrentByUrl(query, "QR code result"); // No torrent title known
|
||
|
else
|
||
|
startSearch(query, false, null, false);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Attaches some view (perhaps contained in a fragment) to this activity's pull to refresh support
|
||
|
* @param view The view to attach
|
||
|
*/
|
||
|
@Override
|
||
|
public void addRefreshableView(View view) {
|
||
|
if (pullToRefreshAttacher == null) {
|
||
|
// Still need to initialise the PullToRefreshAttacher
|
||
|
Options options = new PullToRefreshAttacher.Options();
|
||
|
options.headerTransformer = new NoProgressHeaderTransformer();
|
||
|
pullToRefreshAttacher = PullToRefreshAttacher.get(this, options);
|
||
|
}
|
||
|
pullToRefreshAttacher.addRefreshableView(view, new OnRefreshListener() {
|
||
|
@Override
|
||
|
public void onRefreshStarted(View view) {
|
||
|
// Just refresh the full screen, now that the user has pulled to refresh
|
||
|
pullToRefreshAttacher.setRefreshComplete();
|
||
|
refreshScreen();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@OptionsItem(resName = "action_refresh")
|
||
11 years ago
|
public void refreshScreen() {
|
||
11 years ago
|
fragmentTorrents.updateIsLoading(true);
|
||
11 years ago
|
refreshTorrents();
|
||
11 years ago
|
if (Daemon.supportsStats(currentConnection.getType()))
|
||
|
getAdditionalStats();
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_enableturtle")
|
||
11 years ago
|
protected void enableTurtleMode() {
|
||
|
updateTurtleMode(true);
|
||
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_disableturtle")
|
||
11 years ago
|
protected void disableTurtleMode() {
|
||
|
updateTurtleMode(false);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@OptionsItem(resName = "action_rss")
|
||
|
protected void openRss() {
|
||
|
RssfeedsActivity_.intent(this).start();
|
||
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_settings")
|
||
11 years ago
|
protected void openSettings() {
|
||
|
MainSettingsActivity_.intent(this).start();
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@OptionsItem(resName = "action_help")
|
||
11 years ago
|
protected void openHelp() {
|
||
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/download/")));
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@OptionsItem(resName = "action_sort_byname")
|
||
|
protected void sortByName() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.Alphanumeric);
|
||
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_sort_status")
|
||
|
protected void sortByStatus() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.Status);
|
||
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_sort_done")
|
||
|
protected void sortByDateDone() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.DateDone);
|
||
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_sort_added")
|
||
|
protected void sortByDateAdded() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.DateAdded);
|
||
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_sort_downspeed")
|
||
|
protected void sortByDownspeed() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.DownloadSpeed);
|
||
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_sort_upspeed")
|
||
|
protected void sortByUpspeed() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.UploadSpeed);
|
||
|
}
|
||
|
|
||
|
@OptionsItem(resName = "action_sort_ratio")
|
||
|
protected void sortByRatio() {
|
||
|
fragmentTorrents.sortBy(TorrentsSortBy.Ratio);
|
||
|
}
|
||
|
|
||
11 years ago
|
@OptionsItem(resName = "action_filter")
|
||
|
protected void startFilterEntryDialog() {
|
||
|
FilterEntryDialog.startFilterEntry(this);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Redirect the newly entered list filter to the torrents fragment.
|
||
|
* @param newFilterText The newly entered filter (or empty to clear the current filter).
|
||
|
*/
|
||
|
public void filterTorrents(String newFilterText) {
|
||
|
fragmentTorrents.applyTextFilter(newFilterText);
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Shows the a details fragment for the given torrent, either in the dedicated details fragment pane, in the same
|
||
|
* pane as the torrent list was displayed or by starting a details activity.
|
||
|
* @param torrent The torrent to show detailed statistics for
|
||
|
*/
|
||
|
public void openDetails(Torrent torrent) {
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded()) {
|
||
11 years ago
|
fragmentDetails.updateTorrent(torrent);
|
||
|
} else {
|
||
11 years ago
|
DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels)
|
||
|
.startForResult(RESULT_DETAILS);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
protected void refreshTorrents() {
|
||
10 years ago
|
String startConnectionId = currentConnection.getSettings().getIdString();
|
||
11 years ago
|
DaemonTaskResult result = RetrieveTask.create(currentConnection).execute();
|
||
10 years ago
|
if (!startConnectionId.equals(currentConnection.getSettings().getIdString())) {
|
||
|
// During the command execution the user changed the server, so we are no longer interested in the result
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
if (result instanceof RetrieveTaskSuccessResult) {
|
||
11 years ago
|
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(),
|
||
|
((RetrieveTaskSuccessResult) result).getLabels());
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Background
|
||
|
public void refreshTorrentDetails(Torrent torrent) {
|
||
|
if (!Daemon.supportsFineDetails(currentConnection.getType()))
|
||
|
return;
|
||
10 years ago
|
String startConnectionId = currentConnection.getSettings().getIdString();
|
||
11 years ago
|
DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute();
|
||
10 years ago
|
if (!startConnectionId.equals(currentConnection.getSettings().getIdString())) {
|
||
|
// During the command execution the user changed the server, so we are no longer interested in the result
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
if (result instanceof GetTorrentDetailsTaskSuccessResult) {
|
||
|
onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails());
|
||
|
} else {
|
||
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Background
|
||
|
public void refreshTorrentFiles(Torrent torrent) {
|
||
|
if (!Daemon.supportsFileListing(currentConnection.getType()))
|
||
|
return;
|
||
10 years ago
|
String startConnectionId = currentConnection.getSettings().getIdString();
|
||
11 years ago
|
DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute();
|
||
10 years ago
|
if (!startConnectionId.equals(currentConnection.getSettings().getIdString())) {
|
||
|
// During the command execution the user changed the server, so we are no longer interested in the result
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
if (result instanceof GetFileListTaskSuccessResult) {
|
||
|
onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles());
|
||
|
} else {
|
||
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
protected void getAdditionalStats() {
|
||
10 years ago
|
String startConnectionId = currentConnection.getSettings().getIdString();
|
||
11 years ago
|
DaemonTaskResult result = GetStatsTask.create(currentConnection).execute();
|
||
10 years ago
|
if (!startConnectionId.equals(currentConnection.getSettings().getIdString())) {
|
||
|
// During the command execution the user changed the server, so we are no longer interested in the result
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
if (result instanceof GetStatsTaskSuccessResult) {
|
||
|
onTurtleModeRetrieved(((GetStatsTaskSuccessResult) result).isAlternativeModeEnabled());
|
||
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
@Background
|
||
|
protected void updateTurtleMode(boolean enable) {
|
||
10 years ago
|
String startConnectionId = currentConnection.getSettings().getIdString();
|
||
11 years ago
|
DaemonTaskResult result = SetAlternativeModeTask.create(currentConnection, enable).execute();
|
||
10 years ago
|
if (!startConnectionId.equals(currentConnection.getSettings().getIdString())) {
|
||
|
// During the command execution the user changed the server, so we are no longer interested in the result
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
// Success; no need to retrieve it again - just update the visual indicator
|
||
|
onTurtleModeRetrieved(enable);
|
||
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
public void addTorrentByUrl(String url, String title) {
|
||
11 years ago
|
DaemonTaskResult result = AddByUrlTask.create(currentConnection, url, title).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
|
||
11 years ago
|
refreshTorrents();
|
||
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
10 years ago
|
public void addTorrentByMagnetUrl(String url, String title) {
|
||
11 years ago
|
DaemonTaskResult result = AddByMagnetUrlTask.create(currentConnection, url).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
10 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
|
||
11 years ago
|
refreshTorrents();
|
||
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@Background
|
||
|
protected void addTorrentByFile(String localFile, String title) {
|
||
|
DaemonTaskResult result = AddByFileTask.create(currentConnection, localFile).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
|
||
11 years ago
|
refreshTorrents();
|
||
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
private void addTorrentFromDownloads(Uri contentUri, String title) {
|
||
11 years ago
|
|
||
|
try {
|
||
11 years ago
|
// Open the content uri as input stream and this via a local temporary file
|
||
10 years ago
|
addTorrentFromStream(getContentResolver().openInputStream(contentUri), title);
|
||
11 years ago
|
} catch (SecurityException e) {
|
||
|
// No longer access to this file
|
||
|
Log.e(this, "No access given to " + contentUri.toString() + ": " + e.toString());
|
||
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
} catch (FileNotFoundException e) {
|
||
|
Log.e(this, contentUri.toString() + " does not exist: " + e.toString());
|
||
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
@Background
|
||
|
protected void addTorrentFromPrivateSource(String url, String title, String source) {
|
||
|
|
||
|
try {
|
||
|
InputStream input = SearchHelper_.getInstance_(this).getFile(source, url);
|
||
10 years ago
|
addTorrentFromStream(input, title);
|
||
10 years ago
|
} catch (Exception e) {
|
||
|
Log.e(this, "Can't download private site torrent " + url + " from " + source + ": " + e.toString());
|
||
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
10 years ago
|
protected void addTorrentFromWeb(String url, WebsearchSetting websearchSetting, String title) {
|
||
11 years ago
|
|
||
|
try {
|
||
|
// Cookies are taken from the websearchSetting that we already matched against this target URL
|
||
|
DefaultHttpClient httpclient = HttpHelper.createStandardHttpClient(false, null, null, true, null, 10000,
|
||
|
null, -1);
|
||
|
Map<String, String> cookies = HttpHelper.parseCookiePairs(websearchSetting.getCookies());
|
||
|
String domain = Uri.parse(url).getHost();
|
||
|
for (Entry<String, String> pair : cookies.entrySet()) {
|
||
|
BasicClientCookie cookie = new BasicClientCookie(pair.getKey(), pair.getValue());
|
||
|
cookie.setPath("/");
|
||
|
cookie.setDomain(domain);
|
||
|
httpclient.getCookieStore().addCookie(cookie);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
// 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
|
||
|
HttpResponse response = httpclient.execute(new HttpGet(url));
|
||
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
|
||
|
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN
|
||
|
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
|
||
|
Log.e(this, "Can't retrieve web torrent " + url + ": Unexpected HTTP response status code "
|
||
|
+ response.getStatusLine().toString());
|
||
|
Crouton.showText(this, R.string.error_401, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
return;
|
||
|
}
|
||
|
InputStream input = response.getEntity().getContent();
|
||
10 years ago
|
addTorrentFromStream(input, title);
|
||
11 years ago
|
} catch (Exception e) {
|
||
|
Log.e(this, "Can't retrieve web torrent " + url + ": " + e.toString());
|
||
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Background
|
||
10 years ago
|
protected void addTorrentFromStream(InputStream input, String title) {
|
||
11 years ago
|
|
||
|
File tempFile = new File("/not/yet/set");
|
||
|
try {
|
||
11 years ago
|
// Write a temporary file with the torrent contents
|
||
11 years ago
|
tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
|
||
11 years ago
|
FileOutputStream output = new FileOutputStream(tempFile);
|
||
|
try {
|
||
|
final byte[] buffer = new byte[1024];
|
||
|
int read;
|
||
|
while ((read = input.read(buffer)) != -1)
|
||
|
output.write(buffer, 0, read);
|
||
|
output.flush();
|
||
|
String fileName = Uri.fromFile(tempFile).toString();
|
||
10 years ago
|
addTorrentByFile(fileName, title);
|
||
11 years ago
|
} finally {
|
||
|
output.close();
|
||
|
}
|
||
11 years ago
|
} catch (IOException e) {
|
||
|
Log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString());
|
||
11 years ago
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
11 years ago
|
} finally {
|
||
|
try {
|
||
|
if (input != null)
|
||
|
input.close();
|
||
|
} catch (IOException e) {
|
||
11 years ago
|
Log.e(this, "Error closing the input stream " + tempFile.toString() + ": " + e.toString());
|
||
11 years ago
|
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
@Override
|
||
|
public void resumeTorrent(Torrent torrent) {
|
||
|
torrent.mimicResume();
|
||
|
DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName()));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
|
public void pauseTorrent(Torrent torrent) {
|
||
11 years ago
|
torrent.mimicPause();
|
||
|
DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName()));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
11 years ago
|
public void startTorrent(Torrent torrent, boolean forced) {
|
||
|
torrent.mimicStart();
|
||
|
DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName()));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
|
public void stopTorrent(Torrent torrent) {
|
||
11 years ago
|
torrent.mimicStop();
|
||
|
DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName()));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
|
public void removeTorrent(Torrent torrent, boolean withData) {
|
||
11 years ago
|
DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded(
|
||
|
(DaemonTaskSuccessResult) result,
|
||
|
getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName()));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
11 years ago
|
public void updateLabel(Torrent torrent, String newLabel) {
|
||
|
torrent.mimicNewLabel(newLabel);
|
||
11 years ago
|
DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel)
|
||
|
.execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded(
|
||
|
(DaemonTaskSuccessResult) result,
|
||
|
newLabel == null ? getString(R.string.result_labelremoved) : getString(R.string.result_labelset,
|
||
|
newLabel));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
@Override
|
||
|
public void forceRecheckTorrent(Torrent torrent) {
|
||
|
torrent.mimicCheckingStatus();
|
||
|
DaemonTaskResult result = ForceRecheckTask.create(currentConnection, torrent).execute();
|
||
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
|
onTaskSucceeded((DaemonTaskSuccessResult) result,
|
||
|
getString(R.string.result_recheckedstarted, torrent.getName()));
|
||
|
} else {
|
||
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
11 years ago
|
public void updateTrackers(Torrent torrent, List<String> newTrackers) {
|
||
|
DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
11 years ago
|
@Override
|
||
11 years ago
|
public void updateLocation(Torrent torrent, String newLocation) {
|
||
|
DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
@Override
|
||
|
public void updatePriority(Torrent torrent, List<TorrentFile> files, Priority priority) {
|
||
|
DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority,
|
||
|
new ArrayList<TorrentFile>(files)).execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset));
|
||
|
} else {
|
||
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@Background
|
||
|
public void updateMaxSpeeds(Integer maxDownloadSpeed, Integer maxUploadSpeed) {
|
||
|
DaemonTaskResult result = SetTransferRatesTask.create(currentConnection, maxUploadSpeed, maxDownloadSpeed)
|
||
|
.execute();
|
||
11 years ago
|
if (result instanceof DaemonTaskSuccessResult) {
|
||
11 years ago
|
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_maxspeedsset));
|
||
|
} else {
|
||
|
onCommunicationError((DaemonTaskFailureResult) result, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
@UiThread
|
||
11 years ago
|
protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
|
||
|
// Refresh the screen as well
|
||
|
refreshScreen();
|
||
11 years ago
|
Crouton.showText(this, successMessage, NavigationHelper.CROUTON_INFO_STYLE);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@UiThread
|
||
11 years ago
|
protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
|
||
11 years ago
|
Log.i(this, result.getException().toString());
|
||
11 years ago
|
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
|
||
11 years ago
|
Crouton.showText(this, error, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
11 years ago
|
fragmentTorrents.updateIsLoading(false);
|
||
11 years ago
|
if (isCritical) {
|
||
11 years ago
|
fragmentTorrents.updateError(error);
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded())
|
||
11 years ago
|
fragmentDetails.updateIsLoading(false, error);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@UiThread
|
||
|
protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> labels) {
|
||
11 years ago
|
|
||
11 years ago
|
lastNavigationLabels = Label.convertToNavigationLabels(labels,
|
||
|
getResources().getString(R.string.labels_unlabeled));
|
||
11 years ago
|
|
||
11 years ago
|
// Report the newly retrieved list of torrents to the torrents fragment
|
||
11 years ago
|
fragmentTorrents.updateIsLoading(false);
|
||
11 years ago
|
fragmentTorrents.updateTorrents(new ArrayList<Torrent>(torrents), lastNavigationLabels);
|
||
11 years ago
|
|
||
11 years ago
|
// Update the details fragment if the currently shown torrent is in the newly retrieved list
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded()) {
|
||
11 years ago
|
fragmentDetails.perhapsUpdateTorrent(torrents);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
// Update local list of labels in the navigation
|
||
|
if (navigationListAdapter != null) {
|
||
|
// Labels are shown in the dedicated side navigation
|
||
11 years ago
|
navigationListAdapter.updateLabels(lastNavigationLabels);
|
||
11 years ago
|
} else {
|
||
|
// Labels are shown in the action bar spinner
|
||
11 years ago
|
navigationSpinnerAdapter.updateLabels(lastNavigationLabels);
|
||
11 years ago
|
}
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded())
|
||
11 years ago
|
fragmentDetails.updateLabels(lastNavigationLabels);
|
||
11 years ago
|
|
||
10 years ago
|
// Perhaps we were still waiting to preselect the last used filter (on a fresh application start)
|
||
|
if (preselectNavigationFilter != null) {
|
||
|
FilterListAdapter adapter = navigationListAdapter != null ? navigationListAdapter
|
||
|
: navigationSpinnerAdapter;
|
||
|
for (int i = 0; i < adapter.getCount(); i++) {
|
||
|
// Regardless of the navigation style (side list or action bar spinner), we can look up the navigation
|
||
|
// filter item, which is represented as simple list item (and might not exist any more, such as with a
|
||
|
// label that is deleted on the server)
|
||
|
Object item = adapter.getItem(i);
|
||
|
if (item instanceof SimpleListItem && item instanceof NavigationFilter
|
||
|
&& ((NavigationFilter) item).getCode().equals(preselectNavigationFilter)) {
|
||
|
filterSelected((SimpleListItem) item, false);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// Only preselect after the first update we receive (even if the filter wasn't found any more)
|
||
|
preselectNavigationFilter = null;
|
||
|
}
|
||
|
|
||
11 years ago
|
// Update the server status (counts and speeds) in the action bar
|
||
11 years ago
|
serverStatusView.update(torrents, systemSettings.treatDormantAsInactive());
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
@UiThread
|
||
|
protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) {
|
||
|
// Update the details fragment with the new fine details for the shown torrent
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded())
|
||
11 years ago
|
fragmentDetails.updateTorrentDetails(torrent, torrentDetails);
|
||
|
}
|
||
|
|
||
|
@UiThread
|
||
|
protected void onTorrentFilesRetrieved(Torrent torrent, List<TorrentFile> torrentFiles) {
|
||
|
// Update the details fragment with the newly retrieved list of files
|
||
10 years ago
|
if (fragmentDetails != null && fragmentDetails.isAdded())
|
||
11 years ago
|
fragmentDetails.updateTorrentFiles(torrent, new ArrayList<TorrentFile>(torrentFiles));
|
||
|
}
|
||
|
|
||
11 years ago
|
@UiThread
|
||
|
protected void onTurtleModeRetrieved(boolean turtleModeEnabled) {
|
||
|
turleModeEnabled = turtleModeEnabled;
|
||
10 years ago
|
invalidateOptionsMenu();
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
}
|