SealNotificationReceiver.java 2.49 KB
package com.cnlive.libs.chat.receiver;

import android.content.Context;

import com.cnlive.libs.chat.model.CNNotificationMessage;

import io.rong.push.notification.PushMessageReceiver;
import io.rong.push.notification.PushNotificationMessage;

/**
 * Created by Lynn on 2/17/2017.
 */

public abstract class SealNotificationReceiver extends PushMessageReceiver {

    private static CNNotificationMessage notificationMessage = new CNNotificationMessage();

    @Override
    public boolean onNotificationMessageArrived(Context context, PushNotificationMessage pushNotificationMessage) {
        return onNotificationMessageArrived(context, transform(notificationMessage, pushNotificationMessage));
    }

    @Override
    public boolean onNotificationMessageClicked(Context context, PushNotificationMessage pushNotificationMessage) {
        return onNotificationMessageClicked(context, transform(notificationMessage, pushNotificationMessage));
    }

    private CNNotificationMessage transform(CNNotificationMessage notificationMessage, PushNotificationMessage pushNotificationMessage) {
        notificationMessage.setPushId(pushNotificationMessage.getPushId());
        notificationMessage.setConversationType(pushNotificationMessage.getConversationType());
        notificationMessage.setReceivedTime(pushNotificationMessage.getReceivedTime());
        notificationMessage.setObjectName(pushNotificationMessage.getObjectName());
        notificationMessage.setSenderId(pushNotificationMessage.getSenderId());
        notificationMessage.setSenderName(pushNotificationMessage.getSenderName());
        notificationMessage.setSenderPortrait(pushNotificationMessage.getSenderPortrait());
        notificationMessage.setTargetId(pushNotificationMessage.getPushId());
        notificationMessage.setTargetUserName(pushNotificationMessage.getTargetUserName());
        notificationMessage.setPushTitle(pushNotificationMessage.getPushTitle());
        notificationMessage.setPushContent(pushNotificationMessage.getPushContent());
        notificationMessage.setPushData(pushNotificationMessage.getPushData());
        notificationMessage.setExtra(pushNotificationMessage.getExtra());
        notificationMessage.setPushFlag(pushNotificationMessage.getPushFlag());
        return notificationMessage;
    }

    public abstract boolean onNotificationMessageArrived(Context context, CNNotificationMessage notificationMessage);

    public abstract boolean onNotificationMessageClicked(Context context, CNNotificationMessage notificationMessage);
}