Skip to content

Commit

Permalink
smooth progress loading
Browse files Browse the repository at this point in the history
  • Loading branch information
malmstein committed Aug 26, 2024
1 parent fe1e207 commit 5238820
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ interface Omnibar {

sealed class Content {
data class Suggestions(val list: List<String>) : Content()
object FocusedView : Content()
}

sealed class Event {
Expand Down Expand Up @@ -161,8 +160,8 @@ class OmnibarView @JvmOverloads constructor(
}

private fun render(viewState: ViewState) {
Timber.d("Omnibar: render $viewState")
renderOutline(viewState.hasFocus)
renderLoadingState(viewState.loadingState)
renderButtons(viewState)
if (!viewState.hasFocus) {
renderTabIcon(viewState.tabs)
Expand All @@ -181,10 +180,10 @@ class OmnibarView @JvmOverloads constructor(
}

override fun decorate(event: Event) {
Timber.d("Omnibar: decorate $$event")
Timber.d("Omnibar: decorate $event")
when (event) {
is PrivacyShieldChanged -> renderPrivacyShield(event.privacyShield)
is PageLoading -> viewModel.onNewLoadingState(event.loadingState)
is PageLoading -> renderLoadingState(event.loadingState)
is Scrolling -> changeScrollingBehaviour(event.enabled)
}
}
Expand Down Expand Up @@ -215,8 +214,11 @@ class OmnibarView @JvmOverloads constructor(
Timber.d("Omnibar: renderLoadingState $loadingState")
binding.pageLoadingIndicator.apply {
if (loadingState.isLoading) show()
smoothProgressAnimator.onNewProgress(loadingState.progress) { if (!loadingState.isLoading) hide() }
smoothProgressAnimator.onNewProgress(loadingState.progress) {
if (!loadingState.isLoading) hide()
}
}

if (loadingState.privacyOn) {
if (viewModel.viewState.value.hasFocus) {
cancelTrackersAnimation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ import com.duckduckgo.voice.api.VoiceSearchAvailability
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import timber.log.Timber

@SuppressLint("NoLifecycleObserver") // we don't observe app lifecycle
@ContributesViewModel(ViewScope::class)
Expand Down Expand Up @@ -84,8 +86,8 @@ class OmnibarViewModel @Inject constructor(

override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)

tabRepository.flowTabs.onEach { tabs ->
Timber.d("Omnibar: onCreate")
tabRepository.flowTabs.distinctUntilChanged().onEach { tabs ->
_viewState.update { ViewState(tabs = tabs) }
}.flowOn(dispatcherProvider.io()).launchIn(viewModelScope)
}
Expand All @@ -94,6 +96,7 @@ class OmnibarViewModel @Inject constructor(
hasFocus: Boolean,
query: String,
) {
Timber.d("Omnibar: onOmnibarFocusChanged")
// focus vs unfocused mode
if (hasFocus) {
_viewState.update {
Expand Down Expand Up @@ -129,6 +132,7 @@ class OmnibarViewModel @Inject constructor(
}

fun onNewLoadingState(loadingState: LoadingViewState) {
Timber.d("Omnibar: onNewLoadingState $loadingState")
_viewState.update { ViewState(loadingState = loadingState) }
}
}

0 comments on commit 5238820

Please sign in to comment.