Skip to content

Commit

Permalink
Merge pull request #236 from CleverTap/develop
Browse files Browse the repository at this point in the history
Release push-templates v1.0.1 and xps v1.3.0 SDK-1324
  • Loading branch information
piyush-kukadiya authored Mar 2, 2022
2 parents f1b59aa + 5257945 commit 675ede9
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 120 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Add the Firebase Messaging library and Android Support Library v4 as dependencie
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.4.0"
implementation "androidx.core:core:1.3.0"
implementation "com.google.firebase:firebase-messaging:22.0.0"
implementation "com.google.firebase:firebase-messaging:21.0.0"
implementation "com.google.android.gms:play-services-ads:19.4.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
implementation "com.android.installreferrer:installreferrer:2.2" // Mandatory for v3.6.4 and above
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class PTConstants {

public static final String PT_TIMER_END = "pt_timer_end";

public static final String PT_TIMER_SPLIT = "$D_";
public static final String PT_TIMER_SPLIT = "\\$D_";

public static final int PT_TIMER_MIN_THRESHOLD = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ class TemplateRenderer : INotificationRenderer {
TemplateType.TIMER -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (ValidatorFactory.getValidator(TemplateType.TIMER, this)?.validate() == true) {
val timerEnd = getTimerEnd()
timerRunner(context, extras, notificationId, timerEnd)
return TimerStyle(this, extras).builderFromStyle(context, extras, notificationId, nb)
.setTimeoutAfter(
timerEnd!!.toLong()
)
if (timerEnd != null) {
timerRunner(context, extras, notificationId, timerEnd)
return TimerStyle(this, extras).builderFromStyle(
context,
extras,
notificationId,
nb
).setTimeoutAfter(timerEnd.toLong())
}
}
} else {
PTLog.debug("Push Templates SDK supports Timer Notifications only on or above Android Nougat, reverting to basic template")
Expand Down Expand Up @@ -200,34 +204,36 @@ class TemplateRenderer : INotificationRenderer {
pt_msg = pt_msg_alt
}

handler.postDelayed({
if (Utils.isNotificationInTray(
context,
notificationId
) && ValidatorFactory.getValidator(TemplateType.BASIC, this)?.validate() == true
) {
val applicationContext = context.applicationContext
val basicTemplateBundle = extras.clone() as Bundle
basicTemplateBundle.putString(Constants.WZRK_PUSH_ID, null) // skip dupe check
basicTemplateBundle.putString(PTConstants.PT_ID, "pt_basic") // set to basic
// force random id generation
basicTemplateBundle.putString(PTConstants.PT_COLLAPSE_KEY, null)
basicTemplateBundle.putString(Constants.WZRK_COLLAPSE, null)
basicTemplateBundle.remove(Constants.PT_NOTIF_ID)
val templateRenderer: INotificationRenderer =
TemplateRenderer(applicationContext, basicTemplateBundle)
val cleverTapAPI = CleverTapAPI
.getGlobalInstance(
if (delay != null) {
handler.postDelayed({
if (Utils.isNotificationInTray(
context,
notificationId
) && ValidatorFactory.getValidator(TemplateType.BASIC, this)?.validate() == true
) {
val applicationContext = context.applicationContext
val basicTemplateBundle = extras.clone() as Bundle
basicTemplateBundle.putString(Constants.WZRK_PUSH_ID, null) // skip dupe check
basicTemplateBundle.putString(PTConstants.PT_ID, "pt_basic") // set to basic
// force random id generation
basicTemplateBundle.putString(PTConstants.PT_COLLAPSE_KEY, null)
basicTemplateBundle.putString(Constants.WZRK_COLLAPSE, null)
basicTemplateBundle.remove(Constants.PT_NOTIF_ID)
val templateRenderer: INotificationRenderer =
TemplateRenderer(applicationContext, basicTemplateBundle)
val cleverTapAPI = CleverTapAPI
.getGlobalInstance(
applicationContext,
PushNotificationUtil.getAccountIdFromNotificationBundle(basicTemplateBundle)
)
cleverTapAPI?.renderPushNotification(
templateRenderer,
applicationContext,
PushNotificationUtil.getAccountIdFromNotificationBundle(basicTemplateBundle)
basicTemplateBundle
)
cleverTapAPI?.renderPushNotification(
templateRenderer,
applicationContext,
basicTemplateBundle
)
}
}, (delay!! - 100).toLong())
}
}, (delay - 100).toLong())
}
}

override fun setSmallIcon(smallIcon: Int, context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ public static int getTimerEnd(Bundle extras) {
}
long currentts = System.currentTimeMillis();
int diff = (int) (Long.parseLong(val) - (currentts / 1000));
if (val.equals("-1")){
return Integer.MIN_VALUE;
}//For empty check in timer_end
return diff;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ class IntSizeChecker(var entity: Int, var size: Int, var errorMsg: String) :
SizeChecker<Int>(entity, size, errorMsg) {

override fun check(): Boolean {
val b = entity == size
if (b) {
PTLog.verbose("$errorMsg. Not showing notification")
}
if (entity == Int.MIN_VALUE){
PTLog.verbose("Timer End Value not defined. Not showing notification")
return false
}else {
val b = entity <= size
if (b) {
PTLog.verbose("$errorMsg. Not showing notification")
}

return !b
return !b
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.clevertap.android.pushtemplates.checkers.Checker
class TimerTemplateValidator(private var validator: Validator) : TemplateValidator(validator.keys) {

override fun validate(): Boolean {
return validator.validate() && super.validateKeys()// All check must be true
return validator.validate() && super.validateORKeys()// All check must be true
}

override fun loadKeys(): List<Checker<out Any>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import com.clevertap.android.pushtemplates.checkers.Checker
abstract class Validator(val keys: Map<String, Checker<out Any>>) {

abstract fun loadKeys(): List<Checker<out Any>>
open fun validate(): Boolean {
open fun validate(): Boolean {//Does AND check inside Collections.
return validateKeys()
}

open fun validateOR(): Boolean {//Does OR check inside Collections.
return validateORKeys()
}



fun validateKeys(): Boolean {
val keys = loadKeys()
return keys.and()
}

fun validateORKeys(): Boolean {
val keys = loadKeys()
return keys.or()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ const val PT_INPUT_FEEDBACK = "PT_INPUT_FEEDBACK"
const val PT_ACTIONS = "PT_ACTIONS"

fun Iterable<Checker<out Any>>.and(): Boolean {
var and: Boolean = true
var and = true
for (element in this) {
and =
element.check() && and // checking first will allow us to execute all checks(for printing errors) instead of short circuiting
}
return and
}

fun Iterable<Checker<out Any>>.or(): Boolean {
var or = false
for (element in this) {
or =
element.check() || or
if (or) break
}
return or
}

internal class ValidatorFactory {
companion object {

Expand Down Expand Up @@ -68,7 +78,7 @@ internal class ValidatorFactory {
}
}

fun createKeysMap(templateRenderer: TemplateRenderer): Map<String, Checker<out Any>> {
private fun createKeysMap(templateRenderer: TemplateRenderer): Map<String, Checker<out Any>> {
val hashMap = HashMap<String, Checker<out Any>>()
//----------BASIC-------------
hashMap[PT_TITLE] =
Expand Down Expand Up @@ -150,13 +160,13 @@ internal class ValidatorFactory {
IntSizeChecker(
templateRenderer.pt_timer_threshold,
-1,
"Timer Threshold or End time not defined"
"Timer threshold not defined"
)
hashMap[PT_TIMER_END] =
IntSizeChecker(
templateRenderer.pt_timer_end,
-1,
"Timer Threshold or End time not defined"
"Not rendering notification Timer End value lesser than threshold (10 seconds) from current time"
)
//----------INPUT BOX----------------
hashMap[PT_INPUT_FEEDBACK] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt"
android:autoStart="true"
android:inAnimation="@anim/slide_in_right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_view_big"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_height="wrap_content"
android:orientation="vertical">

<include
Expand All @@ -13,7 +12,6 @@
<ImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:scaleType="centerCrop" />
android:layout_height="196dp"
android:scaleType="centerCrop"/>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt">

<LinearLayout
Expand Down
2 changes: 1 addition & 1 deletion clevertap-pushtemplates/src/main/res/layout-v31/timer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<ImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
android:id="@+id/content_view_big"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">

<ImageView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt"
android:autoStart="true"
android:inAnimation="@anim/slide_in_right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_view_big"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_height="wrap_content"
android:orientation="vertical">

<include
Expand All @@ -13,6 +12,6 @@
<ImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:scaleType="centerCrop" />
</LinearLayout>
3 changes: 1 addition & 2 deletions clevertap-pushtemplates/src/main/res/layout/image_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/tester">
android:orientation="vertical">

<ImageView
android:id="@+id/fimg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tester"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt">

<LinearLayout
Expand Down
2 changes: 1 addition & 1 deletion clevertap-pushtemplates/src/main/res/layout/timer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<ImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="196dp"
android:layout_below="@id/rel_lyt"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop" />
Expand Down
Binary file not shown.
22 changes: 12 additions & 10 deletions docs/CTPUSHTEMPLATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CleverTap Push Templates SDK helps you engage with your users using fancy push n
1. Add the dependencies to the `build.gradle`

```groovy
implementation "com.clevertap.android:push-templates:1.0.0"
implementation "com.clevertap.android:push-templates:1.0.1"
implementation "com.clevertap.android:clevertap-android-sdk:4.4.0" // 4.4.0 and above
```

Expand Down Expand Up @@ -421,8 +421,8 @@ pt_big_img | Optional | Image
pt_big_img_alt | Optional | Image to show when timer expires
pt_bg | Required | Background Color in HEX
pt_chrono_title_clr | Optional | Color for timer text in HEX
pt_timer_threshold | Required | Timer duration in seconds (minimum 10)
pt_timer_end | Required | Epoch Timestamp to countdown to (for example, $D_1595871380 or 1595871380). Not needed if pt_timer_threshold is specified.
pt_timer_threshold | Required | Timer duration in seconds (minimum 10). Will be given higher priority.
pt_timer_end | Optional | Epoch Timestamp to countdown to (for example, $D_1595871380 or 1595871380). Not needed if pt_timer_threshold is specified.
pt_title_clr | Optional | Title Color in HEX
pt_msg_clr | Optional | Message Color in HEX
pt_small_icon_clr | Optional | Small Icon Color in HEX
Expand Down Expand Up @@ -490,18 +490,20 @@ pt_json | Optional | Above keys in JSON format

Template | Aspect Ratios | File Type
---:|:---:|:---
Basic | 4:3 or 2:1 | .JPG
Auto Carousel | 2:1 (Android 11 & 12) and 4:3 (Below Android 11) | .JPG
Manual Carousel | 2:1 (Android 11 & 12) and 4:3 (Below Android 11) | .JPG
Rating | 4:3 (Android 11 & 12) and 2:1 (Below Android 11) | .JPG
Basic | 4:3 or 3:2 or 2:1 | .JPG
Auto Carousel | 3:2 (Android 11 & 12) and 4:3 (Below Android 11) | .JPG
Manual Carousel | 3:2 (Android 11 & 12) and 4:3 (Below Android 11) | .JPG
Manual Carousel-FilmStrip| 1:1 | .JPG
Rating | 4:3 | .JPG
Five Icon | 1:1 | .JPG or .PNG
Zero Bezel | 4:3 or 2:1 | .JPG
Timer | 4:3 or 2:1 | .JPG
Zero Bezel | 4:3 or 3:2 or 2:1 | .JPG
Timer | 3:2 (Android 11 & 12) and 4:3 (Below Android 11) | .JPG
Input Box | 4:3 or 2:1 | .JPG
Product Catalog | 1:1 | .JPG

* For Auto and Manual Carousel the image dimensions should not exceed more than 850x425 for Android 11 and Android 12 devices and with 2:1 image aspect ratio
* For Auto and Manual Carousel the image dimensions should not exceed more than 840x560 for Android 11 and Android 12 devices and with 3:2 image aspect ratio
* For Product Catalog image aspect ratio should be 1:1 and image size should be less than 80kb for Android 11 and Android 12 devices
* For Zero Bezel it's recommended that if your images have any text it should be present in the middle of the image.

## Android 12 Trampoline restrictions

Expand Down
4 changes: 4 additions & 0 deletions docs/CTPUSHTEMPLATESCHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CleverTap Push Templates SDK CHANGE LOG

### Version 1.0.1 (March 2, 2022)
* Improved image handling for Basic, AutoCarousel, ManualCarousel templates.
* Allows either or both `pt_timer_threshold` and `pt_timer_end` for Timer template.

### Version 1.0.0 (December 20, 2021)
* Stable release! 🎉
* Supports Xiaomi, Huawei notification messages out of the box
Expand Down
Loading

0 comments on commit 675ede9

Please sign in to comment.