管灌系统巡查员智能手机App
zuoxiao
2024-12-12 c91d4503a63013be3242120ae0ad9cd1b0b8127e
app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
@@ -5,8 +5,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -43,13 +41,13 @@
import com.dayu.pipirrapp.net.Constants;
import com.dayu.pipirrapp.net.subscribers.SubscriberListener;
import com.dayu.pipirrapp.observer.MapFragmenObserver;
import com.dayu.pipirrapp.service.MyLocationService;
import com.dayu.pipirrapp.tool.InspectionUtils;
import com.dayu.pipirrapp.utils.CommonData;
import com.dayu.pipirrapp.utils.CommonKeyName;
import com.dayu.pipirrapp.utils.DateUtils;
import com.dayu.pipirrapp.utils.MapJpgUtils;
import com.dayu.pipirrapp.utils.MyLog;
import com.dayu.pipirrapp.utils.ServiceUtils;
import com.dayu.pipirrapp.utils.SharedPreferencesHelper;
import com.dayu.pipirrapp.utils.ToastUtil;
import com.dayu.pipirrapp.utils.WebViewUtils;
@@ -490,8 +488,7 @@
     * @param inspectionState
     */
    private void chageInspecState(int inspectionState) {
        Intent location = new Intent(this.getActivity(), MyLocationService.class);
        location.putExtra("isSingle", false);
        //0没有开始,1开始,2暂停,3关闭
        switch (inspectionState) {
            case InspectionUtils.NO_INSPECTION:
@@ -500,21 +497,21 @@
                binding.inspectButton.setText("巡");
                LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver);
                //关闭定位
                this.getActivity().stopService(location);
                ServiceUtils.stopLocationService(MapFragment.this.getContext());
                break;
            case InspectionUtils.STAT_INSPECTION_ONCLICK:
                //添加新的巡检记录
                mInspectionBean = InspectionUtils.startInspection(this.getContext());
                startLocation(location);
                startLocation();
                break;
            case InspectionUtils.STAT_INSPECTION://1开始
                startLocation(location);
                startLocation();
                break;
            case InspectionUtils.PAUSE_INSPECTION://暂停
                try {
                    //关闭定位
                    this.getActivity().stopService(location);
                    ServiceUtils.stopLocationService(MapFragment.this.getContext());
                    binding.stateText.setText("已暂停巡检");
                    binding.inspectPause.setText("继续");
                    binding.inspectRL.setBackgroundColor(this.getContext().getResources().getColor(R.color.inspect_rl_bg_color));
@@ -584,9 +581,9 @@
    /**
     * 开始巡检的相关逻辑
     *
     * @param location
     * @param
     */
    private void startLocation(Intent location) {
    private void startLocation() {
        //获取定位服务传过来的坐标点
        LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver);
        binding.inspectRL.setVisibility(View.VISIBLE);
@@ -594,14 +591,9 @@
        binding.inspectPause.setText("暂停");
        binding.stateText.setText("已开启巡检");
        binding.inspectRL.setBackgroundColor(this.getContext().getResources().getColor(R.color.base_blue));
        //开启定位
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            this.getActivity().startForegroundService(location);
        } else {
            this.getActivity().startService(location);
        }
        inspectionRequest = new InspectionRequest();
        SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.inspectionState, InspectionUtils.STAT_INSPECTION);
        ServiceUtils.startLocationService(MapFragment.this.getContext(), false);
    }