When searching "Available" tab, search all the things.
Removed the option to search the currently selected category, as suggested by others on gitlab.
This commit is contained in:
parent
cc759b17a4
commit
86fb652fc3
@ -2,7 +2,8 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:animateLayoutChanges="true">
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/category_spinner"
|
android:id="@+id/category_spinner"
|
||||||
|
@ -431,11 +431,8 @@ public class AppProvider extends FDroidProvider {
|
|||||||
private static final String PATH_NO_APKS = "noApks";
|
private static final String PATH_NO_APKS = "noApks";
|
||||||
private static final String PATH_APPS = "apps";
|
private static final String PATH_APPS = "apps";
|
||||||
private static final String PATH_RECENTLY_UPDATED = "recentlyUpdated";
|
private static final String PATH_RECENTLY_UPDATED = "recentlyUpdated";
|
||||||
private static final String PATH_SEARCH_RECENTLY_UPDATED = "searchRecentlyUpdated";
|
|
||||||
private static final String PATH_NEWLY_ADDED = "newlyAdded";
|
private static final String PATH_NEWLY_ADDED = "newlyAdded";
|
||||||
private static final String PATH_SEARCH_NEWLY_ADDED = "searchNewlyAdded";
|
|
||||||
private static final String PATH_CATEGORY = "category";
|
private static final String PATH_CATEGORY = "category";
|
||||||
private static final String PATH_SEARCH_CATEGORY = "searchCategory";
|
|
||||||
private static final String PATH_IGNORED = "ignored";
|
private static final String PATH_IGNORED = "ignored";
|
||||||
private static final String PATH_CALC_APP_DETAILS_FROM_INDEX = "calcDetailsFromIndex";
|
private static final String PATH_CALC_APP_DETAILS_FROM_INDEX = "calcDetailsFromIndex";
|
||||||
private static final String PATH_REPO = "repo";
|
private static final String PATH_REPO = "repo";
|
||||||
@ -454,9 +451,6 @@ public class AppProvider extends FDroidProvider {
|
|||||||
private static final int SEARCH_REPO = REPO + 1;
|
private static final int SEARCH_REPO = REPO + 1;
|
||||||
private static final int SEARCH_INSTALLED = SEARCH_REPO + 1;
|
private static final int SEARCH_INSTALLED = SEARCH_REPO + 1;
|
||||||
private static final int SEARCH_CAN_UPDATE = SEARCH_INSTALLED + 1;
|
private static final int SEARCH_CAN_UPDATE = SEARCH_INSTALLED + 1;
|
||||||
private static final int SEARCH_CATEGORY = SEARCH_CAN_UPDATE + 1;
|
|
||||||
private static final int SEARCH_NEWLY_ADDED = SEARCH_CATEGORY + 1;
|
|
||||||
private static final int SEARCH_RECENTLY_UPDATED = SEARCH_NEWLY_ADDED + 1;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
matcher.addURI(getAuthority(), null, CODE_LIST);
|
matcher.addURI(getAuthority(), null, CODE_LIST);
|
||||||
@ -466,9 +460,6 @@ public class AppProvider extends FDroidProvider {
|
|||||||
matcher.addURI(getAuthority(), PATH_NEWLY_ADDED, NEWLY_ADDED);
|
matcher.addURI(getAuthority(), PATH_NEWLY_ADDED, NEWLY_ADDED);
|
||||||
matcher.addURI(getAuthority(), PATH_CATEGORY + "/*", CATEGORY);
|
matcher.addURI(getAuthority(), PATH_CATEGORY + "/*", CATEGORY);
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH + "/*", SEARCH);
|
matcher.addURI(getAuthority(), PATH_SEARCH + "/*", SEARCH);
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_NEWLY_ADDED + "/*", SEARCH_NEWLY_ADDED);
|
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_RECENTLY_UPDATED + "/*", SEARCH_RECENTLY_UPDATED);
|
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_CATEGORY + "/*/*", SEARCH_CATEGORY);
|
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_INSTALLED + "/*", SEARCH_INSTALLED);
|
matcher.addURI(getAuthority(), PATH_SEARCH_INSTALLED + "/*", SEARCH_INSTALLED);
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_CAN_UPDATE + "/*", SEARCH_CAN_UPDATE);
|
matcher.addURI(getAuthority(), PATH_SEARCH_CAN_UPDATE + "/*", SEARCH_CAN_UPDATE);
|
||||||
matcher.addURI(getAuthority(), PATH_SEARCH_REPO + "/*/*", SEARCH_REPO);
|
matcher.addURI(getAuthority(), PATH_SEARCH_REPO + "/*/*", SEARCH_REPO);
|
||||||
@ -488,24 +479,10 @@ public class AppProvider extends FDroidProvider {
|
|||||||
return Uri.withAppendedPath(getContentUri(), PATH_RECENTLY_UPDATED);
|
return Uri.withAppendedPath(getContentUri(), PATH_RECENTLY_UPDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri getSearchRecentlyUpdatedUri(String query) {
|
|
||||||
return getContentUri().buildUpon()
|
|
||||||
.appendPath(PATH_SEARCH_RECENTLY_UPDATED)
|
|
||||||
.appendEncodedPath(query)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Uri getNewlyAddedUri() {
|
public static Uri getNewlyAddedUri() {
|
||||||
return Uri.withAppendedPath(getContentUri(), PATH_NEWLY_ADDED);
|
return Uri.withAppendedPath(getContentUri(), PATH_NEWLY_ADDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri getSearchNewlyAddedUri(String query) {
|
|
||||||
return getContentUri().buildUpon()
|
|
||||||
.appendPath(PATH_SEARCH_NEWLY_ADDED)
|
|
||||||
.appendEncodedPath(query)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Uri getIgnoredUri() {
|
public static Uri getIgnoredUri() {
|
||||||
return Uri.withAppendedPath(getContentUri(), PATH_IGNORED);
|
return Uri.withAppendedPath(getContentUri(), PATH_IGNORED);
|
||||||
}
|
}
|
||||||
@ -521,14 +498,6 @@ public class AppProvider extends FDroidProvider {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri getSearchCategoryUri(String category, String query) {
|
|
||||||
return getContentUri().buildUpon()
|
|
||||||
.appendPath(PATH_SEARCH_CATEGORY)
|
|
||||||
.appendEncodedPath(category)
|
|
||||||
.appendEncodedPath(query)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Uri getNoApksUri() {
|
public static Uri getNoApksUri() {
|
||||||
return Uri.withAppendedPath(getContentUri(), PATH_NO_APKS);
|
return Uri.withAppendedPath(getContentUri(), PATH_NO_APKS);
|
||||||
}
|
}
|
||||||
@ -820,37 +789,18 @@ public class AppProvider extends FDroidProvider {
|
|||||||
includeSwap = false;
|
includeSwap = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEARCH_CATEGORY:
|
|
||||||
String query = uri.getPathSegments().get(2);
|
|
||||||
String category = uri.getPathSegments().get(1);
|
|
||||||
selection = selection.add(queryCategory(category)).add(querySearch(query));
|
|
||||||
includeSwap = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RECENTLY_UPDATED:
|
case RECENTLY_UPDATED:
|
||||||
sortOrder = getTableName() + ".lastUpdated DESC";
|
sortOrder = getTableName() + ".lastUpdated DESC";
|
||||||
selection = selection.add(queryRecentlyUpdated());
|
selection = selection.add(queryRecentlyUpdated());
|
||||||
includeSwap = false;
|
includeSwap = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEARCH_RECENTLY_UPDATED:
|
|
||||||
sortOrder = " fdroid_app.lastUpdated DESC";
|
|
||||||
selection = selection.add(queryRecentlyUpdated()).add(querySearch(uri.getLastPathSegment()));
|
|
||||||
includeSwap = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NEWLY_ADDED:
|
case NEWLY_ADDED:
|
||||||
sortOrder = getTableName() + ".added DESC";
|
sortOrder = getTableName() + ".added DESC";
|
||||||
selection = selection.add(queryNewlyAdded());
|
selection = selection.add(queryNewlyAdded());
|
||||||
includeSwap = false;
|
includeSwap = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEARCH_NEWLY_ADDED:
|
|
||||||
sortOrder = " fdroid_app.added DESC";
|
|
||||||
selection = selection.add(queryNewlyAdded()).add(querySearch(uri.getLastPathSegment()));
|
|
||||||
includeSwap = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Invalid URI for app content provider: " + uri);
|
Log.e(TAG, "Invalid URI for app content provider: " + uri);
|
||||||
throw new UnsupportedOperationException("Invalid URI for app content provider: " + uri);
|
throw new UnsupportedOperationException("Invalid URI for app content provider: " + uri);
|
||||||
|
@ -64,6 +64,26 @@ public abstract class AppListFragment extends ListFragment implements
|
|||||||
|
|
||||||
protected abstract Uri getDataUri(String query);
|
protected abstract Uri getDataUri(String query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclasses can choose to do different things based on when a user begins searching.
|
||||||
|
* For example, the "Available" tab chooses to hide its category spinner to make it clear
|
||||||
|
* that it is searching all apps, not the current category.
|
||||||
|
* NOTE: This will get called <em>multiple</em> times, every time the user changes the
|
||||||
|
* search query.
|
||||||
|
*/
|
||||||
|
protected void onSearch() {
|
||||||
|
// Do nothing by default.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alerts the child class that the user is no longer performing a search.
|
||||||
|
* This is triggered every time the search query is blank.
|
||||||
|
* @see AppListFragment#onSearch()
|
||||||
|
*/
|
||||||
|
protected void onSearchStopped() {
|
||||||
|
// Do nothing by default.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
@ -150,11 +170,26 @@ public abstract class AppListFragment extends ListFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
Uri uri = TextUtils.isEmpty(searchQuery) ? getDataUri() : getDataUri(searchQuery);
|
Uri uri = updateSearchStatus() ? getDataUri(searchQuery) : getDataUri();
|
||||||
return new CursorLoader(
|
return new CursorLoader(
|
||||||
getActivity(), uri, APP_PROJECTION, null, null, APP_SORT);
|
getActivity(), uri, APP_PROJECTION, null, null, APP_SORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies the subclass via {@link AppListFragment#onSearch()} and {@link AppListFragment#onSearchStopped()}
|
||||||
|
* about whether or not a search is taking place.
|
||||||
|
* @return True if a user is searching.
|
||||||
|
*/
|
||||||
|
private boolean updateSearchStatus() {
|
||||||
|
if (TextUtils.isEmpty(searchQuery)) {
|
||||||
|
onSearchStopped();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
onSearch();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateSearchQuery(@Nullable String query) {
|
public void updateSearchQuery(@Nullable String query) {
|
||||||
searchQuery = query;
|
searchQuery = query;
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
|
@ -164,14 +164,9 @@ public class AvailableAppsFragment extends AppListFragment implements
|
|||||||
return AppProvider.getCategoryUri(currentCategory);
|
return AppProvider.getCategoryUri(currentCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Uri getDataUri(String query) {
|
protected Uri getDataUri(String query) {
|
||||||
if (currentCategory == null || currentCategory.equals(AppProvider.Helper.getCategoryAll(getActivity())))
|
|
||||||
return AppProvider.getSearchUri(query);
|
return AppProvider.getSearchUri(query);
|
||||||
if (currentCategory.equals(AppProvider.Helper.getCategoryRecentlyUpdated(getActivity())))
|
|
||||||
return AppProvider.getSearchRecentlyUpdatedUri(query);
|
|
||||||
if (currentCategory.equals(AppProvider.Helper.getCategoryWhatsNew(getActivity())))
|
|
||||||
return AppProvider.getSearchNewlyAddedUri(query);
|
|
||||||
return AppProvider.getSearchCategoryUri(currentCategory, query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCurrentCategory(String category) {
|
private void setCurrentCategory(String category) {
|
||||||
@ -207,4 +202,18 @@ public class AvailableAppsFragment extends AppListFragment implements
|
|||||||
e.putString(CATEGORY_KEY, currentCategory);
|
e.putString(CATEGORY_KEY, currentCategory);
|
||||||
e.commit();
|
e.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSearch() {
|
||||||
|
if (categorySpinner != null) {
|
||||||
|
categorySpinner.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSearchStopped() {
|
||||||
|
if (categorySpinner != null) {
|
||||||
|
categorySpinner.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user