mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-23 19:48:30 +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
|
package org.linphone.ui.main.calls.fragment
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
@ -81,6 +82,8 @@ class StartCallFragment : GenericFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var numberOrAddressPickerDialog: Dialog? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
|
@ -175,6 +178,13 @@ class StartCallFragment : GenericFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
|
||||||
|
numberOrAddressPickerDialog?.dismiss()
|
||||||
|
numberOrAddressPickerDialog = null
|
||||||
|
}
|
||||||
|
|
||||||
private fun startCall(model: ContactAvatarModel) {
|
private fun startCall(model: ContactAvatarModel) {
|
||||||
coreContext.postOnCoreThread { core ->
|
coreContext.postOnCoreThread { core ->
|
||||||
val friend = model.friend
|
val friend = model.friend
|
||||||
|
|
@ -200,6 +210,7 @@ class StartCallFragment : GenericFragment() {
|
||||||
val model = NumberOrAddressPickerDialogModel(list)
|
val model = NumberOrAddressPickerDialogModel(list)
|
||||||
val dialog =
|
val dialog =
|
||||||
DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
||||||
|
numberOrAddressPickerDialog = dialog
|
||||||
|
|
||||||
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
||||||
event.consume {
|
event.consume {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.ui.main.contacts.fragment
|
package org.linphone.ui.main.contacts.fragment
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
@ -59,6 +60,8 @@ class ContactFragment : GenericFragment() {
|
||||||
|
|
||||||
private val args: ContactFragmentArgs by navArgs()
|
private val args: ContactFragmentArgs by navArgs()
|
||||||
|
|
||||||
|
private var numberOrAddressPickerDialog: Dialog? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
|
@ -143,6 +146,7 @@ class ContactFragment : GenericFragment() {
|
||||||
viewModel.sipAddressesAndPhoneNumbers.value.orEmpty()
|
viewModel.sipAddressesAndPhoneNumbers.value.orEmpty()
|
||||||
)
|
)
|
||||||
val dialog = DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
val dialog = DialogUtils.getNumberOrAddressPickerDialog(requireActivity(), model)
|
||||||
|
numberOrAddressPickerDialog = dialog
|
||||||
|
|
||||||
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
model.dismissEvent.observe(viewLifecycleOwner) { event ->
|
||||||
event.consume {
|
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) {
|
private fun copyNumberOrAddressToClipboard(value: String, isSip: Boolean) {
|
||||||
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
val label = if (isSip) "SIP address" else "Phone number"
|
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.FriendListenerStub
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -43,6 +44,8 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
||||||
|
|
||||||
val initials = LinphoneUtils.getInitials(friend.name.orEmpty())
|
val initials = LinphoneUtils.getInitials(friend.name.orEmpty())
|
||||||
|
|
||||||
|
val lastPresenceInfo = MutableLiveData<String>()
|
||||||
|
|
||||||
val presenceStatus = MutableLiveData<ConsolidatedPresence>()
|
val presenceStatus = MutableLiveData<ConsolidatedPresence>()
|
||||||
|
|
||||||
val name = MutableLiveData<String>()
|
val name = MutableLiveData<String>()
|
||||||
|
|
@ -59,7 +62,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
||||||
Log.d(
|
Log.d(
|
||||||
"$TAG Presence received for friend [${fr.name}]: [${fr.consolidatedPresence}]"
|
"$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)
|
friend.addListener(friendListener)
|
||||||
|
|
||||||
name.postValue(friend.name)
|
name.postValue(friend.name)
|
||||||
presenceStatus.postValue(friend.consolidatedPresence)
|
computePresence()
|
||||||
Log.d("$TAG Friend [${friend.name}] presence status is [${friend.consolidatedPresence}]")
|
|
||||||
avatar.postValue(getAvatarUri())
|
avatar.postValue(getAvatarUri())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,4 +104,57 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) {
|
||||||
|
|
||||||
return null
|
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:visibility="@{viewModel.callLogModel.avatarModel.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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:textColor="@{viewModel.callLogModel.avatarModel.presenceStatus == ConsolidatedPresence.Online ? @color/green_online : @color/orange_away, default=@color/green_online}"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@
|
||||||
android:visibility="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
|
android:visibility="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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:textColor="@{viewModel.contact.presenceStatus == ConsolidatedPresence.Online ? @color/green_online : @color/orange_away, default=@color/green_online}"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue