mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 01:45:22 +00:00
Dm header icons reactive (#190)
* header reactive to noise session * favorite button reactive * icon change * nice
This commit is contained in:
@@ -80,6 +80,8 @@ class ChatViewModel(
|
||||
val showCommandSuggestions: LiveData<Boolean> = state.showCommandSuggestions
|
||||
val commandSuggestions: LiveData<List<CommandSuggestion>> = state.commandSuggestions
|
||||
val favoritePeers: LiveData<Set<String>> = state.favoritePeers
|
||||
val peerSessionStates: LiveData<Map<String, String>> = state.peerSessionStates
|
||||
val peerFingerprints: LiveData<Map<String, String>> = state.peerFingerprints
|
||||
val showAppInfo: LiveData<Boolean> = state.showAppInfo
|
||||
|
||||
init {
|
||||
@@ -115,6 +117,9 @@ class ChatViewModel(
|
||||
dataManager.logAllFavorites()
|
||||
logCurrentFavoriteState()
|
||||
|
||||
// Initialize session state monitoring
|
||||
initializeSessionStateMonitoring()
|
||||
|
||||
// Note: Mesh service is now started by MainActivity
|
||||
|
||||
// Show welcome message if no peers after delay
|
||||
@@ -279,6 +284,35 @@ class ChatViewModel(
|
||||
Log.i("ChatViewModel", "==============================")
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize session state monitoring for reactive UI updates
|
||||
*/
|
||||
private fun initializeSessionStateMonitoring() {
|
||||
viewModelScope.launch {
|
||||
while (true) {
|
||||
delay(1000) // Check session states every second
|
||||
updateReactiveStates()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update reactive states for all connected peers (session states and fingerprints)
|
||||
*/
|
||||
private fun updateReactiveStates() {
|
||||
val currentPeers = state.getConnectedPeersValue()
|
||||
|
||||
// Update session states
|
||||
val sessionStates = currentPeers.associateWith { peerID ->
|
||||
meshService.getSessionState(peerID).toString()
|
||||
}
|
||||
state.setPeerSessionStates(sessionStates)
|
||||
|
||||
// Update fingerprint mappings from centralized manager
|
||||
val fingerprints = privateChatManager.getAllPeerFingerprints()
|
||||
state.setPeerFingerprints(fingerprints)
|
||||
}
|
||||
|
||||
// MARK: - Debug and Troubleshooting
|
||||
|
||||
fun getDebugStatus(): String {
|
||||
|
||||
Reference in New Issue
Block a user