Browse Source

Allow filtering (with text entry) on torrents list.\nUpgraded to Eclipse ADT tools v22.

pull/11/head
Eric Kok 12 years ago
parent
commit
865385ec78
  1. 1
      android/.classpath
  2. 4
      android/src/org/transdroid/gui/TorrentsFragment.java
  3. 3
      core/.classpath
  4. 39
      core/src/org/transdroid/core/gui/FilterEntryDialog.java
  5. 19
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 62
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  7. 4
      core/src/org/transdroid/core/gui/search/UrlEntryDialog.java
  8. 3
      external/ColorPickerPreference/.classpath
  9. 3
      external/Crouton/library/.classpath
  10. 1
      external/JakeWharton-ActionBarSherlock/library/.classpath
  11. 3
      full/.classpath
  12. 3
      lite/.classpath

1
android/.classpath

@ -5,5 +5,6 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/Transdroid Torrent Connect"/> <classpathentry combineaccessrules="false" exported="true" kind="src" path="/Transdroid Torrent Connect"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

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

@ -1749,7 +1749,7 @@ public class TorrentsFragment extends SherlockFragment implements IDaemonCallbac
// Sort the new list of torrents // Sort the new list of torrents
allTorrents = ((RetrieveTaskSuccessResult) result).getTorrents(); allTorrents = ((RetrieveTaskSuccessResult) result).getTorrents();
Collections.sort(allTorrents, new TorrentsComparator(daemon, sortSetting, sortReversed)); Collections.sort(allTorrents, new TorrentsComparator(daemon.getType(), sortSetting, sortReversed));
// Sort the new list of labels // Sort the new list of labels
allLabels = ((RetrieveTaskSuccessResult) result).getLabels(); allLabels = ((RetrieveTaskSuccessResult) result).getLabels();
@ -1936,7 +1936,7 @@ public class TorrentsFragment extends SherlockFragment implements IDaemonCallbac
if (!(getTorrentListAdapter() == null || getTorrentListAdapter().getCount() == 0)) { if (!(getTorrentListAdapter() == null || getTorrentListAdapter().getCount() == 0)) {
// Sort the shown list of torrents using the new sortBy criteria // Sort the shown list of torrents using the new sortBy criteria
Collections.sort(allTorrents, new TorrentsComparator(daemon, sortSetting, sortReversed)); Collections.sort(allTorrents, new TorrentsComparator(daemon.getType(), sortSetting, sortReversed));
updateTorrentsView(true); updateTorrentsView(true);
} }

3
core/.classpath

@ -3,12 +3,13 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path=".apt_generated"> <classpathentry kind="src" path=".apt_generated">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/Transdroid Torrent Connect"/> <classpathentry combineaccessrules="false" exported="true" kind="src" path="/Transdroid Torrent Connect"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

39
core/src/org/transdroid/core/gui/FilterEntryDialog.java

@ -0,0 +1,39 @@
package org.transdroid.core.gui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.DialogFragment;
import android.text.InputType;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
public class FilterEntryDialog {
/**
* Opens a dialog that allows entry of a filter string, which (on confirmation) will be used to filter the list of
* torrents.
* @param activity The activity that opens (and owns) this dialog
*/
public static void startFilterEntry(final TorrentsActivity activity) {
new DialogFragment() {
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
final EditText filterInput = new EditText(activity);
filterInput.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return new AlertDialog.Builder(activity).setView(filterInput)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String filterText = filterInput.getText().toString();
if (activity != null)
activity.filterTorrents(filterText);
}
}).setNegativeButton(android.R.string.cancel, null).create();
};
}.show(activity.getSupportFragmentManager(), "filterentry");
}
}

