Skip to content

Commit b78368c

Browse files
committed
Create whatsnew dialog
1 parent 33ddd44 commit b78368c

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ publish {
4040
desc = 'An Android library for frequently used UI components'
4141
website = 'https://github.com/bufferapp/android-components'
4242
}
43+

app/src/main/java/org/buffer/android/components/DialogFactory.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,68 @@ import androidx.annotation.StringRes
2222
import androidx.appcompat.app.AlertDialog
2323
import androidx.core.content.ContextCompat
2424
import com.google.android.material.dialog.MaterialAlertDialogBuilder
25+
import kotlinx.android.synthetic.main.dialog_whats_new.view.*
2526

2627
object DialogFactory {
2728

29+
fun createWhatsNewDialog(
30+
context: Context,
31+
@StringRes header: Int? = null,
32+
@DrawableRes heading: Int? = null,
33+
@StringRes title: Int? = null,
34+
@StringRes message: Int? = null,
35+
@StringRes positive: Int? = null,
36+
@StringRes neutral: Int? = null,
37+
positiveListener: View.OnClickListener? = null,
38+
neutralListener: View.OnClickListener? = null
39+
): AlertDialog {
40+
val view = LayoutInflater.from(context).inflate(R.layout.dialog_whats_new, null)
41+
42+
title?.let {
43+
view.titleText.text = context.getString(title)
44+
} ?: run {
45+
view.titleText.visibility = View.GONE
46+
}
47+
48+
heading?.let {
49+
view.headerImage.setImageDrawable(ContextCompat.getDrawable(context, heading))
50+
} ?: run {
51+
view.headerImage.visibility = View.GONE
52+
}
53+
54+
header?.let {
55+
view.headerText.text = context.getString(header)
56+
} ?: run {
57+
view.headerText.visibility = View.GONE
58+
}
59+
60+
message?.let {
61+
view.messageText.text = context.getString(message)
62+
} ?: run {
63+
view.messageText.visibility = View.GONE
64+
}
65+
66+
positive?.let {
67+
view.positiveButton.text = context.getString(positive)
68+
view.positiveButton.setOnClickListener {
69+
positiveListener?.onClick(view.positiveButton)
70+
}
71+
} ?: run {
72+
view.positiveButton.visibility = View.GONE
73+
}
74+
75+
neutral?.let {
76+
view.neutralButton.text = context.getString(neutral)
77+
view.neutralButton.setOnClickListener {
78+
neutralListener?.onClick(view.neutralButton)
79+
}
80+
} ?: run {
81+
view.neutralButton.visibility = View.GONE
82+
}
83+
84+
return AlertDialog.Builder(context).setView(view).create()
85+
}
86+
2887
fun createSimpleYesNoDialog(
2988
context: Context,
3089
title: String,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:gravity="center_horizontal"
7+
android:orientation="vertical">
8+
9+
<TextView
10+
android:id="@+id/headerText"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_margin="16dp"
14+
android:layout_marginStart="32dp"
15+
android:layout_marginEnd="32dp"
16+
android:textSize="@dimen/text_large_body" />
17+
18+
<ImageView
19+
android:id="@+id/headerImage"
20+
android:layout_width="match_parent"
21+
android:layout_height="140dp"
22+
android:layout_marginStart="32dp"
23+
android:layout_marginEnd="32dp"
24+
android:layout_marginBottom="16dp"
25+
android:scaleType="centerCrop" />
26+
27+
<TextView
28+
android:id="@+id/titleText"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_marginStart="32dp"
32+
android:layout_marginEnd="32dp"
33+
android:layout_marginBottom="16dp"
34+
android:textSize="@dimen/text_large_body"
35+
android:textStyle="bold" />
36+
37+
<TextView
38+
android:id="@+id/messageText"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:layout_marginStart="32dp"
42+
android:layout_marginEnd="32dp"
43+
android:layout_marginBottom="16dp"
44+
android:gravity="center_horizontal" />
45+
46+
<org.buffer.android.components.RoundedButton
47+
android:id="@+id/positiveButton"
48+
style="@style/RoundedButtonStyle"
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content"
51+
android:layout_marginStart="32dp"
52+
android:layout_marginEnd="32dp"
53+
android:layout_marginBottom="12dp"
54+
app:bufferButtonStyle="light" />
55+
56+
<org.buffer.android.components.RoundedButton
57+
android:id="@+id/neutralButton"
58+
style="@style/RoundedButtonStyle"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:layout_marginStart="32dp"
62+
android:layout_marginEnd="32dp"
63+
android:layout_marginBottom="16dp"
64+
app:bufferButtonStyle="clear" />
65+
66+
</LinearLayout>

0 commit comments

Comments
 (0)