Added Snackbar proton_notification_norm to color taxonomy.
This commit is contained in:
parent
95fe8adbfc
commit
6fd8641378
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,3 +1,16 @@
|
|||
## Presentation [1.18.1]
|
||||
|
||||
28 Oct, 2021
|
||||
|
||||
### Changes
|
||||
|
||||
- Added Snackbar proton_notification_norm to color taxonomy.
|
||||
- Please use View extensions for Snackbar:
|
||||
- View.normSnack
|
||||
- View.warningSnack
|
||||
- View.errorSnack
|
||||
- View.successSnack
|
||||
|
||||
## Auth [1.17.5]
|
||||
|
||||
28 Oct, 2021
|
||||
|
|
|
@ -23,7 +23,11 @@ import android.text.InputType
|
|||
import me.proton.android.core.coreexample.databinding.ActivityCustomViewsBinding
|
||||
import me.proton.core.presentation.ui.ProtonViewBindingActivity
|
||||
import me.proton.core.presentation.ui.view.ProtonProgressButton
|
||||
import me.proton.core.presentation.utils.errorSnack
|
||||
import me.proton.core.presentation.utils.normSnack
|
||||
import me.proton.core.presentation.utils.onClick
|
||||
import me.proton.core.presentation.utils.successSnack
|
||||
import me.proton.core.presentation.utils.warningSnack
|
||||
import me.proton.core.util.kotlin.forEach
|
||||
|
||||
/**
|
||||
|
@ -46,5 +50,10 @@ class CustomViewsActivity : ProtonViewBindingActivity<ActivityCustomViewsBinding
|
|||
|
||||
binding.inputExample.inputType = InputType.TYPE_CLASS_PHONE
|
||||
binding.errorExample.setInputError("Error in your text")
|
||||
|
||||
binding.snackNorm.onClick { binding.snackNorm.normSnack("Norm snackbar, Light/Dark background") }
|
||||
binding.snackWarn.onClick { binding.snackWarn.warningSnack("Warning snackbar, Yellow background.") }
|
||||
binding.snackError.onClick { binding.snackError.errorSnack("Error snackbar, Red background") }
|
||||
binding.snackSuccess.onClick { binding.snackSuccess.successSnack("Success snackbar, Green background") }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,5 +352,51 @@
|
|||
android:text="@string/example_radio2_label" />
|
||||
</RadioGroup>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/snackbars"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/default_top_margin"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintTop_toBottomOf="@id/radioGroupExample">
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonButton
|
||||
android:id="@+id/snackNorm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/gap_small"
|
||||
android:layout_weight="1"
|
||||
android:text="Norm" />
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonButton
|
||||
android:id="@+id/snackWarn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/gap_small"
|
||||
android:layout_weight="1"
|
||||
android:text="Warn" />
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonButton
|
||||
android:id="@+id/snackError"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/gap_small"
|
||||
android:layout_weight="1"
|
||||
android:text="Error" />
|
||||
|
||||
<me.proton.core.presentation.ui.view.ProtonButton
|
||||
android:id="@+id/snackSuccess"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/gap_small"
|
||||
android:layout_weight="1"
|
||||
android:text="Success" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/snackbars"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -26,7 +26,7 @@ plugins {
|
|||
id("kotlin-parcelize")
|
||||
}
|
||||
|
||||
libVersion = Version(1, 18, 0)
|
||||
libVersion = Version(1, 18, 1)
|
||||
|
||||
android(useViewBinding = true)
|
||||
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Proton Technologies AG
|
||||
* This file is part of Proton Technologies AG and ProtonCore.
|
||||
*
|
||||
* ProtonCore is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ProtonCore is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ProtonCore. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.proton.core.presentation.utils
|
||||
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import me.proton.core.presentation.R
|
||||
|
||||
/**
|
||||
* Shows normal snack bar.
|
||||
*/
|
||||
fun View.normSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.snackbar_background_norm)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows normal snack bar.
|
||||
*/
|
||||
fun View.normSnack(message: String) {
|
||||
snack(message = message, color = R.drawable.snackbar_background_norm)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows warning snack bar.
|
||||
*/
|
||||
fun View.warningSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.snackbar_background_warning)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows warning snack bar.
|
||||
*/
|
||||
fun View.warningSnack(message: String) {
|
||||
snack(message = message, color = R.drawable.snackbar_background_warning)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows red error snack bar.
|
||||
*/
|
||||
fun View.errorSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.snackbar_background_error)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows red error snack bar.
|
||||
*/
|
||||
fun View.errorSnack(message: String) {
|
||||
snack(message = message, color = R.drawable.snackbar_background_error)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows red error snack bar.
|
||||
*/
|
||||
fun View.errorSnack(message: String, action: String?, actionOnClick: (() -> Unit)?) {
|
||||
snack(
|
||||
message = message,
|
||||
color = R.drawable.snackbar_background_error,
|
||||
action = action,
|
||||
actionOnClick = actionOnClick
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows green success snack bar.
|
||||
*/
|
||||
fun View.successSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.snackbar_background_success)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows green success snack bar.
|
||||
*/
|
||||
fun View.successSnack(message: String) {
|
||||
snack(message = message, color = R.drawable.snackbar_background_success)
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message and color as config.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*
|
||||
* @param messageRes the String resource message id
|
||||
*/
|
||||
fun View.snack(
|
||||
@StringRes messageRes: Int,
|
||||
@DrawableRes color: Int
|
||||
) {
|
||||
snack(message = resources.getString(messageRes), color = color)
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message, color and length as config.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*/
|
||||
fun View.snack(
|
||||
message: String,
|
||||
@DrawableRes color: Int,
|
||||
action: String? = null,
|
||||
actionOnClick: (() -> Unit)? = null,
|
||||
length: Int = Snackbar.LENGTH_LONG
|
||||
) {
|
||||
snack(message, color, length) {
|
||||
if (action != null && actionOnClick != null) setAction(action) { actionOnClick() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message, color and length and a configuration block.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*/
|
||||
fun View.snack(
|
||||
message: String,
|
||||
@DrawableRes color: Int,
|
||||
length: Int = Snackbar.LENGTH_LONG,
|
||||
configBlock: (Snackbar.() -> Unit)? = null
|
||||
) {
|
||||
Snackbar.make(this, message, length).apply {
|
||||
view.background = ResourcesCompat.getDrawable(context.resources, color, null)
|
||||
view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text).apply { maxLines = 5 }
|
||||
configBlock?.invoke(this)
|
||||
}.show()
|
||||
}
|
|
@ -30,11 +30,7 @@ import android.view.ViewGroup
|
|||
import android.widget.Adapter
|
||||
import android.widget.AdapterView
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.children
|
||||
|
@ -42,8 +38,6 @@ import androidx.core.view.marginBottom
|
|||
import androidx.core.view.marginEnd
|
||||
import androidx.core.view.marginStart
|
||||
import androidx.core.view.marginTop
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import me.proton.core.presentation.R
|
||||
import me.proton.core.presentation.ui.view.ProtonInput
|
||||
import me.proton.core.util.kotlin.times
|
||||
|
||||
|
@ -144,82 +138,6 @@ inline fun View.onClick(crossinline block: () -> Unit) {
|
|||
fun ViewGroup.inflate(@LayoutRes layoutId: Int, attachToRoot: Boolean = false): View =
|
||||
LayoutInflater.from(context).inflate(layoutId, this, attachToRoot)
|
||||
|
||||
/**
|
||||
* Shows red error snack bar. Usually as a general way to display various errors to the user.
|
||||
*
|
||||
* @param messageRes the String resource error message id
|
||||
*/
|
||||
fun View.errorSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.background_error)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows red error snack bar. Usually as a general way to display various errors to the user.
|
||||
*/
|
||||
fun View.errorSnack(message: String) {
|
||||
snack(message = message, color = R.drawable.background_error)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows red error snack bar. Usually as a general way to display various errors to the user.
|
||||
*/
|
||||
fun View.errorSnack(message: String, action: String?, actionOnClick: (() -> Unit)?) {
|
||||
snack(message = message, color = R.drawable.background_error, action = action, actionOnClick = actionOnClick)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows green success snack bar. Usually as a general way to display success result of an operation to the user.
|
||||
*/
|
||||
fun View.successSnack(@StringRes messageRes: Int) {
|
||||
snack(messageRes = messageRes, color = R.drawable.background_success)
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message and color as config.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*
|
||||
* @param messageRes the String resource message id
|
||||
*/
|
||||
fun View.snack(
|
||||
@StringRes messageRes: Int,
|
||||
@DrawableRes color: Int
|
||||
) {
|
||||
snack(message = resources.getString(messageRes), color = color)
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message, color and length as config.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*/
|
||||
fun View.snack(
|
||||
message: String,
|
||||
@DrawableRes color: Int,
|
||||
action: String? = null,
|
||||
actionOnClick: (() -> Unit)? = null,
|
||||
length: Int = Snackbar.LENGTH_LONG
|
||||
) {
|
||||
snack(message, color, length) {
|
||||
if (action != null && actionOnClick != null) setAction(action) { actionOnClick() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* General snack bar util function which takes message, color and length and a configuration block.
|
||||
* The default showing length is [Snackbar.LENGTH_LONG].
|
||||
*/
|
||||
fun View.snack(
|
||||
message: String,
|
||||
@DrawableRes color: Int,
|
||||
length: Int = Snackbar.LENGTH_LONG,
|
||||
configBlock: (Snackbar.() -> Unit)? = null
|
||||
) {
|
||||
Snackbar.make(this, message, length).apply {
|
||||
view.background = ResourcesCompat.getDrawable(context.resources, color, null)
|
||||
view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text).apply { maxLines = 5 }
|
||||
configBlock?.invoke(this)
|
||||
}.show()
|
||||
}
|
||||
|
||||
fun View.requestApplyInsetsWhenAttached() {
|
||||
if (isAttachedToWindow) {
|
||||
requestApplyInsets()
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (c) 2020 Proton Technologies AG
|
||||
~ This file is part of Proton Technologies AG and ProtonCore.
|
||||
~
|
||||
~ ProtonCore is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ ProtonCore is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with ProtonCore. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/notification_norm" />
|
||||
<corners android:radius="5dp" />
|
||||
<padding
|
||||
android:left="@dimen/corner_padding"
|
||||
android:right="@dimen/corner_padding" />
|
||||
</shape>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (c) 2020 Proton Technologies AG
|
||||
~ This file is part of Proton Technologies AG and ProtonCore.
|
||||
~
|
||||
~ ProtonCore is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ ProtonCore is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with ProtonCore. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/notification_warning" />
|
||||
<corners android:radius="5dp" />
|
||||
<padding
|
||||
android:left="@dimen/corner_padding"
|
||||
android:right="@dimen/corner_padding" />
|
||||
</shape>
|
||||
|
|
@ -52,6 +52,7 @@
|
|||
<attr name="proton_background_norm" format="reference" />
|
||||
<attr name="proton_background_secondary" format="reference" />
|
||||
<attr name="proton_separator_norm" format="reference" />
|
||||
<attr name="proton_notification_norm" format="reference" />
|
||||
<attr name="proton_notification_error" format="reference" />
|
||||
<attr name="proton_notification_success" format="reference" />
|
||||
<attr name="proton_notification_warning" format="reference" />
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
|
||||
<color name="separator_norm">@color/shade_20</color>
|
||||
|
||||
<color name="notification_norm">@color/shade_100</color>
|
||||
<color name="notification_error">@color/pomegranate</color>
|
||||
<color name="notification_success">@color/apple</color>
|
||||
<color name="notification_warning">@color/sunglow</color>
|
||||
|
|
|
@ -299,12 +299,12 @@
|
|||
|
||||
<style name="ProtonSnackbarButton" parent="Widget.MaterialComponents.Button.TextButton.Snackbar">
|
||||
<item name="android:textAppearance">@style/Proton.Text.DefaultSmall.Medium</item>
|
||||
<item name="android:textColor">@color/white</item>
|
||||
<item name="android:textColor">@color/text_inverted</item>
|
||||
</style>
|
||||
|
||||
<style name="ProtonSnackbarText" parent="Widget.MaterialComponents.Snackbar.TextView">
|
||||
<item name="android:textAppearance">@style/Proton.Text.DefaultSmall</item>
|
||||
<item name="android:textColor">@color/white</item>
|
||||
<item name="android:textColor">@color/text_inverted</item>
|
||||
</style>
|
||||
<!-- endregion -->
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
<item name="proton_background_norm">@color/background_norm</item>
|
||||
<item name="proton_background_secondary">@color/background_secondary</item>
|
||||
<item name="proton_separator_norm">@color/separator_norm</item>
|
||||
<item name="proton_notification_norm">@color/notification_norm</item>
|
||||
<item name="proton_notification_error">@color/notification_error</item>
|
||||
<item name="proton_notification_success">@color/notification_success</item>
|
||||
<item name="proton_notification_warning">@color/notification_warning</item>
|
||||
|
|
Loading…
Reference in New Issue