From c91d4503a63013be3242120ae0ad9cd1b0b8127e Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期四, 12 十二月 2024 17:18:54 +0800
Subject: [PATCH] 优化定位服务相关代码

---
 app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java |   26 +++++++++-----------------
 1 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
index d4f825f..fb357d8 100644
--- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
+++ b/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);
     }
 
 

--
Gitblit v1.8.0