Fixing ripple effect

This commit is contained in:
Maxime Naturel 2022-03-02 15:58:51 +01:00
parent 8bcc594320
commit 42fca9bd6f
5 changed files with 51 additions and 37 deletions

View File

@ -59,12 +59,7 @@ class LocationSharingFragment @Inject constructor(
views.mapView.initialize(urlMapProvider.getMapUrl()) views.mapView.initialize(urlMapProvider.getMapUrl())
} }
// TODO change the options dynamically depending on the current chosen location initOptionsPicker()
// set correct click listener on each option
views.shareLocationOptionsPicker.setOptions(LocationSharingOption.PINNED)
views.shareLocationOptionsPicker.debouncedClicks {
viewModel.handle(LocationSharingAction.OnShareLocation)
}
viewModel.observeViewEvents { viewModel.observeViewEvents {
when (it) { when (it) {
@ -110,6 +105,11 @@ class LocationSharingFragment @Inject constructor(
super.onDestroy() super.onDestroy()
} }
override fun invalidate() = withState(viewModel) { state ->
views.mapView.render(state.toMapState())
views.shareLocationGpsLoading.isGone = state.lastKnownLocation != null
}
private fun handleLocationNotAvailableError() { private fun handleLocationNotAvailableError() {
MaterialAlertDialogBuilder(requireActivity()) MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.location_not_available_dialog_title) .setTitle(R.string.location_not_available_dialog_title)
@ -121,8 +121,19 @@ class LocationSharingFragment @Inject constructor(
.show() .show()
} }
override fun invalidate() = withState(viewModel) { state -> private fun initOptionsPicker() {
views.mapView.render(state.toMapState()) // TODO
views.shareLocationGpsLoading.isGone = state.lastKnownLocation != null // set avatar and user color for the current user location option
// change the options dynamically depending on the current chosen location
views.shareLocationOptionsPicker.setOptions(LocationSharingOption.PINNED)
views.shareLocationOptionsPicker.optionPinned.debouncedClicks {
viewModel.handle(LocationSharingAction.OnShareLocation)
}
views.shareLocationOptionsPicker.optionUserCurrent.debouncedClicks {
// TODO
}
views.shareLocationOptionsPicker.optionUserLive.debouncedClicks {
// TODO
}
} }
} }

View File

@ -19,6 +19,7 @@ package im.vector.app.features.location.view
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import im.vector.app.databinding.ViewLocationSharingOptionPickerBinding import im.vector.app.databinding.ViewLocationSharingOptionPickerBinding
@ -31,6 +32,21 @@ class LocationSharingOptionPickerView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) { ) : ConstraintLayout(context, attrs, defStyleAttr) {
val optionPinned: LocationSharingOptionView
get() = binding.locationSharingOptionPinned
val optionUserCurrent: LocationSharingOptionView
get() = binding.locationSharingOptionUserCurrent
val optionUserLive: LocationSharingOptionView
get() = binding.locationSharingOptionUserLive
private val divider1: View
get() = binding.locationSharingOptionsDivider1
private val divider2: View
get() = binding.locationSharingOptionsDivider2
private val binding = ViewLocationSharingOptionPickerBinding.inflate( private val binding = ViewLocationSharingOptionPickerBinding.inflate(
LayoutInflater.from(context), LayoutInflater.from(context),
this this
@ -42,10 +58,10 @@ class LocationSharingOptionPickerView @JvmOverloads constructor(
val isUserCurrentVisible = options.contains(LocationSharingOption.USER_CURRENT) val isUserCurrentVisible = options.contains(LocationSharingOption.USER_CURRENT)
val isUserLiveVisible = options.contains(LocationSharingOption.USER_LIVE) val isUserLiveVisible = options.contains(LocationSharingOption.USER_LIVE)
binding.locationSharingOptionPinned.isVisible = isPinnedVisible optionPinned.isVisible = isPinnedVisible
binding.locationSharingOptionsDivider1.isVisible = isPinnedVisible && optionsNumber > 1 divider1.isVisible = isPinnedVisible && optionsNumber > 1
binding.locationSharingOptionUserCurrentLocation.isVisible = isUserCurrentVisible optionUserCurrent.isVisible = isUserCurrentVisible
binding.locationSharingOptionsDivider2.isVisible = isUserCurrentVisible && isUserLiveVisible divider2.isVisible = isUserCurrentVisible && isUserLiveVisible
binding.locationSharingOptionUserLiveLocation.isVisible = isUserLiveVisible optionUserLive.isVisible = isUserLiveVisible
} }
} }

View File

