Use new way to start Activity with uCrop - other case
This commit is contained in:
parent
487e82df3f
commit
03d925b5ab
|
@ -19,7 +19,6 @@ package im.vector.app.features.attachments.preview
|
||||||
|
|
||||||
import android.app.Activity.RESULT_CANCELED
|
import android.app.Activity.RESULT_CANCELED
|
||||||
import android.app.Activity.RESULT_OK
|
import android.app.Activity.RESULT_OK
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
@ -39,6 +38,7 @@ import com.airbnb.mvrx.withState
|
||||||
import com.yalantis.ucrop.UCrop
|
import com.yalantis.ucrop.UCrop
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.cleanup
|
import im.vector.app.core.extensions.cleanup
|
||||||
|
import im.vector.app.core.extensions.registerStartForActivityResult
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.core.resources.ColorProvider
|
import im.vector.app.core.resources.ColorProvider
|
||||||
import im.vector.app.core.utils.OnSnapPositionChangeListener
|
import im.vector.app.core.utils.OnSnapPositionChangeListener
|
||||||
|
@ -49,7 +49,6 @@ import kotlinx.android.parcel.Parcelize
|
||||||
import kotlinx.android.synthetic.main.fragment_attachments_preview.*
|
import kotlinx.android.synthetic.main.fragment_attachments_preview.*
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
|
||||||
import timber.log.Timber
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -80,20 +79,15 @@ class AttachmentsPreviewFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
private val uCropActivityResultLauncher = registerStartForActivityResult { activityResult ->
|
||||||
// TODO handle this one (Ucrop lib)
|
if (activityResult.resultCode == RESULT_OK) {
|
||||||
@Suppress("DEPRECATION")
|
val resultUri = activityResult.data?.let { UCrop.getOutput(it) }
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
if (resultUri != null) {
|
||||||
|
viewModel.handle(AttachmentsPreviewAction.UpdatePathOfCurrentAttachment(resultUri))
|
||||||
if (resultCode == RESULT_OK) {
|
} else {
|
||||||
if (requestCode == UCrop.REQUEST_CROP && data != null) {
|
Toast.makeText(requireContext(), "Cannot retrieve cropped value", Toast.LENGTH_SHORT).show()
|
||||||
Timber.v("Crop success")
|
|
||||||
handleCropResult(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resultCode == UCrop.RESULT_ERROR) {
|
|
||||||
Timber.v("Crop error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
@ -170,15 +164,6 @@ class AttachmentsPreviewFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCropResult(result: Intent) {
|
|
||||||
val resultUri = UCrop.getOutput(result)
|
|
||||||
if (resultUri != null) {
|
|
||||||
viewModel.handle(AttachmentsPreviewAction.UpdatePathOfCurrentAttachment(resultUri))
|
|
||||||
} else {
|
|
||||||
Toast.makeText(requireContext(), "Cannot retrieve cropped value", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleRemoveAction() {
|
private fun handleRemoveAction() {
|
||||||
viewModel.handle(AttachmentsPreviewAction.RemoveCurrentAttachment)
|
viewModel.handle(AttachmentsPreviewAction.RemoveCurrentAttachment)
|
||||||
}
|
}
|
||||||
|
@ -188,7 +173,8 @@ class AttachmentsPreviewFragment @Inject constructor(
|
||||||
val destinationFile = File(requireContext().cacheDir, "${currentAttachment.name}_edited_image_${System.currentTimeMillis()}")
|
val destinationFile = File(requireContext().cacheDir, "${currentAttachment.name}_edited_image_${System.currentTimeMillis()}")
|
||||||
val uri = currentAttachment.queryUri
|
val uri = currentAttachment.queryUri
|
||||||
createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), currentAttachment.name)
|
createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), currentAttachment.name)
|
||||||
.start(requireContext(), this)
|
.getIntent(requireContext())
|
||||||
|
.let { intent -> uCropActivityResultLauncher.launch(intent) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerViews() {
|
private fun setupRecyclerViews() {
|
||||||
|
|
Loading…
Reference in New Issue