Skip to content

Commit

Permalink
Merge pull request #122 from Trendyol/dialog-close-button-visual-capa…
Browse files Browse the repository at this point in the history
…bilities

Dialog close button drawable and color support
  • Loading branch information
ysnarsln authored Feb 14, 2024
2 parents ae70b97 + 871e1ef commit 57bc7c7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 14 deletions.
16 changes: 10 additions & 6 deletions libraries/dialogs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-1.png" width="280"/> <img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-2.png" width="280"/> <img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-3.png" width="280"/> <img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-4.png" width="280"/> <img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-5.png" width="280"/>

$dialogsVersion = dialogs-1.4.2 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
$dialogsVersion = dialogs-1.4.3 [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## Dialogs
Dialogs is a bunch of BottomSheetDialogs to use in app to show user an information, agreement or list.
Expand Down Expand Up @@ -34,6 +34,8 @@ Simple dialog to show information, error or text.
|---------------------------------|--------------------------|---------------------------------------------------------------------------------------------------------------------------|---------------|
| `title` | CharSequence | Title of the dialog | "" |
| `showCloseButton` | Boolean | Close button visibility | false |
| `closeButtonColor` | Int | Close button color | false |
| `closeButtonDrawable` | Int | Close button drawable | false |
| `animateCornerRadiusWhenExpand` | Boolean | Corner radius will be removed with an animation when set true. | false |
| `cornerRadius` | Float | Corner radius will be applied. | 16dp |
| `horizontalPadding` | Float | Horizontal padding will be applied. | 16dp |
Expand All @@ -48,12 +50,14 @@ Simple dialog to show information, error or text.

Sample usage:
```kotlin
infoDialog {
infoDialog {
title = "Info Title"
showCloseButton = true
closeButtonListener = { onInfoDialogClosed(it) }
content = SpannableString.valueOf(getSpannableString())
contentImage = android.R.drawable.btn_plus
showCloseButton = true
closeButtonColor = R.color.sample_color
closeButtonDrawable = R.drawable.sample_drawable
closeButtonListener = { onInfoDialogClosed(it) }
content = SpannableString.valueOf(getSpannableString())
contentImage = android.R.drawable.btn_plus
}.show(supportFragmentManager)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.trendyol.uicomponents.dialogs
import android.text.SpannableString
import android.webkit.DownloadListener
import android.webkit.WebView
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes

open class Builder internal constructor() {
Expand All @@ -12,6 +13,8 @@ open class Builder internal constructor() {
var titleTextColor: Int? = null
var titleTextPosition: TextPosition? = null
var showCloseButton: Boolean = false
@ColorInt var closeButtonColor: Int? = null
@DrawableRes var closeButtonDrawable: Int? = null
var closeButtonListener: ((DialogFragment) -> Unit)? = null
var animateCornerRadiusWhenExpand: Boolean = false
var onDialogDismissListener: ((DialogFragment) -> Unit)? = null
Expand All @@ -38,6 +41,8 @@ open class InfoDialogBuilder internal constructor() : Builder() {
arguments = DialogFragmentArguments(
title = it.title,
showCloseButton = it.showCloseButton,
closeButtonColor = it.closeButtonColor,
closeButtonDrawable = it.closeButtonDrawable,
animateCornerRadiusWhenExpand = it.animateCornerRadiusWhenExpand,
cornerRadius = it.cornerRadius,
horizontalPadding = it.horizontalPadding,
Expand Down Expand Up @@ -73,6 +78,8 @@ open class AgreementDialogBuilder internal constructor() : InfoDialogBuilder() {
arguments = DialogFragmentArguments(
title = it.title,
showCloseButton = it.showCloseButton,
closeButtonColor = it.closeButtonColor,
closeButtonDrawable = it.closeButtonDrawable,
content = SpannableString(it.content),
cornerRadius = it.cornerRadius,
horizontalPadding = it.horizontalPadding,
Expand Down Expand Up @@ -110,6 +117,8 @@ class SelectionDialogBuilder internal constructor() : InfoDialogBuilder() {
arguments = DialogFragmentArguments(
title = it.title,
showCloseButton = it.showCloseButton,
closeButtonColor = it.closeButtonColor,
closeButtonDrawable = it.closeButtonDrawable,
content = SpannableString(it.content),
showContentAsHtml = it.showContentAsHtml,
contentImage = it.contentImage,
Expand Down Expand Up @@ -148,6 +157,8 @@ class InfoListDialogBuilder internal constructor() : InfoDialogBuilder() {
arguments = DialogFragmentArguments(
title = it.title,
showCloseButton = it.showCloseButton,
closeButtonColor = it.closeButtonColor,
closeButtonDrawable = it.closeButtonDrawable,
content = SpannableString(it.content),
animateCornerRadiusWhenExpand = it.animateCornerRadiusWhenExpand,
cornerRadius = it.cornerRadius,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() {
val viewState = DialogViewState(
title = dialogArguments.title,
showCloseButton = dialogArguments.showCloseButton,
closeButtonColor = dialogArguments.closeButtonColor,
closeButtonDrawable = dialogArguments.closeButtonDrawable,
content = dialogArguments.content ?: SpannableString(""),
showContentAsHtml = dialogArguments.showContentAsHtml,
contentImage = dialogArguments.contentImage,
Expand All @@ -173,7 +175,10 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() {
textAlignment = viewState.getTitleTextPosition()
setTextColor(viewState.getTitleTextColor(context))
}
viewDialogHeader.imageClose.visibility = viewState.getCloseButtonVisibility()
with(viewDialogHeader.imageClose) {
visibility = viewState.getCloseButtonVisibility()
setImageDrawable(viewState.getCloseButtonDrawable(context))
}
with(imageContent) {
setImageDrawable(viewState.getContentImageDrawable(context))
visibility = viewState.getContentImageVisibility()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.trendyol.uicomponents.dialogs
import android.os.Bundle
import android.os.Parcelable
import android.webkit.WebView
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.os.bundleOf
Expand All @@ -12,6 +13,8 @@ import kotlinx.parcelize.Parcelize
class DialogFragmentArguments(
val title: CharSequence? = null,
val showCloseButton: Boolean? = null,
@ColorInt val closeButtonColor: Int? = null,
@DrawableRes val closeButtonDrawable: Int? = null,
val animateCornerRadiusWhenExpand: Boolean = true,
val cornerRadius: Float? = null,
val horizontalPadding: Float? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import com.trendyol.dialog.R

data class DialogViewState(
val title: CharSequence?,
private val showCloseButton: Boolean?,
@ColorInt val closeButtonColor: Int?,
@DrawableRes val closeButtonDrawable: Int?,
private val content: CharSequence,
val showContentAsHtml: Boolean,
@DrawableRes val contentImage: Int?,
Expand Down Expand Up @@ -59,6 +62,15 @@ data class DialogViewState(

fun getCloseButtonVisibility(): Int = if (showCloseButton == true) View.VISIBLE else View.GONE

fun getCloseButtonDrawable(
context: Context
): Drawable? {
val drawableId = closeButtonDrawable ?: R.drawable.ic_ui_components_dialogs_close
return ContextCompat.getDrawable(context, drawableId)?.apply {
closeButtonColor?.let { color -> setTint(color) }
}
}

fun getContentImageVisibility(): Int = if (contentImage?.takeIf { it != 0 } != null) View.VISIBLE else View.GONE

fun getContentTextVisibility(): Int = if (content.isNotEmpty()) View.VISIBLE else View.GONE
Expand Down
13 changes: 6 additions & 7 deletions libraries/dialogs/src/main/res/layout/layout_dialog_header.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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:id="@+id/viewTitleBackground"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingStart="@dimen/ui_components_dialogs_margin_outer"
android:paddingEnd="@dimen/ui_components_dialogs_margin_outer">
android:paddingStart="@dimen/ui_components_dialogs_margin_outer">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/textTitle"
Expand All @@ -22,8 +20,9 @@
android:id="@+id/imageClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?selectableItemBackgroundBorderless"
android:padding="@dimen/ui_components_dialogs_margin_inner"
android:layout_gravity="center"
android:background="?actionBarItemBackground"
android:padding="@dimen/ui_components_dialogs_close_margin_outer"
app:srcCompat="@drawable/ic_ui_components_dialogs_close" />

</LinearLayout>
1 change: 1 addition & 0 deletions libraries/dialogs/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>

<dimen name="ui_components_dialogs_margin_outer">16dp</dimen>
<dimen name="ui_components_dialogs_close_margin_outer">12dp</dimen>
<dimen name="ui_components_dialogs_margin_inner">8dp</dimen>

<dimen name="ui_components_dialogs_corner_radius">16dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class DialogsActivity : AppCompatActivity() {
infoDialog {
title = "Info Dialog Sample"
showCloseButton = true
closeButtonColor = ContextCompat.getColor(this@DialogsActivity, R.color.civ_error_stroke)
closeButtonListener = infoDialogClosed
content = SpannableString.valueOf(getSpannableString())
contentImage = R.mipmap.ic_launcher_round
Expand Down

0 comments on commit 57bc7c7

Please sign in to comment.