mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-21 13:48:11 +00:00
Fixed a few things with AvatarView
This commit is contained in:
parent
1a9e11a258
commit
52238e5d27
15 changed files with 103 additions and 26 deletions
|
|
@ -38,6 +38,8 @@ class AccountModel @WorkerThread constructor(
|
|||
|
||||
val avatar = MutableLiveData<String>()
|
||||
|
||||
val initials = MutableLiveData<String>()
|
||||
|
||||
val registrationState = MutableLiveData<String>()
|
||||
|
||||
val isConnected = MutableLiveData<Boolean>()
|
||||
|
|
@ -46,6 +48,8 @@ class AccountModel @WorkerThread constructor(
|
|||
|
||||
val isDefault = MutableLiveData<Boolean>()
|
||||
|
||||
val showTrust = MutableLiveData<Boolean>()
|
||||
|
||||
private val accountListener = object : AccountListenerStub() {
|
||||
@WorkerThread
|
||||
override fun onRegistrationStateChanged(
|
||||
|
|
@ -61,6 +65,7 @@ class AccountModel @WorkerThread constructor(
|
|||
account.addListener(accountListener)
|
||||
|
||||
avatar.postValue(account.getPicturePath())
|
||||
showTrust.postValue(account.isInSecureMode())
|
||||
|
||||
update()
|
||||
}
|
||||
|
|
@ -92,7 +97,9 @@ class AccountModel @WorkerThread constructor(
|
|||
|
||||
@WorkerThread
|
||||
private fun update() {
|
||||
displayName.postValue(LinphoneUtils.getDisplayName(account.params.identityAddress))
|
||||
val name = LinphoneUtils.getDisplayName(account.params.identityAddress)
|
||||
displayName.postValue(name)
|
||||
initials.postValue(LinphoneUtils.getInitials(name))
|
||||
|
||||
isDefault.postValue(coreContext.core.defaultAccount == account)
|
||||
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
|
|||
isMicrophoneMuted.postValue(call.microphoneMuted)
|
||||
isOutgoing.postValue(call.dir == Call.Dir.Outgoing)
|
||||
|
||||
val address = call.remoteAddress
|
||||
val address = call.remoteAddress.clone()
|
||||
address.clean()
|
||||
displayedAddress.postValue(address.asStringUriOnly())
|
||||
|
||||
|
|
|
|||
32
app/src/main/java/org/linphone/utils/AppUtils.kt
Normal file
32
app/src/main/java/org/linphone/utils/AppUtils.kt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2023 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.utils
|
||||
|
||||
import androidx.annotation.AnyThread
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
||||
class AppUtils {
|
||||
companion object {
|
||||
@AnyThread
|
||||
fun getDimension(id: Int): Float {
|
||||
return coreContext.context.resources.getDimension(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ import org.linphone.core.ConsolidatedPresence
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.ui.main.model.AccountModel
|
||||
|
||||
/**
|
||||
* This file contains all the data binding necessary for the app
|
||||
|
|
@ -190,6 +191,34 @@ fun ImageView.setPresenceIcon(presence: ConsolidatedPresence?) {
|
|||
setImageResource(icon)
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("accountAvatar")
|
||||
fun AvatarView.loadAccountAvatar(account: AccountModel?) {
|
||||
if (account == null) {
|
||||
loadImage(R.drawable.contact_avatar)
|
||||
} else {
|
||||
val uri = account.avatar.value
|
||||
loadImage(
|
||||
data = uri,
|
||||
onStart = {
|
||||
// Use initials as placeholder
|
||||
avatarInitials = account.initials.value.orEmpty()
|
||||
|
||||
if (account.showTrust.value == true) {
|
||||
avatarBorderColor = resources.getColor(R.color.trusted_blue, context.theme)
|
||||
avatarBorderWidth = AppUtils.getDimension(R.dimen.avatar_trust_border_width).toInt()
|
||||
} else {
|
||||
avatarBorderWidth = AppUtils.getDimension(R.dimen.zero).toInt()
|
||||
}
|
||||
},
|
||||
onSuccess = { _, _ ->
|
||||
// If loading is successful, remove initials otherwise image won't be visible
|
||||
avatarInitials = ""
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("contactAvatar")
|
||||
fun AvatarView.loadContactAvatar(contact: ContactAvatarModel?) {
|
||||
|
|
|
|||
|
|
@ -33,23 +33,27 @@
|
|||
android:layout_marginBottom="5dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/shape_button_round"
|
||||
coil="@{model.avatar}"
|
||||
accountAvatar="@{model}"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="16sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderColor="@color/trusted_blue"
|
||||
app:avatarViewBorderWidth="2dp"
|
||||
app:avatarViewIndicatorSizeCriteria="3"
|
||||
app:avatarViewIndicatorEnabled="true"
|
||||
app:avatarViewIndicatorDrawable="@drawable/trusted"
|
||||
app:avatarViewIndicatorPosition="bottomLeft"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trust_badge"
|
||||
android:layout_width="@dimen/avatar_presence_badge_size"
|
||||
android:layout_height="@dimen/avatar_presence_badge_size"
|
||||
android:src="@drawable/trusted"
|
||||
android:visibility="@{model.showTrust ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintStart_toStartOf="@id/avatar"
|
||||
app:layout_constraintBottom_toBottomOf="@id/avatar"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/name"
|
||||
|
|
|
|||
|
|
@ -91,13 +91,13 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{viewModel.callLogModel.avatarModel}"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="21sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -38,14 +38,13 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{model.avatarModel}"
|
||||
app:avatarViewInitials="JD"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="16sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="2dp"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
app:avatarViewInitialsTextSize="16sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -109,13 +109,13 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{viewModel.contact}"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="21sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -61,13 +61,13 @@
|
|||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{model}"
|
||||
app:avatarViewInitials="SB"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="16sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/header"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
|
|
|||
|
|
@ -41,23 +41,27 @@
|
|||
android:layout_height="@dimen/avatar_list_cell_size"
|
||||
android:layout_marginStart="15dp"
|
||||
android:background="@drawable/shape_button_round"
|
||||
coil="@{viewModel.account.avatar}"
|
||||
app:avatarViewBorderColor="@color/trusted_blue"
|
||||
app:avatarViewBorderWidth="2dp"
|
||||
app:avatarViewIndicatorSizeCriteria="3"
|
||||
app:avatarViewIndicatorEnabled="true"
|
||||
app:avatarViewIndicatorDrawable="@drawable/trusted"
|
||||
app:avatarViewIndicatorPosition="bottomLeft"
|
||||
accountAvatar="@{viewModel.account}"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="21sp"
|
||||
app:avatarViewInitialsTextSize="16sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trust_badge"
|
||||
android:layout_width="@dimen/avatar_presence_badge_size"
|
||||
android:layout_height="@dimen/avatar_presence_badge_size"
|
||||
android:src="@drawable/trusted"
|
||||
android:visibility="@{viewModel.account.showTrust ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintStart_toStartOf="@id/avatar"
|
||||
app:layout_constraintBottom_toBottomOf="@id/avatar"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_800"
|
||||
android:id="@+id/title"
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@
|
|||
android:id="@+id/avatar"
|
||||
android:layout_width="@dimen/avatar_in_call_size"
|
||||
android:layout_height="@dimen/avatar_in_call_size"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{viewModel.contact}"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
|
|
@ -105,6 +104,7 @@
|
|||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintEnd_toEndOf="@id/background"
|
||||
app:layout_constraintStart_toStartOf="@id/background"
|
||||
app:layout_constraintTop_toTopOf="@id/background"
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@
|
|||
android:id="@+id/avatar"
|
||||
android:layout_width="@dimen/avatar_in_call_size"
|
||||
android:layout_height="@dimen/avatar_in_call_size"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{viewModel.contact}"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
|
|
@ -65,6 +64,7 @@
|
|||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintEnd_toEndOf="@id/background"
|
||||
app:layout_constraintStart_toStartOf="@id/background"
|
||||
app:layout_constraintTop_toTopOf="@id/background"
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@
|
|||
android:layout_height="@dimen/avatar_in_call_size"
|
||||
android:background="@drawable/shape_button_round"
|
||||
contactAvatar="@{viewModel.contact}"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:avatarViewInitialsBackgroundColor="@color/blue_outgoing_message"
|
||||
app:avatarViewInitialsTextColor="@color/gray_9"
|
||||
app:avatarViewInitialsTextSize="36sp"
|
||||
app:avatarViewInitialsTextStyle="bold"
|
||||
app:avatarViewPlaceholder="@drawable/contact_avatar"
|
||||
app:avatarViewShape="circle"
|
||||
app:avatarViewBorderWidth="0dp"
|
||||
app:layout_constraintEnd_toEndOf="@id/background"
|
||||
app:layout_constraintStart_toStartOf="@id/background"
|
||||
app:layout_constraintTop_toTopOf="@id/background"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<dimen name="avatar_presence_badge_big_size">22dp</dimen>
|
||||
<dimen name="avatar_presence_badge_big_padding">3dp</dimen>
|
||||
<dimen name="avatar_presence_badge_big_end_margin">5dp</dimen>
|
||||
<dimen name="avatar_trust_border_width">2dp</dimen>
|
||||
|
||||
<dimen name="top_bar_height">55dp</dimen>
|
||||
<dimen name="toast_top_margin">70dp</dimen> <!-- 15dp + top_bar_height -->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue