diff --git a/vector/src/main/java/im/vector/app/core/dialogs/GalleryOrCameraDialogHelper.kt b/vector/src/main/java/im/vector/app/core/dialogs/GalleryOrCameraDialogHelper.kt
index 43bfa617bd..7198cdb4a2 100644
--- a/vector/src/main/java/im/vector/app/core/dialogs/GalleryOrCameraDialogHelper.kt
+++ b/vector/src/main/java/im/vector/app/core/dialogs/GalleryOrCameraDialogHelper.kt
@@ -33,7 +33,14 @@ import im.vector.lib.multipicker.MultiPicker
import im.vector.lib.multipicker.entity.MultiPickerImageType
import java.io.File
+/**
+ * Use to let the user choose between Camera (with permission handling) and Gallery (with single image selection),
+ * then edit the image
+ * [Listener.onImageReady] will be called with an uri of a square image store in the cache of the application.
+ * It's up to the caller to delete the file.
+ */
class GalleryOrCameraDialogHelper(
+ // must implement GalleryOrCameraDialogHelper.Listener
private val fragment: Fragment,
private val colorProvider: ColorProvider
) {
@@ -41,9 +48,10 @@ class GalleryOrCameraDialogHelper(
fun onImageReady(uri: Uri?)
}
- private val activity by lazy { fragment.requireActivity() }
+ private val activity
+ get() = fragment.requireActivity()
- private val listener: Listener = fragment as? Listener ?: error("Fragment must implement GalleryOrCameraDialogHelper.Listener")
+ private val listener = fragment as? Listener ?: error("Fragment must implement GalleryOrCameraDialogHelper.Listener")
private val takePhotoPermissionActivityResultLauncher = fragment.registerForPermissionsResult { allGranted ->
if (allGranted) {
@@ -78,39 +86,40 @@ class GalleryOrCameraDialogHelper(
}
private fun startUCrop(image: MultiPickerImageType) {
- val destinationFile = File(activity.cacheDir, "${image.displayName}_edited_image_${System.currentTimeMillis()}")
+ val destinationFile = File(activity.cacheDir, "${image.displayName}_e_${System.currentTimeMillis()}")
val uri = image.contentUri
- createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), image.displayName)
+ createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), fragment.getString(R.string.rotate_and_crop_screen_title))
.withAspectRatio(1f, 1f)
.getIntent(activity)
.let { uCropActivityResultLauncher.launch(it) }
}
private enum class Type {
- Gallery,
- Camera
+ Camera,
+ Gallery
}
fun show() {
AlertDialog.Builder(activity)
+ .setTitle(R.string.attachment_type_dialog_title)
.setItems(arrayOf(
fragment.getString(R.string.attachment_type_camera),
fragment.getString(R.string.attachment_type_gallery)
- )) { dialog, which ->
- dialog.cancel()
+ )) { _, which ->
onAvatarTypeSelected(if (which == 0) Type.Camera else Type.Gallery)
}
+ .setPositiveButton(R.string.cancel, null)
.show()
}
private fun onAvatarTypeSelected(type: Type) {
when (type) {
- Type.Gallery ->
- MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher)
Type.Camera ->
if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, activity, takePhotoPermissionActivityResultLauncher)) {
avatarCameraUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(activity, takePhotoActivityResultLauncher)
}
+ Type.Gallery ->
+ MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher)
}
}
diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt
index b3819a1707..2a91378cc1 100644
--- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt
+++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt
@@ -113,6 +113,7 @@ class CreateRoomFragment @Inject constructor(
}
override fun onBackPressed(toolbarButton: Boolean): Boolean {
+ // TODO BMA, as per the other PR, ask the user if he has started to input elements before leaving the screen
viewModel.handle(CreateRoomAction.Reset)
return false
}
diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt
index a0e0672d25..97d8ba9386 100644
--- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt
+++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt
@@ -16,6 +16,7 @@
package im.vector.app.features.roomdirectory.createroom
+import androidx.core.net.toFile
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.ActivityViewModelContext
@@ -104,6 +105,10 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
private fun doReset() {
setState {
+ // Delete temporary file with the avatar
+ // TODO BMA Do this also in the other PR
+ avatarUri?.let { tryOrNull { it.toFile().delete() }}
+
CreateRoomViewState(
isEncrypted = adminE2EByDefault,
hsAdminHasDisabledE2E = !adminE2EByDefault
diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml
index a78e295a5a..93220808f1 100644
--- a/vector/src/main/res/values/strings.xml
+++ b/vector/src/main/res/values/strings.xml
@@ -1840,12 +1840,14 @@
"The file '%1$s' (%2$s) is too large to upload. The limit is %3$s."
"An error occurred while retrieving the attachment."
+ "Add image from"
"File"
"Contact"
"Camera"
"Audio"
"Gallery"
"Sticker"
+ Rotate and crop
Couldn\'t handle share data
MEDIA