Fixed crash when app is started from chat notification and app day/night mode doesn't match the system's one, causing activity to be recreated and navigation event to happen without a valid FragmentManager
This commit is contained in:
parent
f6cc435396
commit
cacf1f4472
4 changed files with 26 additions and 3 deletions
|
@ -36,6 +36,9 @@ import org.linphone.core.tools.Log
|
||||||
|
|
||||||
abstract class GenericActivity : AppCompatActivity() {
|
abstract class GenericActivity : AppCompatActivity() {
|
||||||
private var timer: Timer? = null
|
private var timer: Timer? = null
|
||||||
|
private var _isDestructionPending = false
|
||||||
|
val isDestructionPending: Boolean
|
||||||
|
get() = _isDestructionPending
|
||||||
|
|
||||||
@SuppressLint("SourceLockedOrientationActivity")
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -49,19 +52,24 @@ abstract class GenericActivity : AppCompatActivity() {
|
||||||
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isDestructionPending = false
|
||||||
val nightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
val nightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||||
val darkModeEnabled = corePreferences.darkMode
|
val darkModeEnabled = corePreferences.darkMode
|
||||||
when (nightMode) {
|
when (nightMode) {
|
||||||
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
|
Configuration.UI_MODE_NIGHT_NO, Configuration.UI_MODE_NIGHT_UNDEFINED -> {
|
||||||
if (darkModeEnabled == 1) {
|
if (darkModeEnabled == 1) {
|
||||||
// Force dark mode
|
// Force dark mode
|
||||||
|
Log.w("[Generic Activity] Forcing night mode")
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
|
_isDestructionPending = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Configuration.UI_MODE_NIGHT_YES -> {
|
Configuration.UI_MODE_NIGHT_YES -> {
|
||||||
if (darkModeEnabled == 0) {
|
if (darkModeEnabled == 0) {
|
||||||
// Force light mode
|
// Force light mode
|
||||||
|
Log.w("[Generic Activity] Forcing day mode")
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
_isDestructionPending = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
import org.linphone.activities.GenericActivity
|
||||||
import org.linphone.activities.main.MainActivity
|
import org.linphone.activities.main.MainActivity
|
||||||
import org.linphone.activities.main.chat.adapters.ChatRoomsListAdapter
|
import org.linphone.activities.main.chat.adapters.ChatRoomsListAdapter
|
||||||
import org.linphone.activities.main.chat.viewmodels.ChatRoomsListViewModel
|
import org.linphone.activities.main.chat.viewmodels.ChatRoomsListViewModel
|
||||||
|
@ -141,8 +142,13 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
|
|
||||||
adapter.selectedChatRoomEvent.observe(viewLifecycleOwner, {
|
adapter.selectedChatRoomEvent.observe(viewLifecycleOwner, {
|
||||||
it.consume { chatRoom ->
|
it.consume { chatRoom ->
|
||||||
sharedViewModel.selectedChatRoom.value = chatRoom
|
if ((requireActivity() as GenericActivity).isDestructionPending) {
|
||||||
navigateToChatRoom()
|
Log.w("[Chat] Activity is pending destruction, don't start navigating now!")
|
||||||
|
sharedViewModel.destructionPendingChatRoom = chatRoom
|
||||||
|
} else {
|
||||||
|
sharedViewModel.selectedChatRoom.value = chatRoom
|
||||||
|
navigateToChatRoom()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -159,6 +165,14 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
navigateToChatRoomCreation(true)
|
navigateToChatRoomCreation(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val pendingDestructionChatRoom = sharedViewModel.destructionPendingChatRoom
|
||||||
|
if (pendingDestructionChatRoom != null) {
|
||||||
|
Log.w("[Chat] Found pending chat room from before activity was recreated")
|
||||||
|
sharedViewModel.destructionPendingChatRoom = null
|
||||||
|
sharedViewModel.selectedChatRoom.value = pendingDestructionChatRoom
|
||||||
|
navigateToChatRoom()
|
||||||
|
}
|
||||||
|
|
||||||
val localSipUri = arguments?.getString("LocalSipUri")
|
val localSipUri = arguments?.getString("LocalSipUri")
|
||||||
val remoteSipUri = arguments?.getString("RemoteSipUri")
|
val remoteSipUri = arguments?.getString("RemoteSipUri")
|
||||||
if (localSipUri != null && remoteSipUri != null) {
|
if (localSipUri != null && remoteSipUri != null) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ class AdvancedSettingsFragment : GenericFragment<SettingsAdvancedFragmentBinding
|
||||||
when (value) {
|
when (value) {
|
||||||
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
||||||
else -> AppCompatDelegate.MODE_NIGHT_UNSPECIFIED
|
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ class SharedMainViewModel : ViewModel() {
|
||||||
/* Chat */
|
/* Chat */
|
||||||
|
|
||||||
val selectedChatRoom = MutableLiveData<ChatRoom>()
|
val selectedChatRoom = MutableLiveData<ChatRoom>()
|
||||||
|
var destructionPendingChatRoom: ChatRoom? = null
|
||||||
|
|
||||||
val selectedGroupChatRoom = MutableLiveData<ChatRoom>()
|
val selectedGroupChatRoom = MutableLiveData<ChatRoom>()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue