Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13331: Make toggle button update lifecycle-aware #13339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dautovicharis
Copy link
Contributor

Contributor checklist

  • Redmi Note 10 Pro, Android 13, MUI 14
  • Samsung Galaxy A14, Android 13
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Issue

Fixes: #13331

Description

Update UI state following the Android lifecycle.

Videos

Redmi.Note.10.Pro.-.OK.mov

Tested

Device info

Device Android Version Signal Version
Redmi Note 10 Pro Android Version Image 6.42.3
Samsung Galaxy A14 Android Version Image 6.42.3

Copy link

stale bot commented Feb 29, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 29, 2024
Copy link

stale bot commented Mar 7, 2024

This issue has been closed due to inactivity.

@stale stale bot closed this Mar 7, 2024
@alex-signal alex-signal reopened this Mar 7, 2024
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch

class ToggleUpdateViewModel : ViewModel() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some documentation to this class describing what it's for? It's fairly unclear just looking. And I think perhaps ToggleUpdate* isn't the best name. Feels like it should have a better descriptor there (though admittedly, I realize this was probably just pulled from the original method name)


lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
toggleUpdateViewModel.state.collect {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My knowledge of the Flow apis is quite limited, my understanding is that this will be subscribed between onStart / onStop and the subscription is managed automatically?

val state = _state.asSharedFlow()

fun update() = viewModelScope.launch {
_state.emit(Unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really any state here... is this just a pulse? How is this different from just calling toggle update fn from the appropriate lifecycle method in the fragment? (I've yet to have coffee this morning so appologies if I missed something obvious.)

Copy link

stale bot commented May 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

The Send button is missing after lifecycle changes
2 participants