diff --git a/CHANGES.md b/CHANGES.md index f7682028e1..87628e23b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,11 +5,12 @@ Features ✨: - Improvements 🙌: - - + - Add long click gesture to copy userId, user display name, room name, room topic and room alias (#1774) Bugfix 🐛: - Display name not shown under Settings/General (#1926) - Fix bad color for settings icon on Android < 24 (#1786) + - Change user or room avatar: when selecting Gallery, I'm not proposed to crop the selected image (#1590) Translations 🗣: - diff --git a/vector/build.gradle b/vector/build.gradle index c04de62367..ef2d6c3d9e 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -378,7 +378,7 @@ dependencies { implementation "com.github.bumptech.glide:glide:$glide_version" kapt "com.github.bumptech.glide:compiler:$glide_version" implementation 'com.danikula:videocache:2.7.1' - implementation 'com.github.yalantis:ucrop:2.2.4' + implementation 'com.github.yalantis:ucrop:2.2.6' // Badge for compatibility implementation 'me.leolin:ShortcutBadger:1.1.22@aar' diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt index cafcf6d1d8..44b85df93a 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextView.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextView.kt @@ -24,7 +24,9 @@ import android.widget.TextView import androidx.annotation.AttrRes import androidx.annotation.StringRes import androidx.core.view.isVisible +import com.google.android.material.snackbar.Snackbar import im.vector.app.R +import im.vector.app.core.utils.copyToClipboard import im.vector.app.features.themes.ThemeUtils /** @@ -68,3 +70,18 @@ fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int, } } } + +/** + * Set long click listener to copy the current text of the TextView to the clipboard and show a Snackbar + */ +fun TextView.copyOnLongClick() { + setOnLongClickListener { view -> + (view as? TextView) + ?.text + ?.let { text -> + copyToClipboard(view.context, text, false) + Snackbar.make(view, view.resources.getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT).show() + } + true + } +} diff --git a/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt index 9d0a931a32..c619b4aa92 100644 --- a/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/BigImageViewerActivity.kt @@ -144,9 +144,7 @@ class BigImageViewerActivity : VectorBaseActivity() { .get(MultiPicker.IMAGE) .getSelectedFiles(this, requestCode, resultCode, data) .firstOrNull()?.let { - // TODO. UCrop library cannot read from Gallery. For now, we will set avatar as it is. - // onRoomAvatarSelected(it) - onAvatarCropped(it.contentUri) + onRoomAvatarSelected(it) } } UCrop.REQUEST_CROP -> data?.let { onAvatarCropped(UCrop.getOutput(it)) } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt index 9c6e813f0b..cda2d83e3d 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -35,6 +35,7 @@ import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener import im.vector.app.core.dialogs.ConfirmationDialogBuilder import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith +import im.vector.app.core.extensions.copyOnLongClick import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.platform.StateView @@ -44,11 +45,11 @@ import im.vector.app.features.crypto.verification.VerificationBottomSheet import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.roommemberprofile.devices.DeviceListBottomSheet import im.vector.app.features.roommemberprofile.powerlevel.EditPowerLevelDialogs -import org.matrix.android.sdk.api.session.room.powerlevels.Role -import org.matrix.android.sdk.api.util.MatrixItem import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_matrix_profile.* import kotlinx.android.synthetic.main.view_stub_room_member_profile_header.* +import org.matrix.android.sdk.api.session.room.powerlevels.Role +import org.matrix.android.sdk.api.util.MatrixItem import javax.inject.Inject @Parcelize @@ -110,6 +111,12 @@ class RoomMemberProfileFragment @Inject constructor( is RoomMemberProfileViewEvents.OnInviteActionSuccess -> Unit }.exhaustive } + setupLongClicks() + } + + private fun setupLongClicks() { + memberProfileNameView.copyOnLongClick() + memberProfileIdView.copyOnLongClick() } private fun handleShowPowerLevelDemoteWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index 2722d54950..d94a326ba9 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -34,16 +34,12 @@ import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.yalantis.ucrop.UCrop -import im.vector.lib.multipicker.MultiPicker -import im.vector.lib.multipicker.entity.MultiPickerImageType -import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState -import org.matrix.android.sdk.api.util.MatrixItem -import org.matrix.android.sdk.api.util.toMatrixItem import im.vector.app.R import im.vector.app.core.animations.AppBarStateChangeListener import im.vector.app.core.animations.MatrixItemAppBarStateChangeListener import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith +import im.vector.app.core.extensions.copyOnLongClick import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.intent.getFilenameFromUri @@ -62,9 +58,14 @@ import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedA import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel import im.vector.app.features.media.BigImageViewerActivity import im.vector.app.features.media.createUCropWithDefaultSettings +import im.vector.lib.multipicker.MultiPicker +import im.vector.lib.multipicker.entity.MultiPickerImageType import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_matrix_profile.* import kotlinx.android.synthetic.main.view_stub_room_profile_header.* +import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState +import org.matrix.android.sdk.api.util.MatrixItem +import org.matrix.android.sdk.api.util.toMatrixItem import timber.log.Timber import java.io.File import javax.inject.Inject @@ -120,6 +121,13 @@ class RoomProfileFragment @Inject constructor( .observe() .subscribe { handleQuickActions(it) } .disposeOnDestroyView() + setupLongClicks() + } + + private fun setupLongClicks() { + roomProfileNameView.copyOnLongClick() + roomProfileAliasView.copyOnLongClick() + roomProfileTopicView.copyOnLongClick() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -301,9 +309,7 @@ class RoomProfileFragment @Inject constructor( .get(MultiPicker.IMAGE) .getSelectedFiles(requireContext(), requestCode, resultCode, data) .firstOrNull()?.let { - // TODO. UCrop library cannot read from Gallery. For now, we will set avatar as it is. - // onRoomAvatarSelected(it) - onAvatarCropped(it.contentUri) + onRoomAvatarSelected(it) } } UCrop.REQUEST_CROP -> data?.let { onAvatarCropped(UCrop.getOutput(it)) } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt index 31de5ddd67..e31b81b162 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt @@ -356,8 +356,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { .get(MultiPicker.IMAGE) .getSelectedFiles(requireContext(), requestCode, resultCode, data) .firstOrNull()?.let { - // TODO. UCrop library cannot read from Gallery. For now, we will set avatar as it is. - onAvatarCropped(it.contentUri) + onAvatarSelected(it) } } UCrop.REQUEST_CROP -> data?.let { onAvatarCropped(UCrop.getOutput(it)) }