Browse Source

Details screen working.

material
Eric Kok 10 years ago
parent
commit
1cf19c9a31
  1. 19
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  2. 115
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  3. 44
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 11
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  5. 4
      app/src/main/java/org/transdroid/core/gui/navigation/RefreshableActivity.java
  6. 2
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java
  7. 6
      app/src/main/res/layout/activity_details.xml
  8. 1
      app/src/main/res/layout/activity_torrents.xml
  9. 31
      app/src/main/res/layout/fragment_details.xml
  10. 14
      app/src/main/res/menu/fragment_details.xml
  11. 2
      app/src/main/res/values/strings.xml

19
app/src/main/java/org/transdroid/core/gui/DetailsActivity.java

@ -20,7 +20,6 @@ import android.annotation.TargetApi;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.widget.Toast; import android.widget.Toast;
@ -107,7 +106,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx
// Details view components // Details view components
@ViewById @ViewById
protected Toolbar torrentsToolbar; protected Toolbar selectionToolbar;
@FragmentById(R.id.torrentdetails_fragment) @FragmentById(R.id.torrentdetails_fragment)
protected DetailsFragment fragmentDetails; protected DetailsFragment fragmentDetails;
@ -130,7 +129,7 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx
} }
// Simple action bar with up, torrent name as title and refresh button // Simple action bar with up, torrent name as title and refresh button
setSupportActionBar(torrentsToolbar); setSupportActionBar(selectionToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName()));
@ -157,20 +156,6 @@ public class DetailsActivity extends ActionBarActivity implements TorrentTasksEx
TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
} }
/**
* 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() {
fragmentDetails.updateIsLoading(true, null); fragmentDetails.updateIsLoading(true, null);

115
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -24,6 +24,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.ActionMenuView;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -39,7 +40,6 @@ import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick; import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
@ -76,7 +76,6 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
* @author Eric Kok * @author Eric Kok
*/ */
@EFragment(R.layout.fragment_details) @EFragment(R.layout.fragment_details)
@OptionsMenu(R.menu.fragment_details)
public class DetailsFragment extends Fragment implements OnTrackersUpdatedListener, OnLabelPickedListener, OnStorageLocationUpdatedListener { public class DetailsFragment extends Fragment implements OnTrackersUpdatedListener, OnLabelPickedListener, OnStorageLocationUpdatedListener {
// Local data // Local data
@ -99,6 +98,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
// Views // Views
@ViewById @ViewById
protected View detailsContainer; protected View detailsContainer;
@ViewById(R.id.details_menu)
protected ActionMenuView detailsMenu;
@ViewById @ViewById
protected SwipeRefreshLayout swipeRefreshLayout; protected SwipeRefreshLayout swipeRefreshLayout;
@ViewById @ViewById
@ -111,6 +112,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
@AfterViews @AfterViews
protected void init() { protected void init() {
// Inject menu options in the actions toolbar
setHasOptionsMenu(true);
// On large screens where this fragment is shown next to the torrents list, we show a continues grey vertical // On large screens where this fragment is shown next to the torrents list, we show a continues grey vertical
// line to separate the lists visually // line to separate the lists visually
if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) { if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) {
@ -121,13 +125,21 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
} }
} }
createMenuOptions();
// Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast // Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast
// scrolling // scrolling
detailsList.setAdapter(new DetailsAdapter(getActivity())); detailsList.setAdapter(new DetailsAdapter(getActivity()));
detailsList.setMultiChoiceModeListener(onDetailsSelected); detailsList.setMultiChoiceModeListener(onDetailsSelected);
detailsList.setFastScrollEnabled(true); detailsList.setFastScrollEnabled(true);
if (getActivity() != null && getActivity() instanceof RefreshableActivity) { if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).addSwipeRefreshLayout(swipeRefreshLayout); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
});
} }
// Restore the fragment state (on orientation changes et al.) // Restore the fragment state (on orientation changes et al.)
@ -162,7 +174,7 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
errorText.setVisibility(View.GONE); errorText.setVisibility(View.GONE);
loadingProgress.setVisibility(View.GONE); loadingProgress.setVisibility(View.GONE);
// Also update the available actions in the action bar // Also update the available actions in the action bar
getActivity().invalidateOptionsMenu(); updateMenuOptions();
// Refresh the detailed statistics (errors) and list of files // Refresh the detailed statistics (errors) and list of files
torrentDetails = null; torrentDetails = null;
torrentFiles = null; torrentFiles = null;
@ -252,7 +264,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
this.isLoadingTorrent = isLoading; this.isLoadingTorrent = isLoading;
this.hasCriticalError = connectionErrorMessage != null; this.hasCriticalError = connectionErrorMessage != null;
errorText.setText(connectionErrorMessage); errorText.setText(connectionErrorMessage);
swipeRefreshLayout.setRefreshing(isLoading);
if (isLoading || hasCriticalError) { if (isLoading || hasCriticalError) {
clear(); clear();
} }
@ -263,43 +274,89 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
detailsList.setItemChecked(position, false); detailsList.setItemChecked(position, false);
} }
public void createMenuOptions() {
getActivity().getMenuInflater().inflate(R.menu.fragment_details, detailsMenu.getMenu());
detailsMenu.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
@Override @Override
public void onPrepareOptionsMenu(Menu menu) { public boolean onMenuItemClick(MenuItem menuItem) {
super.onPrepareOptionsMenu(menu); switch (menuItem.getItemId()) {
case R.id.action_pause:
pauseTorrent();
return true;
case R.id.action_updatetrackers:
updateTrackers();
return true;
case R.id.action_start_forced:
startTorrentForced();
return true;
case R.id.action_remove_withdata:
removeTorrentWithData();
return true;
case R.id.action_stop:
stopTorrent();
return true;
case R.id.action_forcerecheck:
setForceRecheck();
return true;
case R.id.action_changelocation:
changeStorageLocation();
return true;
case R.id.action_start_default:
startTorrentDefault();
return true;
case R.id.action_remove_default:
removeTorrentDefault();
return true;
case R.id.action_start_direct:
startTorrentDirect();
return true;
case R.id.action_setlabel:
setLabel();
return true;
case R.id.action_resume:
resumeTorrent();
return true;
}
return false;
}
});
}
private void updateMenuOptions() {
if (torrent == null) { if (torrent == null) {
menu.findItem(R.id.action_resume).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_resume).setVisible(false);
menu.findItem(R.id.action_pause).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_pause).setVisible(false);
menu.findItem(R.id.action_start).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_start).setVisible(false);
menu.findItem(R.id.action_start_direct).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_start_direct).setVisible(false);
menu.findItem(R.id.action_stop).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_stop).setVisible(false);
menu.findItem(R.id.action_remove).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_remove).setVisible(false);
menu.findItem(R.id.action_remove_withdata).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_remove_withdata).setVisible(false);
menu.findItem(R.id.action_setlabel).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_setlabel).setVisible(false);
menu.findItem(R.id.action_forcerecheck).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_forcerecheck).setVisible(false);
menu.findItem(R.id.action_updatetrackers).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_updatetrackers).setVisible(false);
menu.findItem(R.id.action_changelocation).setVisible(false); detailsMenu.getMenu().findItem(R.id.action_changelocation).setVisible(false);
return; return;
} }
// Update action availability // Update action availability
boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon()); boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon());
menu.findItem(R.id.action_resume).setVisible(torrent.canResume()); detailsMenu.getMenu().findItem(R.id.action_resume).setVisible(torrent.canResume());
menu.findItem(R.id.action_pause).setVisible(torrent.canPause()); detailsMenu.getMenu().findItem(R.id.action_pause).setVisible(torrent.canPause());
boolean forcedStart = Daemon.supportsForcedStarting(torrent.getDaemon()); boolean forcedStart = Daemon.supportsForcedStarting(torrent.getDaemon());
menu.findItem(R.id.action_start).setVisible(startStop && forcedStart && torrent.canStart()); detailsMenu.getMenu().findItem(R.id.action_start).setVisible(startStop && forcedStart && torrent.canStart());
menu.findItem(R.id.action_start_direct).setVisible(startStop && !forcedStart && torrent.canStart()); detailsMenu.getMenu().findItem(R.id.action_start_direct).setVisible(startStop && !forcedStart && torrent.canStart());
menu.findItem(R.id.action_stop).setVisible(startStop && torrent.canStop()); detailsMenu.getMenu().findItem(R.id.action_stop).setVisible(startStop && torrent.canStop());
menu.findItem(R.id.action_remove).setVisible(true); detailsMenu.getMenu().findItem(R.id.action_remove).setVisible(true);
boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon()); boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon());
menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData); detailsMenu.getMenu().findItem(R.id.action_remove_withdata).setVisible(removeWithData);
boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon()); boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon());
menu.findItem(R.id.action_setlabel).setVisible(setLabel); detailsMenu.getMenu().findItem(R.id.action_setlabel).setVisible(setLabel);
boolean forceRecheck = Daemon.supportsForceRecheck(torrent.getDaemon()); boolean forceRecheck = Daemon.supportsForceRecheck(torrent.getDaemon());
menu.findItem(R.id.action_forcerecheck).setVisible(forceRecheck); detailsMenu.getMenu().findItem(R.id.action_forcerecheck).setVisible(forceRecheck);
boolean setTrackers = Daemon.supportsSetTrackers(torrent.getDaemon()); boolean setTrackers = Daemon.supportsSetTrackers(torrent.getDaemon());
menu.findItem(R.id.action_updatetrackers).setVisible(setTrackers); detailsMenu.getMenu().findItem(R.id.action_updatetrackers).setVisible(setTrackers);
boolean setLocation = Daemon.supportsSetDownloadLocation(torrent.getDaemon()); boolean setLocation = Daemon.supportsSetDownloadLocation(torrent.getDaemon());
menu.findItem(R.id.action_changelocation).setVisible(setLocation); detailsMenu.getMenu().findItem(R.id.action_changelocation).setVisible(setLocation);
} }

