package com.mogo.cloud;

import android.os.Bundle;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.mogo.cloud.location.LocationManager;
import com.mogo.cloud.location.MogoLocationInfoServices;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.cloud.tanlu.bean.location.MogoLocation;
import com.mogo.realtime.socket.SocketHandler;

/**
 * @author arrow
 * @description 描述
 * @since: 2021/1/21
 */
public class LocationActivity extends AppCompatActivity {

    private static final String TAG = "LocationActivity";

    private Button snapshotLocStart;
    private Button snapshotLocStop;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location);
        MogoLocationInfoServices.getInstance().init(this);
        SocketHandler.getInstance().initSocket(this,  MoGoAiCloudClientConfig.getInstance().getServiceAppId(),0,0);

        MogoLocation mogoLocation = new MogoLocation();
        mogoLocation.setAccuracy(0.0f);
        mogoLocation.setAdCode("110113");
        mogoLocation.setCityCode("010");
        mogoLocation.setAddress("北京测试");
        mogoLocation.setAltitude(20);
        mogoLocation.setSpeed(20.0f);
        mogoLocation.setLocationDetail("北京东城环球贸易中心");
        mogoLocation.setBearing(185.8831f);
        mogoLocation.setAltitude(0.0);
        mogoLocation.setLatitude(40.201138738452414);
        mogoLocation.setLongitude(116.74181952698365);
        mogoLocation.setLocType(0);
        mogoLocation.setGpsAccuracyStatus(0);
        mogoLocation.setProvider("AGPS");

        snapshotLocStart = findViewById(R.id.snapshotLocStart);
        snapshotLocStart.setOnClickListener(view -> {
            MogoLocationInfoServices.getInstance().start();
            MogoLocationInfoServices.getInstance().provideLocation(mogoLocation);
        });

        snapshotLocStop = findViewById(R.id.snapshotLocStop);
        snapshotLocStop.setOnClickListener(view -> {
            SocketHandler.getInstance().stop();
            MogoLocationInfoServices.getInstance().stop();
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SocketHandler.getInstance().stop();
        MogoLocationInfoServices.getInstance().stop();
    }
}
