package com.xensear.xensear_integrate_native_aar;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

import com.unity3d.communication.XenseARUnityInterface;
import com.unity3d.player.CommunicationActivity;

public class MainUnityActivity extends CommunicationActivity {

    XenseARUnityInterface xenseARUnityInterface = getXenseARUnityInterface();

    @Override public void onUnityPlayerUnloaded() {
        finish();
    }

    @Override
    protected void onReceiveMessageFromUnity(String message) {
        Log.i("xenseAR", "SUCCESS!" + message);
        if(message.contains("unityReady") || message.contains("backToHomeScreen")) {
            xenseARUnityInterface.SendCommandString("updateHomeScreenUrl","https://xensear.vn/kam/homescreen?kamExperienceId=KAMGiftWYF", new XenseARUnityInterface.DefaultResponseInterface() {
                @Override
                public void onSuccess(String message) {
                    Log.i("xenseAR", "SUCCESS!"+message);

                }

                @Override
                public void onError(String message) {
                    Log.i("xenseAR", "ERROR: " + message);
                }
            });
        }else if(message.contains("getNativeParameters")) {
            if(xenseARUnityInterface != null) {
                Log.i("xenseAR", "Not null");

                xenseARUnityInterface.SendCommandString("updateNativeParameters","{\\\"userID\\\": \\\"abc\\\", \\\"auth_key\\\": \\\"xyz\\\"}", new XenseARUnityInterface.DefaultResponseInterface() {
                    @Override
                    public void onSuccess(String message) {
                        Log.i("xenseAR", "SUCCESS!"+message);

                    }

                    @Override
                    public void onError(String message) {
                        Log.i("xenseAR", "ERROR: " + message);
                    }
                });
            }else{
                Log.i("xenseAR", "Null");
            }
        }
        else if(message.contains("backToNativeView")) {
            finish();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}