Fix a few details
This commit is contained in:
parent
03d925b5ab
commit
cd56059a77
@ -33,7 +33,14 @@ import im.vector.lib.multipicker.MultiPicker
|
|||||||
import im.vector.lib.multipicker.entity.MultiPickerImageType
|
import im.vector.lib.multipicker.entity.MultiPickerImageType
|
||||||
import java.io.File
|
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(
|
class GalleryOrCameraDialogHelper(
|
||||||
|
// must implement GalleryOrCameraDialogHelper.Listener
|
||||||
private val fragment: Fragment,
|
private val fragment: Fragment,
|
||||||
private val colorProvider: ColorProvider
|
private val colorProvider: ColorProvider
|
||||||
) {
|
) {
|
||||||
@ -41,9 +48,10 @@ class GalleryOrCameraDialogHelper(
|
|||||||
fun onImageReady(uri: Uri?)
|
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 ->
|
private val takePhotoPermissionActivityResultLauncher = fragment.registerForPermissionsResult { allGranted ->
|
||||||
if (allGranted) {
|
if (allGranted) {
|
||||||
@ -78,39 +86,40 @@ class GalleryOrCameraDialogHelper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startUCrop(image: MultiPickerImageType) {
|
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
|
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)
|
.withAspectRatio(1f, 1f)
|
||||||
.getIntent(activity)
|
.getIntent(activity)
|
||||||
.let { uCropActivityResultLauncher.launch(it) }
|
.let { uCropActivityResultLauncher.launch(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum class Type {
|
private enum class Type {
|
||||||
Gallery,
|
Camera,
|
||||||
Camera
|
Gallery
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show() {
|
fun show() {
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
|
.setTitle(R.string.attachment_type_dialog_title)
|
||||||
.setItems(arrayOf(
|
.setItems(arrayOf(
|
||||||
fragment.getString(R.string.attachment_type_camera),
|
fragment.getString(R.string.attachment_type_camera),
|
||||||
fragment.getString(R.string.attachment_type_gallery)
|
fragment.getString(R.string.attachment_type_gallery)
|
||||||
)) { dialog, which ->
|
)) { _, which ->
|
||||||
dialog.cancel()
|
|
||||||
onAvatarTypeSelected(if (which == 0) Type.Camera else Type.Gallery)
|
onAvatarTypeSelected(if (which == 0) Type.Camera else Type.Gallery)
|
||||||
}
|
}
|
||||||
|
.setPositiveButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onAvatarTypeSelected(type: Type) {
|
private fun onAvatarTypeSelected(type: Type) {
|
||||||
when (type) {
|
when (type) {
|
||||||
Type.Gallery ->
|
|
||||||
MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher)
|
|
||||||
Type.Camera ->
|
Type.Camera ->
|
||||||
if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, activity, takePhotoPermissionActivityResultLauncher)) {
|
if (checkPermissions(PERMISSIONS_FOR_TAKING_PHOTO, activity, takePhotoPermissionActivityResultLauncher)) {
|
||||||
avatarCameraUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(activity, takePhotoActivityResultLauncher)
|
avatarCameraUri = MultiPicker.get(MultiPicker.CAMERA).startWithExpectingFile(activity, takePhotoActivityResultLauncher)
|
||||||
}
|
}
|
||||||
|
Type.Gallery ->
|
||||||
|
MultiPicker.get(MultiPicker.IMAGE).single().startWith(pickImageActivityResultLauncher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ class CreateRoomFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(toolbarButton: Boolean): Boolean {
|
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)
|
viewModel.handle(CreateRoomAction.Reset)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.app.features.roomdirectory.createroom
|
package im.vector.app.features.roomdirectory.createroom
|
||||||
|
|
||||||
|
import androidx.core.net.toFile
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
@ -104,6 +105,10 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr
|
|||||||
|
|
||||||
private fun doReset() {
|
private fun doReset() {
|
||||||
setState {
|
setState {
|
||||||
|
// Delete temporary file with the avatar
|
||||||
|
// TODO BMA Do this also in the other PR
|
||||||
|
avatarUri?.let { tryOrNull { it.toFile().delete() }}
|
||||||
|
|
||||||
CreateRoomViewState(
|
CreateRoomViewState(
|
||||||
isEncrypted = adminE2EByDefault,
|
isEncrypted = adminE2EByDefault,
|
||||||
hsAdminHasDisabledE2E = !adminE2EByDefault
|
hsAdminHasDisabledE2E = !adminE2EByDefault
|
||||||
|
@ -1840,12 +1840,14 @@
|
|||||||
<string name="error_file_too_big">"The file '%1$s' (%2$s) is too large to upload. The limit is %3$s."</string>
|
<string name="error_file_too_big">"The file '%1$s' (%2$s) is too large to upload. The limit is %3$s."</string>
|
||||||
|
|
||||||
<string name="error_attachment">"An error occurred while retrieving the attachment."</string>
|
<string name="error_attachment">"An error occurred while retrieving the attachment."</string>
|
||||||
|
<string name="attachment_type_dialog_title">"Add image from"</string>
|
||||||
<string name="attachment_type_file">"File"</string>
|
<string name="attachment_type_file">"File"</string>
|
||||||
<string name="attachment_type_contact">"Contact"</string>
|
<string name="attachment_type_contact">"Contact"</string>
|
||||||
<string name="attachment_type_camera">"Camera"</string>
|
<string name="attachment_type_camera">"Camera"</string>
|
||||||
<string name="attachment_type_audio">"Audio"</string>
|
<string name="attachment_type_audio">"Audio"</string>
|
||||||
<string name="attachment_type_gallery">"Gallery"</string>
|
<string name="attachment_type_gallery">"Gallery"</string>
|
||||||
<string name="attachment_type_sticker">"Sticker"</string>
|
<string name="attachment_type_sticker">"Sticker"</string>
|
||||||
|
<string name="rotate_and_crop_screen_title">Rotate and crop</string>
|
||||||
<string name="error_handling_incoming_share">Couldn\'t handle share data</string>
|
<string name="error_handling_incoming_share">Couldn\'t handle share data</string>
|
||||||
|
|
||||||
<string name="uploads_media_title">MEDIA</string>
|
<string name="uploads_media_title">MEDIA</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user