From 1a273407de3e3b5f4ad96693d9c3cd8fed2ef93b Mon Sep 17 00:00:00 2001 From: onurays Date: Wed, 26 Feb 2020 12:12:49 +0300 Subject: [PATCH] Display avatar in fullscreen. --- CHANGES.md | 1 + vector/src/main/AndroidManifest.xml | 1 + .../vector/riotx/core/di/ScreenComponent.kt | 3 + .../features/media/BigImageViewerActivity.kt | 68 +++++++++++++++++++ .../RoomMemberProfileFragment.kt | 18 +++++ .../roomprofile/RoomProfileFragment.kt | 18 +++++ .../res/layout/activity_big_image_viewer.xml | 28 ++++++++ .../layout/view_stub_room_profile_header.xml | 1 + 8 files changed, 138 insertions(+) create mode 100644 vector/src/main/java/im/vector/riotx/features/media/BigImageViewerActivity.kt create mode 100644 vector/src/main/res/layout/activity_big_image_viewer.xml diff --git a/CHANGES.md b/CHANGES.md index ffbaa42b3b..100aea1bda 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features ✨: Improvements 🙌: - Migrate to binary QR code verification (#994) - Share action is added to room profile and room member profile (#858) + - Display avatar in fullscreen (#861) Bugfix 🐛: - Account creation: wrongly hints that an email can be used to create an account (#941) diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 9d7495ef23..defb1386d1 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -40,6 +40,7 @@ android:name=".features.login.LoginActivity" android:windowSoftInputMode="adjustResize" /> + diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt index f03f6cb784..fd15dc3387 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt @@ -40,6 +40,7 @@ import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBotto import im.vector.riotx.features.invite.VectorInviteView import im.vector.riotx.features.link.LinkHandlerActivity import im.vector.riotx.features.login.LoginActivity +import im.vector.riotx.features.media.BigImageViewerActivity import im.vector.riotx.features.media.ImageMediaViewerActivity import im.vector.riotx.features.media.VideoMediaViewerActivity import im.vector.riotx.features.navigation.Navigator @@ -151,6 +152,8 @@ interface ScreenComponent { fun inject(deviceListBottomSheet: DeviceListBottomSheet) + fun inject(bigImageViewerActivity: BigImageViewerActivity) + @Component.Factory interface Factory { fun create(vectorComponent: VectorComponent, diff --git a/vector/src/main/java/im/vector/riotx/features/media/BigImageViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/BigImageViewerActivity.kt new file mode 100644 index 0000000000..2848cff352 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/media/BigImageViewerActivity.kt @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.media + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.core.net.toUri +import im.vector.riotx.R +import im.vector.riotx.core.di.ActiveSessionHolder +import im.vector.riotx.core.di.ScreenComponent +import im.vector.riotx.core.platform.VectorBaseActivity +import kotlinx.android.synthetic.main.activity_big_image_viewer.* +import javax.inject.Inject + +class BigImageViewerActivity : VectorBaseActivity() { + + @Inject lateinit var sessionHolder: ActiveSessionHolder + + private val imageUrl by lazy { intent.getStringExtra(EXTRA_IMAGE_URL) } + + override fun injectWith(injector: ScreenComponent) { + injector.inject(this) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_big_image_viewer) + + setSupportActionBar(imageMediaViewerToolbar) + supportActionBar?.apply { + title = intent.getStringExtra(EXTRA_TITLE) + setHomeButtonEnabled(true) + setDisplayHomeAsUpEnabled(true) + } + + val contentUrlResolver = sessionHolder.getActiveSession().contentUrlResolver() + val fullSize = contentUrlResolver.resolveFullSize(imageUrl) + bigImageViewerImageView.showImage(fullSize?.toUri()) + } + + companion object { + + private const val EXTRA_TITLE = "EXTRA_TITLE" + private const val EXTRA_IMAGE_URL = "EXTRA_IMAGE_URL" + + fun newIntent(context: Context, title: String?, imageUrl: String): Intent { + return Intent(context, BigImageViewerActivity::class.java).apply { + putExtra(EXTRA_TITLE, title) + putExtra(EXTRA_IMAGE_URL, imageUrl) + } + } + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt index c62e8ce226..edeb12dd2d 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -22,6 +22,8 @@ import android.os.Parcelable import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog +import androidx.core.app.ActivityOptionsCompat +import androidx.core.view.ViewCompat import androidx.core.view.isVisible import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Incomplete @@ -42,6 +44,7 @@ import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.startSharePlainTextIntent import im.vector.riotx.features.crypto.verification.VerificationBottomSheet import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.media.BigImageViewerActivity import im.vector.riotx.features.roommemberprofile.devices.DeviceListBottomSheet import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_matrix_profile.* @@ -192,6 +195,15 @@ class RoomMemberProfileFragment @Inject constructor( } else { memberProfileDecorationImageView.isVisible = false } + + memberProfileAvatarView.setOnClickListener { view -> + userMatrixItem.avatarUrl + ?.takeIf { it.isNotBlank() } + ?.let { avatarUrl -> + val title = userMatrixItem.displayName ?: "" + onAvatarClicked(view, title, avatarUrl) + } + } } } memberProfilePowerLevelView.setTextOrHide(state.userPowerLevelString()) @@ -227,4 +239,10 @@ class RoomMemberProfileFragment @Inject constructor( private fun handleShareRoomMemberProfile(permalink: String) { startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink) } + + private fun onAvatarClicked(view: View, title: String, avatarUrl: String) { + val intent = BigImageViewerActivity.newIntent(context!!, title, avatarUrl) + val options = ActivityOptionsCompat.makeSceneTransitionAnimation(requireActivity(), view, ViewCompat.getTransitionName(view) ?: "") + startActivity(intent, options.toBundle()) + } } diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt index 869810b08b..4b3c25aa2a 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt @@ -22,6 +22,8 @@ import android.os.Parcelable import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog +import androidx.core.app.ActivityOptionsCompat +import androidx.core.view.ViewCompat import androidx.core.view.isVisible import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel @@ -44,6 +46,7 @@ import im.vector.riotx.features.home.room.list.actions.RoomListActionsArgs import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsBottomSheet import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.riotx.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel +import im.vector.riotx.features.media.BigImageViewerActivity import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_matrix_profile.* import kotlinx.android.synthetic.main.view_stub_room_profile_header.* @@ -164,6 +167,15 @@ class RoomProfileFragment @Inject constructor( roomProfileDecorationImageView.isVisible = it.roomEncryptionTrustLevel != null roomProfileDecorationImageView.setImageResource(it.roomEncryptionTrustLevel.toImageRes()) matrixProfileDecorationToolbarAvatarImageView.setImageResource(it.roomEncryptionTrustLevel.toImageRes()) + + roomProfileAvatarView.setOnClickListener { view -> + matrixItem.avatarUrl + ?.takeIf { it.isNotBlank() } + ?.let { avatarUrl -> + val title = state.roomSummary()?.displayName ?: "" + onAvatarClicked(view, title, avatarUrl) + } + } } } roomProfileController.setData(state) @@ -211,4 +223,10 @@ class RoomProfileFragment @Inject constructor( private fun onShareRoomProfile(permalink: String) { startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink) } + + private fun onAvatarClicked(view: View, title: String, avatarUrl: String) { + val intent = BigImageViewerActivity.newIntent(context!!, title, avatarUrl) + val options = ActivityOptionsCompat.makeSceneTransitionAnimation(requireActivity(), view, ViewCompat.getTransitionName(view) ?: "") + startActivity(intent, options.toBundle()) + } } diff --git a/vector/src/main/res/layout/activity_big_image_viewer.xml b/vector/src/main/res/layout/activity_big_image_viewer.xml new file mode 100644 index 0000000000..e98436a001 --- /dev/null +++ b/vector/src/main/res/layout/activity_big_image_viewer.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/layout/view_stub_room_profile_header.xml b/vector/src/main/res/layout/view_stub_room_profile_header.xml index 9b733b7fa6..f7ae1c77a5 100644 --- a/vector/src/main/res/layout/view_stub_room_profile_header.xml +++ b/vector/src/main/res/layout/view_stub_room_profile_header.xml @@ -12,6 +12,7 @@ android:layout_width="128dp" android:layout_height="128dp" android:layout_marginBottom="16dp" + android:transitionName="roomProfileAvatarView" app:layout_constraintBottom_toTopOf="@+id/roomProfileNameView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"