Skip to content
Merged
Show file tree
Hide file tree
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 @@ -54,10 +54,11 @@ public final class IterableConstants {
public static final String MESSAGING_PLATFORM_AMAZON = "ADM";

public static final String IS_GHOST_PUSH = "isGhostPush";
public static final String ITERABLE_DATA_KEY = "itbl";
public static final String ITERABLE_DATA_BODY = "body";
public static final String ITERABLE_DATA_TITLE = "title";
public static final String ITERABLE_DATA_KEY = "itbl";
public static final String ITERABLE_DATA_PUSH_IMAGE = "attachment_url";
public static final String ITERABLE_DATA_SOUND = "sound";
public static final String ITERABLE_DATA_TITLE = "title";

//Device
public static final String DEVICE_BRAND = "brand";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ static void showFullScreenDialog(Context context, JSONObject dialogParameters, S
verticalLayout.addView(imageView);
try {
Class picassoClass = Class.forName(IterableConstants.PICASSO_CLASS);
if (picassoClass != null) {

String imageUrl = dialogParameters.optString(IterableConstants.ITERABLE_IN_APP_MAIN_IMAGE);
if (picassoClass != null && !imageUrl.isEmpty()) {
Picasso.
with(context.getApplicationContext()).
load(dialogParameters.optString(IterableConstants.ITERABLE_IN_APP_MAIN_IMAGE)).
load(imageUrl).
resize(dialogWidth, dialogHeight/2).
centerInside().
into(imageView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import java.util.Date;
import com.squareup.picasso.Picasso;

/**
*
Expand All @@ -20,13 +23,45 @@
public class IterableNotification extends NotificationCompat.Builder {
static final String TAG = "IterableNotification";
private boolean isGhostPush;
private String imageUrl;
int requestCode;
IterableNotificationData iterableNotificationData;

protected IterableNotification(Context context) {
super(context);
}

/**
* Combine all of the options that have been set and return a new {@link Notification}
* object.
*/
public Notification build() {
final Notification notification = super.build();

final int iconId = android.R.id.icon;
final int bigIconId = mContext.getResources().getIdentifier("android:id/big_picture", null, null);

Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN && imageUrl != null) {
final RemoteViews bigContentView = notification.bigContentView;
try {
Class picassoClass = Class.forName(IterableConstants.PICASSO_CLASS);
if (picassoClass != null) {
Picasso.with(mContext).load(imageUrl).into(bigContentView, bigIconId, requestCode, notification);
}
} catch (ClassNotFoundException e) {
IterableLogger.w(TAG, "ClassNotFoundException: Check that picasso is added " +
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok to ask people to rely on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically this isn't needed since we embed that reference in our SDK export. However I thought it would be good to have it in there just in case that changes in the future.

"to the build dependencies", e);
}
}
}
});
return notification;
}

/**
* Creates and returns an instance of IterableNotification.
* @param context
Expand All @@ -40,13 +75,15 @@ public static IterableNotification createNotification(Context context, Bundle ex
String notificationBody = null;
String soundName = null;
String messageId = null;
String pushImage = null;

IterableNotification notificationBuilder = new IterableNotification(context);

if (extras.containsKey(IterableConstants.ITERABLE_DATA_KEY)) {
applicationName = extras.getString(IterableConstants.ITERABLE_DATA_TITLE, applicationName);
notificationBody = extras.getString(IterableConstants.ITERABLE_DATA_BODY);
soundName = extras.getString(IterableConstants.ITERABLE_DATA_SOUND);
pushImage = extras.getString(IterableConstants.ITERABLE_DATA_PUSH_IMAGE);

String iterableData = extras.getString(IterableConstants.ITERABLE_DATA_KEY);
notificationBuilder.iterableNotificationData = new IterableNotificationData(iterableData);
Expand All @@ -66,10 +103,20 @@ public static IterableNotification createNotification(Context context, Bundle ex
.setTicker(applicationName).setWhen(0)
.setAutoCancel(true)
.setContentTitle(applicationName)
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody))
.setPriority(Notification.PRIORITY_HIGH)
.setContentText(notificationBody);

if (pushImage != null) {
notificationBuilder.imageUrl = pushImage;
notificationBuilder.setContentText(notificationBody)
.setStyle(new NotificationCompat.BigPictureStyle()
.setBigContentTitle(applicationName)
.setSummaryText(notificationBody)
);
} else {
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody));
}

if (soundName != null) {
//Removes the file type from the name
String[] soundFile = soundName.split("\\.");
Expand Down Expand Up @@ -142,6 +189,7 @@ private static int getIconId(Context context) {
try {
ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
iconId = info.metaData.getInt(IterableConstants.NOTIFICATION_ICON_NAME, 0);
IterableLogger.d(TAG, "iconID: "+ info.metaData.get(IterableConstants.NOTIFICATION_ICON_NAME));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;

/**
Expand Down Expand Up @@ -55,16 +56,27 @@ private void handlePushReceived(Context context, Intent intent) {
try {
mainClass = Class.forName(mainClassName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
IterableLogger.w(TAG, e.toString());
}

IterableNotification notificationBuilder = IterableNotification.createNotification(
appContext, intent.getExtras(), mainClass);

IterableNotification.postNotificationOnDevice(appContext, notificationBuilder);
new IterableNotificationBuilder().execute(notificationBuilder);
} else {
IterableLogger.d(TAG, "Iterable ghost silent push received");
}
}
}
}

class IterableNotificationBuilder extends AsyncTask<IterableNotification, Void, Void> {

@Override
protected Void doInBackground(IterableNotification... params) {
if ( params != null && params[0] != null) {
IterableNotification notificationBuilder = params[0];
IterableNotification.postNotificationOnDevice(notificationBuilder.mContext, notificationBuilder);
}
return null;
}
}