Browse Source

Filter list dialog added. (Thanks Tom Briden\!)

pull/11/head
Eric Kok 12 years ago
parent
commit
783f370fd4
  1. 14
      android/res/layout/dialog_set_filter.xml
  2. 6
      android/res/values/strings.xml
  3. 54
      android/src/org/transdroid/gui/TorrentsFragment.java

14
android/res/layout/dialog_set_filter.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/filter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>

6
android/res/values/strings.xml

@ -19,6 +19,8 @@
<string name="torrent_server">Torrent server</string> <string name="torrent_server">Torrent server</string>
<string name="no_servers">No servers have been configured yet</string> <string name="no_servers">No servers have been configured yet</string>
<string name="reset">Reset</string>
<string name="labels_showall">All labels</string> <string name="labels_showall">All labels</string>
<string name="labels_unlabeled">Unlabeled</string> <string name="labels_unlabeled">Unlabeled</string>
<string name="labels_newlabel">New label</string> <string name="labels_newlabel">New label</string>
@ -42,7 +44,7 @@
<string name="menu_forall_stop">Stop all</string> <string name="menu_forall_stop">Stop all</string>
<string name="menu_forall_start">Start all</string> <string name="menu_forall_start">Start all</string>
<string name="menu_filter">Filter list</string> <string name="menu_filter">Filter list</string>
<string name="menu_sort_reverse">Sort by (resort to reverse order)</string> <string name="menu_sort">Sort list</string><string name="menu_sort_reverse">Sort by (resort to reverse order)</string>
<string name="menu_sort_alpha">Name</string> <string name="menu_sort_alpha">Name</string>
<string name="menu_sort_status">Status</string> <string name="menu_sort_status">Status</string>
<string name="menu_sort_done">Date done</string> <string name="menu_sort_done">Date done</string>
@ -63,6 +65,7 @@
<string name="menu_forcestart">Force start</string> <string name="menu_forcestart">Force start</string>
<string name="menu_setlabel">Set label</string> <string name="menu_setlabel">Set label</string>
<string name="menu_setdownloadlocation">Set download location</string> <string name="menu_setdownloadlocation">Set download location</string>
<string name="menu_setfilter">Set list filter</string>
<string name="menu_set_default">Set as default</string> <string name="menu_set_default">Set as default</string>
<string name="menu_default_site_set_to">Default site set to</string> <string name="menu_default_site_set_to">Default site set to</string>
<string name="menu_moveup">Move up</string> <string name="menu_moveup">Move up</string>
@ -418,4 +421,5 @@
<item>Black</item> <item>Black</item>
<item>Transparent</item> <item>Transparent</item>
</string-array> </string-array>
</resources> </resources>

54
android/src/org/transdroid/gui/TorrentsFragment.java

