Show appropriate message when search results are empty

Closes #512.
This commit is contained in:
relan 2015-12-18 21:50:54 +03:00
parent fa5b7d8099
commit 8b89b52d2b
6 changed files with 53 additions and 1 deletions

View File

@ -105,6 +105,7 @@
<activity <activity
android:name=".FDroid" android:name=".FDroid"
android:launchMode="singleTop" android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:configChanges="layoutDirection|locale|keyboardHidden|orientation|screenSize" > android:configChanges="layoutDirection|locale|keyboardHidden|orientation|screenSize" >
<!-- App URLs --> <!-- App URLs -->

View File

@ -258,6 +258,9 @@
<string name="empty_installed_app_list">No apps installed.\n\nThere are apps on your device, but they are not available from F-Droid. This could be because you need to update your repositories, or the repositories genuinely don\'t have your apps available.</string> <string name="empty_installed_app_list">No apps installed.\n\nThere are apps on your device, but they are not available from F-Droid. This could be because you need to update your repositories, or the repositories genuinely don\'t have your apps available.</string>
<string name="empty_available_app_list">No apps in this category.\n\nTry selecting a different category or updating your repositories to get a fresh list of apps.</string> <string name="empty_available_app_list">No apps in this category.\n\nTry selecting a different category or updating your repositories to get a fresh list of apps.</string>
<string name="empty_can_update_app_list">All apps up to date.\n\nCongratulations! All of your apps are up to date (or your repositories are out of date).</string> <string name="empty_can_update_app_list">All apps up to date.\n\nCongratulations! All of your apps are up to date (or your repositories are out of date).</string>
<string name="empty_search_installed_app_list">No matching installed applications.</string>
<string name="empty_search_available_app_list">No matching applications available.</string>
<string name="empty_search_can_update_app_list">No matching applications for update.</string>
<string name="requesting_root_access_body">Requesting root access…</string> <string name="requesting_root_access_body">Requesting root access…</string>
<string name="root_access_denied_title">Root access denied</string> <string name="root_access_denied_title">Root access denied</string>

View File

@ -14,6 +14,7 @@ import android.support.v4.content.Loader;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.TextView;
import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
@ -64,6 +65,10 @@ public abstract class AppListFragment extends ListFragment implements
protected abstract Uri getDataUri(String query); protected abstract Uri getDataUri(String query);
protected abstract int getEmptyMessage();
protected abstract int getNoSearchResultsMessage();
/** /**
* Subclasses can choose to do different things based on when a user begins searching. * 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 * For example, the "Available" tab chooses to hide its category spinner to make it clear
@ -84,6 +89,14 @@ public abstract class AppListFragment extends ListFragment implements
// Do nothing by default. // Do nothing by default.
} }
/**
* Utility function to set empty view text which should be different
* depending on whether search is active or not.
*/
private void setEmptyText(int resId) {
((TextView) getListView().getEmptyView()).setText(resId);
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -177,15 +190,18 @@ public abstract class AppListFragment extends ListFragment implements
/** /**
* Notifies the subclass via {@link AppListFragment#onSearch()} and {@link AppListFragment#onSearchStopped()} * Notifies the subclass via {@link AppListFragment#onSearch()} and {@link AppListFragment#onSearchStopped()}
* about whether or not a search is taking place. * about whether or not a search is taking place and changes empty message
* appropriately.
* @return True if a user is searching. * @return True if a user is searching.
*/ */
private boolean updateSearchStatus() { private boolean updateSearchStatus() {
if (TextUtils.isEmpty(searchQuery)) { if (TextUtils.isEmpty(searchQuery)) {
onSearchStopped(); onSearchStopped();
setEmptyText(getEmptyMessage());
return false; return false;
} else { } else {
onSearch(); onSearch();
setEmptyText(getNoSearchResultsMessage());
return true; return true;
} }
} }

View File

@ -176,6 +176,16 @@ public class AvailableAppsFragment extends AppListFragment implements
return AppProvider.getSearchUri(query); return AppProvider.getSearchUri(query);
} }
@Override
protected int getEmptyMessage() {
return R.string.empty_available_app_list;
}
@Override
protected int getNoSearchResultsMessage() {
return R.string.empty_search_available_app_list;
}
private void setCurrentCategory(String category) { private void setCurrentCategory(String category) {
currentCategory = category; currentCategory = category;
Utils.debugLog(TAG, "Category '" + currentCategory + "' selected."); Utils.debugLog(TAG, "Category '" + currentCategory + "' selected.");

View File

@ -28,10 +28,21 @@ public class CanUpdateAppsFragment extends AppListFragment {
return AppProvider.getCanUpdateUri(); return AppProvider.getCanUpdateUri();
} }
@Override
protected Uri getDataUri(String query) { protected Uri getDataUri(String query) {
return AppProvider.getSearchCanUpdateUri(query); return AppProvider.getSearchCanUpdateUri(query);
} }
@Override
protected int getEmptyMessage() {
return R.string.empty_can_update_app_list;
}
@Override
protected int getNoSearchResultsMessage() {
return R.string.empty_search_can_update_app_list;
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.can_update_app_list, container, false); return inflater.inflate(R.layout.can_update_app_list, container, false);

View File

@ -28,10 +28,21 @@ public class InstalledAppsFragment extends AppListFragment {
return AppProvider.getInstalledUri(); return AppProvider.getInstalledUri();
} }
@Override
protected Uri getDataUri(String query) { protected Uri getDataUri(String query) {
return AppProvider.getSearchInstalledUri(query); return AppProvider.getSearchInstalledUri(query);
} }
@Override
protected int getEmptyMessage() {
return R.string.empty_installed_app_list;
}
@Override
protected int getNoSearchResultsMessage() {
return R.string.empty_search_installed_app_list;
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.installed_app_list, container, false); return inflater.inflate(R.layout.installed_app_list, container, false);