diff --git a/android/jni/com/mapswithme/maps/SearchFragment.cpp b/android/jni/com/mapswithme/maps/SearchFragment.cpp index dff1d9d6d4..63dfe9adc1 100644 --- a/android/jni/com/mapswithme/maps/SearchFragment.cpp +++ b/android/jni/com/mapswithme/maps/SearchFragment.cpp @@ -29,10 +29,18 @@ class SearchAdapter void OnResults(search::Results const & res, int queryID) { + if (m_fragment == 0) + { + // In case when fragment is destroyed, but search thread passed any results. + return; + } + + JNIEnv * env = jni::GetEnv(); + if (res.IsEndMarker()) { - /// @todo Process end markers for Android in future. - /// It's not so necessary now because we store search ID's. + jmethodID const methodId = jni::GetJavaMethodID(env, m_fragment, "endData", "()V"); + env->CallVoidMethod(m_fragment, methodId); return; } @@ -41,12 +49,6 @@ class SearchAdapter { threads::MutexGuard guard(m_updateMutex); - if (m_fragment == 0) - { - // In case when fragment is destroyed, but search thread passed any results. - return; - } - // store current results m_storeResults = res; @@ -63,9 +65,6 @@ class SearchAdapter } } - // get new environment pointer here because of different thread - JNIEnv * env = jni::GetEnv(); - // post message to update ListView in UI thread jmethodID const id = jni::GetJavaMethodID(env, m_fragment, "updateData", "(II)V"); env->CallVoidMethod(m_fragment, id, diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 342ca15917..0fe54aef6b 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -6,6 +6,7 @@ import android.location.Location; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -353,9 +354,6 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL if (!isAdded()) return; - if (isCurrentResult(resultId)) - displaySearchProgress(false); - if (!doShowCategories()) { mAdapter.updateData(count, resultId); @@ -366,6 +364,23 @@ public class SearchFragment extends BaseMwmListFragment implements View.OnClickL }); } + // Called from native code + @SuppressWarnings("unused") + public void endData() + { + getActivity().runOnUiThread(new Runnable() + { + @Override + public void run() + { + if (!isAdded()) + return; + + displaySearchProgress(false); + } + }); + } + private void setSearchQuery(String query) { Utils.setTextAndCursorToEnd(mEtSearchQuery, query);