Initial ReSearch export
This commit is contained in:
commit
e8a49575c1
145 files changed
+14188
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package com.example.research
|
||||
|
||||
import android.app.Application
|
||||
import com.example.research.common.progress.DictionaryProgressStateHolder
|
||||
import com.example.research.data.local.preferences.PreferencesManager
|
||||
import com.example.research.data.repository.LocalDictionaryRepository
|
||||
import com.example.research.feature.download.DownloadManager
|
||||
import com.example.research.feature.download.repository.DictionaryRepository
|
||||
import com.example.research.common.util.FileStorageManager
|
||||
import com.example.research.feature.import.DictionaryImportManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
|
||||
class ReSearchApplication : Application() {
|
||||
|
||||
lateinit var preferencesManager: PreferencesManager
|
||||
private set
|
||||
|
||||
lateinit var localDictionaryRepository: LocalDictionaryRepository
|
||||
private set
|
||||
|
||||
lateinit var downloadDictionaryRepository: DictionaryRepository
|
||||
private set
|
||||
|
||||
lateinit var downloadManager: DownloadManager
|
||||
private set
|
||||
|
||||
lateinit var dictionaryImportManager: DictionaryImportManager
|
||||
private set
|
||||
|
||||
lateinit var okHttpClient: OkHttpClient
|
||||
private set
|
||||
lateinit var dictionaryProgressStateHolder: DictionaryProgressStateHolder
|
||||
private set
|
||||
private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
preferencesManager = PreferencesManager(this)
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
preferencesManager.sanitizeDictionarySources()
|
||||
}
|
||||
localDictionaryRepository = LocalDictionaryRepository(this)
|
||||
|
||||
okHttpClient = OkHttpClient.Builder()
|
||||
.protocols(listOf(Protocol.HTTP_1_1))
|
||||
.build()
|
||||
|
||||
val fileStorageManager = FileStorageManager()
|
||||
|
||||
downloadDictionaryRepository = DictionaryRepository(
|
||||
context = this,
|
||||
preferencesManager = preferencesManager,
|
||||
fileStorageManager = fileStorageManager,
|
||||
client = okHttpClient
|
||||
)
|
||||
|
||||
downloadManager = DownloadManager(
|
||||
dictionaryRepository = downloadDictionaryRepository,
|
||||
unknownErrorMessage = getString(R.string.unknown_error)
|
||||
)
|
||||
|
||||
dictionaryImportManager = DictionaryImportManager(
|
||||
application = this
|
||||
)
|
||||
|
||||
dictionaryProgressStateHolder = DictionaryProgressStateHolder(
|
||||
scope = applicationScope,
|
||||
downloadManager = downloadManager,
|
||||
dictionaryImportManager = dictionaryImportManager,
|
||||
localDictionaryRepository = localDictionaryRepository,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
super.onTrimMemory(level)
|
||||
if (::localDictionaryRepository.isInitialized) {
|
||||
localDictionaryRepository.trimMemory(level)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user