Merge pull request #8410 from vector-im/feature/bma/fixCrashes

Fix crashes
This commit is contained in:
Benoit Marty 2023-05-11 14:51:33 +02:00 committed by GitHub
commit f9f341e0ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 111 deletions

1
changelog.d/8410.bugfix Normal file
View file

@ -0,0 +1 @@
Fix crash when opening "Protect access" screen, and various other issue with `repeatOnLifecycle`

View file

@ -21,10 +21,9 @@ import android.text.Editable
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import androidx.autofill.HintConstants import androidx.autofill.HintConstants
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.withResumed
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import im.vector.app.core.platform.SimpleTextWatcher import im.vector.app.core.platform.SimpleTextWatcher
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -88,7 +87,7 @@ fun TextInputLayout.setOnImeDoneListener(action: () -> Unit) {
fun TextInputLayout.setOnFocusLostListener(lifecycleOwner: LifecycleOwner, action: () -> Unit) { fun TextInputLayout.setOnFocusLostListener(lifecycleOwner: LifecycleOwner, action: () -> Unit) {
editText().setOnFocusChangeListener { _, hasFocus -> editText().setOnFocusChangeListener { _, hasFocus ->
when (hasFocus) { when (hasFocus) {
false -> lifecycleOwner.lifecycleScope.launch { lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { action() } } false -> lifecycleOwner.lifecycleScope.launch { lifecycleOwner.withResumed { action() } }
else -> { else -> {
// do nothing // do nothing
} }

View file

@ -30,9 +30,8 @@ import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.withResumed
import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.viewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -402,7 +401,9 @@ class HomeActivity :
private fun handleStartRecoverySetup() { private fun handleStartRecoverySetup() {
// To avoid IllegalStateException in case the transaction was executed after onSaveInstanceState // To avoid IllegalStateException in case the transaction was executed after onSaveInstanceState
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) { navigator.open4SSetup(this@HomeActivity, SetupMode.NORMAL) } withResumed {
navigator.open4SSetup(this@HomeActivity, SetupMode.NORMAL)
}
} }
} }

View file

@ -47,9 +47,8 @@ import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.withResumed
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -1112,7 +1111,8 @@ class TimelineFragment :
private fun updateJumpToReadMarkerViewVisibility() { private fun updateJumpToReadMarkerViewVisibility() {
if (isThreadTimeLine()) return if (isThreadTimeLine()) return
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { withResumed {
viewLifecycleOwner.lifecycleScope.launch {
val state = timelineViewModel.awaitState() val state = timelineViewModel.awaitState()
val showJumpToUnreadBanner = when (state.unreadState) { val showJumpToUnreadBanner = when (state.unreadState) {
UnreadState.Unknown, UnreadState.Unknown,
@ -1138,6 +1138,7 @@ class TimelineFragment :
} }
} }
} }
}
override fun invalidate() = withState(timelineViewModel, messageComposerViewModel) { mainState, messageComposerState -> override fun invalidate() = withState(timelineViewModel, messageComposerViewModel) { mainState, messageComposerState ->
invalidateOptionsMenu() invalidateOptionsMenu()
@ -1625,7 +1626,8 @@ class TimelineFragment :
override fun onRoomCreateLinkClicked(url: String) { override fun onRoomCreateLinkClicked(url: String) {
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { withResumed {
viewLifecycleOwner.lifecycleScope.launch {
permalinkHandler permalinkHandler
.launch(requireActivity(), url, object : NavigationInterceptor { .launch(requireActivity(), url, object : NavigationInterceptor {
override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean { override fun navToRoom(roomId: String?, eventId: String?, deepLink: Uri?, rootThreadEventId: String?): Boolean {
@ -1636,6 +1638,7 @@ class TimelineFragment :
} }
} }
} }
}
override fun onReadReceiptsClicked(readReceipts: List<ReadReceiptData>) { override fun onReadReceiptsClicked(readReceipts: List<ReadReceiptData>) {
DisplayReadReceiptsBottomSheet.newInstance(readReceipts) DisplayReadReceiptsBottomSheet.newInstance(readReceipts)

View file

@ -26,9 +26,7 @@ import androidx.core.content.ContextCompat
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -101,13 +99,11 @@ class LocationSharingFragment :
views.mapView.onCreate(savedInstanceState) views.mapView.onCreate(savedInstanceState)
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
views.mapView.initialize( views.mapView.initialize(
url = urlMapProvider.getMapUrl(), url = urlMapProvider.getMapUrl(),
locationTargetChangeListener = this@LocationSharingFragment locationTargetChangeListener = this@LocationSharingFragment
) )
} }
}
initLocateButton() initLocateButton()
initOptionsPicker() initOptionsPicker()

View file

@ -22,9 +22,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
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 com.airbnb.mvrx.args import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
@ -81,10 +79,8 @@ class LocationPreviewFragment :
views.mapView.onCreate(savedInstanceState) views.mapView.onCreate(savedInstanceState)
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
views.mapView.initialize(urlMapProvider.getMapUrl()) views.mapView.initialize(urlMapProvider.getMapUrl())
} }
}
observeViewEvents() observeViewEvents()
initLocateButton() initLocateButton()

View file

@ -16,9 +16,7 @@
package im.vector.app.features.settings package im.vector.app.features.settings
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -80,13 +78,13 @@ class VectorSettingsPinFragment :
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateBiometricPrefState(isPinCodeChecked = usePinCodePref.isChecked) updateBiometricPrefState(isPinCodeChecked = usePinCodePref.isChecked)
viewLifecycleOwner.lifecycleScope.launch {
refreshPinCodeStatus()
}
} }
override fun bindPref() { override fun bindPref() {
refreshPinCodeStatus()
usePinCodePref.setOnPreferenceChangeListener { _, value -> usePinCodePref.setOnPreferenceChangeListener { _, value ->
val isChecked = (value as? Boolean).orFalse() val isChecked = (value as? Boolean).orFalse()
updateBiometricPrefState(isPinCodeChecked = isChecked) updateBiometricPrefState(isPinCodeChecked = isChecked)
@ -130,9 +128,7 @@ class VectorSettingsPinFragment :
.onFailure { Timber.e(it) } .onFailure { Timber.e(it) }
} }
private fun refreshPinCodeStatus() { private suspend fun refreshPinCodeStatus() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
val hasPinCode = pinCodeStore.hasEncodedPin() val hasPinCode = pinCodeStore.hasEncodedPin()
usePinCodePref.isChecked = hasPinCode usePinCodePref.isChecked = hasPinCode
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener { usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
@ -162,14 +158,12 @@ class VectorSettingsPinFragment :
true true
} }
} }
}
}
private fun showEnableBiometricErrorMessage() { private fun showEnableBiometricErrorMessage() {
context?.toast(R.string.settings_security_pin_code_use_biometrics_error) context?.toast(R.string.settings_security_pin_code_use_biometrics_error)
} }
private val pinActivityResultLauncher = registerStartForActivityResult { private val pinActivityResultLauncher = registerStartForActivityResult {
refreshPinCodeStatus() // Nothing to do, refreshPinCodeStatus() will be called by `onResume`
} }
} }

