diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationEphemeralLifetimeFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationEphemeralLifetimeFragment.kt
new file mode 100644
index 000000000..9704a51bf
--- /dev/null
+++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationEphemeralLifetimeFragment.kt
@@ -0,0 +1,68 @@
+package org.linphone.ui.main.chat.fragment
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.annotation.UiThread
+import androidx.lifecycle.ViewModelProvider
+import androidx.navigation.fragment.findNavController
+import androidx.navigation.fragment.navArgs
+import org.linphone.core.tools.Log
+import org.linphone.databinding.ChatEphemeralLifetimeFragmentBinding
+import org.linphone.ui.main.chat.viewmodel.ConversationEphemeralLifetimeViewModel
+import org.linphone.ui.main.fragment.GenericFragment
+import org.linphone.utils.Event
+
+@UiThread
+class ConversationEphemeralLifetimeFragment : GenericFragment() {
+ companion object {
+ private const val TAG = "[Conversation Ephemeral Lifetime Fragment]"
+ }
+
+ private lateinit var binding: ChatEphemeralLifetimeFragmentBinding
+
+ private lateinit var viewModel: ConversationEphemeralLifetimeViewModel
+
+ private val args: ConversationEphemeralLifetimeFragmentArgs by navArgs()
+
+ override fun goBack(): Boolean {
+ return findNavController().popBackStack()
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ binding = ChatEphemeralLifetimeFragmentBinding.inflate(layoutInflater)
+ return binding.root
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ // This fragment is displayed in a SlidingPane "child" area
+ isSlidingPaneChild = true
+
+ super.onViewCreated(view, savedInstanceState)
+
+ binding.lifecycleOwner = viewLifecycleOwner
+
+ viewModel = ViewModelProvider(this)[ConversationEphemeralLifetimeViewModel::class.java]
+ binding.viewModel = viewModel
+
+ val lifetime = args.currentEphemeralLifetime
+ Log.i("$TAG Current lifetime for ephemeral messages is [$lifetime]")
+ viewModel.currentlySelectedValue.value = lifetime
+
+ binding.setBackClickListener {
+ goBack()
+ }
+ }
+
+ override fun onPause() {
+ sharedViewModel.newChatMessageEphemeralLifetimeToSet.value = Event(
+ viewModel.currentlySelectedValue.value ?: 0L
+ )
+ super.onPause()
+ }
+}
diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationInfoFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationInfoFragment.kt
index c6356daf8..7f538a967 100644
--- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationInfoFragment.kt
+++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationInfoFragment.kt
@@ -37,7 +37,6 @@ import org.linphone.core.tools.Log
import org.linphone.databinding.ChatInfoFragmentBinding
import org.linphone.databinding.ChatParticipantAdminPopupMenuBinding
import org.linphone.ui.main.chat.adapter.ConversationParticipantsAdapter
-import org.linphone.ui.main.chat.model.ConversationConfigureEphemeralDurationDialogModel
import org.linphone.ui.main.chat.model.ConversationEditSubjectDialogModel
import org.linphone.ui.main.chat.model.ParticipantModel
import org.linphone.ui.main.chat.viewmodel.ConversationInfoViewModel
@@ -158,6 +157,15 @@ class ConversationInfoFragment : GenericFragment() {
}
}
+ sharedViewModel.newChatMessageEphemeralLifetimeToSet.observe(viewLifecycleOwner) {
+ it.consume { ephemeralLifetime ->
+ Log.i(
+ "$TAG Setting [$ephemeralLifetime] as new ephemeral lifetime for chat messages"
+ )
+ viewModel.updateEphemeralLifetime(ephemeralLifetime)
+ }
+ }
+
binding.setBackClickListener {
goBack()
}
@@ -198,37 +206,15 @@ class ConversationInfoFragment : GenericFragment() {
}
binding.setConfigureEphemeralMessagesClickListener {
- val currentValue = viewModel.ephemeralLifetime.value ?: 0
- val model = ConversationConfigureEphemeralDurationDialogModel(currentValue)
-
- val dialog = DialogUtils.getConfigureChatMessagesEphemeralDurationDialog(
- requireContext(),
- model
- )
-
- model.dismissEvent.observe(viewLifecycleOwner) {
- it.consume {
- Log.i("$TAG Ephemeral lifetime value wasn't changed")
- dialog.dismiss()
- }
+ val currentValue = viewModel.ephemeralLifetime.value ?: 0L
+ if (findNavController().currentDestination?.id == R.id.conversationInfoFragment) {
+ Log.i("$TAG Going to ephemeral lifetime fragment (currently [$currentValue])")
+ val action =
+ ConversationInfoFragmentDirections.actionConversationInfoFragmentToConversationEphemeralLifetimeFragment(
+ currentValue
+ )
+ findNavController().navigate(action)
}
-
- model.newValueSelectedEvent.observe(viewLifecycleOwner) {
- it.consume { duration ->
- if (duration != currentValue) {
- Log.i(
- "$TAG Conversation chat message lifetime updated to [$duration] (previous one was [$currentValue])"
- )
- viewModel.updateEphemeralLifetime(duration)
- }
- dialog.dismiss()
- }
- }
-
- Log.i(
- "$TAG Showing dialog to change chat messages ephemeral duration (currently [$currentValue])"
- )
- dialog.show()
}
}
diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt
index f3a1f325f..7b1e18d5c 100644
--- a/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt
+++ b/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt
@@ -98,22 +98,22 @@ class EventModel @WorkerThread constructor(private val eventLog: EventLog) {
private fun formatEphemeralExpiration(duration: Long): String {
return when (duration) {
0L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_disabled
+ R.string.conversation_ephemeral_messages_duration_disabled
)
60L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_one_minute
+ R.string.conversation_ephemeral_messages_duration_one_minute
)
3600L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_one_hour
+ R.string.conversation_ephemeral_messages_duration_one_hour
)
86400L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_one_day
+ R.string.conversation_ephemeral_messages_duration_one_day
)
259200L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_three_days
+ R.string.conversation_ephemeral_messages_duration_three_days
)
604800L -> AppUtils.getString(
- R.string.dialog_conversation_message_ephemeral_duration_one_week
+ R.string.conversation_ephemeral_messages_duration_one_week
)
else -> "$duration s"
}
diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/ConversationConfigureEphemeralDurationDialogModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationEphemeralLifetimeViewModel.kt
similarity index 65%
rename from app/src/main/java/org/linphone/ui/main/chat/model/ConversationConfigureEphemeralDurationDialogModel.kt
rename to app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationEphemeralLifetimeViewModel.kt
index d4f34a054..dcc42e23e 100644
--- a/app/src/main/java/org/linphone/ui/main/chat/model/ConversationConfigureEphemeralDurationDialogModel.kt
+++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationEphemeralLifetimeViewModel.kt
@@ -17,26 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package org.linphone.ui.main.chat.model
+package org.linphone.ui.main.chat.viewmodel
import androidx.annotation.UiThread
import androidx.lifecycle.MutableLiveData
-import org.linphone.utils.Event
+import androidx.lifecycle.ViewModel
-class ConversationConfigureEphemeralDurationDialogModel @UiThread constructor(
- val currentlySelectedValue: Int
-) {
- val dismissEvent = MutableLiveData>()
+class ConversationEphemeralLifetimeViewModel @UiThread constructor() : ViewModel() {
+ val currentlySelectedValue = MutableLiveData()
- val newValueSelectedEvent = MutableLiveData>()
-
- @UiThread
- fun dismiss() {
- dismissEvent.value = Event(true)
+ init {
+ currentlySelectedValue.value = 0
}
@UiThread
- fun onValueSelected(value: Int) {
- newValueSelectedEvent.value = Event(value)
+ fun onValueSelected(value: Long) {
+ currentlySelectedValue.value = value
}
}
diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt
index 254e93110..ca275d4a4 100644
--- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt
+++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationInfoViewModel.kt
@@ -58,7 +58,7 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
val isMuted = MutableLiveData()
- val ephemeralLifetime = MutableLiveData()
+ val ephemeralLifetime = MutableLiveData()
val expandParticipants = MutableLiveData()
@@ -335,9 +335,9 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
}
@UiThread
- fun updateEphemeralLifetime(lifetime: Int) {
+ fun updateEphemeralLifetime(lifetime: Long) {
coreContext.postOnCoreThread {
- if (lifetime == 0) {
+ if (lifetime == 0L) {
if (chatRoom.isEphemeralEnabled) {
Log.i("$TAG Disabling ephemeral messages")
chatRoom.isEphemeralEnabled = false
@@ -348,14 +348,13 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
chatRoom.isEphemeralEnabled = true
}
- val longLifetime = lifetime.toLong()
- if (chatRoom.ephemeralLifetime != longLifetime) {
- Log.i("$TAG Updating lifetime to [$longLifetime]")
- chatRoom.ephemeralLifetime = longLifetime
+ if (chatRoom.ephemeralLifetime != lifetime) {
+ Log.i("$TAG Updating lifetime to [$lifetime]")
+ chatRoom.ephemeralLifetime = lifetime
}
}
ephemeralLifetime.postValue(
- if (!chatRoom.isEphemeralEnabled) 0 else chatRoom.ephemeralLifetime.toInt()
+ if (!chatRoom.isEphemeralEnabled) 0L else chatRoom.ephemeralLifetime
)
Log.i(
"$TAG Ephemeral chat messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]"
@@ -383,7 +382,7 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
sipUri.postValue(chatRoom.participants.firstOrNull()?.address?.asStringUriOnly())
ephemeralLifetime.postValue(
- if (!chatRoom.isEphemeralEnabled) 0 else chatRoom.ephemeralLifetime.toInt()
+ if (!chatRoom.isEphemeralEnabled) 0L else chatRoom.ephemeralLifetime
)
computeParticipantsList()
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 123078636..6ec0b742a 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
@@ -114,6 +114,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
MutableLiveData>()
}
+ val newChatMessageEphemeralLifetimeToSet: MutableLiveData> by lazy {
+ MutableLiveData>()
+ }
+
/* Meetings related */
val forceRefreshMeetingsListEvent: MutableLiveData> by lazy {
diff --git a/app/src/main/java/org/linphone/utils/DialogUtils.kt b/app/src/main/java/org/linphone/utils/DialogUtils.kt
index f8a5e36fc..e7b491cf5 100644
--- a/app/src/main/java/org/linphone/utils/DialogUtils.kt
+++ b/app/src/main/java/org/linphone/utils/DialogUtils.kt
@@ -35,7 +35,6 @@ import org.linphone.databinding.DialogAccountModesExplanationBinding
import org.linphone.databinding.DialogAssistantAcceptConditionsAndPolicyBinding
import org.linphone.databinding.DialogAssistantCreateAccountConfirmPhoneNumberBinding
import org.linphone.databinding.DialogCancelContactChangesBinding
-import org.linphone.databinding.DialogConfigureConversationEphemeralMessagesBinding
import org.linphone.databinding.DialogConfirmZrtpSasBinding
import org.linphone.databinding.DialogContactConfirmTrustCallBinding
import org.linphone.databinding.DialogContactTrustProcessBinding
@@ -50,7 +49,6 @@ import org.linphone.databinding.DialogUpdateAvailableBinding
import org.linphone.ui.assistant.model.AcceptConditionsAndPolicyDialogModel
import org.linphone.ui.assistant.model.ConfirmPhoneNumberDialogModel
import org.linphone.ui.call.model.ZrtpSasConfirmationDialogModel
-import org.linphone.ui.main.chat.model.ConversationConfigureEphemeralDurationDialogModel
import org.linphone.ui.main.chat.model.ConversationEditSubjectDialogModel
import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel
import org.linphone.ui.main.contacts.model.TrustCallDialogModel
@@ -285,22 +283,6 @@ class DialogUtils {
return getDialog(context, binding)
}
- @UiThread
- fun getConfigureChatMessagesEphemeralDurationDialog(
- context: Context,
- viewModel: ConversationConfigureEphemeralDurationDialogModel
- ): Dialog {
- val binding: DialogConfigureConversationEphemeralMessagesBinding = DataBindingUtil.inflate(
- LayoutInflater.from(context),
- R.layout.dialog_configure_conversation_ephemeral_messages,
- null,
- false
- )
- binding.viewModel = viewModel
-
- return getDialog(context, binding)
- }
-
@UiThread
fun getUpdateAvailableDialog(
context: Context,
diff --git a/app/src/main/res/layout/chat_ephemeral_lifetime_fragment.xml b/app/src/main/res/layout/chat_ephemeral_lifetime_fragment.xml
new file mode 100644
index 000000000..e62a5555d
--- /dev/null
+++ b/app/src/main/res/layout/chat_ephemeral_lifetime_fragment.xml
@@ -0,0 +1,229 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_configure_conversation_ephemeral_messages.xml b/app/src/main/res/layout/dialog_configure_conversation_ephemeral_messages.xml
deleted file mode 100644
index 2e7390daa..000000000
--- a/app/src/main/res/layout/dialog_configure_conversation_ephemeral_messages.xml
+++ /dev/null
@@ -1,223 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/navigation/chat_nav_graph.xml b/app/src/main/res/navigation/chat_nav_graph.xml
index 286fda8b1..80744b3f8 100644
--- a/app/src/main/res/navigation/chat_nav_graph.xml
+++ b/app/src/main/res/navigation/chat_nav_graph.xml
@@ -54,6 +54,13 @@
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6a9708c26..b06b75174 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -120,14 +120,6 @@
Blah blah blah
Edit conversation subject
Confirm
- Enable ephemeral messages
- New messages will be automatically deleted once read by everyone.\nChoose a duration:
- Disabled
- 1 minute
- 1 hour
- 1 day
- 3 days
- 1 week
Invalid QR code!
SIP address copied into clipboard
@@ -362,6 +354,14 @@
Delete conversation
Leave the group
Configure ephemeral messages
+ Ephemeral messages
+ New messages will be automatically deleted once read by everyone.\nChoose a duration:
+ Disabled
+ 1 minute
+ 1 hour
+ 1 day
+ 3 days
+ 1 week
New conversation
Search contact
Create a group conversation