|
|
@ -36,6 +36,7 @@ import android.view.Menu; |
|
|
|
import android.view.MenuItem; |
|
|
|
import android.view.MenuItem; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View.OnClickListener; |
|
|
|
import android.view.View.OnClickListener; |
|
|
|
|
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.AdapterView; |
|
|
|
import android.widget.AdapterView; |
|
|
|
import android.widget.AdapterView.OnItemClickListener; |
|
|
|
import android.widget.AdapterView.OnItemClickListener; |
|
|
|
import android.widget.ListView; |
|
|
|
import android.widget.ListView; |
|
|
@ -171,6 +172,8 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
protected FloatingActionButton addmenuFileButton; |
|
|
|
protected FloatingActionButton addmenuFileButton; |
|
|
|
@ViewById |
|
|
|
@ViewById |
|
|
|
protected DrawerLayout drawerLayout; |
|
|
|
protected DrawerLayout drawerLayout; |
|
|
|
|
|
|
|
@ViewById(R.id.drawer_container) |
|
|
|
|
|
|
|
protected ViewGroup drawerContainer; |
|
|
|
@ViewById |
|
|
|
@ViewById |
|
|
|
protected ListView drawerList; |
|
|
|
protected ListView drawerList; |
|
|
|
@ViewById |
|
|
|
@ViewById |
|
|
@ -193,7 +196,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
@InstanceState |
|
|
|
@InstanceState |
|
|
|
protected String preselectNavigationFilter = null; |
|
|
|
protected String preselectNavigationFilter = null; |
|
|
|
@InstanceState |
|
|
|
@InstanceState |
|
|
|
protected boolean turleModeEnabled = false; |
|
|
|
protected boolean turtleModeEnabled = false; |
|
|
|
@InstanceState |
|
|
|
@InstanceState |
|
|
|
protected ArrayList<Label> lastNavigationLabels; |
|
|
|
protected ArrayList<Label> lastNavigationLabels; |
|
|
|
// Contained torrent and details fragments
|
|
|
|
// Contained torrent and details fragments
|
|
|
@ -232,6 +235,13 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
torrentsToolbar.addView(serverSelectionView); |
|
|
|
torrentsToolbar.addView(serverSelectionView); |
|
|
|
} |
|
|
|
} |
|
|
|
actionsToolbar.addView(serverStatusView); |
|
|
|
actionsToolbar.addView(serverStatusView); |
|
|
|
|
|
|
|
actionsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onMenuItemClick(MenuItem menuItem) { |
|
|
|
|
|
|
|
// Redirect to the classic activity implementation so we can use @OptionsItem methods
|
|
|
|
|
|
|
|
return onOptionsItemSelected(menuItem); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments
|
|
|
|
setSupportActionBar(torrentsToolbar); // For direct menu item inflation by the contained fragments
|
|
|
|
getSupportActionBar().setDisplayShowTitleEnabled(false); |
|
|
|
getSupportActionBar().setDisplayShowTitleEnabled(false); |
|
|
|
|
|
|
|
|
|
|
@ -405,7 +415,9 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
super.onCreateOptionsMenu(menu); |
|
|
|
super.onCreateOptionsMenu(menu); |
|
|
|
// Manually insert the actions into the main torrent and secondary actions toolbars
|
|
|
|
// Manually insert the actions into the main torrent and secondary actions toolbars
|
|
|
|
torrentsToolbar.inflateMenu(R.menu.activity_torrents_main); |
|
|
|
torrentsToolbar.inflateMenu(R.menu.activity_torrents_main); |
|
|
|
|
|
|
|
if (actionsToolbar.getMenu().size() == 0) { |
|
|
|
actionsToolbar.inflateMenu(R.menu.activity_torrents_secondary); |
|
|
|
actionsToolbar.inflateMenu(R.menu.activity_torrents_secondary); |
|
|
|
|
|
|
|
} |
|
|
|
if (navigationHelper.enableSearchUi()) { |
|
|
|
if (navigationHelper.enableSearchUi()) { |
|
|
|
// Add an expandable SearchView to the action bar
|
|
|
|
// Add an expandable SearchView to the action bar
|
|
|
|
MenuItem item = menu.findItem(R.id.action_search); |
|
|
|
MenuItem item = menu.findItem(R.id.action_search); |
|
|
@ -447,6 +459,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
if (currentConnection == null) { |
|
|
|
if (currentConnection == null) { |
|
|
|
torrentsToolbar.setNavigationIcon(null); |
|
|
|
torrentsToolbar.setNavigationIcon(null); |
|
|
|
addmenuButton.setVisibility(View.GONE); |
|
|
|
addmenuButton.setVisibility(View.GONE); |
|
|
|
|
|
|
|
actionsToolbar.setVisibility(View.GONE); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_search).setVisible(false); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(false); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_rss).setVisible(false); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_settings).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); |
|
|
@ -464,6 +477,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
// There is a connection (read: settings to some server known)
|
|
|
|
// There is a connection (read: settings to some server known)
|
|
|
|
torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); |
|
|
|
torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); |
|
|
|
addmenuButton.setVisibility(View.VISIBLE); |
|
|
|
addmenuButton.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
actionsToolbar.setVisibility(View.VISIBLE); |
|
|
|
boolean addByFile = Daemon.supportsAddByFile(currentConnection.getType()); |
|
|
|
boolean addByFile = Daemon.supportsAddByFile(currentConnection.getType()); |
|
|
|
addmenuFileButton.setVisibility(addByFile ? View.VISIBLE : View.GONE); |
|
|
|
addmenuFileButton.setVisibility(addByFile ? View.VISIBLE : View.GONE); |
|
|
|
// Primary toolbar menu
|
|
|
|
// Primary toolbar menu
|
|
|
@ -473,8 +487,8 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false); |
|
|
|
torrentsToolbar.getMenu().findItem(R.id.action_help).setVisible(false); |
|
|
|
// Secondary toolbar menu
|
|
|
|
// Secondary toolbar menu
|
|
|
|
boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType()); |
|
|
|
boolean hasAltMode = Daemon.supportsSetAlternativeMode(currentConnection.getType()); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(hasAltMode && !turleModeEnabled); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_enableturtle).setVisible(hasAltMode && !turtleModeEnabled); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_disableturtle).setVisible(hasAltMode && turleModeEnabled); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_disableturtle).setVisible(hasAltMode && turtleModeEnabled); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_refresh).setVisible(true); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_refresh).setVisible(true); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_sort).setVisible(true); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_sort).setVisible(true); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_sort_added).setVisible(Daemon.supportsDateAdded(currentConnection.getType())); |
|
|
|
actionsToolbar.getMenu().findItem(R.id.action_sort_added).setVisible(Daemon.supportsDateAdded(currentConnection.getType())); |
|
|
@ -502,7 +516,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
if (item instanceof SimpleListItem) { |
|
|
|
if (item instanceof SimpleListItem) { |
|
|
|
filterSelected((SimpleListItem) item, false); |
|
|
|
filterSelected((SimpleListItem) item, false); |
|
|
|
} |
|
|
|
} |
|
|
|
drawerLayout.closeDrawer(drawerList); |
|
|
|
drawerLayout.closeDrawer(drawerContainer); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -762,20 +776,6 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Attaches some view (perhaps contained in a fragment) to this activity's pull to refresh support |
|
|
|
|
|
|
|
* @param container The refresh container to handle user refresh requests and show the progress |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void addSwipeRefreshLayout(SwipeRefreshLayout container) { |
|
|
|
|
|
|
|
container.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onRefresh() { |
|
|
|
|
|
|
|
refreshScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptionsItem(R.id.action_refresh) |
|
|
|
@OptionsItem(R.id.action_refresh) |
|
|
|
public void refreshScreen() { |
|
|
|
public void refreshScreen() { |
|
|
|
fragmentTorrents.updateIsLoading(true); |
|
|
|
fragmentTorrents.updateIsLoading(true); |
|
|
@ -1229,7 +1229,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
@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, new ArrayList<TorrentFile>(files)).execute(log); |
|
|
|
DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority, new ArrayList<>(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 { |
|
|
@ -1276,7 +1276,7 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
fragmentTorrents.updateTorrents(new ArrayList<Torrent>(torrents), lastNavigationLabels); |
|
|
|
fragmentTorrents.updateTorrents(new ArrayList<>(torrents), lastNavigationLabels); |
|
|
|
|
|
|
|
|
|
|
|
// Update the details fragment if the currently shown torrent is in the newly retrieved list
|
|
|
|
// Update the details fragment if the currently shown torrent is in the newly retrieved list
|
|
|
|
if (fragmentDetails != null && fragmentDetails.isAdded()) { |
|
|
|
if (fragmentDetails != null && fragmentDetails.isAdded()) { |
|
|
@ -1323,13 +1323,13 @@ public class TorrentsActivity extends ActionBarActivity implements TorrentTasksE |
|
|
|
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<>(torrentFiles)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@UiThread |
|
|
|
@UiThread |
|
|
|
protected void onTurtleModeRetrieved(boolean turtleModeEnabled) { |
|
|
|
protected void onTurtleModeRetrieved(boolean turtleModeEnabled) { |
|
|
|
turleModeEnabled = turtleModeEnabled; |
|
|
|
this.turtleModeEnabled = turtleModeEnabled; |
|
|
|
invalidateOptionsMenu(); |
|
|
|
invalidateOptionsMenu(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|