View file

@ -27,9 +27,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
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.lifecycle.withResumed
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceCategory import androidx.preference.PreferenceCategory
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
@ -190,6 +189,10 @@ class VectorSettingsSecurityPrivacyFragment :
rawService rawService
.getElementWellknown(session.sessionParams) .getElementWellknown(session.sessionParams)
?.isE2EByDefault() == false ?.isE2EByDefault() == false
refreshXSigningStatus()
// My device name may have been updated
refreshMyDevice()
} }
} }
@ -288,19 +291,6 @@ class VectorSettingsSecurityPrivacyFragment :
true true
} }
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
refreshXSigningStatus()
}
}
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
// My device name may have been updated
refreshMyDevice()
}
}
secureBackupPreference.icon = activity?.let { secureBackupPreference.icon = activity?.let {
ThemeUtils.tintDrawable( ThemeUtils.tintDrawable(
it, it,
@ -429,7 +419,8 @@ class VectorSettingsSecurityPrivacyFragment :
private fun openPinCodePreferenceScreen() { private fun openPinCodePreferenceScreen() {
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { withResumed {
viewLifecycleOwner.lifecycleScope.launch {
val hasPinCode = pinCodeStore.hasEncodedPin() val hasPinCode = pinCodeStore.hasEncodedPin()
if (hasPinCode) { if (hasPinCode) {
navigator.openPinCode( navigator.openPinCode(
@ -443,6 +434,7 @@ class VectorSettingsSecurityPrivacyFragment :
} }
} }
} }
}
private fun doOpenPinCodePreferenceScreen() { private fun doOpenPinCodePreferenceScreen() {
(vectorActivity as? VectorSettingsActivity)?.navigateTo(VectorSettingsPinFragment::class.java) (vectorActivity as? VectorSettingsActivity)?.navigateTo(VectorSettingsPinFragment::class.java)

View file

@ -24,9 +24,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ScrollView import android.widget.ScrollView
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.lifecycle.withResumed
import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.args import com.airbnb.mvrx.args
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
@ -178,7 +177,7 @@ class UserListFragment :
// Scroll to the bottom when adding chips. When removing chips, do not scroll // Scroll to the bottom when adding chips. When removing chips, do not scroll
if (newNumberOfChips >= currentNumberOfChips) { if (newNumberOfChips >= currentNumberOfChips) {
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { withResumed {
views.chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN) views.chipGroupScrollView.fullScroll(ScrollView.FOCUS_DOWN)
} }
} }