Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(offline): offline support for user records #288

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MapboxSearch/gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ext {
common_sdk_version = '24.7.0-beta.1'
mapbox_base_version = '0.8.0'

search_native_version = '2.5.0-beta.1'
search_native_version = '2.4.0-feat_offline_user_record_searching-SNAPSHOT'

detekt_version = '1.19.0'

Expand Down
1 change: 1 addition & 0 deletions MapboxSearch/offline/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ android {
dependencies {
implementation project(path: ':base')
api project(path: ':sdk-common')
api project(path: ':sdk')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.mapbox.common.TileStoreOptions
import com.mapbox.common.TilesetDescriptor
import com.mapbox.geojson.Feature
import com.mapbox.geojson.Point
import com.mapbox.search.IndexableDataProviderManager
import com.mapbox.search.MapboxSearchSdk
import com.mapbox.search.base.BaseSearchSdkInitializerImpl
import com.mapbox.search.base.SearchRequestContextProvider
import com.mapbox.search.base.core.CoreApiType
Expand All @@ -15,8 +17,6 @@ import com.mapbox.search.base.core.CoreSearchEngine
import com.mapbox.search.base.core.getUserActivityReporter
import com.mapbox.search.base.location.LocationEngineAdapter
import com.mapbox.search.base.location.WrapperLocationProvider
import com.mapbox.search.base.record.IndexableRecordResolver
import com.mapbox.search.base.result.SearchResultFactory
import com.mapbox.search.base.utils.AndroidKeyboardLocaleProvider
import com.mapbox.search.base.utils.UserAgentProvider
import com.mapbox.search.base.utils.orientation.AndroidScreenOrientationProvider
Expand All @@ -31,7 +31,7 @@ import java.util.concurrent.Executor
* The API of this class is temporary and subject to change.
* Tiles loading functionality is available to selected customers only. Contact our team, to get early preview.
*/
public interface OfflineSearchEngine {
public interface OfflineSearchEngine : IndexableDataProviderManager {

/**
* Interface definition for a callback to be invoked when the [OfflineSearchEngine] is ready for use.
Expand Down Expand Up @@ -383,14 +383,15 @@ public interface OfflineSearchEngine {
AndroidScreenOrientationProvider(app)
)

val searchResultFactory = SearchResultFactory(IndexableRecordResolver.EMPTY)
val searchResultFactory = MapboxSearchSdk.searchResultFactory

return OfflineSearchEngineImpl(
settings = settings,
coreEngine = coreEngine,
activityReporter = getUserActivityReporter(),
requestContextProvider = requestContextProvider,
searchResultFactory = searchResultFactory,
indexableDataProvidersRegistry = MapboxSearchSdk.indexableDataProvidersRegistry
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mapbox.geojson.BoundingBox
import com.mapbox.geojson.Feature
import com.mapbox.geojson.LineString
import com.mapbox.geojson.Point
import com.mapbox.search.IndexableDataProvidersRegistry
import com.mapbox.search.base.BaseSearchSdkInitializerImpl
import com.mapbox.search.base.SearchRequestContextProvider
import com.mapbox.search.base.core.CoreApiType
Expand All @@ -16,11 +17,14 @@ import com.mapbox.search.base.logger.logd
import com.mapbox.search.base.result.SearchResultFactory
import com.mapbox.search.base.task.AsyncOperationTaskImpl
import com.mapbox.search.common.AsyncOperationTask
import com.mapbox.search.common.CompletionCallback
import com.mapbox.search.internal.bindgen.OfflineIndexChangeEvent
import com.mapbox.search.internal.bindgen.OfflineIndexError
import com.mapbox.search.internal.bindgen.UserActivityReporterInterface
import com.mapbox.search.offline.OfflineSearchEngine.EngineReadyCallback
import com.mapbox.search.offline.OfflineSearchEngine.OnIndexChangeListener
import com.mapbox.search.record.IndexableDataProvider
import com.mapbox.search.record.IndexableRecord
import com.mapbox.turf.TurfMeasurement
import com.mapbox.turf.TurfMisc
import java.util.concurrent.Executor
Expand All @@ -34,6 +38,7 @@ internal class OfflineSearchEngineImpl(
private val requestContextProvider: SearchRequestContextProvider,
private val searchResultFactory: SearchResultFactory,
private val engineExecutorService: ExecutorService = DEFAULT_EXECUTOR,
private val indexableDataProvidersRegistry: IndexableDataProvidersRegistry,
) : BaseSearchEngine(), OfflineSearchEngine {

private val initializationLock = Any()
Expand Down Expand Up @@ -256,6 +261,32 @@ internal class OfflineSearchEngineImpl(
}
}

override fun <R : IndexableRecord> registerDataProvider(
dataProvider: IndexableDataProvider<R>,
executor: Executor,
callback: CompletionCallback<Unit>
): AsyncOperationTask {
return indexableDataProvidersRegistry.register(
dataProvider = dataProvider,
searchEngine = coreEngine,
executor = executor,
callback = callback,
)
}

override fun <R : IndexableRecord> unregisterDataProvider(
dataProvider: IndexableDataProvider<R>,
executor: Executor,
callback: CompletionCallback<Unit>
): AsyncOperationTask {
return indexableDataProvidersRegistry.unregister(
dataProvider = dataProvider,
searchEngine = coreEngine,
executor = executor,
callback = callback,
)
}

private fun bufferBoundingBox(coords: DoubleArray, percentage: Double = 5.0): DoubleArray {
var minLon = coords[0]
var minLat = coords[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum class OfflineSearchResultType {
* Individual residential or business addresses.
*/
ADDRESS,

USER_RECORD,
}

@JvmSynthetic
Expand All @@ -31,6 +33,7 @@ internal fun BaseRawResultType.tryMapToOfflineSdkType(): OfflineSearchResultType
BaseRawResultType.PLACE -> OfflineSearchResultType.PLACE
BaseRawResultType.STREET -> OfflineSearchResultType.STREET
BaseRawResultType.ADDRESS -> OfflineSearchResultType.ADDRESS
BaseRawResultType.USER_RECORD -> OfflineSearchResultType.USER_RECORD
else -> null
}
}
Loading