mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Compute & show last seen online at + close sip address/phone number picker dialog when used
This commit is contained in:
parent
3f6339887b
commit
db3117b92e
5 changed files with 82 additions and 5 deletions
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
package org.linphone.ui.main.calls.fragment
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -81,6 +82,8 @@ class StartCallFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private var numberOrAddressPickerDialog: Dialog? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -175,6 +178,13 @@ class StartCallFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
numberOrAddressPickerDialog?.dismiss()
|
||||
numberOrAddressPickerDialog = null
|
||||
}
|
||||
|
||||
private fun startCall(model: ContactAvatarModel) {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
val friend = model.friend
|
||||
|
|
@ -200,6 +210,7 @@ class StartCallFragment : GenericFragment() {
|
|||
val model = NumberOrAddressPickerDialogModel(list)
|
||||
val dialog =
|
||||
DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
||||
numberOrAddressPickerDialog = dialog
|
||||
|
||||
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
||||
event.consume {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
package org.linphone.ui.main.contacts.fragment
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
|
|
@ -59,6 +60,8 @@ class ContactFragment : GenericFragment() {
|
|||
|
||||
private val args: ContactFragmentArgs by navArgs()
|
||||
|
||||
private var numberOrAddressPickerDialog: Dialog? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -143,6 +146,7 @@ class ContactFragment : GenericFragment() {
|
|||
viewModel.sipAddressesAndPhoneNumbers.value.orEmpty()
|
||||
)
|
||||
val dialog = DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
||||
numberOrAddressPickerDialog = dialog
|
||||
|
||||
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
||||
event.consume {
|
||||
|
|
@ -197,6 +201,13 @@ class ContactFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
numberOrAddressPickerDialog?.dismiss()
|
||||
numberOrAddressPickerDialog = null
|
||||
}
|
||||
|
||||
private fun copyNumberOrAddressToClipboard(value: String, isSip: Boolean) {
|
||||
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val label = if (isSip) "SIP address" else "Phone number"
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.linphone.core.Friend
|
|||
import org.linphone.core.FriendListenerStub
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.TimestampUtils
|
||||
|
||||
class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
||||
companion object {
|
||||
|
|
@ -43,6 +44,8 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
|||
|
||||
val initials = LinphoneUtils.getInitials(friend.name.orEmpty())
|
||||
|
||||
val lastPresenceInfo = MutableLiveData<String>()
|
||||
|
||||
val presenceStatus = MutableLiveData<ConsolidatedPresence>()
|
||||
|
||||
val name = MutableLiveData<String>()
|
||||
|
|
@ -59,7 +62,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
|||
Log.d(
|
||||
"$TAG Presence received for friend [${fr.name}]: [${fr.consolidatedPresence}]"
|
||||
)
|
||||
presenceStatus.postValue(fr.consolidatedPresence)
|
||||
computePresence()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,8 +70,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
|||
friend.addListener(friendListener)
|
||||
|
||||
name.postValue(friend.name)
|
||||
presenceStatus.postValue(friend.consolidatedPresence)
|
||||
Log.d("$TAG Friend [${friend.name}] presence status is [${friend.consolidatedPresence}]")
|
||||
computePresence()
|
||||
avatar.postValue(getAvatarUri())
|
||||
}
|
||||
|
||||
|
|
@ -102,4 +104,57 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
|||
|
||||
return null
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun computePresence() {
|
||||
val presence = friend.consolidatedPresence
|
||||
Log.d("$TAG Friend [${friend.name}] presence status is [$presence]")
|
||||
presenceStatus.postValue(presence)
|
||||
|
||||
val presenceString = when (presence) {
|
||||
ConsolidatedPresence.Online -> {
|
||||
"Online"
|
||||
}
|
||||
ConsolidatedPresence.Busy -> {
|
||||
val timestamp = friend.presenceModel?.latestActivityTimestamp ?: -1L
|
||||
if (timestamp != -1L) {
|
||||
when {
|
||||
TimestampUtils.isToday(timestamp) -> {
|
||||
val time = TimestampUtils.timeToString(
|
||||
timestamp,
|
||||
timestampInSecs = true
|
||||
)
|
||||
val text = "Online today at"
|
||||
"$text $time"
|
||||
}
|
||||
TimestampUtils.isYesterday(timestamp) -> {
|
||||
val time = TimestampUtils.timeToString(
|
||||
timestamp,
|
||||
timestampInSecs = true
|
||||
)
|
||||
val text = "Online yesterday at"
|
||||
"$text $time"
|
||||
}
|
||||
else -> {
|
||||
val date = TimestampUtils.toString(
|
||||
timestamp,
|
||||
onlyDate = true,
|
||||
shortDate = false,
|
||||
hideYear = true
|
||||
)
|
||||
val text = "Online on"
|
||||
"$text $date"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
"Away"
|
||||
}
|
||||
}
|
||||
ConsolidatedPresence.DoNotDisturb -> {
|
||||
"Do not disturb"
|
||||
}
|
||||
else -> ""
|
||||
}
|
||||
lastPresenceInfo.postValue(presenceString)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@
|
|||
android:visibility="@{viewModel.callLogModel.avatarModel.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.callLogModel.avatarModel.presenceStatus == ConsolidatedPresence.Online ? `En ligne` : `Absent`, default=`En ligne`}"
|
||||
android:text="@{viewModel.callLogModel.avatarModel.lastPresenceInfo, default=`En ligne`}"
|
||||
android:textColor="@{viewModel.callLogModel.avatarModel.presenceStatus == ConsolidatedPresence.Online ? @color/green_online : @color/orange_away, default=@color/green_online}"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@
|
|||
android:visibility="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Online ? `En ligne` : `Absent`, default=`En ligne`}"
|
||||
android:text="@{viewModel.contact.lastPresenceInfo, default=`En ligne`}"
|
||||
android:textColor="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Online ? @color/green_online : @color/orange_away, default=@color/green_online}"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue