diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt index ed82d6056..675aba57e 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt @@ -551,7 +551,11 @@ class ConversationFragment : SlidingPaneChildFragment() { } binding.setWarningConversationDisabledClickListener { - // TODO: go to account profile mode fragment + Log.i( + "$TAG Navigating to account profile mode fragment to let user change mode to interop" + ) + sharedViewModel.goToAccountProfileModeEvent.value = Event(true) + sharedViewModel.goToAccountProfileEvent.value = Event(true) } sendMessageViewModel.emojiToAddEvent.observe(viewLifecycleOwner) { diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt index 392bc207c..f5f4e8958 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationsListFragment.kt @@ -42,6 +42,7 @@ import org.linphone.ui.main.fragment.AbstractMainFragment import org.linphone.ui.main.history.fragment.HistoryMenuDialogFragment import org.linphone.utils.AppUtils import org.linphone.utils.Event +import org.linphone.utils.LinphoneUtils @UiThread class ConversationsListFragment : AbstractMainFragment() { @@ -213,6 +214,19 @@ class ConversationsListFragment : AbstractMainFragment() { } } + sharedViewModel.goToAccountProfileEvent.observe(viewLifecycleOwner) { + it.consume { + if (findNavController().currentDestination?.id == R.id.conversationsListFragment) { + val identity = LinphoneUtils.getDefaultAccount()?.params?.identityAddress?.asStringUriOnly().orEmpty() + val action = + ConversationsListFragmentDirections.actionConversationsListFragmentToAccountProfileFragment( + identity + ) + findNavController().navigate(action) + } + } + } + sharedViewModel.displayFileEvent.observe(viewLifecycleOwner) { it.consume { bundle -> if (findNavController().currentDestination?.id == R.id.conversationsListFragment) { diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt index d1620b5df..827c78406 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt @@ -430,6 +430,8 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo val id = LinphoneUtils.getChatRoomId(chatRoom) Log.i("$TAG Asking notifications manager not to notify messages for conversation [$id]") coreContext.notificationsManager.setCurrentlyDisplayedChatRoomId(id) + + checkIfConversationShouldBeDisabledForSecurityReasons() } } @@ -478,6 +480,23 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo } } + @WorkerThread + fun checkIfConversationShouldBeDisabledForSecurityReasons() { + if (!chatRoom.hasCapability(ChatRoom.Capabilities.Encrypted.toInt())) { + val account = LinphoneUtils.getDefaultAccount() + if (account?.isEndToEndEncryptionMandatory() == true) { + Log.w( + "$TAG Conversation with subject [${chatRoom.subject}] has been disabled because it isn't encrypted and default account is in secure mode" + ) + isDisabledBecauseNotSecured.postValue(true) + } else { + isDisabledBecauseNotSecured.postValue(false) + } + } else { + isDisabledBecauseNotSecured.postValue(false) + } + } + @WorkerThread private fun configureChatRoom() { scrollingPosition = SCROLLING_POSITION_NOT_SET @@ -507,15 +526,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo Log.w("$TAG Conversation with subject [${chatRoom.subject}] is read only!") } - if (!chatRoom.hasCapability(ChatRoom.Capabilities.Encrypted.toInt())) { - val account = LinphoneUtils.getDefaultAccount() - if (account?.isEndToEndEncryptionMandatory() == true) { - Log.w( - "$TAG Conversation with subject [${chatRoom.subject}] has been disabled because it isn't encrypted and default account is in secure mode" - ) - isDisabledBecauseNotSecured.postValue(true) - } - } + checkIfConversationShouldBeDisabledForSecurityReasons() subject.postValue(chatRoom.subject) diff --git a/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt b/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt index 5a518f0ac..f823204a6 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/fragment/AccountProfileFragment.kt @@ -134,15 +134,17 @@ class AccountProfileFragment : GenericFragment() { } binding.setChangeModeClickListener { - val action = AccountProfileFragmentDirections.actionAccountProfileFragmentToAccountProfileModeFragment() - findNavController().navigate(action) + goToAccountProfileModeFragment() } binding.setSettingsClickListener { - val action = AccountProfileFragmentDirections.actionAccountProfileFragmentToAccountSettingsFragment( - identity - ) - findNavController().navigate(action) + if (findNavController().currentDestination?.id == R.id.accountProfileFragment) { + val action = + AccountProfileFragmentDirections.actionAccountProfileFragmentToAccountSettingsFragment( + identity + ) + findNavController().navigate(action) + } } binding.setDeleteAccountClickListener { @@ -181,8 +183,16 @@ class AccountProfileFragment : GenericFragment() { if (found) { (view.parent as? ViewGroup)?.doOnPreDraw { startPostponedEnterTransition() - setupDialPlanPicker() + + sharedViewModel.goToAccountProfileModeEvent.observe(viewLifecycleOwner) { + it.consume { + Log.i( + "$TAG Account was found, going directly to AccountProfileMode fragment" + ) + goToAccountProfileModeFragment() + } + } } } else { Log.e( @@ -203,6 +213,14 @@ class AccountProfileFragment : GenericFragment() { sharedViewModel.refreshDrawerMenuAccountsListEvent.value = Event(true) } + private fun goToAccountProfileModeFragment() { + if (findNavController().currentDestination?.id == R.id.accountProfileFragment) { + val action = + AccountProfileFragmentDirections.actionAccountProfileFragmentToAccountProfileModeFragment() + findNavController().navigate(action) + } + } + private fun pickImage() { pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) } diff --git a/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt b/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt index 58e736098..7be60a83b 100644 --- a/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/viewmodel/SharedMainViewModel.kt @@ -75,6 +75,16 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() { MutableLiveData>() } + /* Account Profile related */ + + val goToAccountProfileEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + + val goToAccountProfileModeEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + /* Contacts related */ var displayedFriend: Friend? = null // Prevents the need to go look for the friend diff --git a/app/src/main/res/layout/chat_conversation_fragment.xml b/app/src/main/res/layout/chat_conversation_fragment.xml index c9e09b5e3..d46c15192 100644 --- a/app/src/main/res/layout/chat_conversation_fragment.xml +++ b/app/src/main/res/layout/chat_conversation_fragment.xml @@ -278,8 +278,8 @@ android:onClick="@{warningConversationDisabledClickListener}" android:layout_width="match_parent" android:layout_height="wrap_content" - layout="@layout/chat_conversation_send_area_disabled_unsecured_warning" android:visibility="@{viewModel.isDisabledBecauseNotSecured ? View.VISIBLE : View.GONE, default=gone}" + layout="@layout/chat_conversation_send_area_disabled_unsecured_warning" app:layout_constraintBottom_toTopOf="@id/send_area"/> +