Adding warning info view

This commit is contained in:
Maxime NATUREL 2022-09-21 11:02:42 +02:00
parent bd9b843df7
commit 5de097e251
4 changed files with 140 additions and 0 deletions

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SessionWarningInfoView">
<attr name="sessionsWarningInfoDescription" format="string" />
<attr name="sessionsWarningInfoHasLearnMore" format="boolean" />
</declare-styleable>
</resources>

View file

@ -0,0 +1,75 @@
/*
* 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.settings.devices.v2
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.res.use
import im.vector.app.R
import im.vector.app.core.extensions.setTextWithColoredPart
import im.vector.app.databinding.ViewSessionWarningInfoBinding
class SessionWarningInfoView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val binding = ViewSessionWarningInfoBinding.inflate(
LayoutInflater.from(context),
this
)
var onLearnMoreClickListener: (() -> Unit)? = null
init {
context.obtainStyledAttributes(
attrs,
R.styleable.SessionWarningInfoView,
0,
0
).use {
setDescription(it)
}
}
private fun setDescription(typedArray: TypedArray) {
val description = typedArray.getString(R.styleable.SessionWarningInfoView_sessionsWarningInfoDescription)
val hasLearnMore = typedArray.getBoolean(R.styleable.SessionWarningInfoView_sessionsWarningInfoHasLearnMore, false)
if (hasLearnMore) {
val learnMore = context.getString(R.string.action_learn_more)
val fullDescription = buildString {
append(description)
append(" ")
append(learnMore)
}
binding.sessionWarningInfoDescription.setTextWithColoredPart(
fullText = fullDescription,
coloredPart = learnMore,
underline = false
) {
onLearnMoreClickListener?.invoke()
}
} else {
binding.sessionWarningInfoDescription.text = description
}
}
}

View file

@ -59,4 +59,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/renameSessionInputLayout" />
<im.vector.app.features.settings.devices.v2.SessionWarningInfoView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/layout_horizontal_margin"
android:layout_marginVertical="@dimen/layout_vertical_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/renameSessionDescription"
app:sessionsWarningInfoDescription="@string/device_manager_session_rename_warning"
app:sessionsWarningInfoHasLearnMore="false" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,45 @@
<?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">
<View
android:id="@+id/sessionWarningInfoBackground"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/rounded_rect_shape_8"
android:backgroundTint="?colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/sessionWarningInfoIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="14dp"
android:layout_marginVertical="14dp"
android:layout_marginEnd="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/sessionWarningInfoDescription"
android:src="@drawable/ic_info"
app:tint="?colorOnSurface" />
<TextView
android:id="@+id/sessionWarningInfoDescription"
style="@style/TextAppearance.Vector.Body.DevicesManagement"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:layout_marginEnd="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/sessionWarningInfoIcon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/sessionWarningInfoBackground"
tools:text="Please be aware that session names are also visible to people you communicate with. Learn more" />
</merge>