From 2ce72139e3d821e7869b6f80a6091fe38310dce2 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Fri, 5 Apr 2019 13:52:20 -0700 Subject: [PATCH] For #1430 - Replaces existing snackbar and adapts text size --- .../mozilla/fenix/components/FenixSnackbar.kt | 5 ++++ .../mozilla/fenix/utils/ItsNotBrokenSnack.kt | 27 ++++++++----------- app/src/main/res/layout/fenix_snackbar.xml | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/FenixSnackbar.kt b/app/src/main/java/org/mozilla/fenix/components/FenixSnackbar.kt index 2c4ac38aa8..ea6f5fdc9a 100644 --- a/app/src/main/java/org/mozilla/fenix/components/FenixSnackbar.kt +++ b/app/src/main/java/org/mozilla/fenix/components/FenixSnackbar.kt @@ -4,10 +4,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.fenix.components +import android.util.TypedValue import android.view.View import android.view.ViewGroup import com.google.android.material.snackbar.BaseTransientBottomBar import android.view.LayoutInflater +import android.widget.TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM +import androidx.core.widget.TextViewCompat import kotlinx.android.synthetic.main.fenix_snackbar.view.* import org.mozilla.fenix.R import org.mozilla.fenix.ext.increaseTapArea @@ -22,6 +25,8 @@ class FenixSnackbar private constructor( init { view.background = null content.snackbar_btn.increaseTapArea(16) + + TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(content.snackbar_text, 12, 18, 1, TypedValue.COMPLEX_UNIT_SP) } fun setText(text: String) = this.apply { diff --git a/app/src/main/java/org/mozilla/fenix/utils/ItsNotBrokenSnack.kt b/app/src/main/java/org/mozilla/fenix/utils/ItsNotBrokenSnack.kt index 4a6a340f62..6df97597e1 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/ItsNotBrokenSnack.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/ItsNotBrokenSnack.kt @@ -6,9 +6,11 @@ package org.mozilla.fenix.utils import android.content.Context import android.view.View +import android.view.ViewGroup import androidx.core.content.ContextCompat import com.google.android.material.snackbar.Snackbar import org.mozilla.fenix.R +import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.ext.asActivity import org.mozilla.fenix.ext.components @@ -16,22 +18,15 @@ class ItsNotBrokenSnack(val context: Context) { fun showSnackbar(issueNumber: String) { val rootView = - context.asActivity()?.window?.decorView?.findViewById(android.R.id.content) - rootView?.let { - Snackbar.make(rootView, message.replace("%", issueNumber), Snackbar.LENGTH_SHORT) - .apply { - setAction("Add Tab to Issue") { - context.components.useCases.tabsUseCases.addTab - .invoke(issues + issueNumber) - }.setActionTextColor( - ContextCompat.getColor( - context, - R.color.accent_bright_dark_theme - ) - ) - show() - } - } + context.asActivity()?.window?.decorView?.findViewById(android.R.id.content) as ViewGroup + + FenixSnackbar.make(rootView, Snackbar.LENGTH_SHORT) + .setText(message.replace("%", issueNumber)) + .setAction("Add Tab to Issue") { + context.components.useCases.tabsUseCases.addTab + .invoke(issues + issueNumber) + } + .show() } companion object { diff --git a/app/src/main/res/layout/fenix_snackbar.xml b/app/src/main/res/layout/fenix_snackbar.xml index 76e458bc38..52d48a9517 100644 --- a/app/src/main/res/layout/fenix_snackbar.xml +++ b/app/src/main/res/layout/fenix_snackbar.xml @@ -25,13 +25,13 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:ellipsize="end" - android:maxLines="3" + android:maxLines="1" android:textColor="@color/photonWhite" android:textSize="18sp" android:textStyle="bold" android:typeface="sans" android:letterSpacing="0.05" - android:lineSpacingMultiplier="1.25" + android:gravity="center" tools:text="This is a custom Snackbar text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/snackbar_btn" @@ -45,6 +45,7 @@ android:layout_height="wrap_content" android:textColor="@color/photonWhite" android:textAlignment="textEnd" + android:layout_marginStart="16dp" tools:text="Action text" android:padding="0dp" android:minHeight="0dp" @@ -54,7 +55,6 @@ android:textStyle="bold" android:typeface="sans" android:letterSpacing="0.05" - android:lineSpacingMultiplier="1.25" android:visibility="gone" app:layout_constraintStart_toEndOf="@id/snackbar_text" app:layout_constraintEnd_toEndOf="parent"