增加realm 在离线地图中的使用
This commit is contained in:
@@ -6,11 +6,13 @@ import com.google.gson.Gson
|
||||
import com.navinfo.omqs.Constant
|
||||
import com.navinfo.omqs.OMQSApplication
|
||||
import com.navinfo.omqs.http.RetrofitNetworkServiceAPI
|
||||
import com.navinfo.omqs.tools.RealmCoroutineScope
|
||||
import dagger.Lazy
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.*
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
@@ -25,11 +27,11 @@ import javax.inject.Singleton
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class GlobalModule {
|
||||
|
||||
// @Singleton
|
||||
// @Provides
|
||||
// fun provideApplication(application: Application): OMQSApplication {
|
||||
// return application as OMQSApplication
|
||||
// }
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideApplication(application: Application): OMQSApplication {
|
||||
return application as OMQSApplication
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入 网络OKHttp 对象
|
||||
@@ -92,4 +94,13 @@ class GlobalModule {
|
||||
fun provideNetworkService(retrofit: Retrofit): RetrofitNetworkServiceAPI {
|
||||
return retrofit.create(RetrofitNetworkServiceAPI::class.java)
|
||||
}
|
||||
|
||||
/**
|
||||
* realm 注册
|
||||
*/
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRealmService(context: Application): RealmCoroutineScope {
|
||||
return RealmCoroutineScope(context)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.navinfo.omqs.hilt
|
||||
|
||||
import android.content.Context
|
||||
import com.navinfo.collect.library.map.NIMapController
|
||||
import com.navinfo.omqs.http.RetrofitNetworkServiceAPI
|
||||
import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager
|
||||
import com.navinfo.omqs.tools.RealmCoroutineScope
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityRetainedComponent
|
||||
import dagger.hilt.android.qualifiers.ActivityContext
|
||||
import dagger.hilt.android.scopes.ActivityRetainedScoped
|
||||
|
||||
@InstallIn(ActivityRetainedComponent::class)
|
||||
@@ -28,9 +27,10 @@ class MainActivityModule {
|
||||
@ActivityRetainedScoped
|
||||
@Provides
|
||||
fun providesOfflineMapDownloadManager(
|
||||
networkServiceAPI: RetrofitNetworkServiceAPI
|
||||
networkServiceAPI: RetrofitNetworkServiceAPI,
|
||||
realmManager: RealmCoroutineScope
|
||||
): OfflineMapDownloadManager =
|
||||
OfflineMapDownloadManager( networkServiceAPI)
|
||||
OfflineMapDownloadManager(networkServiceAPI, realmManager)
|
||||
|
||||
/**
|
||||
* 实验失败,这样创建,viewmodel不会在activity销毁的时候同时销毁
|
||||
|
||||
Reference in New Issue
Block a user