Skip to content

Commit

Permalink
Add count of search results
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejenny committed Sep 30, 2014
1 parent 37cb725 commit e8a8303
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/assets/locales/messages_ccodk_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ demo.mode.warning=You are logging into CommCare in Demo mode. Demo mode is for t
demo.mode.warning.dismiss=I Understand

select.search.label=Search:
select.search.empty=No results for your search: "${0}"
select.search.empty=${0} of ${1} results for your search: "${2}"
select.detail.confirm=Select

mult.install.no.browser=There is no File Browsing application installed on this device! Please download one and try again.
Expand Down
15 changes: 11 additions & 4 deletions app/src/org/commcare/android/adapters/EntityListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,24 @@ public boolean isEnabled(int position) {
* @see android.widget.Adapter#getCount()
*/
public int getCount() {
return getCount(false);
return getCount(false, false);
}

/*
* Returns total number of items, ignoring any filter.
*/
public int getFullCount() {
return getCount(false, true);
}

/*
* Get number of items, with a parameter to decide whether or not action counts as an item.
*/
public int getCount(boolean ignoreAction) {
public int getCount(boolean ignoreAction, boolean fullCount) {
//Always one extra element if the action is defined
return current.size() + (actionEnabled && !ignoreAction ? 1 : 0);
return (fullCount ? full.size() : current.size()) + (actionEnabled && !ignoreAction ? 1 : 0);
}

/* (non-Javadoc)
* @see android.widget.Adapter#getItem(int)
*/
Expand Down
14 changes: 12 additions & 2 deletions app/src/org/commcare/dalvik/activities/EntitySelectActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,18 @@ public void afterTextChanged(Editable s) {
filterString = s.toString();
if(adapter != null) {
adapter.applyFilter(filterString);
noSearchResults.setText(Localization.get("select.search.empty", new String[] {searchbox.getText().toString()}));
noSearchResults.setVisibility(adapter.getCount() == 0 ? View.VISIBLE : View.GONE);
String query = searchbox.getText().toString();
if (!"".equals(query)) {
noSearchResults.setText(Localization.get("select.search.empty", new String[] {
""+adapter.getCount(),
""+adapter.getFullCount(),
query
}));
noSearchResults.setVisibility(View.VISIBLE);
}
else {
noSearchResults.setVisibility(View.GONE);
}
}
}
}
Expand Down

0 comments on commit e8a8303

Please sign in to comment.