Browse Source

When no search sites are enabled (in the Torrent Search config), still allow web bases searches. Fixes #263.

pull/280/head
Eric Kok 9 years ago
parent
commit
dce15b89f2
  1. 15
      app/src/main/java/org/transdroid/core/app/search/SearchHelper.java
  2. 2
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  3. 10
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java
  4. 6
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java

15
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 // The installed Torrent Search version is corrupt or incompatible
return null; return null;
} }
List<SearchSite> sites = new ArrayList<>();
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
List<SearchSite> sites = new ArrayList<SearchSite>();
do { do {
// Read the cursor fields into the SearchSite object // Read the cursor fields into the SearchSite object
sites.add(new SearchSite(cursor.getInt(CURSOR_SITE_ID), cursor.getString(CURSOR_SITE_CODE), cursor sites.add(new SearchSite(cursor.getInt(CURSOR_SITE_ID), cursor.getString(CURSOR_SITE_CODE), cursor
.getString(CURSOR_SITE_NAME), cursor.getString(CURSOR_SITE_RSSURL), .getString(CURSOR_SITE_NAME), cursor.getString(CURSOR_SITE_RSSURL),
cursor.getColumnNames().length > 4 ? (cursor.getInt(CURSOR_SITE_ISPRIVATE) == 1 ? true : false) cursor.getColumnNames().length > 4 && cursor.getInt(CURSOR_SITE_ISPRIVATE) == 1));
: false));
} while (cursor.moveToNext()); } 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. * be called in a background thread.
* @param query The search query to pass to the torrent site * @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 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 * @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 * there is no internet connection
*/ */
@ -128,7 +126,7 @@ public class SearchHelper {
return null; return null;
} }
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
ArrayList<SearchResult> results = new ArrayList<SearchResult>(); ArrayList<SearchResult> results = new ArrayList<>();
do { do {
// Read the cursor fields into the SearchResult object // Read the cursor fields into the SearchResult object
results.add(new SearchResult(cursor.getInt(CURSOR_SEARCH_ID), cursor.getString(CURSOR_SEARCH_NAME), 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 // Torrent Search package is not yet installed
cursor.close();
return null; return null;
} }

2
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 // Should be an in-app search key
if (allsites != null) { if (allsites != null && !allsites.isEmpty()) {
for (SearchSite searchSite : allsites) { for (SearchSite searchSite : allsites) {
if (searchSite.getKey().equals(lastKey)) { if (searchSite.getKey().equals(lastKey)) {
return searchSite; return searchSite;

10
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -140,6 +140,8 @@ public class SearchActivity extends AppCompatActivity {
searchsitesList.setItemChecked(lastUsedPosition, true); searchsitesList.setItemChecked(lastUsedPosition, true);
lastUsedSite = searchSites.get(lastUsedPosition); lastUsedSite = searchSites.get(lastUsedPosition);
refreshSearch(); refreshSearch();
} else {
fragmentResults.clearResults();
} }
} else { } else {
// Use the action bar spinner to select sites // Use the action bar spinner to select sites
@ -153,6 +155,8 @@ public class SearchActivity extends AppCompatActivity {
sitesSpinner.setSelection(lastUsedPosition); sitesSpinner.setSelection(lastUsedPosition);
lastUsedSite = searchSites.get(lastUsedPosition); lastUsedSite = searchSites.get(lastUsedPosition);
refreshSearch(); refreshSearch();
} else {
fragmentResults.clearResults();
} }
} }
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -169,8 +173,8 @@ public class SearchActivity extends AppCompatActivity {
final SearchView searchView = new SearchView(searchToolbar.getContext()); final SearchView searchView = new SearchView(searchToolbar.getContext());
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true); searchView.setQueryRefinementEnabled(true);
//searchView.setIconified(false); searchView.setIconified(false);
//searchView.setIconifiedByDefault(false); searchView.setIconifiedByDefault(false);
MenuItemCompat.setActionView(item, searchView); MenuItemCompat.setActionView(item, searchView);
searchMenu = item; searchMenu = item;
return true; return true;
@ -280,7 +284,7 @@ public class SearchActivity extends AppCompatActivity {
protected void refreshSearch() { protected void refreshSearch() {
if (searchMenu != null) { if (searchMenu != null) {
// Close the search view in the ation bar // Close the search view in the action bar
searchMenu.collapseActionView(); searchMenu.collapseActionView();
} }

6
app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java

@ -129,6 +129,12 @@ public class SearchResultsFragment extends Fragment {
emptyText.setVisibility(View.GONE); emptyText.setVisibility(View.GONE);
} }
public void clearResults() {
loadingProgress.setVisibility(View.GONE);
resultsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
}
@ItemClick(R.id.searchresults_list) @ItemClick(R.id.searchresults_list)
protected void onItemClicked(SearchResult item) { protected void onItemClicked(SearchResult item) {
if (item.getTorrentUrl() == null) { if (item.getTorrentUrl() == null) {

Loading…
Cancel
Save