forked from organicmaps/organicmaps
[android] Added search cancel before 'ShowOnMap' button is clicked
[android] Refactored SearchEngine java class [android] Fixed the bad caching of search query string when it's no needed
This commit is contained in:
parent
afc28c3e0f
commit
bd67563081
6 changed files with 66 additions and 62 deletions
|
@ -591,7 +591,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
org.alohalytics.Statistics.logEvent("MapsWithMeIntentProcessor::process", apiUrl == null ? "null" : apiUrl);
|
||||
if (apiUrl != null)
|
||||
{
|
||||
SearchEngine.nativeCancelInteractiveSearch();
|
||||
SearchEngine.INSTANCE.cancelInteractiveSearch();
|
||||
|
||||
final ParsedMwmRequest request = ParsedMwmRequest.extractFromIntent(intent);
|
||||
ParsedMwmRequest.setCurrentRequest(request);
|
||||
|
|
|
@ -481,7 +481,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
args.putBoolean(DownloaderActivity.EXTRA_OPEN_DOWNLOADED, openDownloaded);
|
||||
if (mIsFragmentContainer)
|
||||
{
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
mSearchController.refreshToolbar();
|
||||
replaceFragment(MapManager.nativeIsLegacyMode() ? MigrationFragment.class : DownloaderFragment.class, args, null);
|
||||
}
|
||||
|
@ -612,13 +612,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
// The previous search should be cancelled before the new one is started, since previous search
|
||||
// results are no longer needed.
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
SearchEngine.searchInteractive(mSearchController.getQuery(), System.nanoTime(),
|
||||
SearchEngine.INSTANCE.searchInteractive(mSearchController.getQuery(), System.nanoTime(),
|
||||
false /* isMapAndTable */,
|
||||
mFilterController != null ? mFilterController.getFilter() : null,
|
||||
mFilterController != null ? mFilterController.getBookingFilterParams() : null);
|
||||
SearchEngine.setQuery(mSearchController.getQuery());
|
||||
SearchEngine.INSTANCE.setQuery(mSearchController.getQuery());
|
||||
}
|
||||
|
||||
private void initPositionChooser()
|
||||
|
@ -1199,7 +1199,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
BookingFilterParams params = intent.getParcelableExtra(FilterActivity.EXTRA_FILTER_PARAMS);
|
||||
if (mFilterController != null)
|
||||
{
|
||||
mFilterController.show(filter != null || params != null || !TextUtils.isEmpty(SearchEngine.getQuery()), true);
|
||||
mFilterController.show(filter != null || params != null
|
||||
|| !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()), true);
|
||||
mFilterController.setFilterAndParams(filter, params);
|
||||
return filter != null || params != null;
|
||||
}
|
||||
|
@ -1350,9 +1351,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
if (mSearchController.hide())
|
||||
{
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
SearchEngine.INSTANCE.cancelInteractiveSearch();
|
||||
if (mFilterController != null)
|
||||
mFilterController.resetFilter();
|
||||
if (mSearchController != null)
|
||||
mSearchController.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2058,7 +2061,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
setNavButtonsTopLimit(visible ? toolbarHeight : 0);
|
||||
if (mFilterController != null)
|
||||
{
|
||||
boolean show = visible && !TextUtils.isEmpty(SearchEngine.getQuery())
|
||||
boolean show = visible && !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery())
|
||||
&& !RoutingController.get().isNavigating();
|
||||
mFilterController.show(show, true);
|
||||
mMainMenu.show(!show);
|
||||
|
@ -2180,7 +2183,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
private void updateSearchBar()
|
||||
{
|
||||
if (!TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
if (!TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
|
||||
mSearchController.refreshToolbar();
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class SearchWheel implements View.OnClickListener
|
|||
{
|
||||
mIsExpanded = false;
|
||||
mCurrentOption = null;
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
SearchEngine.INSTANCE.cancelInteractiveSearch();
|
||||
resetSearchButtonImage();
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ class SearchWheel implements View.OnClickListener
|
|||
return;
|
||||
}
|
||||
|
||||
final String query = SearchEngine.getQuery();
|
||||
final String query = SearchEngine.INSTANCE.getQuery();
|
||||
if (TextUtils.isEmpty(query))
|
||||
{
|
||||
resetSearchButtonImage();
|
||||
|
@ -227,7 +227,7 @@ class SearchWheel implements View.OnClickListener
|
|||
case R.id.btn_search:
|
||||
if (RoutingController.get().isPlanning())
|
||||
{
|
||||
if (TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
if (TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
|
||||
{
|
||||
showSearchInParent();
|
||||
Statistics.INSTANCE.trackRoutingEvent(ROUTING_SEARCH_CLICK, true);
|
||||
|
@ -240,9 +240,9 @@ class SearchWheel implements View.OnClickListener
|
|||
}
|
||||
|
||||
Statistics.INSTANCE.trackRoutingEvent(ROUTING_SEARCH_CLICK, false);
|
||||
if (mCurrentOption != null || !TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
if (mCurrentOption != null || !TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
|
||||
{
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
SearchEngine.INSTANCE.cancelInteractiveSearch();
|
||||
mCurrentOption = null;
|
||||
mIsExpanded = false;
|
||||
resetSearchButtonImage();
|
||||
|
@ -288,7 +288,7 @@ class SearchWheel implements View.OnClickListener
|
|||
private void startSearch(SearchOption searchOption)
|
||||
{
|
||||
mCurrentOption = searchOption;
|
||||
SearchEngine.searchInteractive(searchOption.mSearchQuery, System.nanoTime(), false /* isMapAndTable */,
|
||||
SearchEngine.INSTANCE.searchInteractive(searchOption.mSearchQuery, System.nanoTime(), false /* isMapAndTable */,
|
||||
null /* hotelsFilter */, null /* bookingParams */);
|
||||
refreshSearchButtonImage();
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
});
|
||||
setQuery(ParsedMwmRequest.getCurrentRequest().getTitle());
|
||||
}
|
||||
else if (!TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
else if (!TextUtils.isEmpty(SearchEngine.INSTANCE.getQuery()))
|
||||
{
|
||||
Animations.appearSliding(mToolbar, Animations.TOP, new Runnable()
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
mVisibilityListener.onSearchVisibilityChanged(true);
|
||||
}
|
||||
});
|
||||
setQuery(SearchEngine.getQuery());
|
||||
setQuery(SearchEngine.INSTANCE.getQuery());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
|
||||
private void cancelSearchApiAndHide(boolean clearText)
|
||||
{
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
if (clearText)
|
||||
clear();
|
||||
|
|
|
@ -20,7 +20,7 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
|
||||
// Query, which results are shown on the map.
|
||||
@Nullable
|
||||
private static String sSavedQuery;
|
||||
private String mQuery;
|
||||
|
||||
@Override
|
||||
public void onResultsUpdate(final SearchResult[] results, final long timestamp,
|
||||
|
@ -119,7 +119,7 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
* @return whether search was actually started.
|
||||
*/
|
||||
@MainThread
|
||||
public static boolean search(String query, long timestamp, boolean hasLocation,
|
||||
public boolean search(String query, long timestamp, boolean hasLocation,
|
||||
double lat, double lon, @Nullable HotelsFilter hotelsFilter,
|
||||
@Nullable BookingFilterParams bookingParams)
|
||||
{
|
||||
|
@ -133,7 +133,7 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
}
|
||||
|
||||
@MainThread
|
||||
public static void searchInteractive(@NonNull String query, @NonNull String locale, long timestamp,
|
||||
public void searchInteractive(@NonNull String query, @NonNull String locale, long timestamp,
|
||||
boolean isMapAndTable, @Nullable HotelsFilter hotelsFilter,
|
||||
@Nullable BookingFilterParams bookingParams)
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
}
|
||||
|
||||
@MainThread
|
||||
public static void searchInteractive(@NonNull String query, long timestamp, boolean isMapAndTable,
|
||||
public void searchInteractive(@NonNull String query, long timestamp, boolean isMapAndTable,
|
||||
@Nullable HotelsFilter hotelsFilter, @Nullable BookingFilterParams bookingParams)
|
||||
{
|
||||
searchInteractive(query, Language.getKeyboardLocale(), timestamp, isMapAndTable, hotelsFilter, bookingParams);
|
||||
|
@ -160,19 +160,19 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
} catch (UnsupportedEncodingException ignored) { }
|
||||
}
|
||||
|
||||
public static void setQuery(@Nullable String query)
|
||||
public void setQuery(@Nullable String query)
|
||||
{
|
||||
sSavedQuery = query;
|
||||
mQuery = query;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getQuery()
|
||||
public String getQuery()
|
||||
{
|
||||
return sSavedQuery;
|
||||
return mQuery;
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public static void cancel()
|
||||
public void cancel()
|
||||
{
|
||||
cancelApiCall();
|
||||
cancelAllSearches();
|
||||
|
@ -186,23 +186,23 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
}
|
||||
|
||||
@MainThread
|
||||
public static void cancelInteractiveSearch()
|
||||
public void cancelInteractiveSearch()
|
||||
{
|
||||
sSavedQuery = "";
|
||||
mQuery = "";
|
||||
nativeCancelInteractiveSearch();
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private static void cancelAllSearches()
|
||||
private void cancelAllSearches()
|
||||
{
|
||||
sSavedQuery = "";
|
||||
mQuery = "";
|
||||
nativeCancelAllSearches();
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public static void showResult(int index)
|
||||
public void showResult(int index)
|
||||
{
|
||||
sSavedQuery = "";
|
||||
mQuery = "";
|
||||
nativeShowResult(index);
|
||||
}
|
||||
|
||||
|
@ -228,11 +228,11 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
|
||||
private static native void nativeShowResult(int index);
|
||||
|
||||
public static native void nativeCancelInteractiveSearch();
|
||||
private static native void nativeCancelInteractiveSearch();
|
||||
|
||||
public static native void nativeCancelEverywhereSearch();
|
||||
private static native void nativeCancelEverywhereSearch();
|
||||
|
||||
public static native void nativeCancelAllSearches();
|
||||
private static native void nativeCancelAllSearches();
|
||||
|
||||
/**
|
||||
* @return all existing hotel types
|
||||
|
|
|
@ -127,7 +127,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
if (mLuggageCategorySelected)
|
||||
return;
|
||||
|
||||
if (mAdsLoader != null && !isInteractiveSearch() && query.length() >= MIN_QUERY_LENGTH_FOR_AD)
|
||||
if (mAdsLoader != null && !isTabletSearch() && query.length() >= MIN_QUERY_LENGTH_FOR_AD)
|
||||
{
|
||||
mAdsRequested = true;
|
||||
mAdsLoader.scheduleAdsLoading(getActivity(), query);
|
||||
|
@ -190,7 +190,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
private SearchToolbarController mToolbarController;
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private SearchAdapter mSearchAdapter;
|
||||
|
||||
private final List<RecyclerView> mAttachedRecyclers = new ArrayList<>();
|
||||
|
@ -325,7 +326,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
UiUtils.showIf(show, mResultsPlaceholder);
|
||||
if (mFilterController != null)
|
||||
mFilterController.showPopulateButton(mSearchAdapter.showPopulateButton());
|
||||
mFilterController.showPopulateButton(mSearchAdapter.showPopulateButton() && !isTabletSearch());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -339,6 +340,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mSearchAdapter = new SearchAdapter(this);
|
||||
readArguments();
|
||||
|
||||
if (ConnectionState.isWifiConnected() && SharedPropertiesUtils.isShowcaseSwitchedOnLocal())
|
||||
|
@ -406,18 +408,14 @@ public class SearchFragment extends BaseMwmFragment
|
|||
mFilterController.setFilterAndParams(mInitialHotelsFilter, mInitialFilterParams);
|
||||
mFilterController.updateFilterButtonVisibility(mInitialFilterParams != null);
|
||||
|
||||
if (mSearchAdapter == null)
|
||||
mSearchAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
|
||||
{
|
||||
mSearchAdapter = new SearchAdapter(this);
|
||||
mSearchAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
|
||||
@Override
|
||||
public void onChanged()
|
||||
{
|
||||
@Override
|
||||
public void onChanged()
|
||||
{
|
||||
updateResultsPlaceholder();
|
||||
}
|
||||
});
|
||||
}
|
||||
updateResultsPlaceholder();
|
||||
}
|
||||
});
|
||||
|
||||
mResults.setLayoutManager(new LinearLayoutManager(view.getContext()));
|
||||
mResults.setAdapter(mSearchAdapter);
|
||||
|
@ -547,10 +545,10 @@ public class SearchFragment extends BaseMwmFragment
|
|||
{
|
||||
final String query = getQuery();
|
||||
SearchRecents.add(query);
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
if (!RoutingController.get().isWaitingPoiPick())
|
||||
SearchEngine.showResult(resultIndex);
|
||||
SearchEngine.INSTANCE.showResult(resultIndex);
|
||||
|
||||
processSelected(result);
|
||||
|
||||
|
@ -559,6 +557,10 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
void showAllResultsOnMap()
|
||||
{
|
||||
// The previous search should be cancelled before the new one is started, since previous search
|
||||
// results are no longer needed.
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
final String query = getQuery();
|
||||
SearchRecents.add(query);
|
||||
mLastQueryTimestamp = System.nanoTime();
|
||||
|
@ -571,12 +573,12 @@ public class SearchFragment extends BaseMwmFragment
|
|||
bookingFilterParams = mFilterController.getBookingFilterParams();
|
||||
}
|
||||
|
||||
SearchEngine.searchInteractive(
|
||||
SearchEngine.INSTANCE.searchInteractive(
|
||||
query, !TextUtils.isEmpty(mInitialLocale)
|
||||
? mInitialLocale : com.mapswithme.util.Language.getKeyboardLocale(),
|
||||
mLastQueryTimestamp, false /* isMapAndTable */,
|
||||
hotelsFilter, bookingFilterParams);
|
||||
SearchEngine.setQuery(query);
|
||||
SearchEngine.INSTANCE.setQuery(query);
|
||||
Utils.navigateToParent(getActivity());
|
||||
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.SEARCH_ON_MAP_CLICKED);
|
||||
|
@ -598,11 +600,11 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
private void stopSearch()
|
||||
{
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
updateSearchView();
|
||||
}
|
||||
|
||||
private boolean isInteractiveSearch()
|
||||
private boolean isTabletSearch()
|
||||
{
|
||||
// TODO @yunitsky Implement more elegant solution.
|
||||
return getActivity() instanceof MwmActivity;
|
||||
|
@ -612,7 +614,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
{
|
||||
// The previous search should be cancelled before the new one is started, since previous search
|
||||
// results are no longer needed.
|
||||
SearchEngine.cancel();
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
HotelsFilter hotelsFilter = null;
|
||||
BookingFilterParams bookingFilterParams = null;
|
||||
|
@ -623,14 +625,14 @@ public class SearchFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
mLastQueryTimestamp = System.nanoTime();
|
||||
if (isInteractiveSearch())
|
||||
if (isTabletSearch())
|
||||
{
|
||||
SearchEngine.searchInteractive(getQuery(), mLastQueryTimestamp, true /* isMapAndTable */,
|
||||
SearchEngine.INSTANCE.searchInteractive(getQuery(), mLastQueryTimestamp, true /* isMapAndTable */,
|
||||
hotelsFilter, bookingFilterParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SearchEngine.search(getQuery(), mLastQueryTimestamp, mLastPosition.valid,
|
||||
if (!SearchEngine.INSTANCE.search(getQuery(), mLastQueryTimestamp, mLastPosition.valid,
|
||||
mLastPosition.lat, mLastPosition.lon,
|
||||
hotelsFilter, bookingFilterParams))
|
||||
{
|
||||
|
@ -681,7 +683,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void onFilterAvailableHotels(@Nullable FeatureId[] availableHotels)
|
||||
{
|
||||
if (mSearchAdapter == null || availableHotels == null)
|
||||
if (availableHotels == null)
|
||||
return;
|
||||
|
||||
mSearchAdapter.setAvailableHotels(availableHotels);
|
||||
|
@ -714,8 +716,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
stopAdsLoading();
|
||||
mSearchRunning = true;
|
||||
updateFrames();
|
||||
if (mSearchAdapter != null)
|
||||
mSearchAdapter.refreshData(combineResultsWithAds());
|
||||
mSearchAdapter.refreshData(combineResultsWithAds());
|
||||
mToolbarController.showProgress(true);
|
||||
updateFilterButton(mIsHotel);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue