fix: add legacy config subscription to the home activity to enable showing banner at any time

This commit is contained in:
0x330a 2023-04-24 12:03:07 +10:00
parent cd13da647c
commit c777c05456
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
2 changed files with 15 additions and 1 deletions

View File

@ -13,7 +13,9 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -204,6 +206,15 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
this.broadcastReceiver = broadcastReceiver this.broadcastReceiver = broadcastReceiver
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, IntentFilter("blockedContactsChanged")) LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, IntentFilter("blockedContactsChanged"))
// 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 }.collect {
updateLegacyConfigView()
}
}
}
lifecycleScope.launchWhenStarted { lifecycleScope.launchWhenStarted {
launch(Dispatchers.IO) { launch(Dispatchers.IO) {
// Double check that the long poller is up // Double check that the long poller is up
@ -224,6 +235,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
} }
} }
} }
// monitor the global search VM query // monitor the global search VM query
launch { launch {
binding.globalSearchInputLayout.query binding.globalSearchInputLayout.query

View File

@ -638,6 +638,7 @@ interface TextSecurePreferences {
@JvmStatic @JvmStatic
fun setHasLegacyConfig(context: Context, newValue: Boolean) { fun setHasLegacyConfig(context: Context, newValue: Boolean) {
setBooleanPreference(context, HAS_RECEIVED_LEGACY_CONFIG, newValue) setBooleanPreference(context, HAS_RECEIVED_LEGACY_CONFIG, newValue)
_events.tryEmit(HAS_RECEIVED_LEGACY_CONFIG)
} }
fun setLocalNumber(context: Context, localNumber: String) { fun setLocalNumber(context: Context, localNumber: String) {
@ -1299,7 +1300,8 @@ class AppTextSecurePreferences @Inject constructor(
} }
override fun setHasLegacyConfig(newValue: Boolean) { override fun setHasLegacyConfig(newValue: Boolean) {
return setBooleanPreference(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG, newValue) setBooleanPreference(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG, newValue)
TextSecurePreferences._events.tryEmit(TextSecurePreferences.HAS_RECEIVED_LEGACY_CONFIG)
} }
override fun setLocalNumber(localNumber: String) { override fun setLocalNumber(localNumber: String) {