Skip to content

Commit 1f5340f

Browse files
author
Prateek Prasad
authored
Fixes icon height to use wrap_content (#6)
1 parent a28e707 commit 1f5340f

File tree

11 files changed

+154
-5
lines changed

11 files changed

+154
-5
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ dependencies {
2929
implementation 'androidx.appcompat:appcompat:1.1.0'
3030
implementation 'com.google.android.material:material:1.1.0'
3131
implementation 'com.github.bufferapp:CounterView:115e659a89'
32+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3233
}
3334

3435
publish {
3536
repoName = 'Maven'
3637
userOrg = 'buffer'
3738
groupId = 'org.buffer.android'
3839
artifactId = 'android-components'
39-
publishVersion = '1.1'
40+
publishVersion = '1.3'
4041
desc = 'An Android library for frequently used UI components'
4142
website = 'https://github.com/bufferapp/android-components'
4243
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import android.view.View
66
import android.widget.AdapterView
77
import android.widget.ArrayAdapter
88
import android.widget.LinearLayout
9+
import androidx.annotation.DrawableRes
910
import androidx.annotation.StringRes
11+
import androidx.core.content.ContextCompat
1012
import com.google.android.material.bottomsheet.BottomSheetDialog
1113
import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.list_item_selection_sheet_options
1214
import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.text_item_selection_message
1315
import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.text_item_selection_title
16+
import kotlinx.android.synthetic.main.view_simple_alert_sheet.view.*
1417

1518
object BottomSheetFactory {
1619

@@ -67,4 +70,30 @@ object BottomSheetFactory {
6770
setContentView(view)
6871
}
6972
}
70-
}
73+
74+
fun createSimpleAlertStyleBottomSheet(
75+
context: Context,
76+
@StringRes title: Int,
77+
@StringRes message: Int,
78+
@StringRes positiveButtonText: Int,
79+
@StringRes neutralButtonText: Int,
80+
@DrawableRes icon: Int,
81+
postiveListener: View.OnClickListener? = null,
82+
neutralListener: View.OnClickListener? = null
83+
) = BottomSheetDialog(context, R.style.BottomSheetDialog).apply {
84+
val view = layoutInflater.inflate(R.layout.view_simple_alert_sheet, null)
85+
86+
view.icon.setImageDrawable(ContextCompat.getDrawable(context, icon))
87+
view.title.text = context.getString(title)
88+
view.message.text = context.getString(message)
89+
view.button_positive.apply {
90+
text = context.getString(positiveButtonText)
91+
setOnClickListener(postiveListener)
92+
}
93+
view.button_neutral.apply {
94+
text = context.getString(neutralButtonText)
95+
setOnClickListener(neutralListener)
96+
}
97+
setContentView(view)
98+
}
99+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:background="@drawable/background_bottom_sheet"
8+
android:orientation="vertical"
9+
android:padding="24dp"
10+
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
11+
12+
<ImageView
13+
android:id="@+id/icon"
14+
style="@style/AlertSheetImageStyle"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_marginTop="8dp"
18+
app:layout_constraintEnd_toEndOf="parent"
19+
app:layout_constraintStart_toStartOf="parent"
20+
app:layout_constraintTop_toTopOf="parent" />
21+
22+
<TextView
23+
android:id="@+id/title"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_marginTop="24dp"
27+
android:textColor="@color/text_primary"
28+
android:textSize="@dimen/text_body"
29+
android:textStyle="bold"
30+
app:layout_constraintEnd_toEndOf="parent"
31+
app:layout_constraintStart_toStartOf="parent"
32+
app:layout_constraintTop_toBottomOf="@id/icon" />
33+
34+
<TextView
35+
android:id="@+id/message"
36+
android:layout_width="@dimen/bottom_sheet_content_width"
37+
android:layout_height="wrap_content"
38+
android:layout_marginTop="16dp"
39+
android:textAlignment="center"
40+
android:textColor="@color/text_primary"
41+
android:textSize="@dimen/text_body"
42+
android:textStyle="normal"
43+
app:layout_constraintEnd_toEndOf="parent"
44+
app:layout_constraintStart_toStartOf="parent"
45+
app:layout_constraintTop_toBottomOf="@id/title" />
46+
47+
<org.buffer.android.components.RoundedButton
48+
android:id="@+id/button_positive"
49+
style="@style/RoundedButtonStyle"
50+
android:layout_width="@dimen/bottom_sheet_content_width"
51+
android:layout_height="wrap_content"
52+
android:layout_marginStart="16dp"
53+
android:layout_marginTop="24dp"
54+
android:layout_marginEnd="16dp"
55+
app:bufferButtonStyle="light"
56+
app:layout_constraintBottom_toTopOf="@id/button_neutral"
57+
app:layout_constraintEnd_toEndOf="parent"
58+
app:layout_constraintStart_toStartOf="parent"
59+
app:layout_constraintTop_toBottomOf="@id/message" />
60+
61+
<TextView
62+
android:id="@+id/button_neutral"
63+
android:layout_width="@dimen/bottom_sheet_content_width"
64+
android:layout_height="wrap_content"
65+
android:layout_marginStart="16dp"
66+
android:layout_marginTop="4dp"
67+
android:layout_marginEnd="16dp"
68+
android:background="?android:selectableItemBackground"
69+
android:clickable="true"
70+
android:focusable="true"
71+
android:gravity="center_horizontal"
72+
android:padding="16dp"
73+
android:textColor="@color/colorAccent"
74+
app:layout_constraintBottom_toBottomOf="parent"
75+
app:layout_constraintEnd_toEndOf="parent"
76+
app:layout_constraintHorizontal_bias="0.487"
77+
app:layout_constraintStart_toStartOf="parent"
78+
app:layout_constraintTop_toBottomOf="@id/button_positive" />
79+
</androidx.constraintlayout.widget.ConstraintLayout>
80+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<style name="AlertSheetImageStyle">
3+
<item name="android:visibility">gone</item>
4+
</style>
5+
</resources>

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
<dimen name="text_small_body">14sp</dimen>
1212
<dimen name="text_smaller_body">12sp</dimen>
1313
<dimen name="text_smallest_body">11sp</dimen>
14+
<dimen name="bottom_sheet_content_width">340dp</dimen>
1415
</resources>

app/src/main/res/values/styles.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
<item name="cornerSize">4dp</item>
3333
</style>
3434

35+
<style name="AlertSheetImageStyle">
36+
<item name="android:visibility">visible</item>
37+
</style>
38+
3539
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.71'
4+
ext.kotlin_version = '1.3.72'
55
repositories {
66
google()
77
maven { url 'https://maven.fabric.io/public' }
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
package org.buffer.android.components.sample
22

3-
import androidx.appcompat.app.AppCompatActivity
43
import android.os.Bundle
4+
import android.view.View
5+
import androidx.appcompat.app.AppCompatActivity
6+
import com.google.android.material.bottomsheet.BottomSheetDialog
7+
import kotlinx.android.synthetic.main.activity_main.*
8+
import org.buffer.android.components.BottomSheetFactory
59

610
class MainActivity : AppCompatActivity() {
11+
lateinit var reminderBottomSheet: BottomSheetDialog
712

813
override fun onCreate(savedInstanceState: Bundle?) {
914
super.onCreate(savedInstanceState)
1015
setContentView(R.layout.activity_main)
16+
17+
click_me_button.setOnClickListener {
18+
reminderBottomSheet = BottomSheetFactory.createSimpleAlertStyleBottomSheet(this,
19+
R.string.title_ig_reminder,
20+
R.string.subtitle_ig_reminder,
21+
R.string.primary_action_ig_reminder_sheet,
22+
R.string.secondary_action_ig_reminder_sheet,
23+
R.drawable.ig_reminder,
24+
View.OnClickListener {
25+
reminderBottomSheet.hide()
26+
},
27+
View.OnClickListener {
28+
reminderBottomSheet.hide()
29+
})
30+
31+
reminderBottomSheet.show()
32+
}
1133
}
1234
}
Binary file not shown.

sample/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<org.buffer.android.components.RoundedButton
1010
android:layout_width="wrap_content"
1111
android:layout_height="wrap_content"
12-
android:text="Hello World!"
12+
android:id="@+id/click_me_button"
13+
android:text="Click Me!"
1314
android:enabled="true"
1415
app:bufferButtonStyle="light"
1516
app:layout_constraintBottom_toBottomOf="parent"

0 commit comments

Comments
 (0)