package com.zhangxin.starlight.receiver;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.vivo.push.model.UPSNotificationMessage;
import com.vivo.push.sdk.OpenClientPushMessageReceiver;
import com.zhangxin.starlight.activity.MainActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Lidandan
 * on 2022/1/14
 * Description：
 */
public class PushMessageReceiverImpl extends OpenClientPushMessageReceiver {
    @Override
    public void onNotificationMessageClicked(Context context, UPSNotificationMessage upsNotificationMessage) {
        Intent intent = new Intent(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title", upsNotificationMessage.getTitle());
        if (upsNotificationMessage.getParams() != null) {
            try {
                if (upsNotificationMessage.getParams().containsKey("ext")) {
                    String extValue = upsNotificationMessage.getParams().get("ext");
                    if (!TextUtils.isEmpty(extValue)) {
                        JSONObject jsonObject = new JSONObject(extValue);
                        String entity = jsonObject.optString("entity");
                        if (!TextUtils.isEmpty(entity)) {
                            JSONObject childJsonObject = new JSONObject(entity);
                            String senderId = childJsonObject.optString("sender");
                            intent.putExtra("senderId", senderId);
                        }

                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        context.startActivity(intent);
    }

    @Override
    public void onReceiveRegId(Context context, String s) {

    }
}
