Skip to content

Commit 9a64f3e

Browse files
symonbaikovparoj
authored andcommitted
Show "No matches" empty state when search returns no results
Previously SearchFragment.done() installed a SearchAdapter unconditionally, so an empty SearchResult produced a blank screen with no feedback. Detect the empty case and route through the existing setEmpty() helper, reusing the localized search.no_match string. Fixes #139
1 parent ea35de7 commit 9a64f3e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

app/src/main/java/github/paroj/dsub2000/fragments/SearchFragment.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.view.MenuItem;
2323
import android.net.Uri;
2424
import android.view.ViewGroup;
25+
import android.widget.TextView;
2526
import github.paroj.dsub2000.R;
2627
import github.paroj.dsub2000.adapter.ArtistAdapter;
2728
import github.paroj.dsub2000.adapter.EntryGridAdapter;
@@ -194,6 +195,7 @@ public void search(final String query, final boolean autoplay, final String arti
194195
return;
195196
}
196197
currentQuery = query;
198+
setEmpty(false);
197199

198200
BackgroundTask<SearchResult> task = new TabBackgroundTask<SearchResult>(this) {
199201
@Override
@@ -206,7 +208,14 @@ protected SearchResult doInBackground() throws Throwable {
206208
@Override
207209
protected void done(SearchResult result) {
208210
searchResult = result;
209-
recyclerView.setAdapter(adapter = new SearchAdapter(context, searchResult, getImageLoader(), largeAlbums, SearchFragment.this));
211+
if (result == null || (!result.hasArtists() && !result.hasAlbums() && !result.hasSongs())) {
212+
adapter = null;
213+
recyclerView.setAdapter(null);
214+
setEmpty(true);
215+
} else {
216+
setEmpty(false);
217+
recyclerView.setAdapter(adapter = new SearchAdapter(context, searchResult, getImageLoader(), largeAlbums, SearchFragment.this));
218+
}
210219
if (autoplay) {
211220
autoplay(query, artist, album, title);
212221
}
@@ -224,6 +233,18 @@ protected String getCurrentQuery() {
224233
return currentQuery;
225234
}
226235

236+
@Override
237+
public void setEmpty(boolean empty) {
238+
super.setEmpty(empty);
239+
240+
if (empty && rootView != null) {
241+
TextView text = (TextView) rootView.findViewById(R.id.tab_progress_message);
242+
if (text != null) {
243+
text.setText(R.string.search_no_match);
244+
}
245+
}
246+
}
247+
227248
private void onArtistSelected(Artist artist, boolean autoplay) {
228249
SubsonicFragment fragment = new SelectDirectoryFragment();
229250
Bundle args = new Bundle();

0 commit comments

Comments
 (0)