mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-11 19:51:48 +00:00
Use Flow
This commit is contained in:
@@ -8,7 +8,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Telephony.Mms.Addr
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.os.bundleOf
|
||||
@@ -21,7 +20,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -185,9 +183,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
// subscribe to outdated config updates, this should be removed after long enough time for device migration
|
||||
lifecycleScope.launch {
|
||||
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
TextSecurePreferences.events.filter { it == TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG.name }.collect {
|
||||
updateLegacyConfigView()
|
||||
}
|
||||
prefs.hasLegacyConfigFlow().collect(::updateLegacyConfigView)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,10 +220,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
updateProfileButton()
|
||||
TextSecurePreferences.events.filter { it == TextSecurePreferences.PROFILE_NAME_PREF.name }.collect {
|
||||
updateProfileButton()
|
||||
}
|
||||
prefs.profileNameFlow().collect(::updateProfileButton)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,8 +323,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
binding.newConversationButton.isVisible = !isShown
|
||||
}
|
||||
|
||||
private fun updateLegacyConfigView() {
|
||||
binding.configOutdatedView.isVisible = textSecurePreferences.getHasLegacyConfig()
|
||||
private fun updateLegacyConfigView(hasLegacyConfig: Boolean = textSecurePreferences.getHasLegacyConfig()) {
|
||||
binding.configOutdatedView.isVisible = hasLegacyConfig
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -382,9 +375,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateProfileButton() {
|
||||
private fun updateProfileButton(profileName: String? = textSecurePreferences.getProfileName()) {
|
||||
binding.profileButton.publicKey = publicKey
|
||||
binding.profileButton.displayName = textSecurePreferences.getProfileName()
|
||||
binding.profileButton.displayName = profileName
|
||||
binding.profileButton.recycle()
|
||||
binding.profileButton.update()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
@@ -60,11 +59,6 @@ class HomeViewModel @Inject constructor(
|
||||
::Data
|
||||
).stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||
|
||||
private fun hasHiddenMessageRequests() = TextSecurePreferences.events
|
||||
.filter { it == TextSecurePreferences.HAS_HIDDEN_MESSAGE_REQUESTS.name }
|
||||
.map { prefs.hasHiddenMessageRequests() }
|
||||
.onStart { emit(prefs.hasHiddenMessageRequests()) }
|
||||
|
||||
private fun observeTypingStatus(): Flow<Set<Long>> =
|
||||
ApplicationContext.getInstance(context).typingStatusRepository
|
||||
.typingThreads
|
||||
@@ -74,7 +68,7 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
private fun messageRequests() = combine(
|
||||
unapprovedConversationCount(),
|
||||
hasHiddenMessageRequests(),
|
||||
prefs.hasHiddenMessageRequestsFlow(),
|
||||
latestUnapprovedConversationTimestamp(),
|
||||
::createMessageRequests
|
||||
).flowOn(Dispatchers.IO)
|
||||
|
||||
@@ -12,8 +12,6 @@ import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.timeout
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -44,10 +42,8 @@ internal class LoadingViewModel @Inject constructor(
|
||||
init {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
TextSecurePreferences.events
|
||||
.filter { it == TextSecurePreferences.CONFIGURATION_SYNCED.name }
|
||||
.onStart { emit(TextSecurePreferences.CONFIGURATION_SYNCED.name) }
|
||||
.filter { prefs.getConfigurationMessageSynced() }
|
||||
prefs.configurationMessageSyncedFlow()
|
||||
.filter { it }
|
||||
.timeout(TIMEOUT_TIME)
|
||||
.collectLatest { onSuccess() }
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user