Skip to content
Snippets Groups Projects
Commit 2dda806c authored by Pierre Nicolas's avatar Pierre Nicolas :joy: Committed by Adrien Béraud
Browse files

profile: remove profile photo feature

Needed for GitLab: #1739

Change-Id: If54500e3a85611f0bfb4ab8f1a5c7eae539d68c1
parent a375f189
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ import android.content.DialogInterface ...@@ -25,7 +25,7 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.Bitmap import android.graphics.Bitmap
import android.net.Uri import net.jami.model.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.util.Log import android.util.Log
...@@ -47,6 +47,7 @@ import androidx.core.view.isVisible ...@@ -47,6 +47,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.FragmentTransaction
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import cx.ring.R import cx.ring.R
import cx.ring.account.AccountPasswordDialog.UnlockAccountListener import cx.ring.account.AccountPasswordDialog.UnlockAccountListener
...@@ -76,6 +77,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers ...@@ -76,6 +77,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
import net.jami.account.JamiAccountSummaryPresenter import net.jami.account.JamiAccountSummaryPresenter
import net.jami.account.JamiAccountSummaryView import net.jami.account.JamiAccountSummaryView
import net.jami.model.Account import net.jami.model.Account
import net.jami.model.Contact
import net.jami.model.Profile import net.jami.model.Profile
import net.jami.services.AccountService import net.jami.services.AccountService
import java.io.File import java.io.File
...@@ -106,8 +108,9 @@ class JamiAccountSummaryFragment : ...@@ -106,8 +108,9 @@ class JamiAccountSummaryFragment :
private var mAccount: Account? = null private var mAccount: Account? = null
private var mCacheArchive: File? = null private var mCacheArchive: File? = null
private var mProfilePhoto: ImageView? = null private var mProfilePhoto: ImageView? = null
private var mDialogRemovePhoto: FloatingActionButton? = null
private var mSourcePhoto: Bitmap? = null private var mSourcePhoto: Bitmap? = null
private var tmpProfilePhotoUri: Uri? = null private var tmpProfilePhotoUri: android.net.Uri? = null
private var mDeviceAdapter: DeviceAdapter? = null private var mDeviceAdapter: DeviceAdapter? = null
private val mDisposableBag = CompositeDisposable() private val mDisposableBag = CompositeDisposable()
private var mBinding: FragAccSummaryBinding? = null private var mBinding: FragAccSummaryBinding? = null
...@@ -135,7 +138,7 @@ class JamiAccountSummaryFragment : ...@@ -135,7 +138,7 @@ class JamiAccountSummaryFragment :
private val exportBackupLauncher: ActivityResultLauncher<Intent> = private val exportBackupLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(StartActivityForResult()) { result -> registerForActivityResult(StartActivityForResult()) { result ->
if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult if (result.resultCode != Activity.RESULT_OK) return@registerForActivityResult
result.data?.data?.let { uri: Uri -> result.data?.data?.let { uri: android.net.Uri ->
mCacheArchive?.let { cacheArchive -> mCacheArchive?.let { cacheArchive ->
AndroidFileUtils.moveToUri(requireContext().contentResolver, cacheArchive, uri) AndroidFileUtils.moveToUri(requireContext().contentResolver, cacheArchive, uri)
.observeOn(DeviceUtils.uiScheduler) .observeOn(DeviceUtils.uiScheduler)
...@@ -309,8 +312,23 @@ class JamiAccountSummaryFragment : ...@@ -309,8 +312,23 @@ class JamiAccountSummaryFragment :
val view = DialogProfileBinding.inflate(inflater).apply { val view = DialogProfileBinding.inflate(inflater).apply {
camera.setOnClickListener { presenter.cameraClicked() } camera.setOnClickListener { presenter.cameraClicked() }
gallery.setOnClickListener { presenter.galleryClicked() } gallery.setOnClickListener { presenter.galleryClicked() }
removePhoto.setOnClickListener {
removePhoto(account.loadedProfile!!.blockingGet().displayName)
}
} }
mProfilePhoto = view.profilePhoto mProfilePhoto = view.profilePhoto
// Show `delete` option if the account has a profile photo.
mDialogRemovePhoto = view.removePhoto
mDisposableBag.add(
mAccountService.getObservableAccountProfile(account.accountId)
.observeOn(DeviceUtils.uiScheduler)
.subscribe {
view.removePhoto.visibility =
if (it.second.avatar != null) View.VISIBLE else View.GONE
}
)
mDisposableBag.add(AvatarDrawable.load(inflater.context, account) mDisposableBag.add(AvatarDrawable.load(inflater.context, account)
.observeOn(DeviceUtils.uiScheduler) .observeOn(DeviceUtils.uiScheduler)
.subscribe { a -> view.profilePhoto.setImageDrawable(a) }) .subscribe { a -> view.profilePhoto.setImageDrawable(a) })
...@@ -322,10 +340,12 @@ class JamiAccountSummaryFragment : ...@@ -322,10 +340,12 @@ class JamiAccountSummaryFragment :
mSourcePhoto?.let { source -> mSourcePhoto?.let { source ->
presenter.saveVCard(mBinding!!.username.text.toString(), presenter.saveVCard(mBinding!!.username.text.toString(),
Single.just(source).map { obj -> BitmapUtils.bitmapToPhoto(obj) }) Single.just(source).map { obj -> BitmapUtils.bitmapToPhoto(obj) })
} } ?: presenter.saveVCard(mBinding!!.username.text.toString(), null)
} }
.setOnDismissListener { .setOnDismissListener {
// Todo: Should release dialog disposable here.
mProfilePhoto = null mProfilePhoto = null
mDialogRemovePhoto = null
mSourcePhoto = null mSourcePhoto = null
} }
.show() .show()
...@@ -512,10 +532,28 @@ class JamiAccountSummaryFragment : ...@@ -512,10 +532,28 @@ class JamiAccountSummaryFragment :
pickProfilePicture.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) pickProfilePicture.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly))
} }
private fun updatePhoto(uriImage: Uri) { private fun updatePhoto(uriImage: android.net.Uri) {
updatePhoto(AndroidFileUtils.loadBitmap(requireContext(), uriImage)) updatePhoto(AndroidFileUtils.loadBitmap(requireContext(), uriImage))
} }
/**
* Remove the photo from the profile picture dialog.
* Replace it with the default avatar.
*/
private fun removePhoto(profileName: String?) {
val account = presenter.account ?: return
mDialogRemovePhoto?.visibility = View.GONE
mProfilePhoto?.setImageDrawable(
AvatarDrawable.Builder()
.withNameData(profileName, account.registeredName)
.withId(Uri(Uri.JAMI_URI_SCHEME, account.username!!).rawUriString)
.withCircleCrop(true)
.withOnlineState(Contact.PresenceStatus.OFFLINE)
.build(requireContext())
)
mSourcePhoto = null
}
private fun updatePhoto(image: Single<Bitmap>) { private fun updatePhoto(image: Single<Bitmap>) {
val account = presenter.account ?: return val account = presenter.account ?: return
mDisposableBag.add(image.subscribeOn(Schedulers.io()) mDisposableBag.add(image.subscribeOn(Schedulers.io())
...@@ -524,12 +562,14 @@ class JamiAccountSummaryFragment : ...@@ -524,12 +562,14 @@ class JamiAccountSummaryFragment :
AvatarDrawable.Builder() AvatarDrawable.Builder()
.withPhoto(img) .withPhoto(img)
.withNameData(null, account.registeredName) .withNameData(null, account.registeredName)
.withId(account.uri) .withId(Uri(Uri.JAMI_URI_SCHEME, account.username!!).rawUriString)
.withCircleCrop(true) .withCircleCrop(true)
.build(requireContext()) .build(requireContext())
} }
.observeOn(DeviceUtils.uiScheduler) .observeOn(DeviceUtils.uiScheduler)
.subscribe({ avatar: AvatarDrawable -> mProfilePhoto?.setImageDrawable(avatar) }) { e: Throwable -> .subscribe({ avatar: AvatarDrawable ->
mDialogRemovePhoto?.visibility = View.VISIBLE
mProfilePhoto?.setImageDrawable(avatar) }) { e: Throwable ->
Log.e(TAG, "Error loading image", e) Log.e(TAG, "Error loading image", e)
}) })
} }
......
...@@ -22,7 +22,6 @@ import android.content.ActivityNotFoundException ...@@ -22,7 +22,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.Bitmap import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.text.Editable import android.text.Editable
...@@ -45,12 +44,13 @@ import dagger.hilt.android.AndroidEntryPoint ...@@ -45,12 +44,13 @@ import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import net.jami.account.ProfileCreationPresenter import net.jami.account.ProfileCreationPresenter
import net.jami.account.ProfileCreationView import net.jami.account.ProfileCreationView
import net.jami.model.Uri
import java.io.IOException import java.io.IOException
@AndroidEntryPoint @AndroidEntryPoint
class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, ProfileCreationView>(), ProfileCreationView { class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, ProfileCreationView>(), ProfileCreationView {
private val model: AccountCreationViewModel by activityViewModels() private val model: AccountCreationViewModel by activityViewModels()
private var tmpProfilePhotoUri: Uri? = null private var tmpProfilePhotoUri: android.net.Uri? = null
private var binding: FragAccProfileCreateBinding? = null private var binding: FragAccProfileCreateBinding? = null
private val pickProfilePicture = private val pickProfilePicture =
...@@ -63,6 +63,7 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr ...@@ -63,6 +63,7 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr
FragAccProfileCreateBinding.inflate(inflater, container, false).apply { FragAccProfileCreateBinding.inflate(inflater, container, false).apply {
gallery.setOnClickListener { presenter.galleryClick() } gallery.setOnClickListener { presenter.galleryClick() }
camera.setOnClickListener { presenter.cameraClick() } camera.setOnClickListener { presenter.cameraClick() }
removePhoto.setOnClickListener { presenter.photoRemoved() }
nextCreateAccount.setOnClickListener { presenter.nextClick() } nextCreateAccount.setOnClickListener { presenter.nextClick() }
skipCreateAccount.setOnClickListener { presenter.skipClick() } skipCreateAccount.setOnClickListener { presenter.skipClick() }
username.addTextChangedListener(object : TextWatcher { username.addTextChangedListener(object : TextWatcher {
...@@ -81,9 +82,11 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr ...@@ -81,9 +82,11 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val binding = binding ?: return
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
if (binding!!.profilePhoto.drawable == null) { if (binding.profilePhoto.drawable == null) {
binding!!.profilePhoto.setImageDrawable(AvatarDrawable.Builder() binding.removePhoto.visibility = View.GONE // Hide `delete` option if no photo.
binding.profilePhoto.setImageDrawable(AvatarDrawable.Builder()
.withNameData(model.model.fullName, model.model.username) .withNameData(model.model.fullName, model.model.username)
.withCircleCrop(true) .withCircleCrop(true)
.build(view.context)) .build(view.context))
...@@ -156,15 +159,18 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr ...@@ -156,15 +159,18 @@ class ProfileCreationFragment : BaseSupportFragment<ProfileCreationPresenter, Pr
} }
override fun setProfile() { override fun setProfile() {
val binding = binding ?: return
val m = model.model val m = model.model
binding!!.profilePhoto.setImageDrawable( val username = m.newAccount?.username ?: return
binding.profilePhoto.setImageDrawable(
AvatarDrawable.Builder() AvatarDrawable.Builder()
.withPhoto(m.photo as Bitmap?) .withPhoto(m.photo as Bitmap?)
.withNameData(m.fullName, m.username) .withNameData(m.fullName, m.username)
.withId(m.newAccount?.username) .withId(Uri(Uri.JAMI_URI_SCHEME, username).rawRingId)
.withCircleCrop(true) .withCircleCrop(true)
.build(requireContext()) .build(requireContext())
) )
binding.removePhoto.visibility = if (m.photo != null) View.VISIBLE else View.GONE
} }
companion object { companion object {
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/profile_scrollview" android:id="@+id/profile_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
android:text="@string/profile_message_warning" android:text="@string/profile_message_warning"
android:textAlignment="center" /> android:textAlignment="center" />
<RelativeLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_container" android:id="@+id/profile_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="180dp" android:layout_height="180dp"
...@@ -32,9 +33,11 @@ ...@@ -32,9 +33,11 @@
android:id="@+id/profile_photo" android:id="@+id/profile_photo"
android:layout_width="120dp" android:layout_width="120dp"
android:layout_height="120dp" android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_margin="15dp" android:layout_margin="15dp"
android:scaleType="fitCenter" android:contentDescription="@null"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_contact_picture_fallback" /> app:srcCompat="@drawable/ic_contact_picture_fallback" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
...@@ -42,37 +45,55 @@ ...@@ -42,37 +45,55 @@
style="@style/Widget.Material3.FloatingActionButton.Primary" style="@style/Widget.Material3.FloatingActionButton.Primary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/anchor" android:layout_marginTop="-20dp"
android:layout_toStartOf="@+id/anchor"
android:contentDescription="@string/open_the_gallery" android:contentDescription="@string/open_the_gallery"
android:text="@string/open_the_gallery" android:text="@string/open_the_gallery"
app:backgroundTint="@color/surface" app:backgroundTint="@color/surface"
app:layout_constraintEnd_toStartOf="@+id/camera"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white" app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_insert_photo_24" app:srcCompat="@drawable/baseline_insert_photo_24"
app:tint="?attr/colorControlNormal" /> app:tint="?attr/colorControlNormal" />
<View
android:id="@+id/anchor"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignBottom="@+id/profile_photo"
android:layout_centerHorizontal="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/camera" android:id="@+id/camera"
style="@style/Widget.Material3.FloatingActionButton.Primary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/anchor" android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/anchor" android:layout_marginTop="-20dp"
android:contentDescription="@string/take_a_photo" android:contentDescription="@string/take_a_photo"
android:text="@string/take_a_photo" android:text="@string/take_a_photo"
app:tint="?attr/colorControlNormal" app:backgroundTint="@color/surface"
app:layout_constraintEnd_toStartOf="@id/remove_photo"
app:layout_constraintStart_toEndOf="@+id/gallery"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_photo_camera_24"
app:tint="?attr/colorControlNormal" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/remove_photo"
style="@style/Widget.Material3.FloatingActionButton.Primary" style="@style/Widget.Material3.FloatingActionButton.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="-20dp"
android:contentDescription="@string/remove_photo"
android:text="@string/remove_photo"
android:visibility="gone"
app:backgroundTint="@color/surface" app:backgroundTint="@color/surface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/camera"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white" app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_photo_camera_24" /> app:srcCompat="@drawable/baseline_cancel_24"
app:tint="?attr/colorControlNormal"
tools:visibility="visible" />
</RelativeLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
\ No newline at end of file
...@@ -54,56 +54,71 @@ ...@@ -54,56 +54,71 @@
android:padding="6dp"/> android:padding="6dp"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_container" android:id="@+id/profile_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_gravity="center" android:clipChildren="false"
android:clipToPadding="false" android:clipToPadding="false">
android:clipChildren="false">
<ImageView <ImageView
android:id="@+id/profile_photo" android:id="@+id/profile_photo"
android:layout_width="90dp" android:layout_width="90dp"
android:layout_height="90dp" android:layout_height="90dp"
android:layout_alignParentTop="true" android:contentDescription="@null"
android:layout_centerHorizontal="true" app:layout_constraintEnd_toEndOf="parent"
android:scaleType="fitCenter" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_contact_picture_fallback" /> tools:src="@drawable/ic_contact_picture_fallback" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/camera" android:id="@+id/gallery"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/anchor" android:layout_marginTop="-20dp"
android:layout_toEndOf="@+id/anchor" android:contentDescription="@string/open_the_gallery"
android:text="@string/open_the_gallery"
app:backgroundTint="@color/light" app:backgroundTint="@color/light"
app:fabCustomSize="40dp" app:fabCustomSize="40dp"
app:srcCompat="@drawable/baseline_photo_camera_24" app:layout_constraintEnd_toStartOf="@+id/camera"
app:rippleColor="@android:color/white" /> app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_insert_photo_24" />
<Space <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/anchor" android:id="@+id/camera"
android:layout_width="15dp" android:layout_width="wrap_content"
android:layout_height="25dp" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/profile_photo" android:layout_marginTop="-20dp"
android:layout_centerHorizontal="true" /> android:contentDescription="@string/take_a_photo"
app:backgroundTint="@color/light"
app:fabCustomSize="40dp"
app:layout_constraintEnd_toStartOf="@+id/remove_photo"
app:layout_constraintStart_toEndOf="@+id/gallery"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_photo_camera_24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/gallery" android:id="@+id/remove_photo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/anchor" android:layout_marginTop="-20dp"
android:layout_toStartOf="@+id/anchor" android:contentDescription="@string/remove_photo"
android:contentDescription="@string/open_the_gallery" android:visibility="gone"
android:text="@string/open_the_gallery"
app:backgroundTint="@color/light" app:backgroundTint="@color/light"
app:fabCustomSize="40dp" app:fabCustomSize="40dp"
app:srcCompat="@drawable/baseline_insert_photo_24" app:layout_constraintEnd_toEndOf="parent"
app:rippleColor="@android:color/white" /> app:layout_constraintStart_toEndOf="@+id/camera"
app:layout_constraintTop_toBottomOf="@id/profile_photo"
app:rippleColor="@android:color/white"
app:srcCompat="@drawable/baseline_cancel_24"
tools:visibility="visible" />
</RelativeLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_box" android:id="@+id/username_box"
......
...@@ -412,6 +412,7 @@ along with this program; if not, write to the Free Software ...@@ -412,6 +412,7 @@ along with this program; if not, write to the Free Software
<string name="profile_message_warning">Your profile is only shared with your contacts</string> <string name="profile_message_warning">Your profile is only shared with your contacts</string>
<string name="open_the_gallery">Open the gallery</string> <string name="open_the_gallery">Open the gallery</string>
<string name="take_a_photo">Take photo</string> <string name="take_a_photo">Take photo</string>
<string name="remove_photo">Remove photo</string>
<string name="profile_name_hint">Enter your name</string> <string name="profile_name_hint">Enter your name</string>
<string name="registered_name">Registered Name</string> <string name="registered_name">Registered Name</string>
<string name="no_registered_name">No name registered</string> <string name="no_registered_name">No name registered</string>
......
...@@ -125,28 +125,57 @@ class JamiAccountSummaryPresenter @Inject constructor( ...@@ -125,28 +125,57 @@ class JamiAccountSummaryPresenter @Inject constructor(
.subscribe({}) { e: Throwable -> Log.e(TAG, "Error saving vCard " + e.message) }) .subscribe({}) { e: Throwable -> Log.e(TAG, "Error saving vCard " + e.message) })
} }
fun saveVCard(username: String?, photo: Single<Photo>) { /**
* Save the vCard to the disk.
* @param username: the username to save, if null, the username will be removed from the vCard
* @param photo: the photo to save, if null, the photo will be removed from the vCard
*/
fun saveVCard(username: String?, photo: Single<Photo>?) {
val accountId = mAccountID ?: return val accountId = mAccountID ?: return
val account = mAccountService.getAccount(accountId)!! val account = mAccountService.getAccount(accountId)!!
val ringId = account.username val ringId = account.username
val filesDir = mDeviceRuntimeService.provideFilesDir() val filesDir = mDeviceRuntimeService.provideFilesDir()
mCompositeDisposable.add(Single.zip(
VCardUtils.loadLocalProfileFromDiskWithDefault(filesDir, accountId).subscribeOn(Schedulers.io()), if (photo == null) {
mCompositeDisposable.add(
VCardUtils.loadLocalProfileFromDiskWithDefault(filesDir, accountId)
.subscribeOn(Schedulers.io())
.map { vcard: VCard ->
vcard.uid = Uid(ringId)
if (!username.isNullOrEmpty()) vcard.setFormattedName(username)
vcard.removeProperties(Photo::class.java)
vcard.removeProperties(RawProperty::class.java)
vcard
}
.flatMap { vcard: VCard ->
VCardUtils.saveLocalProfileToDisk(vcard, accountId, filesDir)
}
.subscribe({ vcard: VCard ->
account.loadedProfile = mVcardService.loadVCardProfile(vcard).cache()
}) { e: Throwable -> Log.e(TAG, "Error saving vCard !", e) }
)
} else {
mCompositeDisposable.add(
Single.zip(
VCardUtils.loadLocalProfileFromDiskWithDefault(filesDir, accountId)
.subscribeOn(Schedulers.io()),
photo photo
) { vcard: VCard, pic: Photo -> ) { vcard: VCard, pic: Photo ->
vcard.uid = Uid(ringId) vcard.uid = Uid(ringId)
if (!username.isNullOrEmpty()) { if (!username.isNullOrEmpty()) vcard.setFormattedName(username)
vcard.setFormattedName(username)
}
vcard.removeProperties(Photo::class.java) vcard.removeProperties(Photo::class.java)
vcard.addPhoto(pic) vcard.addPhoto(pic)
vcard.removeProperties(RawProperty::class.java) vcard.removeProperties(RawProperty::class.java)
vcard vcard
} }
.flatMap { vcard: VCard -> VCardUtils.saveLocalProfileToDisk(vcard, accountId, filesDir) } .flatMap { vcard: VCard ->
VCardUtils.saveLocalProfileToDisk(vcard, accountId, filesDir)
}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.subscribe({ vcard: VCard -> account.loadedProfile = mVcardService.loadVCardProfile(vcard).cache() }) .subscribe({ vcard: VCard ->
{ e: Throwable -> Log.e(TAG, "Error saving vCard !", e) }) account.loadedProfile = mVcardService.loadVCardProfile(vcard).cache()
}) { e: Throwable -> Log.e(TAG, "Error saving vCard !", e) })
}
} }
fun cameraClicked() { fun cameraClicked() {
......
...@@ -59,6 +59,10 @@ class ProfileCreationPresenter @Inject constructor( ...@@ -59,6 +59,10 @@ class ProfileCreationPresenter @Inject constructor(
{ e: Throwable -> Log.e(TAG, "Can't load image", e) }) { e: Throwable -> Log.e(TAG, "Can't load image", e) })
} }
fun photoRemoved() {
mAccountCreationModel?.photo = null
}
fun galleryClick() { fun galleryClick() {
view?.goToGallery() view?.goToGallery()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment