diff --git a/app/src/main/java/com/gh4a/activities/RepositoryActivity.java b/app/src/main/java/com/gh4a/activities/RepositoryActivity.java index 4787ef3d0..637e95797 100644 --- a/app/src/main/java/com/gh4a/activities/RepositoryActivity.java +++ b/app/src/main/java/com/gh4a/activities/RepositoryActivity.java @@ -295,8 +295,8 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; case R.id.search: String initialSearch = "repo:" + mRepoOwner + "/" + mRepoName + " "; - startActivity(SearchActivity.makeIntent(this, - initialSearch, SearchActivity.SEARCH_TYPE_CODE)); + startActivity(SearchActivity.makeIntent(this, initialSearch, + SearchActivity.SEARCH_TYPE_CODE, false)); return true; case R.id.bookmark: String bookmarkUrl = getBookmarkUrl(); diff --git a/app/src/main/java/com/gh4a/activities/SearchActivity.java b/app/src/main/java/com/gh4a/activities/SearchActivity.java index 7bd120a23..575fdf6d4 100644 --- a/app/src/main/java/com/gh4a/activities/SearchActivity.java +++ b/app/src/main/java/com/gh4a/activities/SearchActivity.java @@ -28,10 +28,12 @@ public class SearchActivity extends FragmentContainerActivity { public static final int SEARCH_TYPE_USER = SearchFragment.SEARCH_TYPE_USER; public static final int SEARCH_TYPE_CODE = SearchFragment.SEARCH_TYPE_CODE; - public static Intent makeIntent(Context context, String initialSearch, int searchType) { + public static Intent makeIntent(Context context, String initialSearch, + int searchType, boolean startSearchImmediately) { return makeIntent(context) .putExtra("initial_search", initialSearch) - .putExtra("search_type", searchType); + .putExtra("search_type", searchType) + .putExtra("search_immediately", startSearchImmediately); } public static Intent makeIntent(Context context) { @@ -49,7 +51,8 @@ protected Fragment onCreateFragment() { Intent intent = getIntent(); int searchType = intent.getIntExtra("search_type", SEARCH_TYPE_REPO); String initialQuery = intent.getStringExtra("initial_search"); + boolean startSearchImmediately = intent.getBooleanExtra("search_immediately", true); - return SearchFragment.newInstance(searchType, initialQuery); + return SearchFragment.newInstance(searchType, initialQuery, startSearchImmediately); } } diff --git a/app/src/main/java/com/gh4a/activities/home/SearchFactory.java b/app/src/main/java/com/gh4a/activities/home/SearchFactory.java index 83dd495d6..1a6c8b93f 100644 --- a/app/src/main/java/com/gh4a/activities/home/SearchFactory.java +++ b/app/src/main/java/com/gh4a/activities/home/SearchFactory.java @@ -27,6 +27,6 @@ protected int[] getTabTitleResIds() { @Override protected Fragment makeFragment(int position) { - return SearchFragment.newInstance(SearchFragment.SEARCH_TYPE_REPO, null); + return SearchFragment.newInstance(SearchFragment.SEARCH_TYPE_REPO, null, false); } } diff --git a/app/src/main/java/com/gh4a/fragment/PagedDataBaseFragment.java b/app/src/main/java/com/gh4a/fragment/PagedDataBaseFragment.java index a7747b30b..53320ae49 100644 --- a/app/src/main/java/com/gh4a/fragment/PagedDataBaseFragment.java +++ b/app/src/main/java/com/gh4a/fragment/PagedDataBaseFragment.java @@ -52,11 +52,12 @@ public abstract class PagedDataBaseFragment extends LoadingListFragmentBase i public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - setContentShown(false); - mRxLoader = new RxLoader(getActivity(), getLoaderManager()); resetSubject(); - load(false); + if (shouldDoInitialLoad()) { + setContentShown(false); + load(false); + } } @Override @@ -103,6 +104,10 @@ protected void resetSubject() { mPageSubject.onNext(1); } + protected boolean shouldDoInitialLoad() { + return true; + } + private void load(boolean force) { mSubscription = mPageSubject .flatMap(page -> loadPage(page, force) diff --git a/app/src/main/java/com/gh4a/fragment/SearchFragment.java b/app/src/main/java/com/gh4a/fragment/SearchFragment.java index f4664ea9e..fc77f9e0d 100644 --- a/app/src/main/java/com/gh4a/fragment/SearchFragment.java +++ b/app/src/main/java/com/gh4a/fragment/SearchFragment.java @@ -54,11 +54,13 @@ public class SearchFragment extends PagedDataBaseFragment implements SearchView.OnQueryTextListener, SearchView.OnCloseListener, SearchView.OnSuggestionListener, FilterQueryProvider, AdapterView.OnItemSelectedListener, SearchAdapter.Callback { - public static SearchFragment newInstance(int initialType, String initialQuery) { + public static SearchFragment newInstance(int initialType, String initialQuery, + boolean startSearchImmediately) { SearchFragment f = new SearchFragment(); Bundle args = new Bundle(); args.putInt("search_type", initialType); args.putString("initial_search", initialQuery); + args.putBoolean("do_initial_load", startSearchImmediately); f.setArguments(args); return f; } @@ -149,9 +151,14 @@ public void onSaveInstanceState(Bundle outState) { return mAdapter; } + @Override + protected boolean shouldDoInitialLoad() { + return getArguments().getBoolean("do_initial_load", true); + } + @Override protected Single>> loadPage(int page, boolean bypassCache) { - if (TextUtils.isEmpty(mQuery) || mQuery.equals(getArguments().getString("initial_search"))) { + if (TextUtils.isEmpty(mQuery)) { return Single.just(Response.success(new ApiHelpers.DummyPage<>())); } switch (mSelectedSearchType) { diff --git a/app/src/main/java/com/gh4a/resolver/LinkParser.java b/app/src/main/java/com/gh4a/resolver/LinkParser.java index 4f84394e8..382def25b 100644 --- a/app/src/main/java/com/gh4a/resolver/LinkParser.java +++ b/app/src/main/java/com/gh4a/resolver/LinkParser.java @@ -191,7 +191,7 @@ private static ParseResult parseSearchLink(FragmentActivity activity, @NonNull U } } String query = uri.getQueryParameter("q"); - return new ParseResult(SearchActivity.makeIntent(activity, query, typeInt)); + return new ParseResult(SearchActivity.makeIntent(activity, query, typeInt, true)); } @NonNull