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 { @@ -85,20 +85,18 @@ public class SearchHelper {
// The installed Torrent Search version is corrupt or incompatible
return null;
}
List<SearchSite> sites = new ArrayList<>();
if (cursor.moveToFirst()) {
List<SearchSite> sites = new ArrayList<SearchSite>();
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 { @@ -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 { @@ -128,7 +126,7 @@ public class SearchHelper {
return null;
}
if (cursor.moveToFirst()) {
ArrayList<SearchResult> results = new ArrayList<SearchResult>();
ArrayList<SearchResult> 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 { @@ -141,6 +139,7 @@ public class SearchHelper {
}
// Torrent Search package is not yet installed
cursor.close();
return null;
}

2
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -612,7 +612,7 @@ public class ApplicationSettings { @@ -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;

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

@ -140,6 +140,8 @@ public class SearchActivity extends AppCompatActivity { @@ -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 { @@ -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 { @@ -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 { @@ -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();
}

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

@ -129,6 +129,12 @@ public class SearchResultsFragment extends Fragment { @@ -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) {

Loading…
Cancel
Save