Skip to content

Commit

Permalink
Merge pull request #410 from CleverTap/task/SDK-2858/ios_pariy_for_in…
Browse files Browse the repository at this point in the history
…dex_parameter_in_onInboxItemSelected_callback

[SDK-2851]: App Inbox parity for itemIndex parameter of the on onInboxItemClicked callback
  • Loading branch information
shivamsharma2710 authored Mar 31, 2023
2 parents c134488 + 0e698c9 commit 9adbdb9
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## CHANGE LOG.

### March 31, 2023
* [CleverTap Android SDK v4.6.9](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md#version-469-march-31-2023)

### March 22, 2023
* [CleverTap Android SDK v4.6.8](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md#version-468-march-22-2023)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ We publish the SDK to `mavenCentral` as an `AAR` file. Just declare it as depend

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.6.8"
implementation "com.clevertap.android:clevertap-android-sdk:4.6.9"
}
```

Alternatively, you can download and add the AAR file included in this repo in your Module libs directory and tell gradle to install it like this:

```groovy
dependencies {
implementation (name: "clevertap-android-sdk-4.6.8", ext: 'aar')
implementation (name: "clevertap-android-sdk-4.6.9", ext: 'aar')
}
```

Expand All @@ -46,7 +46,7 @@ Add the Firebase Messaging library and Android Support Library v4 as dependencie

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.6.8"
implementation "com.clevertap.android:clevertap-android-sdk:4.6.9"
implementation "androidx.core:core:1.3.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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public interface Constants {
/**
* Valid indexes for the App Inbox item and buttons.
*/
int APP_INBOX_ITEM_CONTENT_PAGE_INDEX = 0; //used for non-carousel templates as they have only one page of content to display
int APP_INBOX_ITEM_INDEX = -1;
int APP_INBOX_CTA1_INDEX = 0;
int APP_INBOX_CTA2_INDEX = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ public interface InboxMessageListener {
* - CTA clicks for which no custom key-value pairs are associated, i.e., DeepLink and Clipboard CTAs.
*
* @param message - the instance of {@link CTInboxMessage}
* @param itemIndex - the index of the App Inbox item.
* @param contentPageIndex - the page index of the content. It makes sense for the carousel templates.
* For non-carousel templates, it is 0 as they have only one page of content.
* @param buttonIndex - the button index corresponds to the CTA button clicked (0, 1, or 2) in
* the App Inbox, which supports up to three CTAs.
* A value of -1 indicates an app inbox item click.
*/
void onInboxItemClicked(CTInboxMessage message, int itemIndex, int buttonIndex);
void onInboxItemClicked(CTInboxMessage message, int contentPageIndex, int buttonIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void addImageAndSetClick(ImageView imageView, View view, final int position, Vie
public void onClick(View v) {
CTInboxListViewFragment parent = getParent();
if (parent != null) {
parent.handleViewPagerClick(row, position,true);
parent.handleViewPagerClick(row, position);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clevertap.android.sdk.inbox;

import static com.clevertap.android.sdk.Constants.APP_INBOX_ITEM_CONTENT_PAGE_INDEX;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
Expand Down Expand Up @@ -58,9 +60,9 @@ class CTInboxButtonClickListener implements View.OnClickListener {
public void onClick(View v) {
if (viewPager != null) {//Handles viewpager clicks
if (fragment != null) {
fragment.handleViewPagerClick(position, viewPager.getCurrentItem(),isBodyClick);
fragment.handleViewPagerClick(position, viewPager.getCurrentItem());
}
} else {//Handles button clicks
} else {//Handles item and button clicks for non-carousel templates
if (buttonText != null && buttonObject != null) {
if (fragment != null) {
if (inboxMessage.getInboxMessageContents().get(0).getLinktype(buttonObject)
Expand All @@ -70,11 +72,11 @@ public void onClick(View v) {
}
}

fragment.handleClick(this.position, buttonText, buttonObject, getKeyValues(inboxMessage), buttonIndex);
fragment.handleClick(this.position, APP_INBOX_ITEM_CONTENT_PAGE_INDEX, buttonText, buttonObject, getKeyValues(inboxMessage), buttonIndex);
}
} else {
if (fragment != null) {
fragment.handleClick(this.position, null, null, null, buttonIndex);
fragment.handleClick(this.position, APP_INBOX_ITEM_CONTENT_PAGE_INDEX,null, null, null, buttonIndex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ public void onDestroy() {
}
}

void didClick(Bundle data, int position, HashMap<String, String> keyValuePayload, int buttonIndex) {
void didClick(Bundle data, int position, int viewPagerPosition, HashMap<String, String> keyValuePayload, int buttonIndex) {
CTInboxListViewFragment.InboxListener listener = getListener();
if (listener != null) {
//noinspection ConstantConditions
listener.messageDidClick(getActivity().getBaseContext(), position, inboxMessages.get(position), data, keyValuePayload, buttonIndex);
listener.messageDidClick(getActivity().getBaseContext(), viewPagerPosition, inboxMessages.get(position), data, keyValuePayload, buttonIndex);
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ void setMediaRecyclerView(MediaPlayerRecyclerView mediaRecyclerView) {
this.mediaRecyclerView = mediaRecyclerView;
}

void handleClick(int position, String buttonText, JSONObject jsonObject, HashMap<String, String> keyValuePayload, int buttonIndex) {
void handleClick(int position, int viewPagerPosition, String buttonText, JSONObject jsonObject, HashMap<String, String> keyValuePayload, int buttonIndex) {
boolean isInboxMessageButtonClick = jsonObject != null;

try {
Expand Down Expand Up @@ -301,13 +301,13 @@ void handleClick(int position, String buttonText, JSONObject jsonObject, HashMap
if (buttonText != null && !buttonText.isEmpty()) {
data.putString("wzrk_c2a", buttonText);
}
didClick(data, position, keyValuePayload, buttonIndex);
didClick(data, position, viewPagerPosition, keyValuePayload, buttonIndex);
} catch (Throwable t) {
Logger.d("Error handling notification button click: " + t.getCause());
}
}

void handleViewPagerClick(int position, int viewPagerPosition,boolean isInboxMessageBodyClick) {
void handleViewPagerClick(int position, int viewPagerPosition) {
try {
Bundle data = new Bundle();
JSONObject wzrkParams = inboxMessages.get(position).getWzrkParams();
Expand All @@ -318,8 +318,8 @@ void handleViewPagerClick(int position, int viewPagerPosition,boolean isInboxMes
data.putString(keyName, wzrkParams.getString(keyName));
}
}
//pass APP_INBOX_ITEM_INDEX as buttonIndex to indicate the viewPager/item click
didClick(data, position, null, APP_INBOX_ITEM_INDEX);
//pass APP_INBOX_ITEM_INDEX as value of buttonIndex to indicate the item click not the button.
didClick(data, position, viewPagerPosition,null, APP_INBOX_ITEM_INDEX);
String actionUrl = inboxMessages.get(position).getInboxMessageContents().get(viewPagerPosition)
.getActionUrl();
fireUrlThroughIntent(actionUrl);
Expand Down
7 changes: 6 additions & 1 deletion docs/CTCORECHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CleverTap Android SDK CHANGE LOG

### Version 4.6.9 (March 31, 2023)
#### Changes
* Renames the `itemIndex` parameter of the `onInboxItemClicked` callback with the `contentPageIndex`. It's not a breaking change.
* **[Parity with CleverTap iOS SDK]**:
The `onInboxItemClicked` callback now provides a different value for contentPageIndex(ex-`itemIndex`) compared to before. Previously, it used to indicate the position of the clicked item within the list container of the App Inbox. However, now it indicates the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content.

### Version 4.6.8 (March 22, 2023)
#### Breaking Changes
* **Signature change of `onInboxItemClicked` callback**:
Expand All @@ -13,7 +19,6 @@
#### Added
* Adds the new public API `dismissAppInbox()` via `CleverTapAPI` class to dismiss the App Inbox.


### Version 4.6.7 (March 14, 2023)
* Bug fixes and performance improvements.
* **Note:** This release is being done for Android 12 targeted users, satisfying below points.
Expand Down
2 changes: 1 addition & 1 deletion docs/CTGEOFENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the following dependencies to the `build.gradle`

```Groovy
implementation "com.clevertap.android:clevertap-geofence-sdk:1.1.0"
implementation "com.clevertap.android:clevertap-android-sdk:4.6.8" // 3.9.0 and above
implementation "com.clevertap.android:clevertap-android-sdk:4.6.9" // 3.9.0 and above
implementation "com.google.android.gms:play-services-location:18.0.0"
implementation "androidx.work:work-runtime:2.7.0" // required for FETCH_LAST_LOCATION_PERIODIC
implementation "androidx.concurrent:concurrent-futures:1.1.0" // required for FETCH_LAST_LOCATION_PERIODIC
Expand Down
2 changes: 1 addition & 1 deletion docs/CTPUSHTEMPLATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CleverTap Push Templates SDK helps you engage with your users using fancy push n

```groovy
implementation "com.clevertap.android:push-templates:1.0.5.1"
implementation "com.clevertap.android:clevertap-android-sdk:4.6.8" // 4.4.0 and above
implementation "com.clevertap.android:clevertap-android-sdk:4.6.9" // 4.4.0 and above
```

2. Add the following line to your Application class before the `onCreate()`
Expand Down
12 changes: 8 additions & 4 deletions docs/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ cleverTapDefaultInstance.dismissAppInbox();

### App Inbox Item and Button Click Callbacks

Lets's understand the types of buttons first that App Inbox supports:
Let's understand the types of buttons first that App Inbox supports:
- URL button (fires the deeplink with the associated URL)
- Copy to button (Copies the associated text to the clipboard)
- KV button (contains the custom kev-value pair for custom handling)
Expand All @@ -239,14 +239,18 @@ The callback returns `CTInboxMessage` object, `itemIndex` and `buttonIndex` para

```java
@Override
public void onInboxItemClicked(CTInboxMessage message, int itemIndex, int buttonIndex){
Log.i(TAG, "InboxItemClicked at" + itemIndex + " position with button-index:" + buttonIndex);
public void onInboxItemClicked(CTInboxMessage message, int contentPageIndex, int buttonIndex){
Log.i(TAG, "InboxItemClicked at" + contentPageIndex + " page-index with button-index:" + buttonIndex);
//The buttonIndex corresponds to the CTA button clicked (0, 1, or 2). A value of -1 indicates the app inbox body/message clicked.

List<CTInboxMessageContent> inboxMessageContentList = message.getInboxMessageContents();
//The contentPageIndex corresponds to the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content.
CTInboxMessageContent messageContentObject = inboxMessageContentList.get(contentPageIndex);
if (buttonIndex != -1) {
//button is clicked
try {
List<CTInboxMessageContent> inboxMessageContentList = message.getInboxMessageContents();
JSONObject buttonObject = (JSONObject) inboxMessageContentList.get(0).getLinks().get(buttonIndex);
JSONObject buttonObject = (JSONObject) messageContentObject.getLinks().get(buttonIndex);
String buttonType = buttonObject.getString("type");
Log.i(TAG, "type of button clicked: " + buttonType);
} catch (Throwable t) {
Expand Down
10 changes: 6 additions & 4 deletions sample/src/main/java/com/clevertap/demo/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,19 @@ class MyApplication : MultiDexApplication(), CTPushNotificationListener, Activit
//dismissAppInbox()
}

override fun onInboxItemClicked(message: CTInboxMessage?, itemIndex: Int, buttonIndex: Int) {
override fun onInboxItemClicked(message: CTInboxMessage?, contentPageIndex: Int, buttonIndex: Int) {
Log.i(
"MyApplication",
"InboxItemClicked at $itemIndex position with button-index: $buttonIndex"
"InboxItemClicked at $contentPageIndex page-index with button-index: $buttonIndex"
)

//The contentPageIndex corresponds to the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content.
val messageContentObject = message?.inboxMessageContents?.get(contentPageIndex)

//The buttonIndex corresponds to the CTA button clicked (0, 1, or 2). A value of -1 indicates the app inbox body/message clicked.
if (buttonIndex != -1) {
//button is clicked
val buttonObject: JSONObject? =
message?.inboxMessageContents?.get(0)?.links?.get(buttonIndex) as JSONObject?
val buttonObject: JSONObject? = messageContentObject?.links?.get(buttonIndex) as JSONObject?
val buttonType = buttonObject?.optString("type")
buttonType?.let {
when (it) {
Expand Down
6 changes: 6 additions & 0 deletions templates/CTCORECHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CleverTap Android SDK CHANGE LOG

### Version 4.6.9 (March 31, 2023)
#### Changes
* Renames the `itemIndex` parameter of the `onInboxItemClicked` callback with the `contentPageIndex`. It's not a breaking change.
* **[Parity with CleverTap iOS SDK]**:
The `onInboxItemClicked` callback now provides a different value for contentPageIndex(ex-`itemIndex`) compared to before. Previously, it used to indicate the position of the clicked item within the list container of the App Inbox. However, now it indicates the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content.

### Version 4.6.8 (March 22, 2023)
#### Breaking Changes
* **Signature change of `onInboxItemClicked` callback**:
Expand Down
12 changes: 8 additions & 4 deletions templates/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ cleverTapDefaultInstance.dismissAppInbox();

### App Inbox Item and Button Click Callbacks

Lets's understand the types of buttons first that App Inbox supports:
Let's understand the types of buttons first that App Inbox supports:
- URL button (fires the deeplink with the associated URL)
- Copy to button (Copies the associated text to the clipboard)
- KV button (contains the custom kev-value pair for custom handling)
Expand All @@ -239,14 +239,18 @@ The callback returns `CTInboxMessage` object, `itemIndex` and `buttonIndex` para

```java
@Override
public void onInboxItemClicked(CTInboxMessage message, int itemIndex, int buttonIndex){
Log.i(TAG, "InboxItemClicked at" + itemIndex + " position with button-index:" + buttonIndex);
public void onInboxItemClicked(CTInboxMessage message, int contentPageIndex, int buttonIndex){
Log.i(TAG, "InboxItemClicked at" + contentPageIndex + " page-index with button-index:" + buttonIndex);
//The buttonIndex corresponds to the CTA button clicked (0, 1, or 2). A value of -1 indicates the app inbox body/message clicked.

List<CTInboxMessageContent> inboxMessageContentList = message.getInboxMessageContents();
//The contentPageIndex corresponds to the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content.
CTInboxMessageContent messageContentObject = inboxMessageContentList.get(contentPageIndex);
if (buttonIndex != -1) {
//button is clicked
try {
List<CTInboxMessageContent> inboxMessageContentList = message.getInboxMessageContents();
JSONObject buttonObject = (JSONObject) inboxMessageContentList.get(0).getLinks().get(buttonIndex);
JSONObject buttonObject = (JSONObject) messageContentObject.getLinks().get(buttonIndex);
String buttonType = buttonObject.getString("type");
Log.i(TAG, "type of button clicked: " + buttonType);
} catch (Throwable t) {
Expand Down
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ version.com.android.installreferrer..installreferrer=2.2
## # available=2.2
version.com.android.tools.lint..lint-api=27.0.1
version.com.android.tools.lint..lint-checks=27.0.1
version.com.clevertap.android..clevertap-android-sdk=4.6.8
version.com.clevertap.android..clevertap-android-sdk=4.6.9
version.com.clevertap.android..clevertap-geofence-sdk=1.1.0
version.com.clevertap.android..clevertap-hms-sdk=1.3.1
version.com.clevertap.android..clevertap-xiaomi-sdk=1.5.1
Expand Down

0 comments on commit 9adbdb9

Please sign in to comment.