From cf7cce69faa66292bb2da644e0057b15e72e2c52 Mon Sep 17 00:00:00 2001 From: Andrei Shkrob Date: Wed, 22 Jan 2025 21:06:28 +0100 Subject: [PATCH] [android][sdk] Search SDK Signed-off-by: Andrei Shkrob --- android/app/src/main/cpp/CMakeLists.txt | 6 +-- .../cpp/app/organicmaps/SearchRecents.cpp | 40 ---------------- .../cpp/app/organicmaps/UserMarkHelper.cpp | 6 +-- .../{ => sdk/search}/DisplayedCategories.cpp | 3 +- .../{ => sdk/search}/SearchEngine.cpp | 38 +++++++-------- .../organicmaps/sdk/search/SearchRecents.cpp | 37 +++++++++++++++ .../java/app/organicmaps/MwmActivity.java | 2 +- .../java/app/organicmaps/MwmApplication.java | 2 +- .../bookmarks/BookmarksListFragment.java | 6 +-- .../organicmaps/bookmarks/data/Bookmark.java | 2 +- .../organicmaps/bookmarks/data/MapObject.java | 2 +- .../car/screens/search/SearchOnMapScreen.java | 10 ++-- .../car/screens/search/SearchScreen.java | 10 ++-- .../car/screens/search/SearchUiHelpers.java | 2 +- .../car/util/SuggestionsHelpers.java | 2 +- .../downloader/DownloaderFragment.java | 12 ++--- .../java/app/organicmaps/intent/Factory.java | 3 +- .../app/organicmaps/maplayer/SearchWheel.java | 2 +- .../search/BookmarkSearchListener.java} | 8 ++-- .../{ => sdk}/search/DisplayedCategories.java | 4 +- .../sdk/search/MapSearchListener.java | 19 ++++++++ .../{ => sdk}/search/Popularity.java | 6 +-- .../{ => sdk}/search/SearchEngine.java | 46 +++++++++---------- .../search/SearchListener.java} | 6 +-- .../{ => sdk}/search/SearchRecents.java | 5 +- .../{ => sdk}/search/SearchResult.java | 4 +- .../organicmaps/search/CategoriesAdapter.java | 15 +++--- .../FloatingSearchToolbarController.java | 3 +- .../search/NativeMapSearchListener.java | 26 ----------- .../app/organicmaps/search/SearchAdapter.java | 5 +- .../organicmaps/search/SearchFragment.java | 6 ++- .../search/SearchHistoryAdapter.java | 1 + .../settings/SettingsPrefsFragment.java | 2 +- 33 files changed, 168 insertions(+), 173 deletions(-) delete mode 100644 android/app/src/main/cpp/app/organicmaps/SearchRecents.cpp rename android/app/src/main/cpp/app/organicmaps/{ => sdk/search}/DisplayedCategories.cpp (75%) rename android/app/src/main/cpp/app/organicmaps/{ => sdk/search}/SearchEngine.cpp (90%) create mode 100644 android/app/src/main/cpp/app/organicmaps/sdk/search/SearchRecents.cpp rename android/app/src/main/java/app/organicmaps/{search/NativeBookmarkSearchListener.java => sdk/search/BookmarkSearchListener.java} (74%) rename android/app/src/main/java/app/organicmaps/{ => sdk}/search/DisplayedCategories.java (72%) create mode 100644 android/app/src/main/java/app/organicmaps/sdk/search/MapSearchListener.java rename android/app/src/main/java/app/organicmaps/{ => sdk}/search/Popularity.java (90%) rename android/app/src/main/java/app/organicmaps/{ => sdk}/search/SearchEngine.java (78%) rename android/app/src/main/java/app/organicmaps/{search/NativeSearchListener.java => sdk/search/SearchListener.java} (82%) rename android/app/src/main/java/app/organicmaps/{ => sdk}/search/SearchRecents.java (94%) rename android/app/src/main/java/app/organicmaps/{ => sdk}/search/SearchResult.java (97%) delete mode 100644 android/app/src/main/java/app/organicmaps/search/NativeMapSearchListener.java diff --git a/android/app/src/main/cpp/CMakeLists.txt b/android/app/src/main/cpp/CMakeLists.txt index 91a173d7b1..25a839155c 100644 --- a/android/app/src/main/cpp/CMakeLists.txt +++ b/android/app/src/main/cpp/CMakeLists.txt @@ -22,11 +22,13 @@ set(SRC app/organicmaps/vulkan/android_vulkan_context_factory.hpp # JNI sources + app/organicmaps/sdk/search/DisplayedCategories.cpp + app/organicmaps/sdk/search/SearchEngine.cpp + app/organicmaps/sdk/search/SearchRecents.cpp app/organicmaps/core/jni_helper.cpp app/organicmaps/core/jni_java_methods.cpp app/organicmaps/core/logging.cpp app/organicmaps/bookmarks/data/BookmarkManager.cpp - app/organicmaps/DisplayedCategories.cpp app/organicmaps/DownloadResourcesLegacyActivity.cpp app/organicmaps/editor/Editor.cpp app/organicmaps/editor/OpeningHours.cpp @@ -38,8 +40,6 @@ set(SRC app/organicmaps/MapManager.cpp app/organicmaps/MwmApplication.cpp app/organicmaps/routing/RoutingOptions.cpp - app/organicmaps/SearchEngine.cpp - app/organicmaps/SearchRecents.cpp app/organicmaps/settings/UnitLocale.cpp app/organicmaps/settings/MapLanguageCode.cpp app/organicmaps/sound/tts.cpp diff --git a/android/app/src/main/cpp/app/organicmaps/SearchRecents.cpp b/android/app/src/main/cpp/app/organicmaps/SearchRecents.cpp deleted file mode 100644 index 9d5e9f818a..0000000000 --- a/android/app/src/main/cpp/app/organicmaps/SearchRecents.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "Framework.hpp" - -#include "search/result.hpp" - -#include "app/organicmaps/core/jni_helper.hpp" -#include "app/organicmaps/core/jni_java_methods.hpp" - -using SearchRequest = search::QuerySaver::SearchRequest; - -extern "C" -{ - JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchRecents_nativeGetList(JNIEnv * env, jclass thiz, jobject result) - { - auto const & items = g_framework->NativeFramework()->GetSearchAPI().GetLastSearchQueries(); - if (items.empty()) - return; - - auto const listAddMethod = jni::ListBuilder::Instance(env).m_add; - - for (SearchRequest const & item : items) - { - jni::TScopedLocalRef str(env, jni::ToJavaString(env, item.second)); - env->CallBooleanMethod(result, listAddMethod, str.get()); - } - } - - JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchRecents_nativeAdd(JNIEnv * env, jclass thiz, jstring locale, jstring query) - { - SearchRequest const sr(jni::ToNativeString(env, locale), jni::ToNativeString(env, query)); - g_framework->NativeFramework()->GetSearchAPI().SaveSearchQuery(sr); - } - - JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchRecents_nativeClear(JNIEnv * env, jclass thiz) - { - g_framework->NativeFramework()->GetSearchAPI().ClearSearchHistory(); - } -} diff --git a/android/app/src/main/cpp/app/organicmaps/UserMarkHelper.cpp b/android/app/src/main/cpp/app/organicmaps/UserMarkHelper.cpp index 7c4dc611b9..637352fd60 100644 --- a/android/app/src/main/cpp/app/organicmaps/UserMarkHelper.cpp +++ b/android/app/src/main/cpp/app/organicmaps/UserMarkHelper.cpp @@ -28,7 +28,7 @@ void InjectMetadata(JNIEnv * env, jclass const clazz, jobject const mapObject, o //jobject CreatePopularity(JNIEnv * env, place_page::Info const & info) //{ // static jclass const popularityClass = -// jni::GetGlobalClassRef(env, "app/organicmaps/search/Popularity"); +// jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/Popularity"); // static jmethodID const popularityConstructor = // jni::GetConstructorID(env, popularityClass, "(I)V"); // auto const popularityValue = info.GetPopularity(); @@ -57,7 +57,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info, int mapObje "Ljava/lang/String;" // appId "Lapp/organicmaps/routing/RoutePointInfo;" // routePointInfo "I" // openingMode - "Lapp/organicmaps/search/Popularity;" // popularity + "Lapp/organicmaps/sdk/search/Popularity;" // popularity "Ljava/lang/String;" // description "I" // roadWarnType "[Ljava/lang/String;" // rawTypes @@ -105,7 +105,7 @@ jobject CreateBookmark(JNIEnv *env, const place_page::Info &info, "(Lapp/organicmaps/bookmarks/data/FeatureId;JJLjava/lang/String;" "Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;" "Lapp/organicmaps/routing/RoutePointInfo;" - "ILapp/organicmaps/search/Popularity;Ljava/lang/String;" + "ILapp/organicmaps/sdk/search/Popularity;Ljava/lang/String;" "[Ljava/lang/String;)V"); static jmethodID const featureCtorId = jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V"); diff --git a/android/app/src/main/cpp/app/organicmaps/DisplayedCategories.cpp b/android/app/src/main/cpp/app/organicmaps/sdk/search/DisplayedCategories.cpp similarity index 75% rename from android/app/src/main/cpp/app/organicmaps/DisplayedCategories.cpp rename to android/app/src/main/cpp/app/organicmaps/sdk/search/DisplayedCategories.cpp index 3fc3674401..1e05eaa6a3 100644 --- a/android/app/src/main/cpp/app/organicmaps/DisplayedCategories.cpp +++ b/android/app/src/main/cpp/app/organicmaps/sdk/search/DisplayedCategories.cpp @@ -5,8 +5,7 @@ extern "C" { -JNIEXPORT jobjectArray JNICALL -Java_app_organicmaps_search_DisplayedCategories_nativeGetKeys(JNIEnv * env, jclass clazz) +JNIEXPORT jobjectArray JNICALL Java_app_organicmaps_sdk_search_DisplayedCategories_nativeGetKeys(JNIEnv * env, jclass) { ::Framework * fr = g_framework->NativeFramework(); ASSERT(fr, ()); diff --git a/android/app/src/main/cpp/app/organicmaps/SearchEngine.cpp b/android/app/src/main/cpp/app/organicmaps/sdk/search/SearchEngine.cpp similarity index 90% rename from android/app/src/main/cpp/app/organicmaps/SearchEngine.cpp rename to android/app/src/main/cpp/app/organicmaps/sdk/search/SearchEngine.cpp index 90fc262910..afc5420a7e 100644 --- a/android/app/src/main/cpp/app/organicmaps/SearchEngine.cpp +++ b/android/app/src/main/cpp/app/organicmaps/sdk/search/SearchEngine.cpp @@ -39,7 +39,7 @@ Results g_results; // Timestamp of last search query. Results with older stamps are ignored. jlong g_queryTimestamp; -// Implements 'NativeSearchListener' java interface. +// Implements 'SearchListener' java interface. jobject g_javaListener; jmethodID g_updateResultsId; jmethodID g_endResultsId; @@ -52,7 +52,7 @@ jmethodID g_descriptionConstructor; jclass g_popularityClass; jmethodID g_popularityConstructor; -// Implements 'NativeMapSearchListener' java interface. +// Implements 'MapSearchListener' java interface. jmethodID g_mapResultsMethod; jclass g_mapResultClass; jmethodID g_mapResultCtor; @@ -232,21 +232,21 @@ void OnBookmarksSearchResults(search::BookmarksSearchParams::Results results, extern "C" { JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchEngine_nativeInit(JNIEnv * env, jobject thiz) + Java_app_organicmaps_sdk_search_SearchEngine_nativeInit(JNIEnv * env, jobject thiz) { g_javaListener = env->NewGlobalRef(thiz); // public void onResultsUpdate(@NonNull SearchResult[] results, long timestamp) g_updateResultsId = jni::GetMethodID(env, g_javaListener, "onResultsUpdate", - "([Lapp/organicmaps/search/SearchResult;J)V"); + "([Lapp/organicmaps/sdk/search/SearchResult;J)V"); // public void onResultsEnd(long timestamp) g_endResultsId = jni::GetMethodID(env, g_javaListener, "onResultsEnd", "(J)V"); - g_resultClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/SearchResult"); + g_resultClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/SearchResult"); g_resultConstructor = jni::GetConstructorID( env, g_resultClass, - "(Ljava/lang/String;Lapp/organicmaps/search/SearchResult$Description;DD[I[I" - "Lapp/organicmaps/search/Popularity;)V"); + "(Ljava/lang/String;Lapp/organicmaps/sdk/search/SearchResult$Description;DD[I[I" + "Lapp/organicmaps/sdk/search/Popularity;)V"); g_suggestConstructor = jni::GetConstructorID(env, g_resultClass, "(Ljava/lang/String;Ljava/lang/String;DD[I[I)V"); - g_descriptionClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/SearchResult$Description"); + g_descriptionClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/SearchResult$Description"); /* Description(FeatureId featureId, String featureType, String region, Distance distance, String description, int openNow, int minutesUntilOpen, int minutesUntilClosed, @@ -257,12 +257,12 @@ extern "C" "Ljava/lang/String;Ljava/lang/String;Lapp/organicmaps/util/Distance;" "Ljava/lang/String;IIIZ)V"); - g_popularityClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/Popularity"); + g_popularityClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/Popularity"); g_popularityConstructor = jni::GetConstructorID(env, g_popularityClass, "(I)V"); g_mapResultsMethod = jni::GetMethodID(env, g_javaListener, "onMapSearchResults", - "([Lapp/organicmaps/search/NativeMapSearchListener$Result;JZ)V"); - g_mapResultClass = jni::GetGlobalClassRef(env, "app/organicmaps/search/NativeMapSearchListener$Result"); + "([Lapp/organicmaps/sdk/search/MapSearchListener$Result;JZ)V"); + g_mapResultClass = jni::GetGlobalClassRef(env, "app/organicmaps/sdk/search/MapSearchListener$Result"); g_mapResultCtor = jni::GetConstructorID(env, g_mapResultClass, "(Ljava/lang/String;Ljava/lang/String;)V"); g_updateBookmarksResultsId = @@ -271,7 +271,7 @@ extern "C" jni::GetMethodID(env, g_javaListener, "onBookmarkSearchResultsEnd", "([JJ)V"); } - JNIEXPORT jboolean JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearch( + JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearch( JNIEnv * env, jclass clazz, jbyteArray bytes, jboolean isCategory, jstring lang, jlong timestamp, jboolean hasPosition, jdouble lat, jdouble lon) { @@ -288,7 +288,7 @@ extern "C" return searchStarted; } - JNIEXPORT void JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunInteractiveSearch( + JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunInteractiveSearch( JNIEnv * env, jclass clazz, jbyteArray bytes, jboolean isCategory, jstring lang, jlong timestamp, jboolean isMapAndTable, jboolean hasPosition, jdouble lat, jdouble lon) { @@ -321,7 +321,7 @@ extern "C" } } - JNIEXPORT void JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearchMaps( + JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearchMaps( JNIEnv * env, jclass clazz, jbyteArray bytes, jstring lang, jlong timestamp) { storage::DownloaderSearchParams params{ @@ -334,7 +334,7 @@ extern "C" g_queryTimestamp = timestamp; } - JNIEXPORT jboolean JNICALL Java_app_organicmaps_search_SearchEngine_nativeRunSearchInBookmarks( + JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_search_SearchEngine_nativeRunSearchInBookmarks( JNIEnv * env, jclass clazz, jbyteArray query, jlong catId, jlong timestamp) { search::BookmarksSearchParams params{ @@ -350,25 +350,25 @@ extern "C" } JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchEngine_nativeShowResult(JNIEnv * env, jclass clazz, jint index) + Java_app_organicmaps_sdk_search_SearchEngine_nativeShowResult(JNIEnv * env, jclass clazz, jint index) { g_framework->NativeFramework()->ShowSearchResult(g_results[index]); } JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchEngine_nativeCancelInteractiveSearch(JNIEnv * env, jclass clazz) + Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelInteractiveSearch(JNIEnv * env, jclass clazz) { g_framework->NativeFramework()->GetSearchAPI().CancelSearch(search::Mode::Viewport); } JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchEngine_nativeCancelEverywhereSearch(JNIEnv * env, jclass clazz) + Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelEverywhereSearch(JNIEnv * env, jclass clazz) { g_framework->NativeFramework()->GetSearchAPI().CancelSearch(search::Mode::Everywhere); } JNIEXPORT void JNICALL - Java_app_organicmaps_search_SearchEngine_nativeCancelAllSearches(JNIEnv * env, jclass clazz) + Java_app_organicmaps_sdk_search_SearchEngine_nativeCancelAllSearches(JNIEnv * env, jclass clazz) { g_framework->NativeFramework()->GetSearchAPI().CancelAllSearches(); } diff --git a/android/app/src/main/cpp/app/organicmaps/sdk/search/SearchRecents.cpp b/android/app/src/main/cpp/app/organicmaps/sdk/search/SearchRecents.cpp new file mode 100644 index 0000000000..303303c152 --- /dev/null +++ b/android/app/src/main/cpp/app/organicmaps/sdk/search/SearchRecents.cpp @@ -0,0 +1,37 @@ +#include "app/organicmaps/Framework.hpp" +#include "app/organicmaps/core/jni_helper.hpp" +#include "app/organicmaps/core/jni_java_methods.hpp" + +#include "search/result.hpp" + +using SearchRequest = search::QuerySaver::SearchRequest; + +extern "C" +{ +JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeGetList(JNIEnv * env, jclass, jobject result) +{ + auto const & items = g_framework->NativeFramework()->GetSearchAPI().GetLastSearchQueries(); + if (items.empty()) + return; + + auto const listAddMethod = jni::ListBuilder::Instance(env).m_add; + + for (SearchRequest const & item : items) + { + jni::TScopedLocalRef str(env, jni::ToJavaString(env, item.second)); + env->CallBooleanMethod(result, listAddMethod, str.get()); + } +} + +JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeAdd(JNIEnv * env, jclass, jstring locale, + jstring query) +{ + SearchRequest const sr(jni::ToNativeString(env, locale), jni::ToNativeString(env, query)); + g_framework->NativeFramework()->GetSearchAPI().SaveSearchQuery(sr); +} + +JNIEXPORT void JNICALL Java_app_organicmaps_sdk_search_SearchRecents_nativeClear(JNIEnv * env, jclass) +{ + g_framework->NativeFramework()->GetSearchAPI().ClearSearchHistory(); +} +} diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index 416f528e24..ac3f498b48 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -89,7 +89,7 @@ import app.organicmaps.routing.RoutingPlanFragment; import app.organicmaps.routing.RoutingPlanInplaceController; import app.organicmaps.search.FloatingSearchToolbarController; import app.organicmaps.search.SearchActivity; -import app.organicmaps.search.SearchEngine; +import app.organicmaps.sdk.search.SearchEngine; import app.organicmaps.search.SearchFragment; import app.organicmaps.settings.DrivingOptionsActivity; import app.organicmaps.settings.RoadType; diff --git a/android/app/src/main/java/app/organicmaps/MwmApplication.java b/android/app/src/main/java/app/organicmaps/MwmApplication.java index 7170508325..fc06fdb9fe 100644 --- a/android/app/src/main/java/app/organicmaps/MwmApplication.java +++ b/android/app/src/main/java/app/organicmaps/MwmApplication.java @@ -34,7 +34,7 @@ import app.organicmaps.maplayer.subway.SubwayManager; import app.organicmaps.maplayer.traffic.TrafficManager; import app.organicmaps.routing.NavigationService; import app.organicmaps.routing.RoutingController; -import app.organicmaps.search.SearchEngine; +import app.organicmaps.sdk.search.SearchEngine; import app.organicmaps.settings.StoragePathManager; import app.organicmaps.sound.TtsPlayer; import app.organicmaps.util.Config; diff --git a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java index 7a59c0a7fe..fc71ce8fd4 100644 --- a/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java +++ b/android/app/src/main/java/app/organicmaps/bookmarks/BookmarksListFragment.java @@ -39,8 +39,8 @@ import app.organicmaps.bookmarks.data.KmlFileType; import app.organicmaps.bookmarks.data.SortedBlock; import app.organicmaps.bookmarks.data.Track; import app.organicmaps.location.LocationHelper; -import app.organicmaps.search.NativeBookmarkSearchListener; -import app.organicmaps.search.SearchEngine; +import app.organicmaps.sdk.search.BookmarkSearchListener; +import app.organicmaps.sdk.search.SearchEngine; import app.organicmaps.util.Graphics; import app.organicmaps.util.SharingUtils; import app.organicmaps.util.UiUtils; @@ -62,7 +62,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment rs = new ArrayList<>(); for (Result result : results) { - CountryItem item = CountryItem.fill(result.countryId); - item.searchResultName = result.matchedString; + CountryItem item = CountryItem.fill(result.countryId()); + item.searchResultName = result.matchedString(); rs.add(item); } diff --git a/android/app/src/main/java/app/organicmaps/intent/Factory.java b/android/app/src/main/java/app/organicmaps/intent/Factory.java index d8c213602c..0fd3c867e9 100644 --- a/android/app/src/main/java/app/organicmaps/intent/Factory.java +++ b/android/app/src/main/java/app/organicmaps/intent/Factory.java @@ -3,7 +3,6 @@ package app.organicmaps.intent; import android.content.ContentResolver; import android.content.Intent; import android.net.Uri; -import android.util.Log; import androidx.annotation.NonNull; import androidx.core.content.IntentCompat; @@ -22,7 +21,7 @@ import app.organicmaps.bookmarks.data.MapObject; import app.organicmaps.editor.OsmLoginActivity; import app.organicmaps.routing.RoutingController; import app.organicmaps.search.SearchActivity; -import app.organicmaps.search.SearchEngine; +import app.organicmaps.sdk.search.SearchEngine; import app.organicmaps.util.StorageUtils; import app.organicmaps.util.concurrency.ThreadPool; diff --git a/android/app/src/main/java/app/organicmaps/maplayer/SearchWheel.java b/android/app/src/main/java/app/organicmaps/maplayer/SearchWheel.java index 81a9968ee2..077534ab84 100644 --- a/android/app/src/main/java/app/organicmaps/maplayer/SearchWheel.java +++ b/android/app/src/main/java/app/organicmaps/maplayer/SearchWheel.java @@ -16,7 +16,7 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import app.organicmaps.R; import app.organicmaps.routing.RoutingController; -import app.organicmaps.search.SearchEngine; +import app.organicmaps.sdk.search.SearchEngine; import app.organicmaps.util.Graphics; import app.organicmaps.util.UiUtils; import app.organicmaps.util.concurrency.UiThread; diff --git a/android/app/src/main/java/app/organicmaps/search/NativeBookmarkSearchListener.java b/android/app/src/main/java/app/organicmaps/sdk/search/BookmarkSearchListener.java similarity index 74% rename from android/app/src/main/java/app/organicmaps/search/NativeBookmarkSearchListener.java rename to android/app/src/main/java/app/organicmaps/sdk/search/BookmarkSearchListener.java index 8db93d4be8..1595e56a4a 100644 --- a/android/app/src/main/java/app/organicmaps/search/NativeBookmarkSearchListener.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/BookmarkSearchListener.java @@ -1,4 +1,4 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import androidx.annotation.Keep; import androidx.annotation.Nullable; @@ -6,11 +6,11 @@ import androidx.annotation.Nullable; /** * Native search will return results via this interface. */ -public interface NativeBookmarkSearchListener +public interface BookmarkSearchListener { /** * @param bookmarkIds Founded bookmark ids. - * @param timestamp Timestamp of search request. + * @param timestamp Timestamp of search request. */ // Used by JNI. @Keep @@ -19,7 +19,7 @@ public interface NativeBookmarkSearchListener /** * @param bookmarkIds Founded bookmark ids. - * @param timestamp Timestamp of search request. + * @param timestamp Timestamp of search request. */ // Used by JNI. @Keep diff --git a/android/app/src/main/java/app/organicmaps/search/DisplayedCategories.java b/android/app/src/main/java/app/organicmaps/sdk/search/DisplayedCategories.java similarity index 72% rename from android/app/src/main/java/app/organicmaps/search/DisplayedCategories.java rename to android/app/src/main/java/app/organicmaps/sdk/search/DisplayedCategories.java index f9080862ff..2ad6b74656 100644 --- a/android/app/src/main/java/app/organicmaps/search/DisplayedCategories.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/DisplayedCategories.java @@ -1,8 +1,8 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import androidx.annotation.NonNull; -class DisplayedCategories +public class DisplayedCategories { @NonNull public static String[] getKeys() diff --git a/android/app/src/main/java/app/organicmaps/sdk/search/MapSearchListener.java b/android/app/src/main/java/app/organicmaps/sdk/search/MapSearchListener.java new file mode 100644 index 0000000000..df0bb8aa69 --- /dev/null +++ b/android/app/src/main/java/app/organicmaps/sdk/search/MapSearchListener.java @@ -0,0 +1,19 @@ +package app.organicmaps.sdk.search; + +import androidx.annotation.Keep; +import androidx.annotation.NonNull; + +public interface MapSearchListener +{ + // Called from JNI. + @Keep + @SuppressWarnings("unused") + record Result(String countryId, String matchedString) + { + } + + // Called from JNI. + @Keep + @SuppressWarnings("unused") + void onMapSearchResults(@NonNull Result[] results, long timestamp, boolean isLast); +} diff --git a/android/app/src/main/java/app/organicmaps/search/Popularity.java b/android/app/src/main/java/app/organicmaps/sdk/search/Popularity.java similarity index 90% rename from android/app/src/main/java/app/organicmaps/search/Popularity.java rename to android/app/src/main/java/app/organicmaps/sdk/search/Popularity.java index cf2f196c47..0c64bf813e 100644 --- a/android/app/src/main/java/app/organicmaps/search/Popularity.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/Popularity.java @@ -1,4 +1,4 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import android.os.Parcel; import android.os.Parcelable; @@ -38,12 +38,12 @@ public class Popularity implements Parcelable } @Override - public void writeToParcel(Parcel dest, int flags) + public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(this.mType.ordinal()); } - protected Popularity(Parcel in) + protected Popularity(@NonNull Parcel in) { int tmpMPopularity = in.readInt(); this.mType = Type.values()[tmpMPopularity]; diff --git a/android/app/src/main/java/app/organicmaps/search/SearchEngine.java b/android/app/src/main/java/app/organicmaps/sdk/search/SearchEngine.java similarity index 78% rename from android/app/src/main/java/app/organicmaps/search/SearchEngine.java rename to android/app/src/main/java/app/organicmaps/sdk/search/SearchEngine.java index dd899e627b..582e5a2cad 100644 --- a/android/app/src/main/java/app/organicmaps/search/SearchEngine.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/SearchEngine.java @@ -1,4 +1,4 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import android.content.Context; @@ -14,9 +14,9 @@ import app.organicmaps.util.concurrency.UiThread; import java.nio.charset.StandardCharsets; -public enum SearchEngine implements NativeSearchListener, - NativeMapSearchListener, - NativeBookmarkSearchListener +public enum SearchEngine implements SearchListener, + MapSearchListener, + BookmarkSearchListener { INSTANCE; @@ -30,7 +30,7 @@ public enum SearchEngine implements NativeSearchListener, UiThread.run( () -> { - for (NativeSearchListener listener : mListeners) + for (SearchListener listener : mListeners) listener.onResultsUpdate(results, timestamp); }); } @@ -41,18 +41,18 @@ public enum SearchEngine implements NativeSearchListener, UiThread.run( () -> { - for (NativeSearchListener listener : mListeners) + for (SearchListener listener : mListeners) listener.onResultsEnd(timestamp); }); } @Override - public void onMapSearchResults(final NativeMapSearchListener.Result[] results, final long timestamp, final boolean isLast) + public void onMapSearchResults(@NonNull final MapSearchListener.Result[] results, final long timestamp, final boolean isLast) { UiThread.run( () -> { - for (NativeMapSearchListener listener : mMapListeners) + for (MapSearchListener listener : mMapListeners) listener.onMapSearchResults(results, timestamp, isLast); }); } @@ -60,55 +60,53 @@ public enum SearchEngine implements NativeSearchListener, @Override public void onBookmarkSearchResultsUpdate(@Nullable long[] bookmarkIds, long timestamp) { - for (NativeBookmarkSearchListener listener : mBookmarkListeners) + for (BookmarkSearchListener listener : mBookmarkListeners) listener.onBookmarkSearchResultsUpdate(bookmarkIds, timestamp); } @Override public void onBookmarkSearchResultsEnd(@Nullable long[] bookmarkIds, long timestamp) { - for (NativeBookmarkSearchListener listener : mBookmarkListeners) + for (BookmarkSearchListener listener : mBookmarkListeners) listener.onBookmarkSearchResultsEnd(bookmarkIds, timestamp); } - private final ObserverList mListeners = new ObserverList<>(); + private final ObserverList mListeners = new ObserverList<>(); - private final ObserverList mMapListeners = new ObserverList<>(); + private final ObserverList mMapListeners = new ObserverList<>(); - private final ObserverList mBookmarkListeners = new ObserverList<>(); + private final ObserverList mBookmarkListeners = new ObserverList<>(); - public void addListener(NativeSearchListener listener) + public void addListener(SearchListener listener) { mListeners.addObserver(listener); } - public void removeListener(NativeSearchListener listener) + public void removeListener(SearchListener listener) { mListeners.removeObserver(listener); } - public void addMapListener(NativeMapSearchListener listener) + public void addMapListener(MapSearchListener listener) { mMapListeners.addObserver(listener); } - public void removeMapListener(NativeMapSearchListener listener) + public void removeMapListener(MapSearchListener listener) { mMapListeners.removeObserver(listener); } - public void addBookmarkListener(NativeBookmarkSearchListener listener) + public void addBookmarkListener(BookmarkSearchListener listener) { mBookmarkListeners.addObserver(listener); } - public void removeBookmarkListener(NativeBookmarkSearchListener listener) + public void removeBookmarkListener(BookmarkSearchListener listener) { mBookmarkListeners.removeObserver(listener); } - private native void nativeInit(); - /** * * @param context @@ -116,7 +114,7 @@ public enum SearchEngine implements NativeSearchListener, * @return whether search was actually started. */ @MainThread - public boolean search(@NonNull Context context, String query, boolean isCategory, + public boolean search(@NonNull Context context, @NonNull String query, boolean isCategory, long timestamp, boolean hasLocation, double lat, double lon) { return nativeRunSearch(query.getBytes(StandardCharsets.UTF_8), isCategory, @@ -146,7 +144,7 @@ public enum SearchEngine implements NativeSearchListener, } @MainThread - public static void searchMaps(@NonNull Context context, String query, long timestamp) + public static void searchMaps(@NonNull Context context, @NonNull String query, long timestamp) { nativeRunSearchMaps(query.getBytes(StandardCharsets.UTF_8), Language.getKeyboardLocale(context), timestamp); @@ -208,6 +206,8 @@ public enum SearchEngine implements NativeSearchListener, nativeInit(); } + private native void nativeInit(); + /** * @param bytes utf-8 formatted bytes of query. */ diff --git a/android/app/src/main/java/app/organicmaps/search/NativeSearchListener.java b/android/app/src/main/java/app/organicmaps/sdk/search/SearchListener.java similarity index 82% rename from android/app/src/main/java/app/organicmaps/search/NativeSearchListener.java rename to android/app/src/main/java/app/organicmaps/sdk/search/SearchListener.java index f427306828..171ce99753 100644 --- a/android/app/src/main/java/app/organicmaps/search/NativeSearchListener.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/SearchListener.java @@ -1,4 +1,4 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import androidx.annotation.Keep; import androidx.annotation.NonNull; @@ -6,10 +6,10 @@ import androidx.annotation.NonNull; /** * Native search will return results via this interface. */ -public interface NativeSearchListener +public interface SearchListener { /** - * @param results Search results. + * @param results Search results. * @param timestamp Timestamp of search request. */ // Called by JNI. diff --git a/android/app/src/main/java/app/organicmaps/search/SearchRecents.java b/android/app/src/main/java/app/organicmaps/sdk/search/SearchRecents.java similarity index 94% rename from android/app/src/main/java/app/organicmaps/search/SearchRecents.java rename to android/app/src/main/java/app/organicmaps/sdk/search/SearchRecents.java index 54029e8683..e11e528e76 100644 --- a/android/app/src/main/java/app/organicmaps/search/SearchRecents.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/SearchRecents.java @@ -1,8 +1,7 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import android.content.Context; import android.text.TextUtils; -import android.util.Pair; import androidx.annotation.NonNull; @@ -50,6 +49,8 @@ public final class SearchRecents } private static native void nativeGetList(List result); + private static native void nativeAdd(String locale, String query); + private static native void nativeClear(); } diff --git a/android/app/src/main/java/app/organicmaps/search/SearchResult.java b/android/app/src/main/java/app/organicmaps/sdk/search/SearchResult.java similarity index 97% rename from android/app/src/main/java/app/organicmaps/search/SearchResult.java rename to android/app/src/main/java/app/organicmaps/sdk/search/SearchResult.java index f903188ece..2fdcf6861a 100644 --- a/android/app/src/main/java/app/organicmaps/search/SearchResult.java +++ b/android/app/src/main/java/app/organicmaps/sdk/search/SearchResult.java @@ -1,4 +1,4 @@ -package app.organicmaps.search; +package app.organicmaps.sdk.search; import android.content.Context; import android.graphics.Typeface; @@ -32,7 +32,7 @@ public class SearchResult public static final int OPEN_NOW_NO = 2; public static final SearchResult EMPTY = new SearchResult("", "", 0, 0, - new int[] {}, new int[] {}); + new int[]{}, new int[]{}); // Used by JNI. @Keep diff --git a/android/app/src/main/java/app/organicmaps/search/CategoriesAdapter.java b/android/app/src/main/java/app/organicmaps/search/CategoriesAdapter.java index ea8bf7504b..2fecc13de3 100644 --- a/android/app/src/main/java/app/organicmaps/search/CategoriesAdapter.java +++ b/android/app/src/main/java/app/organicmaps/search/CategoriesAdapter.java @@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; import app.organicmaps.R; +import app.organicmaps.sdk.search.DisplayedCategories; import app.organicmaps.util.ThemeUtils; import java.lang.annotation.Retention; @@ -26,9 +27,10 @@ import java.lang.annotation.RetentionPolicy; class CategoriesAdapter extends RecyclerView.Adapter { @Retention(RetentionPolicy.SOURCE) - @IntDef({ TYPE_CATEGORY }) - @interface ViewType {} - private static final int TYPE_CATEGORY = 0; + @IntDef({ ViewType.CATEGORY }) + @interface ViewType { + int CATEGORY = 0; + } @StringRes private int[] mCategoryResIds; @@ -121,15 +123,16 @@ class CategoriesAdapter extends RecyclerView.Adapter