@ -142,6 +142,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
private static final int DIALOG_SETDOWNLOADLOCATION = 6; private static final int DIALOG_SETDOWNLOADLOCATION = 6;
private static final int DIALOG_REFRESH_INTERVAL = 7; private static final int DIALOG_REFRESH_INTERVAL = 7;
private static final int DIALOG_INSTALLBARCODESCANNER = 8; private static final int DIALOG_INSTALLBARCODESCANNER = 8;
private static final int DIALOG_FILTER = 9;
private static final int MENU_ADD_ID = 1; private static final int MENU_ADD_ID = 1;
private static final int MENU_BARCODE_ID = 2; private static final int MENU_BARCODE_ID = 2;
@ -183,6 +184,8 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
private static final int MENU_REMOVE_DATA_ID = 47; private static final int MENU_REMOVE_DATA_ID = 47;
private static final int MENU_SETLABEL_ID = 48; private static final int MENU_SETLABEL_ID = 48;
private static final int MENU_SETDOWNLOADLOCATION_ID = 49; private static final int MENU_SETDOWNLOADLOCATION_ID = 49;
private static final int MENU_FILTER_ID = 60;
protected boolean useTabletInterface; protected boolean useTabletInterface;
private Handler handler; private Handler handler;
@ -206,6 +209,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
private String activeLabel = null; private String activeLabel = null;
private boolean inAlternativeMode = false; // Whether the server is in alternative (speed) mode (i.e. Transmission's Turtle Mode) private boolean inAlternativeMode = false; // Whether the server is in alternative (speed) mode (i.e. Transmission's Turtle Mode)
protected boolean ignoreFirstListNavigation = true; protected boolean ignoreFirstListNavigation = true;
private String activeFilter = null;
private List<Torrent> allTorrents; private List<Torrent> allTorrents;
private List<Label> allLabels; private List<Label> allLabels;
@ -591,7 +595,10 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_RESUME_ID, 0, R.string.menu_forall_resume).setShortcut('5', 'u'); miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_RESUME_ID, 0, R.string.menu_forall_resume).setShortcut('5', 'u');
miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_STOP_ID, 0, R.string.menu_forall_stop).setShortcut('7', 't'); miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_STOP_ID, 0, R.string.menu_forall_stop).setShortcut('7', 't');
miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_START_ID, 0, R.string.menu_forall_start).setShortcut('8', 's'); miForAll.add(MENU_FORALL_GROUP_ID, MENU_FORALL_START_ID, 0, R.string.menu_forall_start).setShortcut('8', 's');
SubMenu miSort = menu.addSubMenu(MENU_SORT_GROUP_ID, MENU_SORT_ID, 0, R.string.menu_filter);
menu.add(0, MENU_FILTER_ID, 0, R.string.menu_filter);
SubMenu miSort = menu.addSubMenu(MENU_SORT_GROUP_ID, MENU_SORT_ID, 0, R.string.menu_sort);
miSort.setIcon(android.R.drawable.ic_menu_sort_alphabetically); miSort.setIcon(android.R.drawable.ic_menu_sort_alphabetically);
//miSort.setHeaderTitle(R.string.menu_sort_reverse); //miSort.setHeaderTitle(R.string.menu_sort_reverse);
miSort.add(MENU_SORT_GROUP_ID, MENU_SORT_ALPHA_ID, 0, R.string.menu_sort_alpha).setAlphabeticShortcut('1').setChecked(true); miSort.add(MENU_SORT_GROUP_ID, MENU_SORT_ALPHA_ID, 0, R.string.menu_sort_alpha).setAlphabeticShortcut('1').setChecked(true);
@ -626,6 +633,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
menu.findItem(MENU_BARCODE_ID).setEnabled(ok); menu.findItem(MENU_BARCODE_ID).setEnabled(ok);
menu.findItem(MENU_RSS_ID).setEnabled(ok); menu.findItem(MENU_RSS_ID).setEnabled(ok);
menu.findItem(MENU_FORALL_ID).setEnabled(ok); menu.findItem(MENU_FORALL_ID).setEnabled(ok);
menu.findItem(MENU_FILTER_ID).setEnabled(ok);
menu.findItem(MENU_SORT_ID).setEnabled(ok); menu.findItem(MENU_SORT_ID).setEnabled(ok);
if (ok) { if (ok) {
menu.findItem(MENU_ALTMODE_ID).setVisible(Daemon.supportsSetAlternativeMode(daemon.getType())); menu.findItem(MENU_ALTMODE_ID).setVisible(Daemon.supportsSetAlternativeMode(daemon.getType()));
@ -916,6 +924,11 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
ErrorLogSender.collectAndSendLog(getActivity(), daemon, allDaemonSettings.get(lastUsedDaemonSettings)); ErrorLogSender.collectAndSendLog(getActivity(), daemon, allDaemonSettings.get(lastUsedDaemonSettings));
break; break;
case MENU_FILTER_ID:
// Present a dialog that allows filtering the list
showDialog(DIALOG_FILTER);
break;
case MENU_SORT_ALPHA_ID: case MENU_SORT_ALPHA_ID:
@ -1195,6 +1208,31 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
case DIALOG_INSTALLBARCODESCANNER: case DIALOG_INSTALLBARCODESCANNER:
return ActivityUtil.buildInstallDialog(getActivity(), R.string.scanner_not_found, Transdroid.SCANNER_MARKET_URI); return ActivityUtil.buildInstallDialog(getActivity(), R.string.scanner_not_found, Transdroid.SCANNER_MARKET_URI);
case DIALOG_FILTER:
// Build a dialog that asks for a new download location for the torrent
final View setFilterLayout = getActivity().getLayoutInflater().inflate(R.layout.dialog_set_filter, null);
final EditText newFilter = (EditText) setFilterLayout.findViewById(R.id.filter);
if(activeFilter != null)
newFilter.setText(activeFilter);
AlertDialog.Builder setFilterDialog = new AlertDialog.Builder(getActivity());
setFilterDialog.setTitle(R.string.menu_setfilter);
setFilterDialog.setView(setFilterLayout);
setFilterDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
setFilter(newFilter.getText().toString());
}
});
setFilterDialog.setNegativeButton(android.R.string.cancel, null);
setFilterDialog.setNeutralButton(R.string.reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
setFilter("");
}
});
return setFilterDialog.create();
} }
return null; return null;
@ -1977,7 +2015,7 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
// Build a list of torrents that should be shown // Build a list of torrents that should be shown
List<Torrent> showTorrents = new ArrayList<Torrent>(); List<Torrent> showTorrents = new ArrayList<Torrent>();
for (Torrent torrent : allTorrents) { for (Torrent torrent : allTorrents) {
if (matchesLabel(torrent, useLabel, showAllLabelsText) && matchesStatus(torrent, activeMainView)) { if (matchesLabel(torrent, useLabel, showAllLabelsText) && matchesStatus(torrent, activeMainView) && matchesFilter(torrent, activeFilter)) {
showTorrents.add(torrent); showTorrents.add(torrent);
} }
} }
@ -2026,6 +2064,10 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
(matchViewType == MainViewType.OnlyActive && (isActivelySeeding || isActivelyDownloading))|| (matchViewType == MainViewType.OnlyActive && (isActivelySeeding || isActivelyDownloading))||
(matchViewType == MainViewType.OnlyInactive && !isActivelyDownloading && !isActivelySeeding)); (matchViewType == MainViewType.OnlyInactive && !isActivelyDownloading && !isActivelySeeding));
} }
private boolean matchesFilter(Torrent torrent, String matchSearchString) {
return ((matchSearchString == null? true : false) || (torrent.getName().toLowerCase().indexOf(matchSearchString.toLowerCase()) > -1));
}
private void setProgressBar(boolean b) { private void setProgressBar(boolean b) {
inProgress = b; inProgress = b;
@ -2055,6 +2097,14 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
getListView().setVisibility(View.VISIBLE); getListView().setVisibility(View.VISIBLE);
} }
} }
public void setFilter(String search_text){
if(search_text.equals(""))
activeFilter = null;
else
activeFilter = search_text.trim();
updateTorrentsView(true);
}
public void showDialog(int id) { public void showDialog(int id) {
new DialogWrapper(onCreateDialog(id)).show(getSupportActivity().getSupportFragmentManager(), DialogWrapper.TAG + id); new DialogWrapper(onCreateDialog(id)).show(getSupportActivity().getSupportFragmentManager(), DialogWrapper.TAG + id);

Loading…
Cancel
Save