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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.thoughtcrime.securesms.conversation.v2 | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class ToggleUpdateViewModel : ViewModel() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
||
private val _state = MutableSharedFlow<Unit>(replay = 1) | ||
val state = _state.asSharedFlow() | ||
|
||
fun update() = viewModelScope.launch { | ||
_state.emit(Unit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.) |
||
} | ||
} |
There was a problem hiding this comment.
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?