19
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -307,7 +307,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Status type or label selection - both of which are navigation filters // Status type or label selection - both of which are navigation filters
if (item instanceof NavigationFilter) { if (item instanceof NavigationFilter) {
currentFilter = (NavigationFilter) item; currentFilter = (NavigationFilter) item;
fragmentTorrents.applyFilter(currentFilter); fragmentTorrents.applyNavigationFilter(currentFilter);
navigationSpinnerAdapter.updateCurrentFilter(currentFilter); navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
// Clear the details view // Clear the details view
if (fragmentDetails != null) { if (fragmentDetails != null) {
@ -444,10 +444,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
updateTurtleMode(false); updateTurtleMode(false);
} }
@OptionsItem(resName = "action_filter")
protected void filterList() {
}
@OptionsItem(resName = "action_settings") @OptionsItem(resName = "action_settings")
protected void openSettings() { protected void openSettings() {
MainSettingsActivity_.intent(this).start(); MainSettingsActivity_.intent(this).start();
@ -488,6 +484,19 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
fragmentTorrents.sortBy(TorrentsSortBy.Ratio); fragmentTorrents.sortBy(TorrentsSortBy.Ratio);
} }
@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);
}
/** /**
* Shows the a details fragment for the given torrent, either in the dedicated details fragment pane, in the same * 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. * pane as the torrent list was displayed or by starting a details activity.

62
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -2,7 +2,9 @@ package org.transdroid.core.gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.Bean;
@ -40,12 +42,14 @@ public class TorrentsFragment extends SherlockFragment {
@InstanceState @InstanceState
protected ArrayList<Torrent> torrents = null; protected ArrayList<Torrent> torrents = null;
@InstanceState @InstanceState
protected NavigationFilter currentFilter = null; protected NavigationFilter currentNavigationFilter = null;
@InstanceState @InstanceState
protected TorrentsSortBy currentSortOrder = TorrentsSortBy.Alphanumeric; protected TorrentsSortBy currentSortOrder = TorrentsSortBy.Alphanumeric;
@InstanceState @InstanceState
protected boolean currentSortDescending = false; protected boolean currentSortDescending = false;
@InstanceState @InstanceState
protected String currentTextFilter = null;
@InstanceState
protected boolean hasAConnection = false; protected boolean hasAConnection = false;
@InstanceState @InstanceState
protected boolean isLoading = true; protected boolean isLoading = true;
@ -80,7 +84,7 @@ public class TorrentsFragment extends SherlockFragment {
*/ */
public void updateTorrents(ArrayList<Torrent> newTorrents) { public void updateTorrents(ArrayList<Torrent> newTorrents) {
torrents = newTorrents; torrents = newTorrents;
applyFilter(null); // Resets the filter and shown list of torrents applyNavigationFilter(null); // Resets the filter and shown list of torrents
} }
/** /**
@ -88,7 +92,9 @@ public class TorrentsFragment extends SherlockFragment {
*/ */
public void clear() { public void clear() {
this.connectionErrorMessage = null; this.connectionErrorMessage = null;
updateTorrents(null); this.currentTextFilter = null;
this.currentNavigationFilter = null;
applyAllFilters();
} }
/** /**
@ -111,27 +117,51 @@ public class TorrentsFragment extends SherlockFragment {
Collections.sort(this.torrents, new TorrentsComparator(serverType, this.currentSortOrder, Collections.sort(this.torrents, new TorrentsComparator(serverType, this.currentSortOrder,
this.currentSortDescending)); this.currentSortDescending));
// Show the new resorted list // Show the new resorted list
applyFilter(this.currentFilter); applyAllFilters();
}
public void applyTextFilter(String newTextFilter) {
this.currentTextFilter = newTextFilter;
// TODO: Actually apply text filter
// Show the new filtered list
applyAllFilters();
} }
/** /**
* Apply a filter on the current list of all torrents, showing the appropriate sublist of torrents only * Apply a filter on the current list of all torrents, showing the appropriate sublist of torrents only
* @param newFilter The new filter to apply to the local list of torrents * @param newFilter The new filter to apply to the local list of torrents
*/ */
public void applyFilter(NavigationFilter newFilter) { public void applyNavigationFilter(NavigationFilter newFilter) {
this.currentFilter = newFilter; this.currentNavigationFilter = newFilter;
if (torrents != null && newFilter != null) { applyAllFilters();
// Build a local list of torrents that match the selected navigation filter }
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>();
for (Torrent torrent : torrents) { private void applyAllFilters() {
if (newFilter.matches(torrent))
filteredTorrents.add(torrent); // No torrents? Directly update views accordingly
if (torrents == null) {
updateViewVisibility();
return;
}
// Filter the list of torrents to show according to navigation and text filters
ArrayList<Torrent> filteredTorrents = torrents;
if (torrents != null && currentNavigationFilter != null) {
// Remove torrents that do not match the selected navigation filter
for (Iterator<Torrent> torrentIter = torrents.iterator(); torrentIter.hasNext();) {
if (!currentNavigationFilter.matches(torrentIter.next()))
torrentIter.remove();
} }
((TorrentsAdapter) torrentsList.getAdapter()).update(filteredTorrents);
} else if (torrents != null) {
// No need to filter any torrents; directly show the full list
((TorrentsAdapter) torrentsList.getAdapter()).update(torrents);
} }
if (torrents != null && currentTextFilter != null) {
// Remove torrent that do not contain the text filter string
for (Iterator<Torrent> torrentIter = torrents.iterator(); torrentIter.hasNext();) {
if (!torrentIter.next().getName().toLowerCase(Locale.getDefault())
.contains(currentTextFilter.toLowerCase(Locale.getDefault())))
torrentIter.remove();
}
}
((TorrentsAdapter) torrentsList.getAdapter()).update(filteredTorrents);
updateViewVisibility(); updateViewVisibility();
} }

4
core/src/org/transdroid/core/gui/search/UrlEntryDialog.java

@ -3,11 +3,13 @@ package org.transdroid.core.gui.search;
import org.transdroid.core.gui.TorrentsActivity; import org.transdroid.core.gui.TorrentsActivity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
public class UrlEntryDialog { public class UrlEntryDialog {
@ -22,6 +24,8 @@ public class UrlEntryDialog {
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
final EditText urlInput = new EditText(activity); final EditText urlInput = new EditText(activity);
urlInput.setInputType(InputType.TYPE_TEXT_VARIATION_URI); urlInput.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return new AlertDialog.Builder(activity).setView(urlInput) return new AlertDialog.Builder(activity).setView(urlInput)
.setPositiveButton(android.R.string.ok, new OnClickListener() { .setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override @Override

3
external/ColorPickerPreference/.classpath vendored

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

3
external/Crouton/library/.classpath vendored

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

1
external/JakeWharton-ActionBarSherlock/library/.classpath vendored

@ -4,5 +4,6 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

3
full/.classpath

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

3
lite/.classpath

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

Loading…
Cancel
Save