44
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -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();
} }

11
app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java

@ -121,7 +121,13 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
} }
// Allow pulls on the list view to refresh the torrents // Allow pulls on the list view to refresh the torrents
if (getActivity() != null && getActivity() instanceof RefreshableActivity) { if (getActivity() != null && getActivity() instanceof RefreshableActivity) {
((RefreshableActivity) getActivity()).addSwipeRefreshLayout(swipeRefreshLayout); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
((RefreshableActivity) getActivity()).refreshScreen();
swipeRefreshLayout.setRefreshing(false); // Use our custom indicator
}
});
} }
nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name))); nosettingsText.setText(getString(R.string.navigation_nosettings, getString(R.string.app_name)));
@ -393,6 +399,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
loadingProgress.setVisibility(View.GONE); loadingProgress.setVisibility(View.GONE);
errorText.setVisibility(View.GONE); errorText.setVisibility(View.GONE);
nosettingsText.setVisibility(View.VISIBLE); nosettingsText.setVisibility(View.VISIBLE);
swipeRefreshLayout.setEnabled(false);
clear(true, true); // Indirectly also calls updateViewVisibility() clear(true, true); // Indirectly also calls updateViewVisibility()
} else { } else {
updateViewVisibility(); updateViewVisibility();
@ -405,7 +412,6 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
*/ */
public void updateIsLoading(boolean isLoading) { public void updateIsLoading(boolean isLoading) {
this.isLoading = isLoading; this.isLoading = isLoading;
swipeRefreshLayout.setRefreshing(isLoading);
if (isLoading) { if (isLoading) {
clear(true, false); // Indirectly also calls updateViewVisibility() clear(true, false); // Indirectly also calls updateViewVisibility()
} else { } else {
@ -438,6 +444,7 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener
torrentsList.setVisibility(!hasError && !isLoading && !isEmpty ? View.VISIBLE : View.GONE); torrentsList.setVisibility(!hasError && !isLoading && !isEmpty ? View.VISIBLE : View.GONE);
loadingProgress.setVisibility(!hasError && isLoading ? View.VISIBLE : View.GONE); loadingProgress.setVisibility(!hasError && isLoading ? View.VISIBLE : View.GONE);
emptyText.setVisibility(!hasError && !isLoading && isEmpty ? View.VISIBLE : View.GONE); emptyText.setVisibility(!hasError && !isLoading && isEmpty ? View.VISIBLE : View.GONE);
swipeRefreshLayout.setEnabled(true);
} }
/** /**

4
app/src/main/java/org/transdroid/core/gui/navigation/RefreshableActivity.java

@ -16,8 +16,6 @@
*/ */
package org.transdroid.core.gui.navigation; package org.transdroid.core.gui.navigation;
import android.support.v4.widget.SwipeRefreshLayout;
/** /**
* Interface to be implemented by any activity that allows its content to be refreshed; fragments can ask for user-initiated refreshes. * Interface to be implemented by any activity that allows its content to be refreshed; fragments can ask for user-initiated refreshes.
* @author Eric Kok * @author Eric Kok
@ -26,6 +24,4 @@ public interface RefreshableActivity {
void refreshScreen(); void refreshScreen();
void addSwipeRefreshLayout(SwipeRefreshLayout container);
} }

2
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsFragment.java

@ -68,7 +68,7 @@ public class RssfeedsFragment extends Fragment {
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
boolean hasFeeds = rssfeedsAdapter != null && rssfeedsAdapter.getCount() > 0; boolean hasFeeds = rssfeedsAdapter != null && rssfeedsAdapter.getCount() > 0;
menu.findItem(R.id.action_refresh).setShowAsAction(hasFeeds ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); menu.findItem(R.id.action_refresh).setVisible(hasFeeds);
menu.findItem(R.id.action_settings).setShowAsAction(!hasFeeds ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); menu.findItem(R.id.action_settings).setShowAsAction(!hasFeeds ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
} }

6
app/src/main/res/layout/activity_details.xml

@ -7,7 +7,7 @@
tools:context=".DetailsActivity"> tools:context=".DetailsActivity">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/torrents_toolbar" android:id="@+id/selection_toolbar"
style="@style/DefaultToolbar" style="@style/DefaultToolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -18,11 +18,11 @@
class="org.transdroid.core.gui.DetailsFragment_" class="org.transdroid.core.gui.DetailsFragment_"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/torrents_toolbar" android:layout_below="@id/selection_toolbar"
tools:layout="@layout/fragment_details" /> tools:layout="@layout/fragment_details" />
<View <View
style="@style/DefaultToolbarShadow" style="@style/DefaultToolbarShadow"
android:layout_below="@id/torrents_toolbar" /> android:layout_below="@id/selection_toolbar" />
</RelativeLayout> </RelativeLayout>

1
app/src/main/res/layout/activity_torrents.xml

@ -81,6 +81,7 @@
<!-- The navigation drawer --> <!-- The navigation drawer -->
<LinearLayout <LinearLayout
android:id="@+id/drawer_container"
android:layout_width="@dimen/ui_filters_list" android:layout_width="@dimen/ui_filters_list"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_gravity="start"

31
app/src/main/res/layout/fragment_details.xml

@ -15,16 +15,27 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>. along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
--> -->
<FrameLayout <RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/details_container" android:id="@+id/details_container"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
tools:context=".core.gui.DetailsActivity_">
<android.support.v7.widget.ActionMenuView
android:id="@+id/details_menu"
style="@style/SplitToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="?attr/actionBarSize" />
<android.support.v4.widget.SwipeRefreshLayout <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout" android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:layout_above="@id/details_menu">
<ListView <ListView
android:id="@+id/details_list" android:id="@+id/details_list"
@ -42,6 +53,7 @@
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_above="@id/details_menu"
android:indeterminate="true" android:indeterminate="true"
android:indeterminateDrawable="?attr/loading_progress" android:indeterminateDrawable="?attr/loading_progress"
android:indeterminateOnly="true" android:indeterminateOnly="true"
@ -51,7 +63,7 @@
android:id="@+id/empty_text" android:id="@+id/empty_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_centerInParent="true"
android:drawablePadding="8dip" android:drawablePadding="8dip"
android:drawableTop="?attr/loading_progress" android:drawableTop="?attr/loading_progress"
android:gravity="center" android:gravity="center"
@ -64,13 +76,18 @@
android:id="@+id/error_text" android:id="@+id/error_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_centerInParent="true"
android:drawablePadding="8dip" android:drawablePadding="8dip"
android:drawableTop="?attr/loading_progress" android:drawableTop="?attr/loading_progress"
android:gravity="center" android:gravity="center"
android:maxWidth="400dip" android:maxWidth="400dip"
android:padding="@dimen/margin_default" android:padding="@dimen/margin_default"
android:textIsSelectable="false" android:textIsSelectable="false"
android:visibility="gone" /> android:visibility="gone"
tools:visibility="visible"/>
<View
style="@style/SplitToolbarShadow"
android:layout_above="@id/details_menu" />
</FrameLayout> </RelativeLayout>

14
app/src/main/res/menu/fragment_details.xml

@ -34,7 +34,7 @@
android:icon="@drawable/ic_action_start" android:icon="@drawable/ic_action_start"
android:orderInCategory="202" android:orderInCategory="202"
android:title="@string/action_start" android:title="@string/action_start"
app:showAsAction="ifRoom"> app:showAsAction="always">
<menu> <menu>
<item <item
android:id="@+id/action_start_default" android:id="@+id/action_start_default"
@ -49,13 +49,13 @@
android:icon="@drawable/ic_action_start" android:icon="@drawable/ic_action_start"
android:orderInCategory="202" android:orderInCategory="202"
android:title="@string/action_start" android:title="@string/action_start"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_stop" android:id="@+id/action_stop"
android:icon="@drawable/ic_action_stop" android:icon="@drawable/ic_action_stop"
android:orderInCategory="203" android:orderInCategory="203"
android:title="@string/action_stop" android:title="@string/action_stop"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_remove" android:id="@+id/action_remove"
android:icon="@drawable/ic_action_remove" android:icon="@drawable/ic_action_remove"
@ -76,24 +76,24 @@
android:icon="@drawable/ic_action_labels" android:icon="@drawable/ic_action_labels"
android:orderInCategory="205" android:orderInCategory="205"
android:title="@string/action_setlabel" android:title="@string/action_setlabel"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_forcerecheck" android:id="@+id/action_forcerecheck"
android:icon="@drawable/ic_action_force_recheck" android:icon="@drawable/ic_action_force_recheck"
android:orderInCategory="206" android:orderInCategory="206"
android:title="@string/action_forcerecheck" android:title="@string/action_forcerecheck"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_updatetrackers" android:id="@+id/action_updatetrackers"
android:icon="@drawable/ic_action_trackers" android:icon="@drawable/ic_action_trackers"
android:orderInCategory="207" android:orderInCategory="207"
android:title="@string/action_updatetrackers" android:title="@string/action_updatetrackers"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
<item <item
android:id="@+id/action_changelocation" android:id="@+id/action_changelocation"
android:icon="@drawable/ic_action_save" android:icon="@drawable/ic_action_save"
android:orderInCategory="208" android:orderInCategory="208"
android:title="@string/action_changelocation" android:title="@string/action_changelocation"
app:showAsAction="ifRoom" /> app:showAsAction="always" />
</menu> </menu>

2
app/src/main/res/values/strings.xml

@ -368,6 +368,7 @@
<item>Buffalo NAS -1.31</item> <item>Buffalo NAS -1.31</item>
<item>Deluge 1.2+</item> <item>Deluge 1.2+</item>
<item>DLink Router BT</item> <item>DLink Router BT</item>
<item>Dummy</item>
<item>Ktorrent</item> <item>Ktorrent</item>
<item>qBittorrent</item> <item>qBittorrent</item>
<item>rTorrent</item> <item>rTorrent</item>
@ -385,6 +386,7 @@
<item>daemon_buffalonas</item> <item>daemon_buffalonas</item>
<item>daemon_deluge</item> <item>daemon_deluge</item>
<item>daemon_dlinkrouterbt</item> <item>daemon_dlinkrouterbt</item>
<item>daemon_dummy</item>
<item>daemon_ktorrent</item> <item>daemon_ktorrent</item>
<item>daemon_qbittorrent</item> <item>daemon_qbittorrent</item>
<item>daemon_rtorrent</item> <item>daemon_rtorrent</item>

Loading…
Cancel
Save