fix: latch terminal notification state and post pipeline progress on one thread
A late ImportState Success snapshot collected after the success notification overwrote it with an ongoing progress record. Post progress on Main behind a volatile terminal latch; notifications go through NotificationPort, the pipeline lives in the coordinator, and the service finish is injected.
This commit is contained in:
1 parent
2f22144d19
commit
8c6e43f3db
9 files changed
+372
-195
No files matched your search
@@ -37,12 +37,17 @@ class ReSearchApplication : Application() {
|
||||
private set
|
||||
lateinit var dictionaryProgressStateHolder: DictionaryProgressStateHolder
|
||||
private set
|
||||
lateinit var dictionaryProgressPresenter: com.example.research.common.progress.DictionaryProgressPresenter
|
||||
private set
|
||||
lateinit var dictionaryPipelineCoordinator: com.example.research.common.progress.DictionaryPipelineCoordinator
|
||||
private set
|
||||
private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
NotificationHelper(this).cancelNotification()
|
||||
val notificationHelper = NotificationHelper(this)
|
||||
notificationHelper.cancelProgressNotification()
|
||||
|
||||
preferencesManager = PreferencesManager(this)
|
||||
applicationScope.launch(Dispatchers.IO) {
|
||||
@@ -80,6 +85,40 @@ class ReSearchApplication : Application() {
|
||||
localDictionaryRepository = localDictionaryRepository,
|
||||
)
|
||||
|
||||
dictionaryProgressPresenter = com.example.research.common.progress.DictionaryProgressPresenter(
|
||||
scope = applicationScope,
|
||||
progressSnapshot = dictionaryProgressStateHolder.progressSnapshot,
|
||||
notifications = notificationHelper,
|
||||
)
|
||||
|
||||
dictionaryPipelineCoordinator = com.example.research.common.progress.DictionaryPipelineCoordinator(
|
||||
scope = applicationScope,
|
||||
steps = com.example.research.common.progress.DefaultReindexingSteps(
|
||||
localDictionaryRepository = localDictionaryRepository,
|
||||
downloadDictionaryRepository = downloadDictionaryRepository,
|
||||
),
|
||||
importOperations = dictionaryImportManager,
|
||||
ui = dictionaryProgressPresenter,
|
||||
dictionaryPath = { preferencesManager.dictionaryPath },
|
||||
finishService = {
|
||||
val intent = android.content.Intent(
|
||||
this,
|
||||
com.example.research.feature.download.service.DictionaryForegroundService::class.java
|
||||
).apply {
|
||||
action = com.example.research.feature.download.service.DictionaryForegroundService.ACTION_FINISH
|
||||
}
|
||||
try {
|
||||
startService(intent)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
dictionaryImportManager.onFlowStarted = { dictionaryProgressPresenter.beginFlow() }
|
||||
dictionaryImportManager.onTerminal = dictionaryPipelineCoordinator::onImportTerminal
|
||||
downloadManager.onFlowStarted = { dictionaryProgressPresenter.beginFlow() }
|
||||
downloadManager.onDownloadSuccess = dictionaryPipelineCoordinator::onDownloadSuccess
|
||||
downloadManager.onTerminal = dictionaryPipelineCoordinator::onDownloadTerminal
|
||||
}
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
|
||||
Reference in new issue
Block a user