diff --git a/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java b/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java index d8c2c53f..d16151fa 100644 --- a/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java +++ b/app/src/main/java/org/transdroid/core/app/search/SearchHelper.java @@ -85,20 +85,18 @@ public class SearchHelper { // The installed Torrent Search version is corrupt or incompatible return null; } + List sites = new ArrayList<>(); if (cursor.moveToFirst()) { - List sites = new ArrayList(); do { // Read the cursor fields into the SearchSite object sites.add(new SearchSite(cursor.getInt(CURSOR_SITE_ID), cursor.getString(CURSOR_SITE_CODE), cursor .getString(CURSOR_SITE_NAME), cursor.getString(CURSOR_SITE_RSSURL), - cursor.getColumnNames().length > 4 ? (cursor.getInt(CURSOR_SITE_ISPRIVATE) == 1 ? true : false) - : false)); + cursor.getColumnNames().length > 4 && cursor.getInt(CURSOR_SITE_ISPRIVATE) == 1)); } while (cursor.moveToNext()); - cursor.close(); - return sites; } - return null; + cursor.close(); + return sites; } @@ -107,7 +105,7 @@ public class SearchHelper { * be called in a background thread. * @param query The search query to pass to the torrent site * @param site The site to search, as retrieved from the TorrentSitesProvider, or null if the Torrent Search package - * @param sortBy.name() The sort order to request from the torrent site, if supported + * @param sortBy The sort order to request from the torrent site, if supported * @return A list of torrent search results as POJOs, or null if the Torrent Search package is not installed or * there is no internet connection */ @@ -128,7 +126,7 @@ public class SearchHelper { return null; } if (cursor.moveToFirst()) { - ArrayList results = new ArrayList(); + ArrayList results = new ArrayList<>(); do { // Read the cursor fields into the SearchResult object results.add(new SearchResult(cursor.getInt(CURSOR_SEARCH_ID), cursor.getString(CURSOR_SEARCH_NAME), @@ -141,6 +139,7 @@ public class SearchHelper { } // Torrent Search package is not yet installed + cursor.close(); return null; } diff --git a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java index 64d518af..ba9fac71 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java @@ -612,7 +612,7 @@ public class ApplicationSettings { } // Should be an in-app search key - if (allsites != null) { + if (allsites != null && !allsites.isEmpty()) { for (SearchSite searchSite : allsites) { if (searchSite.getKey().equals(lastKey)) { return searchSite; diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java index f499839b..ad10d9af 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java @@ -140,6 +140,8 @@ public class SearchActivity extends AppCompatActivity { searchsitesList.setItemChecked(lastUsedPosition, true); lastUsedSite = searchSites.get(lastUsedPosition); refreshSearch(); + } else { + fragmentResults.clearResults(); } } else { // Use the action bar spinner to select sites @@ -153,6 +155,8 @@ public class SearchActivity extends AppCompatActivity { sitesSpinner.setSelection(lastUsedPosition); lastUsedSite = searchSites.get(lastUsedPosition); refreshSearch(); + } else { + fragmentResults.clearResults(); } } invalidateOptionsMenu(); @@ -169,8 +173,8 @@ public class SearchActivity extends AppCompatActivity { final SearchView searchView = new SearchView(searchToolbar.getContext()); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryRefinementEnabled(true); - //searchView.setIconified(false); - //searchView.setIconifiedByDefault(false); + searchView.setIconified(false); + searchView.setIconifiedByDefault(false); MenuItemCompat.setActionView(item, searchView); searchMenu = item; return true; @@ -280,7 +284,7 @@ public class SearchActivity extends AppCompatActivity { protected void refreshSearch() { if (searchMenu != null) { - // Close the search view in the ation bar + // Close the search view in the action bar searchMenu.collapseActionView(); } diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java b/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java index 217cc624..6ecbbea9 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java @@ -129,6 +129,12 @@ public class SearchResultsFragment extends Fragment { emptyText.setVisibility(View.GONE); } + public void clearResults() { + loadingProgress.setVisibility(View.GONE); + resultsList.setVisibility(View.GONE); + emptyText.setVisibility(View.VISIBLE); + } + @ItemClick(R.id.searchresults_list) protected void onItemClicked(SearchResult item) { if (item.getTorrentUrl() == null) {