From 9c2908d8a110eaa28ec63a877291aeea61ee4e60 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期二, 03 十二月 2024 09:38:24 +0800 Subject: [PATCH] 优化自定义二次确认Dialog回调 --- app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java | 108 ++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 68 insertions(+), 40 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 1ce4b82..0cb878e 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java +++ b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java @@ -9,7 +9,6 @@ import android.location.LocationManager; import android.os.Build; import android.os.Bundle; -import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -26,6 +25,7 @@ import androidx.lifecycle.Observer; import com.dayu.pipirrapp.MyApplication; +import com.dayu.pipirrapp.R; import com.dayu.pipirrapp.bean.db.CenterPointBean; import com.dayu.pipirrapp.bean.db.InspectionBean; import com.dayu.pipirrapp.bean.db.InspectionLocationBean; @@ -61,9 +61,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Random; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; @@ -85,8 +83,8 @@ WebView mWebView; CenterPointBean centerPointBean; String strMarkerJson; - //鏄惁鏄剧ず - boolean isStartInspec = false; + //褰撳墠宸℃鐘舵�� + int mInspectionState; MapFragmenObserver mapFragmenObserver; //褰撳墠宸℃璁板綍鐨勭浉鍏充俊鎭� InspectionBean mInspectionBean; @@ -105,7 +103,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); - isStartInspec = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.isStartInspec, false); + mInspectionState = SharedPreferencesHelper.getInstance(this.getContext()).get(CommonKeyName.inspectionState, 0); } @Override @@ -132,7 +130,7 @@ initLocalData(); getMarkerData(); //鏄剧ず宸℃鐘舵�� - chageInspecState(); + chageInspecState(mInspectionState); return binding.getRoot(); } @@ -328,19 +326,19 @@ }); //宸℃鎸夐挳 binding.inspectButton.setOnClickListener(v -> { - if (isStartInspec) { - ConfirmDialog confirmDialog = new ConfirmDialog(MapFragment.this.getActivity(), "鎻愮ず", "纭鍏抽棴宸℃鍚楋紵", new View.OnClickListener() { - @Override - public void onClick(View v) { - isStartInspec = !isStartInspec; - chageInspecState(); - } - }); + chageInspecState(InspectionUtils.STAT_INSPECTION); + }); + //鏆傚仠宸℃ + binding.inspectPause.setOnClickListener(v -> { + if (mInspectionState == InspectionUtils.STAT_INSPECTION) { + chageInspecState(InspectionUtils.PAUSE_INSPECTION); } else { - isStartInspec = !isStartInspec; - chageInspecState(); + chageInspecState(InspectionUtils.STAT_INSPECTION); } - + }); + //鍋滄宸℃ + binding.inspectClose.setOnClickListener(v -> { + chageInspecState(InspectionUtils.STOP_INSPECTION); }); } @@ -475,30 +473,60 @@ /** * 淇敼宸℃鐘舵�� */ - private void chageInspecState() { + private void chageInspecState(int inspectionState) { Intent location = new Intent(this.getActivity(), MyLocationService.class); location.putExtra("isSingle", false); - if (isStartInspec) { - //娣诲姞鏂扮殑宸℃璁板綍 - startInspection(); - //鑾峰彇瀹氫綅鏈嶅姟浼犺繃鏉ョ殑鍧愭爣鐐� - LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); - binding.stateText.setVisibility(View.VISIBLE); - binding.inspectButton.setText("缁�"); - //寮�鍚畾浣� - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - this.getActivity().startForegroundService(location); - } else { - this.getActivity().startService(location); - } - mInspectionBean = InspectionUtils.startInspection(this.getContext()); - inspectionRequest = new InspectionRequest(); - } else { - binding.stateText.setVisibility(View.GONE); - binding.inspectButton.setText("宸�"); - LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); - //鍏抽棴瀹氫綅 - this.getActivity().stopService(location); + //0娌℃湁寮�濮嬶紝1寮�濮嬶紝2鏆傚仠,3鍏抽棴 + switch (inspectionState) { + case 0: + binding.inspectButton.setVisibility(View.VISIBLE); + binding.inspectRL.setVisibility(View.GONE); + binding.inspectButton.setText("宸�"); + LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); + //鍏抽棴瀹氫綅 + this.getActivity().stopService(location); + break; + case 1: + //娣诲姞鏂扮殑宸℃璁板綍 + startInspection(); + //鑾峰彇瀹氫綅鏈嶅姟浼犺繃鏉ョ殑鍧愭爣鐐� + LiveEventBus.get(CommonKeyName.locationData).observeForever(locationObserver); + binding.inspectRL.setVisibility(View.VISIBLE); + binding.inspectButton.setVisibility(View.GONE); + 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); + } + mInspectionBean = InspectionUtils.startInspection(this.getContext()); + inspectionRequest = new InspectionRequest(); + break; + case 2://鏆傚仠 + + LiveEventBus.get(CommonKeyName.locationData).removeObserver(locationObserver); + //鍏抽棴瀹氫綅 + this.getActivity().stopService(location); + binding.stateText.setText("宸叉殏鍋滃贰妫�"); + binding.inspectPause.setText("缁х画"); + binding.inspectRL.setBackgroundColor(this.getContext().getResources().getColor(R.color.inspect_rl_bg_color)); + break; + case 3: + ConfirmDialog confirmDialog = new ConfirmDialog(MapFragment.this.getActivity(), "鎻愮ず", "纭鍏抽棴宸℃鍚楋紵", new ConfirmDialog.ConfirmOnClickListener() { + @Override + public void onClick(ConfirmDialog confirmDialog, View v) { + confirmDialog.dismiss(); + chageInspecState(InspectionUtils.NO_INSPECTION); + } + }); + confirmDialog.show(); + break; + default: } + mInspectionState = inspectionState; + } } -- Gitblit v1.8.0