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

Full Support BigPicture(BannerMode) and Fixed issue of largeIcon using url [Android] #1444

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
import android.util.Log;
import androidx.core.app.NotificationCompat;

import androidx.annotation.Nullable;
import com.facebook.common.executors.CallerThreadExecutor;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.common.Priority;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
Expand Down Expand Up @@ -57,6 +70,8 @@ public class RNPushNotificationHelper {
private static final long ONE_HOUR = 60 * ONE_MINUTE;
private static final long ONE_DAY = 24 * ONE_HOUR;

private String TAG = "RNPushNotificationHelper";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A LOG_TAG constant already exist.


public RNPushNotificationHelper(Application context) {
this.context = context;
this.config = new RNPushNotificationConfig(context);
Expand Down Expand Up @@ -145,12 +160,15 @@ public void sendNotificationScheduledCore(Bundle bundle) {
} else {
getAlarmManager().setExact(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
}
getAlarmManager().setExact(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicate, result is:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if(allowWhileIdle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                getAlarmManager().setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
            } else {
                getAlarmManager().setExact(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
            }
            getAlarmManager().setExact(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
        } else {
            getAlarmManager().set(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
        }

} else {
getAlarmManager().set(AlarmManager.RTC_WAKEUP, fireDate, pendingIntent);
}
}

public void sendToNotificationCentre(Bundle bundle) {
public void sendNotificationWithImage(Bundle bundle, Bitmap image, Bitmap largeIconImage) {
Log.d(TAG, "sendNotificationWithImage: bitmao log: " + image);
Log.d(TAG, "sendNotificationWithImage: bitmao log: " + largeIconImage);
Comment on lines +170 to +171
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A LOG_TAG constant already exist.

try {
Class intentClass = getMainActivityClass();
if (intentClass == null) {
Expand All @@ -172,6 +190,7 @@ public void sendToNotificationCentre(Bundle bundle) {

Resources res = context.getResources();
String packageName = context.getPackageName();
String message = bundle.getString("message");

String channel_id = NOTIFICATION_CHANNEL_ID;

Expand Down Expand Up @@ -330,6 +349,26 @@ public void sendToNotificationCentre(Bundle bundle) {
}

notification.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
if (largeIconImage != null) {
notification.setLargeIcon(largeIconImage);
} else {
if (largeIconResId != 0 && (largeIcon != null || Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
notification.setLargeIcon(largeIconBitmap);
}
}
Comment on lines +354 to +358
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is also duplicate with L340-342


if (image != null) {
notification.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(image)
.setBigContentTitle(title)
.setSummaryText(message)
);
} else {
notification.setContentText(message);
notification.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
}
// notification.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));

Intent intent = new Intent(context, intentClass);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Expand Down Expand Up @@ -410,6 +449,7 @@ public void sendToNotificationCentre(Bundle bundle) {
notification.setVibrate(vibratePattern);
}

soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line introduce a regression by forcing sounds.

checkOrCreateChannel(notificationManager, channel_id, soundUri, importance, vibratePattern);

notification.setChannelId(channel_id);
Expand Down Expand Up @@ -487,6 +527,105 @@ public void sendToNotificationCentre(Bundle bundle) {
}
}

public void sendToNotificationCentre(final Bundle bundle) {
Log.d(TAG, "sendToNotificationCentre: bundle: " + bundle.toString());
String imageUrl = bundle.getString("imageUrl");
String largeIconUrl = bundle.getString("largeIconUrl");

if (imageUrl == null && largeIconUrl == null) {
sendNotificationWithImage(bundle, null, null);
return;
}

ImagePipeline imagePipeline = Fresco.getImagePipeline();

if (imageUrl == null) {
ImageRequest largeIconRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(largeIconUrl))
.setRequestPriority(Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
.build();
DataSource<CloseableReference<CloseableImage>> largeIcondataSource =
imagePipeline.fetchDecodedImage(largeIconRequest, context);

largeIcondataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap2) {
sendNotificationWithImage(bundle, null, bitmap2);
}

@Override
public void onFailureImpl(DataSource dataSource) {
sendNotificationWithImage(bundle, null, null);
}
}, CallerThreadExecutor.getInstance());
} else if (largeIconUrl == null) {
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(imageUrl))
.setRequestPriority(Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
.build();

DataSource<CloseableReference<CloseableImage>> dataSource =
imagePipeline.fetchDecodedImage(imageRequest, context);

dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(final @Nullable Bitmap bitmap1) {
sendNotificationWithImage(bundle, bitmap1, null);
}

@Override
public void onFailureImpl(DataSource dataSource) {
sendNotificationWithImage(bundle, null, null);
;
}
}, CallerThreadExecutor.getInstance());
} else {
ImageRequest imageRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(imageUrl))
.setRequestPriority(Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
.build();

ImageRequest largeIconRequest = ImageRequestBuilder
.newBuilderWithSource(Uri.parse(largeIconUrl))
.setRequestPriority(Priority.HIGH)
.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
.build();

DataSource<CloseableReference<CloseableImage>> dataSource =
imagePipeline.fetchDecodedImage(imageRequest, context);

final DataSource<CloseableReference<CloseableImage>> largeIcondataSource =
imagePipeline.fetchDecodedImage(largeIconRequest, context);

dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(final @Nullable Bitmap bitmap1) {

largeIcondataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap2) {
sendNotificationWithImage(bundle, bitmap1, bitmap2);
}

@Override
public void onFailureImpl(DataSource dataSource) {
return;
}
}, CallerThreadExecutor.getInstance());
}

@Override
public void onFailureImpl(DataSource dataSource) {
return;
}
}, CallerThreadExecutor.getInstance());
}

}

private void scheduleNextNotificationIfRepeating(Bundle bundle) {
String repeatType = bundle.getString("repeatType");
long repeatTime = (long) bundle.getDouble("repeatTime");
Expand Down Expand Up @@ -698,6 +837,9 @@ private void checkOrCreateChannel(NotificationManager manager, String channel_id
.build();

channel.setSound(soundUri, audioAttributes);
channel.setDescription(this.config.getChannelDescription());
channel.enableLights(true);
channel.enableVibration(true);
Comment on lines +840 to +842
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicate with L829-831.

} else {
channel.setSound(null, null);
}
Expand Down