Added edit/remove contact/account picture

This commit is contained in:
Sylvain Berfini 2023-09-27 16:17:00 +02:00
parent 42dd293aa8
commit 95401fb8c4
8 changed files with 120 additions and 15 deletions

View file

@ -139,6 +139,10 @@ class EditContactFragment : GenericFragment() {
pickImage()
}
binding.setDeleteImageClickListener {
viewModel.picturePath.value = ""
}
viewModel.saveChangesEvent.observe(viewLifecycleOwner) {
it.consume { refKey ->
if (refKey.isNotEmpty()) {

View file

@ -126,6 +126,10 @@ class NewContactFragment : GenericFragment() {
pickImage()
}
binding.setDeleteImageClickListener {
viewModel.picturePath.value = ""
}
viewModel.saveChangesEvent.observe(viewLifecycleOwner) {
it.consume { refKey ->
if (refKey.isNotEmpty()) {

View file

@ -102,7 +102,10 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
// TODO ? What to do when vCard is null
}
picturePath.postValue(friend.photo)
val photo = friend.photo.orEmpty()
if (photo.isNotEmpty()) {
picturePath.postValue(photo)
}
for (address in friend.addresses) {
addSipAddress(address.asStringUriOnly())
@ -146,6 +149,8 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
val picture = picturePath.value.orEmpty()
if (picture.isNotEmpty()) {
friend.photo = FileUtils.getProperFilePath(picture)
} else {
friend.photo = null
}
}

View file

@ -83,6 +83,10 @@ class AccountProfileFragment : GenericFragment() {
pickImage()
}
binding.setDeleteImageClickListener {
viewModel.setNewPicturePath("")
}
binding.setChangeModeClickListener {
val action = AccountProfileFragmentDirections.actionAccountProfileFragmentToAccountProfileModeFragment()
findNavController().navigate(action)

View file

@ -133,6 +133,9 @@ class AccountProfileViewModel @UiThread constructor() : ViewModel() {
if (path.isNotEmpty() && path != params.pictureUri) {
Log.i("$TAG New account profile picture [$path]")
copy.pictureUri = path
} else {
Log.i("$TAG Account profile picture removed")
copy.pictureUri = null
}
accountModel.value?.avatar?.postValue(path)

View file

@ -11,6 +11,9 @@
<variable
name="pickImageClickListener"
type="View.OnClickListener" />
<variable
name="deleteImageClickListener"
type="View.OnClickListener" />
<variable
name="changeModeClickListener"
type="View.OnClickListener" />
@ -108,17 +111,6 @@
app:layout_constraintStart_toStartOf="@id/avatar"
app:layout_constraintBottom_toBottomOf="@id/avatar"/>
<ImageView
android:id="@+id/overlay"
android:layout_width="@dimen/avatar_presence_badge_big_size"
android:layout_height="@dimen/avatar_presence_badge_big_size"
android:layout_marginEnd="@dimen/avatar_presence_badge_big_end_margin"
android:padding="@dimen/avatar_presence_badge_big_padding"
android:background="@drawable/led_background"
android:src="@drawable/camera"
app:layout_constraintEnd_toEndOf="@id/avatar"
app:layout_constraintBottom_toBottomOf="@id/avatar" />
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{pickImageClickListener}"
style="@style/default_text_style"
@ -126,12 +118,56 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@{viewModel.accountModel.avatar.empty ? @string/manage_account_add_picture : @string/manage_account_edit_picture, default=@string/manage_account_add_picture}"
android:text="@string/manage_account_add_picture"
android:textSize="14sp"
android:drawableStart="@drawable/camera"
android:drawablePadding="3dp"
android:visibility="@{viewModel.accountModel.avatar.empty ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{pickImageClickListener}"
style="@style/default_text_style"
android:id="@+id/edit_picture_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/manage_account_edit_picture"
android:textSize="14sp"
android:drawableStart="@drawable/pencil_simple"
android:drawablePadding="3dp"
android:visibility="@{viewModel.accountModel.avatar.empty ? View.GONE : View.VISIBLE}"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/remove_picture_label"/>
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{deleteImageClickListener}"
style="@style/default_text_style"
android:id="@+id/remove_picture_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
android:text="@string/manage_account_remove_picture"
android:textSize="14sp"
android:drawableStart="@drawable/trash_simple"
android:drawablePadding="3dp"
android:visibility="@{viewModel.accountModel.avatar.empty ? View.GONE : View.VISIBLE}"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toEndOf="@id/edit_picture_label"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/avatar_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="remove_picture_label, edit_picture_label, add_picture_label"
app:barrierDirection="bottom" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/section_header_style"
android:onClick="@{() -> viewModel.toggleDetailsExpand()}"
@ -147,7 +183,7 @@
android:drawableTint="@color/gray_main2_600"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_picture_label"/>
app:layout_constraintTop_toBottomOf="@id/avatar_barrier"/>
<ImageView
android:id="@+id/details_background"

View file

@ -11,6 +11,9 @@
<variable
name="pickImageClickListener"
type="View.OnClickListener" />
<variable
name="deleteImageClickListener"
type="View.OnClickListener" />
<variable
name="viewModel"
type="org.linphone.ui.main.contacts.viewmodel.ContactNewOrEditViewModel" />
@ -99,6 +102,7 @@
app:layout_constraintBottom_toBottomOf="@id/avatar" />
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{pickImageClickListener}"
style="@style/default_text_style"
android:id="@+id/add_picture_label"
android:layout_width="wrap_content"
@ -106,10 +110,54 @@
android:layout_marginTop="10dp"
android:text="@string/manage_account_add_picture"
android:textSize="14sp"
android:drawableStart="@drawable/camera"
android:drawablePadding="3dp"
android:visibility="@{viewModel.picturePath.empty ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{pickImageClickListener}"
style="@style/default_text_style"
android:id="@+id/edit_picture_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/manage_account_edit_picture"
android:textSize="14sp"
android:drawableStart="@drawable/pencil_simple"
android:drawablePadding="3dp"
android:visibility="@{viewModel.picturePath.empty ? View.GONE : View.VISIBLE}"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/remove_picture_label"/>
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{deleteImageClickListener}"
style="@style/default_text_style"
android:id="@+id/remove_picture_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
android:text="@string/manage_account_remove_picture"
android:textSize="14sp"
android:drawableStart="@drawable/trash_simple"
android:drawablePadding="3dp"
android:visibility="@{viewModel.picturePath.empty ? View.GONE : View.VISIBLE}"
app:layout_constraintTop_toBottomOf="@id/avatar"
app:layout_constraintStart_toEndOf="@id/edit_picture_label"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/avatar_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="remove_picture_label, edit_picture_label, add_picture_label"
app:barrierDirection="bottom" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/header_style"
android:id="@+id/first_name_label"
@ -119,7 +167,7 @@
android:layout_marginEnd="16dp"
android:text="@string/contact_editor_first_name"
app:layout_constraintStart_toStartOf="@id/first_name"
app:layout_constraintTop_toBottomOf="@id/add_picture_label"/>
app:layout_constraintTop_toBottomOf="@id/avatar_barrier"/>
<androidx.appcompat.widget.AppCompatEditText
style="@style/default_text_style"

View file

@ -195,6 +195,7 @@
<string name="manage_account_devices_title">Devices</string>
<string name="manage_account_add_picture">Add a picture</string>
<string name="manage_account_edit_picture">Edit picture</string>
<string name="manage_account_remove_picture">Remove picture</string>
<string name="manage_account_status_connected_summary">This account in online, everybody can call you.</string>
<string name="manage_account_status_cleared_summary">Account has been disabled, you won\'t receive any call or message.</string>
<string name="manage_account_status_progress_summary">Account is connecting to the server, please wait…</string>