Commits

3k  committed 2901c0e

EntryBrowser: added number of results, better filtering

  • Participants
  • Parent commits 3ec69e2

Comments (0)

Files changed (4)

File assets/news/1.4.6.html

 &#8226; Unsupported KVTML files are now removed from recent's list<br />
+&#8226; Better entry browser<br />
 &#8226; Bugfixes

File res/layout/dialog_entry_browser.xml

 			android:layout_height="wrap_content"
 			android:hint="@string/hint_entry_filter"
 			android:inputType="textNoSuggestions" />
+
+		<TextView
+			android:id="@+id/text_results_num"
+			android:layout_width="match_parent"
+			android:layout_height="wrap_content"
+			android:layout_below="@id/text_filter"
+			android:layout_marginBottom="3dp"
+			android:layout_marginTop="3dp"
+			android:includeFontPadding="true"
+			android:visibility="gone" />
 	</RelativeLayout>
 
 	<ListView

File src/com/ekezet/vocabdrill/adapters/EntryListAdapter.java

 		protected void publishResults(CharSequence constraint, FilterResults results)
 		{
 			if (results.count == 0)
-				notifyDataSetInvalidated();
-			else
 			{
-				List<Kvtml.Entry> items = (ArrayList<Kvtml.Entry>) results.values;
-				mItems = items;
+				if (constraint != null && !constraint.toString().trim().equals(""))
+				{
+					mItems = new ArrayList<Kvtml.Entry>();
+					updateAlphaIndices(mItems);
+					notifyDataSetChanged();
+				} else
+					notifyDataSetInvalidated();
+			} else
+			{
+				mItems = (ArrayList<Kvtml.Entry>) results.values;
 				updateAlphaIndices(mItems);
 				notifyDataSetChanged();
 			}

File src/com/ekezet/vocabdrill/dialogs/EntryBrowserDialog.java

 import android.content.Intent;
 import android.os.Bundle;
 import android.text.Editable;
+import android.text.Html;
 import android.text.TextWatcher;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.View;
 import android.view.WindowManager.LayoutParams;
 import android.widget.EditText;
+import android.widget.Filter.FilterListener;
 import android.widget.ListView;
+import android.widget.TextView;
 import android.widget.Toast;
 
 import com.ekezet.vocabdrill.Config;
 
 	private String mDisplayLanguageId = "";
 	private EditText mEditTextFilter = null;
+	private TextView mResultsNumText = null;
 	private static EntryListAdapter sAdapter = null;
 	private String mFilterText = null;
+	private FilterListener mFilterListener;
 
 	/**
 	 * Sort entries alphabetically if True.
 		ListView list = (ListView) findViewById(android.R.id.list);
 		list.setTextFilterEnabled(true);
 
+		mResultsNumText = (TextView) findViewById(R.id.text_results_num);
+		mFilterListener = new FilterListener()
+		{
+			@Override
+			public void onFilterComplete(int count)
+			{
+				if (mFilterText != null)
+				{
+					int ct = sAdapter.getCount();
+					mResultsNumText.setText(Html.fromHtml(String.format("<b>Results: </b>%d", ct)));
+					mResultsNumText.setVisibility(View.VISIBLE);
+				} else
+					mResultsNumText.setVisibility(View.GONE);
+			}
+		};
+
 		mEditTextFilter = (EditText) findViewById(R.id.text_filter);
 		mEditTextFilter.addTextChangedListener(new TextWatcher()
 		{
 			@Override
 			public void onTextChanged(CharSequence s, int start, int before, int count)
 			{
-				if (s == null || s.length() == 0)
+				if (s == null || s.toString().trim().length() == 0)
 					mFilterText = null;
 				else
 					mFilterText = s.toString();
-				sAdapter.getFilter().filter(mFilterText);
+				sAdapter.getFilter().filter(mFilterText, mFilterListener);
 			}
 
 			@Override