mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Adding custom view for options picker
This commit is contained in:
parent
2048b859c5
commit
a98f502c01
7 changed files with 238 additions and 29 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.features.location
|
||||||
|
|
||||||
|
enum class LocationSharingOption {
|
||||||
|
USER_CURRENT, // current user's location
|
||||||
|
USER_LIVE, // user's location during a certain amount of time
|
||||||
|
PINNED // static location pinned by the user
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.features.location.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import im.vector.app.databinding.ViewLocationSharingOptionPickerBinding
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom view to display the location sharing option picker.
|
||||||
|
*/
|
||||||
|
class LocationSharingOptionPickerView @JvmOverloads constructor(
|
||||||
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||||
|
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
/*private val binding = */
|
||||||
|
init {
|
||||||
|
ViewLocationSharingOptionPickerBinding.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
this
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fun setOptions(vararg options: LocationSharingOption) {
|
||||||
|
// TODO show only the options passed in argument
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.features.location.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.TypedArray
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.util.TypedValue
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.graphics.drawable.DrawableCompat
|
||||||
|
import im.vector.app.R
|
||||||
|
import im.vector.app.databinding.ViewLocationSharingOptionBinding
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom view to display a location sharing option.
|
||||||
|
*/
|
||||||
|
class LocationSharingOptionView @JvmOverloads constructor(
|
||||||
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||||
|
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
private val binding = ViewLocationSharingOptionBinding.inflate(
|
||||||
|
LayoutInflater.from(context),
|
||||||
|
this
|
||||||
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
applyRipple()
|
||||||
|
context.theme.obtainStyledAttributes(
|
||||||
|
attrs,
|
||||||
|
R.styleable.LocationSharingOptionView,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
).run {
|
||||||
|
try {
|
||||||
|
setIcon(this)
|
||||||
|
setTitle(this)
|
||||||
|
} finally {
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
val icon = typedArray.getDrawable(R.styleable.LocationSharingOptionView_icon)
|
||||||
|
val background = typedArray.getDrawable(R.styleable.LocationSharingOptionView_iconBackground)
|
||||||
|
val backgroundTint = typedArray.getColor(
|
||||||
|
R.styleable.LocationSharingOptionView_iconBackgroundTint,
|
||||||
|
ContextCompat.getColor(context, android.R.color.transparent)
|
||||||
|
)
|
||||||
|
val description = typedArray.getString(R.styleable.LocationSharingOptionView_iconDescription)
|
||||||
|
|
||||||
|
binding.shareLocationOptionIcon.setImageDrawable(icon)
|
||||||
|
val bkg = background?.let {
|
||||||
|
val backgroundDrawable = DrawableCompat.wrap(it)
|
||||||
|
DrawableCompat.setTint(backgroundDrawable, backgroundTint)
|
||||||
|
backgroundDrawable
|
||||||
|
} ?: background
|
||||||
|
binding.shareLocationOptionIcon.background = bkg
|
||||||
|
binding.shareLocationOptionIcon.contentDescription = description
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setTitle(typedArray: TypedArray) {
|
||||||
|
val title = typedArray.getString(R.styleable.LocationSharingOptionView_title)
|
||||||
|
binding.shareLocationOptionTitle.text = title
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,40 +14,14 @@
|
||||||
app:mapbox_renderTextureMode="true"
|
app:mapbox_renderTextureMode="true"
|
||||||
tools:background="#4F00" />
|
tools:background="#4F00" />
|
||||||
|
|
||||||
<androidx.constraintlayout.helper.widget.Flow
|
<im.vector.app.features.location.view.LocationSharingOptionPickerView
|
||||||
android:id="@+id/shareLocationContainer"
|
android:id="@+id/shareLocationContainer"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="72dp"
|
android:layout_height="wrap_content"
|
||||||
android:background="?android:colorBackground"
|
|
||||||
android:paddingStart="@dimen/layout_horizontal_margin"
|
|
||||||
android:paddingEnd="@dimen/layout_horizontal_margin"
|
|
||||||
app:constraint_referenced_ids="shareLocationImageView,shareLocationText"
|
|
||||||
app:flow_horizontalBias="0"
|
|
||||||
app:flow_horizontalGap="8dp"
|
|
||||||
app:flow_horizontalStyle="packed"
|
|
||||||
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" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/shareLocationImageView"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:background="@drawable/circle"
|
|
||||||
android:backgroundTint="?colorPrimary"
|
|
||||||
android:contentDescription="@string/a11y_location_share_icon"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:src="@drawable/ic_attachment_location_white" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/shareLocationText"
|
|
||||||
style="@style/TextAppearance.Vector.Subtitle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/location_share"
|
|
||||||
android:textColor="?colorPrimary"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/shareLocationGpsLoading"
|
android:id="@+id/shareLocationGpsLoading"
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
|
|
42
vector/src/main/res/layout/view_location_sharing_option.xml
Normal file
42
vector/src/main/res/layout/view_location_sharing_option.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.helper.widget.Flow
|
||||||
|
android:id="@+id/shareLocationOptionContainer"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:background="?android:colorBackground"
|
||||||
|
android:paddingStart="@dimen/layout_horizontal_margin"
|
||||||
|
android:paddingEnd="@dimen/layout_horizontal_margin"
|
||||||
|
app:constraint_referenced_ids="shareLocationOptionIcon,shareLocationOptionTitle"
|
||||||
|
app:flow_horizontalBias="0"
|
||||||
|
app:flow_horizontalGap="8dp"
|
||||||
|
app:flow_horizontalStyle="packed"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/shareLocationOptionIcon"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:contentDescription="@string/a11y_location_share_icon"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:background="@drawable/circle"
|
||||||
|
tools:backgroundTint="?colorPrimary"
|
||||||
|
tools:src="@drawable/ic_attachment_location_white" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/shareLocationOptionTitle"
|
||||||
|
style="@style/TextAppearance.Vector.Subtitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="?vctr_content_primary"
|
||||||
|
tools:text="@string/location_share" />
|
||||||
|
|
||||||
|
</merge>
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
|
||||||
|
|
||||||
|
<im.vector.app.features.location.view.LocationSharingOptionView
|
||||||
|
android:id="@+id/locationSharingOptionPinned"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
app:icon="@drawable/ic_attachment_location_white"
|
||||||
|
app:iconBackground="@drawable/circle"
|
||||||
|
app:iconBackgroundTint="?colorPrimary"
|
||||||
|
app:iconDescription="@string/a11y_location_share_icon"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:title="@string/location_share" />
|
||||||
|
|
||||||
|
</merge>
|
10
vector/src/main/res/values/attrs.xml
Normal file
10
vector/src/main/res/values/attrs.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="LocationSharingOptionView">
|
||||||
|
<attr name="icon" format="reference" />
|
||||||
|
<attr name="iconBackground" format="reference" />
|
||||||
|
<attr name="iconBackgroundTint" format="color" />
|
||||||
|
<attr name="iconDescription" format="string" />
|
||||||
|
<attr name="title" format="string" />
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
Loading…
Reference in a new issue