Skip to content

Commit

Permalink
Patch NotificationCompatBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Apr 25, 2024
1 parent 9e4c4e4 commit e1cff2b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
17 changes: 10 additions & 7 deletions app/src/main/java/androidx/core/app/NotificationCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -8491,14 +8491,15 @@ public void setFlags(int flags) {
* is non-null, otherwise null.
*/
public static @Nullable android.app.Notification.BubbleMetadata toPlatform(
@Nullable BubbleMetadata compatMetadata) {
@Nullable BubbleMetadata compatMetadata,
@NonNull Context context) {
if (compatMetadata == null) {
return null;
}
if (Build.VERSION.SDK_INT >= 30) {
return Api30Impl.toPlatform(compatMetadata);
return Api30Impl.toPlatform(compatMetadata, context);
} else if (Build.VERSION.SDK_INT == 29) {
return Api29Impl.toPlatform(compatMetadata);
return Api29Impl.toPlatform(compatMetadata, context);
}
return null;
}
Expand Down Expand Up @@ -8774,7 +8775,8 @@ private Api29Impl() {
*/
@RequiresApi(29)
@Nullable static android.app.Notification.BubbleMetadata toPlatform(
@Nullable BubbleMetadata compatMetadata) {
@Nullable BubbleMetadata compatMetadata,
@NonNull Context context) {
if (compatMetadata == null) {
return null;
}
Expand All @@ -8785,7 +8787,7 @@ private Api29Impl() {

android.app.Notification.BubbleMetadata.Builder platformMetadataBuilder =
new android.app.Notification.BubbleMetadata.Builder()
.setIcon(compatMetadata.getIcon().toIcon())
.setIcon(compatMetadata.getIcon().toIcon(context))
.setIntent(compatMetadata.getIntent())
.setDeleteIntent(compatMetadata.getDeleteIntent())
.setAutoExpandBubble(compatMetadata.getAutoExpandBubble())
Expand Down Expand Up @@ -8857,7 +8859,8 @@ private Api30Impl() {
*/
@RequiresApi(30)
@Nullable static android.app.Notification.BubbleMetadata toPlatform(
@Nullable BubbleMetadata compatMetadata) {
@Nullable BubbleMetadata compatMetadata,
@NonNull Context context) {
if (compatMetadata == null) {
return null;
}
Expand All @@ -8869,7 +8872,7 @@ private Api30Impl() {
} else {
platformMetadataBuilder =
new android.app.Notification.BubbleMetadata.Builder(
compatMetadata.getIntent(), compatMetadata.getIcon().toIcon());
compatMetadata.getIntent(), compatMetadata.getIcon().toIcon(context));
}
platformMetadataBuilder
.setDeleteIntent(compatMetadata.getDeleteIntent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ class NotificationCompatBuilder implements NotificationBuilderWithBuilderAccesso
}
if (Build.VERSION.SDK_INT >= 28) {
for (Person p : b.mPersonList) {
Api28Impl.addPerson(mBuilder, p.toAndroidPerson());
Api28Impl.addPerson(mBuilder, p.toAndroidPerson(mContext));
}
}
if (Build.VERSION.SDK_INT >= 29) {
Api29Impl.setAllowSystemGeneratedContextualActions(mBuilder,
b.mAllowSystemGeneratedContextualActions);
// TODO: Consider roundtripping NotificationCompat.BubbleMetadata on pre-Q platforms.
Api29Impl.setBubbleMetadata(mBuilder,
NotificationCompat.BubbleMetadata.toPlatform(b.mBubbleMetadata));
NotificationCompat.BubbleMetadata.toPlatform(b.mBubbleMetadata, mContext));
if (b.mLocusId != null) {
Api29Impl.setLocusId(mBuilder, b.mLocusId.toLocusId());
}
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/java/androidx/core/app/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;

Expand All @@ -28,8 +29,6 @@
import androidx.annotation.RestrictTo;
import androidx.core.graphics.drawable.IconCompat;

import com.google.android.samples.socialite.SocialApp;

import java.util.Objects;

/**
Expand Down Expand Up @@ -143,6 +142,17 @@ public Builder toBuilder() {
return new Builder(this);
}

/**
* Converts this compat {@link Person} to the base Android framework {@link android.app.Person}.
*
*/
@RestrictTo(LIBRARY_GROUP_PREFIX)
@NonNull
@RequiresApi(28)
public android.app.Person toAndroidPerson(Context context) {
return Api28Impl.toAndroidPerson(this, context);
}

/**
* Converts this compat {@link Person} to the base Android framework {@link android.app.Person}.
*
Expand All @@ -151,7 +161,7 @@ public Builder toBuilder() {
@NonNull
@RequiresApi(28)
public android.app.Person toAndroidPerson() {
return Api28Impl.toAndroidPerson(this);
return toAndroidPerson(null);
}

/**
Expand Down Expand Up @@ -423,10 +433,10 @@ static Person fromAndroidPerson(android.app.Person person) {

@SuppressWarnings("deprecation")
@DoNotInline
static android.app.Person toAndroidPerson(Person person) {
static android.app.Person toAndroidPerson(Person person, Context context) {
return new android.app.Person.Builder()
.setName(person.getName())
.setIcon((person.getIcon() != null) ? person.getIcon().toIcon(SocialApp.app) : null)
.setIcon((person.getIcon() != null) ? person.getIcon().toIcon(context) : null)
.setUri(person.getUri())
.setKey(person.getKey())
.setBot(person.isBot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class SocialApp : Application() {
override fun onCreate() {
super.onCreate()
app = this
}

companion object {
lateinit var app: SocialApp
}
}
class SocialApp : Application()

0 comments on commit e1cff2b

Please sign in to comment.