Skip to content

Commit

Permalink
move initial update data fetching from UpdateFragment to LoadDataMidd…
Browse files Browse the repository at this point in the history
…leware to fix inconsistent state after process death
  • Loading branch information
solrudev committed Apr 28, 2023
1 parent 8f155ad commit 3d89472
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package ru.solrudev.okkeipatcher.ui.main.screen.update

import android.os.Bundle
import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.viewBinding
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -29,7 +28,6 @@ import ru.solrudev.okkeipatcher.R
import ru.solrudev.okkeipatcher.databinding.FragmentUpdateBinding
import ru.solrudev.okkeipatcher.ui.main.screen.update.controller.RefreshController
import ru.solrudev.okkeipatcher.ui.main.screen.update.controller.UpdateButtonClickController
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateEvent.UpdateDataRequested
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateUiState
import ru.solrudev.okkeipatcher.ui.main.screen.update.view.AppInfoView
import ru.solrudev.okkeipatcher.ui.main.screen.update.view.ChangelogView
Expand Down Expand Up @@ -67,11 +65,4 @@ class UpdateFragment : Fragment(R.layout.fragment_update), HostJetView<UpdateUiS
)

private val binding by viewBinding(FragmentUpdateBinding::bind)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
viewModel.dispatchEvent(UpdateDataRequested(refresh = false))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package ru.solrudev.okkeipatcher.ui.main.screen.update.middleware

import io.github.solrudev.jetmvi.JetMiddleware
import io.github.solrudev.jetmvi.MiddlewareScope
import kotlinx.coroutines.launch
import ru.solrudev.okkeipatcher.app.usecase.GetUpdateDataUseCase
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateEvent
import ru.solrudev.okkeipatcher.ui.main.screen.update.model.UpdateEvent.*
Expand All @@ -31,6 +32,9 @@ class LoadUpdateDataMiddleware @Inject constructor(
) : JetMiddleware<UpdateEvent> {

override fun MiddlewareScope<UpdateEvent>.apply() {
launch {
send(UpdateDataRequested(refresh = false))
}
onEvent<UpdateDataRequested> { event ->
send(UpdateDataLoadingStarted)
val updateData = getUpdateDataUseCase(refresh = event.refresh)
Expand Down

0 comments on commit 3d89472

Please sign in to comment.