/*
* ---------------
* Note: Todo
* ---------------
* Need to be place in huawei_push (package com.huawei.hms.flutter.push.hms) and define in huawei_push manifest.xml
* */

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import com.huawei.hms.flutter.push.hms.FlutterHmsMessageService;
import com.huawei.hms.flutter.push.utils.ApplicationUtils;

import org.json.JSONObject;

//package com.huawei.hms.flutter.push.hms
//
//
//import android.content.Context;
//import android.content.Intent;
//import android.content.SharedPreferences;
//
//import com.huawei.hms.flutter.push.hms.FlutterHmsMessageService;
//import com.huawei.hms.flutter.push.utils.ApplicationUtils;
//import com.huawei.hms.push.RemoteMessage;
//
//import org.json.JSONObject;
//
//public class CustomFlutterHmsMessageService extends FlutterHmsMessageService {
//    @Override
//    public void onMessageReceived(RemoteMessage remoteMessage) {
//        super.onMessageReceived(remoteMessage);
//        try {
//            String jsonStr = remoteMessage.getData();
//            JSONObject json_data = new JSONObject(jsonStr);
//            JSONObject json_data_data = new JSONObject(json_data.getString("data"));
//            if(json_data_data.getString("is_call").equalsIgnoreCase("true")){
//                boolean isApplicationInForeground = ApplicationUtils.isApplicationInForeground(this);
//                if(!isApplicationInForeground){
//                    SharedPreferences preferences = getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE);
//                    preferences.edit().putString("flutter.call_data", json_data.getString("data")).apply();
//
//                    Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
//                    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//                    startActivity(intent);
//                    Log.v("onMessageReceived", "startActivity(intent) called");
//                }
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}
