Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Clevertap-PushTemplates-v1.2.0 #492

Merged
merged 16 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGE LOG.

### October 27, 2023

* [CleverTap Push Templates SDK v1.2.0](docs/CTPUSHTEMPLATESCHANGELOG.md).

### October 12, 2023

* [CleverTap Android SDK v5.2.1](docs/CTCORECHANGELOG.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,6 @@ public class PTConstants {
public static final int PT_FLIP_INTERVAL_TIME = 4 * ONE_SECOND;

public static final String KEY_CLICKED_STAR = "clickedStar";

public static final String KEY_REQUEST_CODES = "requestCodes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.MANUAL_CAROUSEL_LEFT_ARROW_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.MANUAL_CAROUSEL_RIGHT_ARROW_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.PRODUCT_DISPLAY_CONTENT_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.RATING_CLICK1_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.RATING_CLICK2_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.RATING_CLICK3_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.RATING_CLICK4_PENDING_INTENT;
import static com.clevertap.android.pushtemplates.content.PendingIntentFactoryKt.RATING_CLICK5_PENDING_INTENT;
import static com.clevertap.android.sdk.pushnotification.CTNotificationIntentService.TYPE_BUTTON_CLICK;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -38,7 +33,6 @@
import com.clevertap.android.sdk.CleverTapAPI;
import com.clevertap.android.sdk.CleverTapInstanceConfig;
import com.clevertap.android.sdk.Constants;
import com.clevertap.android.sdk.Logger;
import com.clevertap.android.sdk.interfaces.NotificationHandler;
import com.clevertap.android.sdk.pushnotification.CTNotificationIntentService;
import com.clevertap.android.sdk.pushnotification.LaunchPendingIntentFactory;
Expand Down Expand Up @@ -78,8 +72,6 @@ public class PushTemplateReceiver extends BroadcastReceiver {

private ArrayList<String> priceList = new ArrayList<>();

private String channelId;

private int smallIcon = 0;

private boolean requiresChannelId;
Expand Down Expand Up @@ -125,7 +117,6 @@ public void onReceive(final Context context, final Intent intent) {
priceList = Utils.getPriceFromExtras(extras);
pt_product_display_linear = extras.getString(PTConstants.PT_PRODUCT_DISPLAY_LINEAR);
notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
channelId = extras.getString(Constants.WZRK_CHANNEL_ID, "");
pt_big_img_alt = extras.getString(PTConstants.PT_BIG_IMG_ALT);
pt_small_icon_clr = extras.getString(PTConstants.PT_SMALL_ICON_COLOUR);
requiresChannelId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
Expand All @@ -134,23 +125,6 @@ public void onReceive(final Context context, final Intent intent) {
pt_subtitle = extras.getString(PTConstants.PT_SUBTITLE);
setKeysFromDashboard(extras);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelIdError = null;
if (channelId.isEmpty()) {
channelIdError =
"Unable to render notification, channelId is required but not provided in the notification payload: "
+ extras.toString();
} else if (notificationManager != null
&& notificationManager.getNotificationChannel(channelId) == null) {
channelIdError = "Unable to render notification, channelId: " + channelId
+ " not registered by the app.";
}
if (channelIdError != null) {
PTLog.verbose(channelIdError);
return;
}
}

if (pt_id != null) {
templateType = TemplateType.fromString(pt_id);
}
Expand Down Expand Up @@ -213,10 +187,13 @@ private void handleManualCarouselNotification(Context context, Bundle extras) {
if (VERSION.SDK_INT >= VERSION_CODES.M) {
int notificationId = extras.getInt(PTConstants.PT_NOTIF_ID);
Notification notification = Utils.getNotificationById(context, notificationId);
if (notification != null) {
contentViewManualCarousel = notification.bigContentView;
contentViewSmall = notification.contentView;
if (notification == null) {
PTLog.verbose("Manual Carousel Notification is null, returning");
return;
}
contentViewManualCarousel = notification.bigContentView;
contentViewSmall = notification.contentView;

setCustomContentViewBasicKeys(contentViewManualCarousel, context);

final boolean rightSwipe = extras.getBoolean(PTConstants.PT_RIGHT_SWIPE);
Expand Down Expand Up @@ -274,13 +251,7 @@ private void handleManualCarouselNotification(Context context, Bundle extras) {
MANUAL_CAROUSEL_CONTENT_PENDING_INTENT, null
);

NotificationCompat.Builder notificationBuilder;
if (notification != null) {
notificationBuilder = new Builder(context, notification);
} else {
notificationBuilder = setBuilderWithChannelIDCheck(requiresChannelId,
PTConstants.PT_SILENT_CHANNEL_ID, context);
}
NotificationCompat.Builder notificationBuilder = new Builder(context, notification);

PendingIntent dIntent = PendingIntentFactory.getPendingIntent(context, notificationId, extras, false,
MANUAL_CAROUSEL_DISMISS_PENDING_INTENT, null);
Expand Down Expand Up @@ -481,10 +452,12 @@ private void handleRatingNotification(Context context, Bundle extras, Intent int

if (VERSION.SDK_INT >= VERSION_CODES.M) {
Notification notification = Utils.getNotificationById(context, notificationId);
if (notification != null) {
contentViewRating = notification.bigContentView;
contentViewSmall = notification.contentView;
} // why null check just return if no notification exist in drawer
if (notification == null) {
PTLog.verbose("Rating Notification is null, returning");
return;
}
contentViewRating = notification.bigContentView;
contentViewSmall = notification.contentView;

if (1 == extras.getInt(PTConstants.KEY_CLICKED_STAR, 0)) {
contentViewRating.setImageViewResource(R.id.star1, R.drawable.pt_star_filled);
Expand Down Expand Up @@ -533,13 +506,7 @@ private void handleRatingNotification(Context context, Bundle extras, Intent int

setSmallIcon(context);

NotificationCompat.Builder notificationBuilder;
if (notification != null) {
notificationBuilder = new Builder(context, notification);
} else {
notificationBuilder = setBuilderWithChannelIDCheck(requiresChannelId,
PTConstants.PT_SILENT_CHANNEL_ID, context);
}
NotificationCompat.Builder notificationBuilder = new Builder(context, notification);
Intent dismissIntent = new Intent(context, PushTemplateReceiver.class);
PendingIntent dIntent;
dIntent = PendingIntentFactory.setDismissIntent(context, extras, dismissIntent);
Expand Down Expand Up @@ -582,26 +549,20 @@ private void handleRatingNotification(Context context, Bundle extras, Intent int

/**
* This method cancels all pending intents fired on click of rating. Allows the user to
* click only once for Android 11+ devices.
* click only once for Android 11+ devices and prevents collisions for future rating push-templates
* @param context Context required for cancelling pending intents
* @param intent Intent required for cancelling pending intents
*/
private void cancelRatingClickIntents(Context context, Intent intent){
if (VERSION.SDK_INT > VERSION_CODES.S) {
int flagsLaunchPendingIntent = PendingIntent.FLAG_UPDATE_CURRENT;
private void cancelRatingClickIntents(Context context, Intent intent) {
int flagsLaunchPendingIntent = PendingIntent.FLAG_UPDATE_CURRENT;
if (VERSION.SDK_INT >= VERSION_CODES.M) {
flagsLaunchPendingIntent |= PendingIntent.FLAG_IMMUTABLE;
}
int[] requestCodes = intent.getIntArrayExtra(PTConstants.KEY_REQUEST_CODES);

for (int requestCode : requestCodes)
PendingIntent.getBroadcast(context,
RATING_CLICK5_PENDING_INTENT, intent, flagsLaunchPendingIntent).cancel();
PendingIntent.getBroadcast(context,
RATING_CLICK4_PENDING_INTENT, intent, flagsLaunchPendingIntent).cancel();
PendingIntent.getBroadcast(context,
RATING_CLICK3_PENDING_INTENT, intent, flagsLaunchPendingIntent).cancel();
PendingIntent.getBroadcast(context,
RATING_CLICK2_PENDING_INTENT, intent, flagsLaunchPendingIntent).cancel();
PendingIntent.getBroadcast(context,
RATING_CLICK1_PENDING_INTENT, intent, flagsLaunchPendingIntent).cancel();
}
requestCode, intent, flagsLaunchPendingIntent).cancel();
}

@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -640,10 +601,13 @@ private void handleProductDisplayNotification(Context context, Bundle extras) {
if (VERSION.SDK_INT >= VERSION_CODES.M) {
int notificationId = extras.getInt(PTConstants.PT_NOTIF_ID);
Notification notification = Utils.getNotificationById(context, notificationId);
if (notification != null) {
contentViewBig = notification.bigContentView;
contentViewSmall = notification.contentView;
if (notification == null) {
PTLog.verbose("Product Display Notification is null, returning");
return;
}
contentViewBig = notification.bigContentView;
contentViewSmall = notification.contentView;

boolean isLinear = false;
if (pt_product_display_linear == null || pt_product_display_linear.isEmpty()) {
} else {
Expand Down Expand Up @@ -684,13 +648,7 @@ private void handleProductDisplayNotification(Context context, Bundle extras) {
PendingIntentFactory.getCtaLaunchPendingIntent(context,
bundleBuyNow, dl, notificationId));

NotificationCompat.Builder notificationBuilder;
if (notification != null) {
notificationBuilder = new Builder(context, notification);
} else {
notificationBuilder = setBuilderWithChannelIDCheck(requiresChannelId,
PTConstants.PT_SILENT_CHANNEL_ID, context);
}
NotificationCompat.Builder notificationBuilder = new Builder(context, notification);

PendingIntent pIntent;
Bundle bundleLaunchIntent = (Bundle) extras.clone();
Expand Down Expand Up @@ -752,16 +710,6 @@ private void setNotificationBuilderBasics(NotificationCompat.Builder notificatio
.setAutoCancel(true);
}


private NotificationCompat.Builder setBuilderWithChannelIDCheck(boolean requiresChannelId, String channelId,
Context context) {
if (requiresChannelId) {
return new NotificationCompat.Builder(context, channelId);
} else {
return new NotificationCompat.Builder(context);
}
}

private void setCustomContentViewBasicKeys(RemoteViews contentView, Context context) {
contentView.setTextViewText(R.id.app_name, Utils.getApplicationName(context));
contentView.setTextViewText(R.id.timestamp, Utils.getTimeStamp(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ class TemplateRenderer : INotificationRenderer, AudibleNotification {
actionLaunchIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
var actionIntent: PendingIntent?
val requestCode = System.currentTimeMillis().toInt() + i
val requestCode = Random().nextInt()
var flagsActionLaunchPendingIntent = PendingIntent.FLAG_UPDATE_CURRENT
if (VERSION.SDK_INT >= VERSION_CODES.M) {
flagsActionLaunchPendingIntent =
Expand Down
Loading
Loading