Skip to content

Commit

Permalink
[TIMOB-19200] Android: implement 'noresults' event on ListView
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashraf committed Jul 29, 2015
1 parent 67c708a commit 93932e3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ public boolean isFilterOn() {
return false;
}

public void applyFilter(String searchText) {
public int applyFilter(String searchText) {
//Clear previous result
filterIndices.clear();
boolean caseInsensitive = getListView().getCaseInsensitive();
Expand All @@ -958,6 +958,7 @@ public void applyFilter(String searchText) {
filterIndices.add(i);
}
}
return filterIndices.size();
}

public void release() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,16 @@ private void setHeaderOrFooterView (Object viewObj, boolean isHeader) {
}

private void reFilter(String searchText) {
int numResults = 0;
if (searchText != null) {
for (int i = 0; i < sections.size(); ++i) {
ListSectionProxy section = sections.get(i);
section.applyFilter(searchText);
numResults += section.applyFilter(searchText);
}
}
if (numResults == 0) {
fireEvent(TiC.EVENT_NO_RESULTS, null);
}
if (adapter != null) {
adapter.notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public void reIndexItems() {
index.add(i);
}
}
if (index.size() == 0) {
proxy.fireEvent(TiC.EVENT_NO_RESULTS, null);
}
}

public int getCount() {
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public class TiC
*/
public static final String EVENT_NEW_INTENT = "newintent";

/**
* @module.api
*/
public static final String EVENT_NO_RESULTS = "noresults";

/**
* @module.api
*/
Expand Down
7 changes: 5 additions & 2 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,11 @@ events:
While the `searchView` API automatically shows a **No Results** cell in the list view, the `searchText` API does not do so.
Developers can listen to this event and perform appropriate actions when the search result set is empty.
platforms: [iphone, ipad]
since: "3.3.0"
platforms: [android, iphone, ipad]
since:
android: 4.2.0
iphone: 3.3.0
ipad: 3.3.0
properties:
- name: bubbles
summary: false. This event does not bubble.
Expand Down

0 comments on commit 93932e3

Please sign in to comment.