Fix issue after rebase

This commit is contained in:
Benoit Marty 2020-10-28 14:04:26 +01:00 committed by Benoit Marty
parent cd56059a77
commit be2c4597de

View File

@ -16,19 +16,16 @@
package im.vector.app.features.roomprofile.settings package im.vector.app.features.roomprofile.settings
import android.app.Activity import android.net.Uri
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.airbnb.mvrx.args import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.yalantis.ucrop.UCrop
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper import im.vector.app.core.dialogs.GalleryOrCameraDialogHelper
import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.cleanup
@ -37,19 +34,17 @@ import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.intent.getFilenameFromUri import im.vector.app.core.intent.getFilenameFromUri
import im.vector.app.core.platform.OnBackPressed import im.vector.app.core.platform.OnBackPressed
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.utils.toast import im.vector.app.core.utils.toast
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter import im.vector.app.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter
import im.vector.app.features.media.createUCropWithDefaultSettings
import im.vector.app.features.roomprofile.RoomProfileArgs import im.vector.app.features.roomprofile.RoomProfileArgs
import im.vector.lib.multipicker.entity.MultiPickerImageType
import kotlinx.android.synthetic.main.fragment_room_setting_generic.* import kotlinx.android.synthetic.main.fragment_room_setting_generic.*
import kotlinx.android.synthetic.main.merge_overlay_waiting_view.* import kotlinx.android.synthetic.main.merge_overlay_waiting_view.*
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
import java.io.File
import java.util.UUID import java.util.UUID
import javax.inject.Inject import javax.inject.Inject
@ -57,6 +52,7 @@ class RoomSettingsFragment @Inject constructor(
val viewModelFactory: RoomSettingsViewModel.Factory, val viewModelFactory: RoomSettingsViewModel.Factory,
private val controller: RoomSettingsController, private val controller: RoomSettingsController,
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
colorProvider: ColorProvider,
private val avatarRenderer: AvatarRenderer private val avatarRenderer: AvatarRenderer
) : ) :
VectorBaseFragment(), VectorBaseFragment(),
@ -66,7 +62,7 @@ class RoomSettingsFragment @Inject constructor(
private val viewModel: RoomSettingsViewModel by fragmentViewModel() private val viewModel: RoomSettingsViewModel by fragmentViewModel()
private val roomProfileArgs: RoomProfileArgs by args() private val roomProfileArgs: RoomProfileArgs by args()
private val galleryOrCameraDialogHelper = GalleryOrCameraDialogHelper(this) private val galleryOrCameraDialogHelper = GalleryOrCameraDialogHelper(this, colorProvider)
override fun getLayoutResId() = R.layout.fragment_room_setting_generic override fun getLayoutResId() = R.layout.fragment_room_setting_generic
@ -178,12 +174,15 @@ class RoomSettingsFragment @Inject constructor(
viewModel.handle(RoomSettingsAction.SetRoomCanonicalAlias(alias)) viewModel.handle(RoomSettingsAction.SetRoomCanonicalAlias(alias))
} }
override fun onImageReady(image: MultiPickerImageType) { override fun onImageReady(uri: Uri?) {
val destinationFile = File(requireContext().cacheDir, "${image.displayName}_edited_image_${System.currentTimeMillis()}") uri ?: return
val uri = image.contentUri viewModel.handle(
createUCropWithDefaultSettings(requireContext(), uri, destinationFile.toUri(), image.displayName) RoomSettingsAction.SetAvatarAction(
.withAspectRatio(1f, 1f) RoomSettingsViewState.AvatarAction.UpdateAvatar(
.start(requireContext(), this) newAvatarUri = uri,
newAvatarFileName = getFilenameFromUri(requireContext(), uri) ?: UUID.randomUUID().toString())
)
)
} }
override fun onAvatarDelete() { override fun onAvatarDelete() {
@ -208,26 +207,6 @@ class RoomSettingsFragment @Inject constructor(
galleryOrCameraDialogHelper.show() galleryOrCameraDialogHelper.show()
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// TODO handle this one (Ucrop lib)
@Suppress("DEPRECATION")
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
UCrop.REQUEST_CROP -> {
val uri = data?.let { UCrop.getOutput(it) } ?: return
viewModel.handle(RoomSettingsAction.SetAvatarAction(
RoomSettingsViewState.AvatarAction.UpdateAvatar(
newAvatarUri = uri,
newAvatarFileName = getFilenameFromUri(requireContext(), uri) ?: UUID.randomUUID().toString())
)
)
}
}
}
}
private var ignoreChanges = false private var ignoreChanges = false
override fun onBackPressed(toolbarButton: Boolean): Boolean { override fun onBackPressed(toolbarButton: Boolean): Boolean {