forked from organicmaps/organicmaps
Merge pull request #309 from yunikkk/search-tablet-fix
[android] Refactored search.
This commit is contained in:
commit
c45d8cfc42
10 changed files with 109 additions and 76 deletions
|
@ -1161,12 +1161,6 @@ extern "C"
|
|||
g_framework->InjectMetadata(env, javaClazz, jsearchResult, mark);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_cleanSearchLayerOnMap(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
android::Platform::RunOnGuiThreadImpl(bind(&::Framework::CancelInteractiveSearch, frm()));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_invalidate(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
|
|
@ -216,4 +216,13 @@ extern "C"
|
|||
g_framework->NativeFramework()->ShowAllSearchResults(results);
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_search_SearchEngine_nativeCancelInteractiveSearch(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
android::Platform::RunOnGuiThreadImpl([]()
|
||||
{
|
||||
g_framework->NativeFramework()->CancelInteractiveSearch();
|
||||
});
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.mapswithme.maps.api.ParsedMwmRequest;
|
|||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -551,7 +552,7 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity
|
|||
org.alohalytics.Statistics.logEvent("MapsWithMeIntentProcessor::process", apiUrl == null ? "null" : apiUrl);
|
||||
if (apiUrl != null)
|
||||
{
|
||||
Framework.cleanSearchLayerOnMap();
|
||||
SearchEngine.nativeCancelInteractiveSearch();
|
||||
|
||||
final ParsedMwmRequest request = ParsedMwmRequest.extractFromIntent(intent);
|
||||
ParsedMwmRequest.setCurrentRequest(request);
|
||||
|
|
|
@ -103,8 +103,6 @@ public class Framework
|
|||
|
||||
public native static void injectData(SearchResult searchResult, long index);
|
||||
|
||||
public native static void cleanSearchLayerOnMap();
|
||||
|
||||
public native static void invalidate();
|
||||
|
||||
public native static void deactivatePopup();
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.mapswithme.maps.activity.CustomNavigateUpListener;
|
|||
import com.mapswithme.maps.ads.LikesManager;
|
||||
import com.mapswithme.maps.api.ParsedMwmRequest;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.ChooseBookmarkCategoryFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
@ -40,6 +41,7 @@ import com.mapswithme.maps.location.LocationHelper;
|
|||
import com.mapswithme.maps.location.LocationPredictor;
|
||||
import com.mapswithme.maps.routing.RoutingResultCodesProcessor;
|
||||
import com.mapswithme.maps.search.SearchActivity;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.maps.search.SearchFragment;
|
||||
import com.mapswithme.maps.search.FloatingSearchToolbarController;
|
||||
import com.mapswithme.maps.settings.SettingsActivity;
|
||||
|
@ -143,15 +145,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
.putExtra(DownloadResourcesActivity.EXTRA_AUTODOWNLOAD_COUNTRY, doAutoDownload);
|
||||
}
|
||||
|
||||
public static void startSearch(Context context, String query)
|
||||
{
|
||||
final MwmActivity activity = (MwmActivity) context;
|
||||
if (activity.mIsFragmentContainer)
|
||||
activity.showSearch();
|
||||
else
|
||||
SearchActivity.startWithQuery(context, query);
|
||||
}
|
||||
|
||||
public static Intent createUpdateMapsIntent()
|
||||
{
|
||||
return new Intent(MwmApplication.get(), MwmActivity.class)
|
||||
|
@ -219,18 +212,21 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
startActivity(new Intent(this, BookmarkCategoriesActivity.class));
|
||||
}
|
||||
|
||||
private void showSearch()
|
||||
public void showSearch(String query)
|
||||
{
|
||||
if (mIsFragmentContainer)
|
||||
{
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SearchActivity.EXTRA_QUERY, query);
|
||||
|
||||
if (getSupportFragmentManager().findFragmentByTag(SearchFragment.class.getName()) == null)
|
||||
popFragment();
|
||||
|
||||
mSearchController.hide();
|
||||
replaceFragment(SearchFragment.class, true, getIntent().getExtras());
|
||||
replaceFragment(SearchFragment.class, true, args);
|
||||
}
|
||||
else
|
||||
startActivity(new Intent(this, SearchActivity.class));
|
||||
SearchActivity.startWithQuery(this, query);
|
||||
}
|
||||
|
||||
private void shareMyLocation()
|
||||
|
@ -268,7 +264,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
return;
|
||||
|
||||
popFragment();
|
||||
FloatingSearchToolbarController.cancelSearch();
|
||||
SearchEngine.cancelSearch();
|
||||
mSearchController.refreshToolbar();
|
||||
replaceFragment(DownloadFragment.class, true, args);
|
||||
}
|
||||
|
@ -480,7 +476,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
showSearch();
|
||||
showSearch(mSearchController.getQuery());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -848,7 +844,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
if (mSearchController.hide())
|
||||
{
|
||||
FloatingSearchToolbarController.cancelSearch();
|
||||
SearchEngine.cancelSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -864,8 +860,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
private boolean canFragmentInterceptBackPress()
|
||||
{
|
||||
final FragmentManager manager = getSupportFragmentManager();
|
||||
DownloadFragment fragment = (DownloadFragment) manager.findFragmentByTag(DownloadFragment.class.getName());
|
||||
return fragment != null && fragment.isResumed() && fragment.onBackPressed();
|
||||
for (String tag : DOCKED_FRAGMENTS)
|
||||
{
|
||||
final Fragment fragment = manager.findFragmentByTag(tag);
|
||||
if (fragment != null && fragment.isResumed() && fragment instanceof OnBackPressListener)
|
||||
return ((OnBackPressListener) fragment).onBackPressed();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean popFragment()
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
|||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.api.ParsedMwmRequest;
|
||||
import com.mapswithme.maps.widget.SearchToolbarController;
|
||||
|
@ -12,8 +11,6 @@ import com.mapswithme.util.UiUtils;
|
|||
|
||||
public class FloatingSearchToolbarController extends SearchToolbarController
|
||||
{
|
||||
private static String sSavedQuery = "";
|
||||
|
||||
public FloatingSearchToolbarController(Activity activity)
|
||||
{
|
||||
super(activity.getWindow().getDecorView(), activity);
|
||||
|
@ -22,7 +19,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
@Override
|
||||
protected void onUpClick()
|
||||
{
|
||||
MwmActivity.startSearch(mActivity, getQuery());
|
||||
((MwmActivity) mActivity).showSearch(getQuery());
|
||||
cancelSearchApiAndHide(true);
|
||||
}
|
||||
|
||||
|
@ -30,8 +27,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
protected void onQueryClick(String query)
|
||||
{
|
||||
super.onQueryClick(query);
|
||||
|
||||
MwmActivity.startSearch(mActivity, query);
|
||||
((MwmActivity) mActivity).showSearch(getQuery());
|
||||
hide();
|
||||
}
|
||||
|
||||
|
@ -51,37 +47,22 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
UiUtils.appearSlidingDown(mToolbar, null);
|
||||
setQuery(ParsedMwmRequest.getCurrentRequest().getTitle());
|
||||
}
|
||||
else if (!TextUtils.isEmpty(sSavedQuery))
|
||||
else if (!TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
{
|
||||
UiUtils.appearSlidingDown(mToolbar, null);
|
||||
setQuery(sSavedQuery);
|
||||
setQuery(SearchEngine.getQuery());
|
||||
}
|
||||
else
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
public static void saveQuery(String query)
|
||||
{
|
||||
sSavedQuery = (query == null) ? "" : query;
|
||||
}
|
||||
|
||||
public static void cancelApiCall()
|
||||
{
|
||||
if (ParsedMwmRequest.hasRequest())
|
||||
ParsedMwmRequest.setCurrentRequest(null);
|
||||
Framework.nativeClearApiPoints();
|
||||
}
|
||||
|
||||
public static void cancelSearch()
|
||||
{
|
||||
saveQuery(null);
|
||||
Framework.cleanSearchLayerOnMap();
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelSearchApiAndHide(boolean clearText)
|
||||
{
|
||||
cancelApiCall();
|
||||
cancelSearch();
|
||||
SearchEngine.cancelApiCall();
|
||||
SearchEngine.cancelSearch();
|
||||
|
||||
if (clearText)
|
||||
clear();
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.v4.app.NavUtils;
|
|||
|
||||
import com.mapswithme.maps.activity.CustomNavigateUpListener;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
|
||||
public class SearchActivity extends BaseMwmFragmentActivity implements CustomNavigateUpListener
|
||||
{
|
||||
|
@ -38,4 +39,17 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav
|
|||
|
||||
manager.popBackStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(getFragmentClass().getName());
|
||||
if (fragment != null && fragment.isAdded() && fragment instanceof OnBackPressListener)
|
||||
{
|
||||
((OnBackPressListener) fragment).onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.api.ParsedMwmRequest;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -10,6 +12,9 @@ public enum SearchEngine implements NativeSearchListener
|
|||
{
|
||||
INSTANCE;
|
||||
|
||||
// Query, which results are shown on the map.
|
||||
private static String sSavedQuery;
|
||||
|
||||
@Override
|
||||
public void onResultsUpdate(final SearchResult[] results, final long timestamp)
|
||||
{
|
||||
|
@ -80,6 +85,36 @@ public enum SearchEngine implements NativeSearchListener
|
|||
} catch (UnsupportedEncodingException ignored) { }
|
||||
}
|
||||
|
||||
public static String getQuery()
|
||||
{
|
||||
return sSavedQuery;
|
||||
}
|
||||
|
||||
public static void cancelApiCall()
|
||||
{
|
||||
if (ParsedMwmRequest.hasRequest())
|
||||
ParsedMwmRequest.setCurrentRequest(null);
|
||||
Framework.nativeClearApiPoints();
|
||||
}
|
||||
|
||||
public static void cancelSearch()
|
||||
{
|
||||
sSavedQuery = "";
|
||||
nativeCancelInteractiveSearch();
|
||||
}
|
||||
|
||||
public static void showResult(String query, int index)
|
||||
{
|
||||
sSavedQuery = "";
|
||||
nativeShowResult(index);
|
||||
}
|
||||
|
||||
public static void showAllResults(String query)
|
||||
{
|
||||
sSavedQuery = query;
|
||||
nativeShowAllResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bytes utf-8 formatted bytes of query.
|
||||
*/
|
||||
|
@ -90,7 +125,9 @@ public enum SearchEngine implements NativeSearchListener
|
|||
*/
|
||||
private static native void nativeRunInteractiveSearch(byte[] bytes, String language, long timestamp);
|
||||
|
||||
public static native void nativeShowResult(int index);
|
||||
private static native void nativeShowResult(int index);
|
||||
|
||||
public static native void nativeShowAllResults();
|
||||
private static native void nativeShowAllResults();
|
||||
|
||||
public static native void nativeCancelInteractiveSearch();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.support.v4.view.ViewPager;
|
|||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -34,7 +33,6 @@ import com.mapswithme.util.Utils;
|
|||
import com.mapswithme.util.statistics.AlohaHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -97,14 +95,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClearClick()
|
||||
{
|
||||
super.onClearClick();
|
||||
FloatingSearchToolbarController.cancelApiCall();
|
||||
FloatingSearchToolbarController.cancelSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onVoiceInputClick()
|
||||
{
|
||||
|
@ -127,8 +117,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
clear();
|
||||
FloatingSearchToolbarController.cancelSearch();
|
||||
updateFrames();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,9 +353,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
{
|
||||
final String query = getQuery();
|
||||
SearchRecents.add(query);
|
||||
FloatingSearchToolbarController.cancelApiCall();
|
||||
FloatingSearchToolbarController.saveQuery("");
|
||||
SearchEngine.nativeShowResult(resultIndex);
|
||||
SearchEngine.cancelApiCall();
|
||||
SearchEngine.showResult(query, resultIndex);
|
||||
Utils.navigateToParent(getActivity());
|
||||
|
||||
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.SEARCH_KEY_CLICKED);
|
||||
|
@ -378,8 +365,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
final String query = getQuery();
|
||||
mLastQueryTimestamp = System.nanoTime();
|
||||
SearchEngine.runInteractiveSearch(query, Language.getKeyboardLocale(), mLastQueryTimestamp);
|
||||
SearchEngine.nativeShowAllResults();
|
||||
FloatingSearchToolbarController.saveQuery(query);
|
||||
SearchEngine.showAllResults(query);
|
||||
Utils.navigateToParent(getActivity());
|
||||
|
||||
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.SEARCH_ON_MAP_CLICKED);
|
||||
|
@ -400,7 +386,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void onLocationError(int errorCode) {}
|
||||
|
||||
private void stopSearch()
|
||||
private void onSearchEnd()
|
||||
{
|
||||
mSearchRunning = false;
|
||||
mToolbarController.showProgress(false);
|
||||
|
@ -408,6 +394,13 @@ public class SearchFragment extends BaseMwmFragment
|
|||
updateResultsPlaceholder();
|
||||
}
|
||||
|
||||
private void stopSearch()
|
||||
{
|
||||
SearchEngine.cancelApiCall();
|
||||
SearchEngine.cancelSearch();
|
||||
onSearchEnd();
|
||||
}
|
||||
|
||||
private void runSearch()
|
||||
{
|
||||
mLastQueryTimestamp = System.nanoTime();
|
||||
|
@ -445,7 +438,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
public void onResultsEnd(long timestamp)
|
||||
{
|
||||
if (mSearchRunning && isAdded())
|
||||
stopSearch();
|
||||
onSearchEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -470,7 +463,11 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public boolean onBackPressed()
|
||||
{
|
||||
return false;
|
||||
if (!searchActive())
|
||||
return false;
|
||||
|
||||
mToolbarController.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setRecyclerScrollListener(RecyclerView recycler)
|
||||
|
|
Loading…
Add table
Reference in a new issue