Added shortcut to account profile mode fragment from plain text conversation

This commit is contained in:
Sylvain Berfini 2024-04-29 16:23:56 +02:00
parent cf7dbb7f61
commit b4baddcc5b
7 changed files with 81 additions and 18 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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)

View file

@ -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))
}

View file

@ -75,6 +75,16 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Boolean>>()
}
/* Account Profile related */
val goToAccountProfileEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val goToAccountProfileModeEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
/* Contacts related */
var displayedFriend: Friend? = null // Prevents the need to go look for the friend

View file

@ -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"/>
<include

View file

@ -281,6 +281,12 @@
app:launchSingleTop="true"
app:enterAnim="@anim/slide_in"
app:popExitAnim="@anim/slide_out" />
<action
android:id="@+id/action_conversationsListFragment_to_accountProfileFragment"
app:destination="@id/accountProfileFragment"
app:launchSingleTop="true"
app:enterAnim="@anim/slide_in"
app:popExitAnim="@anim/slide_out" />
</fragment>
<fragment