From 81712ae7362813b1e8e6283c8ae2cba5aa7732a6 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 9 Jan 2020 19:47:54 +0100 Subject: [PATCH] RoomProfile: fix some rendering + change anim --- .../animations/AppBarStateChangeListener.kt | 53 +++++++++++ .../core/epoxy/profiles/ProfileItemSection.kt | 2 - .../roomprofile/RoomProfileFragment.kt | 28 ++++-- .../res/layout/fragment_room_member_list.xml | 2 - .../main/res/layout/fragment_room_profile.xml | 91 +++++++++++-------- .../main/res/layout/item_profile_section.xml | 2 +- 6 files changed, 126 insertions(+), 52 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/core/animations/AppBarStateChangeListener.kt diff --git a/vector/src/main/java/im/vector/riotx/core/animations/AppBarStateChangeListener.kt b/vector/src/main/java/im/vector/riotx/core/animations/AppBarStateChangeListener.kt new file mode 100644 index 0000000000..a16b3b52d9 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/animations/AppBarStateChangeListener.kt @@ -0,0 +1,53 @@ +/* + * Copyright 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.core.animations + +import com.google.android.material.appbar.AppBarLayout +import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener +import kotlin.math.abs + + +abstract class AppBarStateChangeListener : OnOffsetChangedListener { + + enum class State { + EXPANDED, COLLAPSED, IDLE + } + + private var currentState = State.IDLE + + override fun onOffsetChanged(appBarLayout: AppBarLayout, i: Int) { + currentState = if (i == 0) { + if (currentState != State.EXPANDED) { + onStateChanged(appBarLayout, State.EXPANDED) + } + State.EXPANDED + } else if (abs(i) >= appBarLayout.totalScrollRange) { + if (currentState != State.COLLAPSED) { + onStateChanged(appBarLayout, State.COLLAPSED) + } + State.COLLAPSED + } else { + if (currentState != State.IDLE) { + onStateChanged(appBarLayout, State.IDLE) + } + State.IDLE + } + } + + abstract fun onStateChanged(appBarLayout: AppBarLayout, state: State) +} diff --git a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt index 24a9d1a57b..1ad6c12606 100644 --- a/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt +++ b/vector/src/main/java/im/vector/riotx/core/epoxy/profiles/ProfileItemSection.kt @@ -34,8 +34,6 @@ abstract class ProfileItemSection: VectorEpoxyModel() holder.sectionView.text = title } - - class Holder : VectorEpoxyHolder() { val sectionView by bind(R.id.itemProfileSectionView) } 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 0ebbbcde6b..50be4a2d87 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 @@ -29,15 +29,14 @@ import androidx.recyclerview.widget.RecyclerView import com.airbnb.mvrx.args import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState -import com.google.android.material.snackbar.Snackbar +import com.google.android.material.appbar.AppBarLayout import im.vector.matrix.android.api.session.room.notification.RoomNotificationState import im.vector.matrix.android.api.util.toMatrixItem import im.vector.riotx.R -import im.vector.riotx.core.error.ErrorFormatter +import im.vector.riotx.core.animations.AppBarStateChangeListener import im.vector.riotx.core.extensions.setTextOrHide import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.features.home.AvatarRenderer -import im.vector.riotx.features.home.room.list.RoomListAction 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 @@ -72,6 +71,18 @@ class RoomProfileFragment @Inject constructor( roomProfileSharedActionViewModel = activityViewModelProvider.get(RoomProfileSharedActionViewModel::class.java) setupToolbar(roomProfileToolbar) setupRecyclerView() + roomProfileAppBarLayout.addOnOffsetChangedListener(object : AppBarStateChangeListener() { + override fun onStateChanged(appBarLayout: AppBarLayout, state: State) { + val animationDuration = roomProfileCollapsingToolbarLayout.scrimAnimationDuration + if (state == State.COLLAPSED) { + roomProfileToolbarAvatarImageView.animate().alpha(1f).duration = animationDuration + 100 + roomProfileToolbarTitleView.animate().alpha(1f).duration = animationDuration + 100 + } else { + roomProfileToolbarAvatarImageView.animate().alpha(0f).duration = animationDuration - 100 + roomProfileToolbarTitleView.animate().alpha(0f).duration = animationDuration - 100 + } + } + }) roomProfileViewModel.viewEvents .observe() .subscribe { @@ -135,17 +146,18 @@ class RoomProfileFragment @Inject constructor( } override fun invalidate() = withState(roomProfileViewModel) { state -> - state.roomSummary()?.let { + state.roomSummary()?.also { if (it.membership.isLeft()) { Timber.w("The room has been left") activity?.finish() } else { roomProfileNameView.text = it.displayName - roomProfileNameView2.text = it.displayName - // Use canonical alias when PR with alias management will be merged - roomProfileAliasView.text = it.roomId + roomProfileToolbarTitleView.text = it.displayName + roomProfileAliasView.setTextOrHide(it.canonicalAlias) roomProfileTopicView.setTextOrHide(it.topic) - avatarRenderer.render(it.toMatrixItem(), roomProfileAvatarView) + val matrixItem = it.toMatrixItem() + avatarRenderer.render(matrixItem, roomProfileAvatarView) + avatarRenderer.render(matrixItem, roomProfileToolbarAvatarImageView) } } roomProfileController.setData(state) diff --git a/vector/src/main/res/layout/fragment_room_member_list.xml b/vector/src/main/res/layout/fragment_room_member_list.xml index ec38848f32..16bb53a2aa 100644 --- a/vector/src/main/res/layout/fragment_room_member_list.xml +++ b/vector/src/main/res/layout/fragment_room_member_list.xml @@ -11,8 +11,6 @@ style="@style/VectorToolbarStyle" android:layout_width="0dp" android:layout_height="?actionBarSize" - android:elevation="4dp" - android:transitionName="toolbar" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> diff --git a/vector/src/main/res/layout/fragment_room_profile.xml b/vector/src/main/res/layout/fragment_room_profile.xml index 8b3ac8f608..78e54f76e2 100644 --- a/vector/src/main/res/layout/fragment_room_profile.xml +++ b/vector/src/main/res/layout/fragment_room_profile.xml @@ -13,8 +13,11 @@ android:layout_height="wrap_content"> + + @@ -60,7 +71,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginStart="40dp" - android:layout_marginTop="16dp" + android:layout_marginBottom="16dp" android:layout_marginEnd="40dp" android:fontFamily="sans-serif" android:gravity="center" @@ -74,7 +85,44 @@ android:id="@+id/roomProfileToolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - app:layout_collapseMode="pin" /> + android:background="@android:color/transparent" + app:layout_collapseMode="pin"> + + + + + + + + + + + @@ -88,39 +136,4 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:listitem="@layout/item_profile_action" /> - - - - \ No newline at end of file diff --git a/vector/src/main/res/layout/item_profile_section.xml b/vector/src/main/res/layout/item_profile_section.xml index e365733d79..89efade46b 100644 --- a/vector/src/main/res/layout/item_profile_section.xml +++ b/vector/src/main/res/layout/item_profile_section.xml @@ -13,5 +13,5 @@ android:textStyle="bold" android:textColor="?riotx_text_primary" android:background="?riotx_header_panel_background" - android:layout_height="68dp"/> + android:layout_height="56dp"/>