Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit 944fea4

Browse files
authored
Merge pull request #136 from android/bubbles-r-dp1
Bubbles: Update for DP1
2 parents dbf5ae9 + 9f3f775 commit 944fea4

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

BubblesKotlin/app/build.gradle

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 29
5+
compileSdkVersion 'android-R'
66
defaultConfig {
77
applicationId "com.example.android.bubbles"
8-
minSdkVersion 29
9-
targetSdkVersion 29
8+
minSdkVersion 'R'
9+
targetSdkVersion 'R'
1010
versionCode 1
1111
versionName '1.0'
1212
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1313
}
14+
kotlinOptions {
15+
jvmTarget = '1.8'
16+
}
1417
buildTypes {
1518
release {
1619
minifyEnabled false
@@ -23,17 +26,17 @@ dependencies {
2326
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2427

2528
implementation 'androidx.appcompat:appcompat:1.1.0'
26-
implementation 'androidx.fragment:fragment-ktx:1.1.0'
27-
implementation 'androidx.core:core-ktx:1.1.0'
29+
implementation 'androidx.fragment:fragment-ktx:1.2.1'
30+
implementation 'androidx.core:core-ktx:1.2.0'
2831
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
2932
implementation 'androidx.recyclerview:recyclerview:1.1.0'
3033

31-
def lifecycle_version = '2.1.0'
34+
def lifecycle_version = '2.2.0'
3235
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
3336
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
34-
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
37+
testImplementation 'androidx.arch.core:core-testing:2.1.0'
3538

36-
implementation 'com.google.android.material:material:1.0.0'
39+
implementation 'com.google.android.material:material:1.1.0'
3740

3841
implementation 'com.github.bumptech.glide:glide:4.9.0'
3942

@@ -42,7 +45,6 @@ dependencies {
4245
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4346

4447
testImplementation 'org.robolectric:robolectric:4.2'
45-
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
4648
testImplementation 'androidx.test.ext:junit:1.1.1'
4749
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4850
testImplementation 'androidx.test.ext:truth:1.2.0'

BubblesKotlin/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,26 @@ class NotificationHelper(private val context: Context) {
8080
// A notification can be shown as a bubble by calling setBubbleMetadata()
8181
.setBubbleMetadata(
8282
Notification.BubbleMetadata.Builder()
83+
.createIntentBubble(
84+
// The Intent to be used for the expanded bubble.
85+
PendingIntent.getActivity(
86+
context,
87+
REQUEST_BUBBLE,
88+
// Launch BubbleActivity as the expanded bubble.
89+
Intent(context, BubbleActivity::class.java)
90+
.setAction(Intent.ACTION_VIEW)
91+
.setData(
92+
Uri.parse(
93+
"https://android.example.com/chat/${chat.contact.id}"
94+
)
95+
),
96+
PendingIntent.FLAG_UPDATE_CURRENT
97+
),
98+
// The icon of the bubble.
99+
icon
100+
)
83101
// The height of the expanded bubble.
84102
.setDesiredHeight(context.resources.getDimensionPixelSize(R.dimen.bubble_height))
85-
// The icon of the bubble.
86-
.setIcon(icon)
87103
.apply {
88104
// When the bubble is explicitly opened by the user, we can show the bubble
89105
// automatically in the expanded state. This works only when the app is in
@@ -93,18 +109,6 @@ class NotificationHelper(private val context: Context) {
93109
setSuppressNotification(true)
94110
}
95111
}
96-
// The Intent to be used for the expanded bubble.
97-
.setIntent(
98-
PendingIntent.getActivity(
99-
context,
100-
REQUEST_BUBBLE,
101-
// Launch BubbleActivity as the expanded bubble.
102-
Intent(context, BubbleActivity::class.java)
103-
.setAction(Intent.ACTION_VIEW)
104-
.setData(Uri.parse("https://android.example.com/chat/${chat.contact.id}")),
105-
PendingIntent.FLAG_UPDATE_CURRENT
106-
)
107-
)
108112
.build()
109113
)
110114
// The user can turn off the bubble in system settings. In that case, this notification
@@ -130,36 +134,33 @@ class NotificationHelper(private val context: Context) {
130134

131135
if (fromUser) {
132136
// This is a Bubble explicitly opened by the user.
133-
builder.setContentText(context.getString(R.string.chat_with_contact, chat.contact.name))
137+
builder
138+
.setStyle(
139+
Notification.MessagingStyle(person)
140+
.addMessage(
141+
context.getString(R.string.chat_with_contact, chat.contact.name),
142+
System.currentTimeMillis(),
143+
person
144+
)
145+
.setGroupConversation(false)
146+
)
147+
.setContentText(context.getString(R.string.chat_with_contact, chat.contact.name))
134148
} else {
135149
// Let's add some more content to the notification in case it falls back to a normal
136150
// notification.
137151
val lastOutgoingId = chat.messages.last { !it.isIncoming }.id
138152
val newMessages = chat.messages.filter { message ->
139153
message.id > lastOutgoingId
140154
}
141-
val lastMessage = newMessages.last()
142155
builder
143156
.setStyle(
144-
if (lastMessage.photo != null) {
145-
Notification.BigPictureStyle()
146-
.bigPicture(
147-
BitmapFactory.decodeResource(
148-
context.resources,
149-
lastMessage.photo
150-
)
151-
)
152-
.bigLargeIcon(icon)
153-
.setSummaryText(lastMessage.text)
154-
} else {
155-
Notification.MessagingStyle(person)
156-
.apply {
157-
for (message in newMessages) {
158-
addMessage(message.text, message.timestamp, person)
159-
}
157+
Notification.MessagingStyle(person)
158+
.apply {
159+
for (message in newMessages) {
160+
addMessage(message.text, message.timestamp, person)
160161
}
161-
.setGroupConversation(false)
162-
}
162+
}
163+
.setGroupConversation(false)
163164
)
164165
.setContentText(newMessages.joinToString("\n") { it.text })
165166
.setWhen(newMessages.last().timestamp)

BubblesKotlin/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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.60'
4+
ext.kotlin_version = '1.3.61'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.2'
10+
classpath 'com.android.tools.build:gradle:3.5.3'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
}
1313
}

0 commit comments

Comments
 (0)