@ -42,7 +42,6 @@ class LocationSharingOptionView @JvmOverloads constructor(
) )
init { init {
applyRipple()
context.theme.obtainStyledAttributes( context.theme.obtainStyledAttributes(
attrs, attrs,
R.styleable.LocationSharingOptionView, R.styleable.LocationSharingOptionView,
@ -66,19 +65,6 @@ class LocationSharingOptionView @JvmOverloads constructor(
binding.shareLocationOptionIcon.background = bkg binding.shareLocationOptionIcon.background = bkg
} }
private fun applyRipple() {
val outValue = TypedValue()
context.theme.resolveAttribute(
android.R.attr.selectableItemBackground,
outValue,
true
)
binding.root.background = ContextCompat.getDrawable(
context,
outValue.resourceId
)
}
private fun setIcon(typedArray: TypedArray) { private fun setIcon(typedArray: TypedArray) {
val icon = typedArray.getDrawable(R.styleable.LocationSharingOptionView_icon) val icon = typedArray.getDrawable(R.styleable.LocationSharingOptionView_icon)
val background = typedArray.getDrawable(R.styleable.LocationSharingOptionView_iconBackground) val background = typedArray.getDrawable(R.styleable.LocationSharingOptionView_iconBackground)

View File

@ -10,7 +10,8 @@
android:id="@+id/shareLocationOptionContainer" android:id="@+id/shareLocationOptionContainer"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="72dp" android:layout_height="72dp"
android:background="?android:colorBackground" android:background="?selectableItemBackground"
android:duplicateParentState="true"
android:paddingStart="@dimen/layout_horizontal_margin" android:paddingStart="@dimen/layout_horizontal_margin"
android:paddingEnd="@dimen/layout_horizontal_margin" android:paddingEnd="@dimen/layout_horizontal_margin"
app:constraint_referenced_ids="shareLocationOptionIcon,shareLocationOptionTitle" app:constraint_referenced_ids="shareLocationOptionIcon,shareLocationOptionTitle"

View File

@ -14,7 +14,7 @@
app:iconBackground="@drawable/circle" app:iconBackground="@drawable/circle"
app:iconBackgroundTint="?colorPrimary" app:iconBackgroundTint="?colorPrimary"
app:iconDescription="@string/a11y_location_share_option_pinned_icon" app:iconDescription="@string/a11y_location_share_option_pinned_icon"
app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserCurrentLocation" app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserCurrent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
@ -26,20 +26,20 @@
android:layout_height="1dp" android:layout_height="1dp"
android:alpha="0.15" android:alpha="0.15"
android:background="?vctr_content_secondary" android:background="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserCurrentLocation" app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserCurrent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/locationSharingOptionPinned" /> app:layout_constraintTop_toBottomOf="@id/locationSharingOptionPinned" />
<im.vector.app.features.location.view.LocationSharingOptionView <im.vector.app.features.location.view.LocationSharingOptionView
android:id="@+id/locationSharingOptionUserCurrentLocation" android:id="@+id/locationSharingOptionUserCurrent"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:iconBackground="@drawable/circle" app:iconBackground="@drawable/circle"
app:iconBackgroundTint="?colorPrimary" app:iconBackgroundTint="?colorPrimary"
app:iconDescription="@string/a11y_location_share_option_user_current_icon" app:iconDescription="@string/a11y_location_share_option_user_current_icon"
app:iconPadding="3dp" app:iconPadding="3dp"
app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserLiveLocation" app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserLive"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/locationSharingOptionPinned" app:layout_constraintTop_toBottomOf="@+id/locationSharingOptionPinned"
@ -51,13 +51,13 @@
android:layout_height="1dp" android:layout_height="1dp"
android:alpha="0.15" android:alpha="0.15"
android:background="?vctr_content_secondary" android:background="?vctr_content_secondary"
app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserLiveLocation" app:layout_constraintBottom_toTopOf="@id/locationSharingOptionUserLive"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/locationSharingOptionUserCurrentLocation" /> app:layout_constraintTop_toBottomOf="@id/locationSharingOptionUserCurrent" />
<im.vector.app.features.location.view.LocationSharingOptionView <im.vector.app.features.location.view.LocationSharingOptionView
android:id="@+id/locationSharingOptionUserLiveLocation" android:id="@+id/locationSharingOptionUserLive"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:icon="@drawable/ic_attachment_location_live_white" app:icon="@drawable/ic_attachment_location_live_white"
@ -68,7 +68,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/locationSharingOptionUserCurrentLocation" app:layout_constraintTop_toBottomOf="@id/locationSharingOptionUserCurrent"
app:title="@string/location_share_option_user_live" /> app:title="@string/location_share_option_user_live" />
</merge> </merge>