Initial move of search logic to FDroid activity from SearchActivity
This commit is contained in:
parent
dba8cd45ed
commit
b1be1dffb6
@ -100,7 +100,7 @@
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.default_searchable"
|
||||
android:value=".SearchResults" />
|
||||
android:value=".FDroid" />
|
||||
|
||||
<activity
|
||||
android:name=".FDroid"
|
||||
@ -224,6 +224,14 @@
|
||||
<data android:path="/store/search" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
|
||||
<!-- Handle NFC tags detected from outside our application -->
|
||||
<intent-filter>
|
||||
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
|
||||
@ -388,25 +396,6 @@
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<activity
|
||||
android:name=".SearchResults"
|
||||
android:label="@string/search_results"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:parentActivityName=".FDroid"
|
||||
android:configChanges="layoutDirection|locale" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".FDroid" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".receiver.StartupReceiver" >
|
||||
<intent-filter>
|
||||
|
@ -29,10 +29,13 @@ import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
@ -48,9 +51,10 @@ import org.fdroid.fdroid.data.NewRepoConfig;
|
||||
import org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity;
|
||||
import org.fdroid.fdroid.views.AppListFragmentPagerAdapter;
|
||||
import org.fdroid.fdroid.views.ManageReposActivity;
|
||||
import org.fdroid.fdroid.views.fragments.AppListFragment;
|
||||
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
|
||||
|
||||
public class FDroid extends ActionBarActivity {
|
||||
public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextListener {
|
||||
|
||||
private static final String TAG = "FDroid";
|
||||
|
||||
@ -66,8 +70,11 @@ public class FDroid extends ActionBarActivity {
|
||||
|
||||
private ViewPager viewPager;
|
||||
|
||||
@Nullable
|
||||
private TabManager tabManager;
|
||||
|
||||
private AppListFragmentPagerAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@ -248,6 +255,7 @@ public class FDroid extends ActionBarActivity {
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
||||
// LayoutParams.MATCH_PARENT does not work, use a big value instead
|
||||
searchView.setMaxWidth(1000000);
|
||||
searchView.setOnQueryTextListener(this);
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
@ -335,8 +343,8 @@ public class FDroid extends ActionBarActivity {
|
||||
|
||||
private void createViews() {
|
||||
viewPager = (ViewPager) findViewById(R.id.main_pager);
|
||||
AppListFragmentPagerAdapter viewPagerAdapter = new AppListFragmentPagerAdapter(this);
|
||||
viewPager.setAdapter(viewPagerAdapter);
|
||||
this.adapter = new AppListFragmentPagerAdapter(this);
|
||||
viewPager.setAdapter(this.adapter);
|
||||
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
@ -345,6 +353,7 @@ public class FDroid extends ActionBarActivity {
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private TabManager getTabManager() {
|
||||
if (tabManager == null) {
|
||||
tabManager = new TabManager(this, viewPager);
|
||||
@ -363,6 +372,20 @@ public class FDroid extends ActionBarActivity {
|
||||
nMgr.cancel(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final String SEARCH_CHANGED = "fdroid.SearchChanged";
|
||||
private static final String SEARCH_QUERY = "fdroid.SearchQuery";
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
this.adapter.updateSearchQuery(newText, getTabManager().getSelectedIndex());
|
||||
return true;
|
||||
}
|
||||
|
||||
private class AppObserver extends ContentObserver {
|
||||
|
||||
AppObserver() {
|
||||
|
@ -35,6 +35,10 @@ public class TabManager {
|
||||
this.pager = pager;
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return actionBar != null ? actionBar.getSelectedNavigationIndex() : -1;
|
||||
}
|
||||
|
||||
protected CharSequence getLabel(int index) {
|
||||
return pager.getAdapter().getPageTitle(index);
|
||||
}
|
||||
|
@ -425,6 +425,8 @@ public class AppProvider extends FDroidProvider {
|
||||
private static final String PATH_INSTALLED = "installed";
|
||||
private static final String PATH_CAN_UPDATE = "canUpdate";
|
||||
private static final String PATH_SEARCH = "search";
|
||||
private static final String PATH_SEARCH_INSTALLED = "seasrchInstalled";
|
||||
private static final String PATH_SEARCH_CAN_UPDATE = "searchCanUpdate";
|
||||
private static final String PATH_SEARCH_REPO = "searchRepo";
|
||||
private static final String PATH_NO_APKS = "noApks";
|
||||
private static final String PATH_APPS = "apps";
|
||||
@ -447,6 +449,8 @@ public class AppProvider extends FDroidProvider {
|
||||
private static final int CALC_APP_DETAILS_FROM_INDEX = IGNORED + 1;
|
||||
private static final int REPO = CALC_APP_DETAILS_FROM_INDEX + 1;
|
||||
private static final int SEARCH_REPO = REPO + 1;
|
||||
private static final int SEARCH_INSTALLED = SEARCH_REPO + 1;
|
||||
private static final int SEARCH_CAN_UPDATE = SEARCH_INSTALLED + 1;
|
||||
|
||||
static {
|
||||
matcher.addURI(getAuthority(), null, CODE_LIST);
|
||||
@ -456,6 +460,8 @@ public class AppProvider extends FDroidProvider {
|
||||
matcher.addURI(getAuthority(), PATH_NEWLY_ADDED, NEWLY_ADDED);
|
||||
matcher.addURI(getAuthority(), PATH_CATEGORY + "/*", CATEGORY);
|
||||
matcher.addURI(getAuthority(), PATH_SEARCH + "/*", SEARCH);
|
||||
matcher.addURI(getAuthority(), PATH_SEARCH_INSTALLED + "/*", SEARCH_INSTALLED);
|
||||
matcher.addURI(getAuthority(), PATH_SEARCH_CAN_UPDATE + "/*", SEARCH_CAN_UPDATE);
|
||||
matcher.addURI(getAuthority(), PATH_SEARCH_REPO + "/*/*", SEARCH_REPO);
|
||||
matcher.addURI(getAuthority(), PATH_REPO + "/#", REPO);
|
||||
matcher.addURI(getAuthority(), PATH_CAN_UPDATE, CAN_UPDATE);
|
||||
@ -540,6 +546,22 @@ public class AppProvider extends FDroidProvider {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Uri getSearchInstalledUri(String query) {
|
||||
return getContentUri()
|
||||
.buildUpon()
|
||||
.appendPath(PATH_SEARCH_INSTALLED)
|
||||
.appendPath(query)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Uri getSearchCanUpdateUri(String query) {
|
||||
return getContentUri()
|
||||
.buildUpon()
|
||||
.appendPath(PATH_SEARCH_CAN_UPDATE)
|
||||
.appendPath(query)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Uri getSearchUri(Repo repo, String query) {
|
||||
return getContentUri().buildUpon()
|
||||
.appendPath(PATH_SEARCH_REPO)
|
||||
@ -735,6 +757,16 @@ public class AppProvider extends FDroidProvider {
|
||||
includeSwap = false;
|
||||
break;
|
||||
|
||||
case SEARCH_INSTALLED:
|
||||
selection = querySearch(uri.getLastPathSegment()).add(queryInstalled());
|
||||
includeSwap = false;
|
||||
break;
|
||||
|
||||
case SEARCH_CAN_UPDATE:
|
||||
selection = querySearch(uri.getLastPathSegment()).add(queryCanUpdate());
|
||||
includeSwap = false;
|
||||
break;
|
||||
|
||||
case SEARCH_REPO:
|
||||
selection = selection.add(querySearch(uri.getPathSegments().get(2)));
|
||||
selection = selection.add(queryRepo(Long.parseLong(uri.getPathSegments().get(1))));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.fdroid.fdroid.views;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
@ -7,6 +9,7 @@ import org.fdroid.fdroid.FDroid;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.compat.TabManager;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.views.fragments.AppListFragment;
|
||||
import org.fdroid.fdroid.views.fragments.AvailableAppsFragment;
|
||||
import org.fdroid.fdroid.views.fragments.CanUpdateAppsFragment;
|
||||
import org.fdroid.fdroid.views.fragments.InstalledAppsFragment;
|
||||
@ -17,11 +20,28 @@ import org.fdroid.fdroid.views.fragments.InstalledAppsFragment;
|
||||
*/
|
||||
public class AppListFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
@NonNull
|
||||
private final FDroid parent;
|
||||
|
||||
@NonNull
|
||||
private final AppListFragment availableFragment;
|
||||
|
||||
@NonNull
|
||||
private final AppListFragment installedFragment;
|
||||
|
||||
@NonNull
|
||||
private final AppListFragment canUpdateFragment;
|
||||
|
||||
@Nullable
|
||||
private String searchQuery;
|
||||
|
||||
public AppListFragmentPagerAdapter(FDroid parent) {
|
||||
super(parent.getSupportFragmentManager());
|
||||
this.parent = parent;
|
||||
|
||||
availableFragment = new AvailableAppsFragment();
|
||||
installedFragment = new InstalledAppsFragment();
|
||||
canUpdateFragment = new CanUpdateAppsFragment();
|
||||
}
|
||||
|
||||
private String getInstalledTabTitle() {
|
||||
@ -34,15 +54,22 @@ public class AppListFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
return parent.getString(R.string.tab_updates_count, updateCount);
|
||||
}
|
||||
|
||||
public void updateSearchQuery(@Nullable String query, int tabIndex) {
|
||||
searchQuery = query;
|
||||
availableFragment.updateSearchQuery(query);
|
||||
installedFragment.updateSearchQuery(query);
|
||||
canUpdateFragment.updateSearchQuery(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
switch (i) {
|
||||
case TabManager.INDEX_AVAILABLE:
|
||||
return new AvailableAppsFragment();
|
||||
return availableFragment;
|
||||
case TabManager.INDEX_INSTALLED:
|
||||
return new InstalledAppsFragment();
|
||||
return installedFragment;
|
||||
default:
|
||||
return new CanUpdateAppsFragment();
|
||||
return canUpdateFragment;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,12 @@ import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
@ -52,12 +54,17 @@ public abstract class AppListFragment extends ListFragment implements
|
||||
|
||||
protected AppListAdapter appAdapter;
|
||||
|
||||
@Nullable
|
||||
private String searchQuery;
|
||||
|
||||
protected abstract AppListAdapter getAppListAdapter();
|
||||
|
||||
protected abstract String getFromTitle();
|
||||
|
||||
protected abstract Uri getDataUri();
|
||||
|
||||
protected abstract Uri getDataUri(String query);
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
@ -144,9 +151,15 @@ public abstract class AppListFragment extends ListFragment implements
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
Uri uri = getDataUri();
|
||||
Uri uri = TextUtils.isEmpty(searchQuery) ? getDataUri() : getDataUri(searchQuery);
|
||||
return new CursorLoader(
|
||||
getActivity(), uri, APP_PROJECTION, null, null, APP_SORT);
|
||||
}
|
||||
|
||||
public void updateSearchQuery(@Nullable String query) {
|
||||
this.searchQuery = query;
|
||||
if (isAdded()) {
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,10 @@ public class AvailableAppsFragment extends AppListFragment implements
|
||||
return AppProvider.getCategoryUri(currentCategory);
|
||||
}
|
||||
|
||||
protected Uri getDataUri(String query) {
|
||||
return AppProvider.getSearchUri(query);
|
||||
}
|
||||
|
||||
private void setCurrentCategory(String category) {
|
||||
currentCategory = category;
|
||||
Utils.debugLog(TAG, "Category '" + currentCategory + "' selected.");
|
||||
|
@ -28,6 +28,10 @@ public class CanUpdateAppsFragment extends AppListFragment {
|
||||
return AppProvider.getCanUpdateUri();
|
||||
}
|
||||
|
||||
protected Uri getDataUri(String query) {
|
||||
return AppProvider.getSearchCanUpdateUri(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.can_update_app_list, container, false);
|
||||
|
@ -28,6 +28,10 @@ public class InstalledAppsFragment extends AppListFragment {
|
||||
return AppProvider.getInstalledUri();
|
||||
}
|
||||
|
||||
protected Uri getDataUri(String query) {
|
||||
return AppProvider.getSearchInstalledUri(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.installed_app_list, container, false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user