From 14c71d6c07c23a365f220f5c8230052d72c5ec16 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 27 Nov 2020 11:50:54 +0100 Subject: [PATCH] Fix issue with too big icons --- .../app/core/extensions/ConstraintLayout.kt | 28 +++++++++++++++++++ .../im/vector/app/core/platform/StateView.kt | 12 +++++++- .../home/room/list/RoomListFragment.kt | 26 +++++++++-------- vector/src/main/res/layout/view_state.xml | 9 ++---- 4 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt diff --git a/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt new file mode 100644 index 000000000..b1b30da15 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/extensions/ConstraintLayout.kt @@ -0,0 +1,28 @@ +/* + * 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.app.core.extensions + +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.constraintlayout.widget.ConstraintSet + +fun ConstraintLayout.updateConstraintSet(block: (ConstraintSet) -> Unit) { + ConstraintSet().let { + it.clone(this) + block.invoke(it) + it.applyTo(this) + } +} diff --git a/vector/src/main/java/im/vector/app/core/platform/StateView.kt b/vector/src/main/java/im/vector/app/core/platform/StateView.kt index 2af3235cd..9ecb03cb1 100755 --- a/vector/src/main/java/im/vector/app/core/platform/StateView.kt +++ b/vector/src/main/java/im/vector/app/core/platform/StateView.kt @@ -21,8 +21,10 @@ import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.View import android.widget.FrameLayout +import androidx.constraintlayout.widget.ConstraintSet import androidx.core.view.isVisible import im.vector.app.R +import im.vector.app.core.extensions.updateConstraintSet import kotlinx.android.synthetic.main.view_state.view.* class StateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) @@ -31,7 +33,12 @@ class StateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? sealed class State { object Content : State() object Loading : State() - data class Empty(val title: CharSequence? = null, val image: Drawable? = null, val message: CharSequence? = null) : State() + data class Empty( + val title: CharSequence? = null, + val image: Drawable? = null, + val isBigImage: Boolean = false, + val message: CharSequence? = null + ) : State() data class Error(val message: CharSequence? = null) : State() } @@ -71,6 +78,9 @@ class StateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? is State.Loading -> Unit is State.Empty -> { emptyImageView.setImageDrawable(newState.image) + emptyView.updateConstraintSet { + it.constrainPercentHeight(R.id.emptyImageView, if (newState.isBigImage) 0.5f else 0.1f) + } emptyMessageView.text = newState.message emptyTitleView.text = newState.title } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index d3dcea10c..c9c9011de 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -295,28 +295,30 @@ class RoomListFragment @Inject constructor( RoomListDisplayMode.NOTIFICATIONS -> { if (hasNoRoom) { StateView.State.Empty( - getString(R.string.room_list_catchup_welcome_title), - ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_catchup), - getString(R.string.room_list_catchup_welcome_body) + title = getString(R.string.room_list_catchup_welcome_title), + image = ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_bottom_catchup), + message = getString(R.string.room_list_catchup_welcome_body) ) } else { StateView.State.Empty( - getString(R.string.room_list_catchup_empty_title), - ContextCompat.getDrawable(requireContext(), R.drawable.ic_noun_party_popper), - getString(R.string.room_list_catchup_empty_body)) + title = getString(R.string.room_list_catchup_empty_title), + image = ContextCompat.getDrawable(requireContext(), R.drawable.ic_noun_party_popper), + message = getString(R.string.room_list_catchup_empty_body)) } } RoomListDisplayMode.PEOPLE -> StateView.State.Empty( - getString(R.string.room_list_people_empty_title), - ContextCompat.getDrawable(requireContext(), R.drawable.empty_state_dm), - getString(R.string.room_list_people_empty_body) + title = getString(R.string.room_list_people_empty_title), + image = ContextCompat.getDrawable(requireContext(), R.drawable.empty_state_dm), + isBigImage = true, + message = getString(R.string.room_list_people_empty_body) ) RoomListDisplayMode.ROOMS -> StateView.State.Empty( - getString(R.string.room_list_rooms_empty_title), - ContextCompat.getDrawable(requireContext(), R.drawable.empty_state_room), - getString(R.string.room_list_rooms_empty_body) + title = getString(R.string.room_list_rooms_empty_title), + image = ContextCompat.getDrawable(requireContext(), R.drawable.empty_state_room), + isBigImage = true, + message = getString(R.string.room_list_rooms_empty_body) ) else -> // Always display the content in this mode, because if the footer diff --git a/vector/src/main/res/layout/view_state.xml b/vector/src/main/res/layout/view_state.xml index a6b0b2550..11f176e40 100644 --- a/vector/src/main/res/layout/view_state.xml +++ b/vector/src/main/res/layout/view_state.xml @@ -34,7 +34,6 @@ android:textSize="16sp" tools:text="Une erreur est survenue" /> - - + tools:layout_constraintHeight_percent="0.5" + tools:src="@drawable/ic_search_no_results" /> -