管灌系统巡查员智能手机App
app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
@@ -5,6 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -35,11 +36,14 @@
import com.dayu.pipirrapp.bean.db.PipeNetWorkDataBean;
import com.dayu.pipirrapp.bean.db.PipeNetworkBean;
import com.dayu.pipirrapp.bean.db.PipeNetworkDataCoordinateBean;
import com.dayu.pipirrapp.bean.net.BaseListResult;
import com.dayu.pipirrapp.bean.net.CenterPointResult;
import com.dayu.pipirrapp.bean.net.DivideListResult;
import com.dayu.pipirrapp.bean.net.DivideResult;
import com.dayu.pipirrapp.bean.net.InsectionResult;
import com.dayu.pipirrapp.bean.net.InspectionRequest;
import com.dayu.pipirrapp.bean.net.IntakeListResult;
import com.dayu.pipirrapp.bean.net.IntakeResult;
import com.dayu.pipirrapp.bean.net.MarkerListResult;
import com.dayu.pipirrapp.bean.net.MarkerResult;
import com.dayu.pipirrapp.bean.net.PipeNetworkResult;
@@ -336,24 +340,31 @@
                    // 检查本地缓存
                    File cachedTile = MapJpgUtils.getInsatance().getCachedTile(androidUrl);
                    if (cachedTile != null && cachedTile.exists()) {
//                        Log.d(TAG, "本地缓存>>>" + androidUrl);
//                        if (MapJpgUtils.getInsatance().validateImageFile(androidUrl,request.))
                        // 判断缓存是否过期
//                    if (!MapJpgUtils.getInsatance(MapFragment.this.getContext()).isCacheExpired(cachedTile)) {
                        // 检查文件是否超过6个月
                        long sixMonthsInMillis = 6L * 30 * 24 * 60 * 60 * 1000; // 6个月的毫秒数
                        long fileAge = System.currentTimeMillis() - cachedTile.lastModified();
                        if (fileAge > sixMonthsInMillis) {
                            // 如果文件超过6个月,删除旧文件并重新下载
                            if (cachedTile.delete()) {
                                Log.d(TAG, "已删除过期瓦片: " + androidUrl);
                            } else {
                                Log.e(TAG, "删除过期瓦片失败: " + androidUrl);
                            }
                            ApiManager.getInstance().donwLoadTile(MapFragment.this.getContext(), androidUrl);
                        } else {
                        try {
                            // 从缓存加载瓦片
                            return new WebResourceResponse("image/jpg", "utf-8", new FileInputStream(cachedTile));
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
//                    }
                        }
                    } else {
                        //下载瓦片
                        ApiManager.getInstance().donwLoadTile(MapFragment.this.getContext(), androidUrl);
                    }
                }
                return super.shouldInterceptRequest(view, request);
            }
@@ -516,8 +527,13 @@
        });
        //上报问题
        binding.putButton.setOnClickListener(v -> {
            new ConfirmDialog(MapFragment.this.getActivity(), "确认上报问题吗?", (confirmDialog, v1) -> {
            Intent issue = new Intent(MapFragment.this.getActivity(), AddIssueActivity.class);
            MapFragment.this.getActivity().startActivity(issue);
                confirmDialog.dismiss();
            }).show();
        });
        binding.expandButton.setLegendsArray(new ExpandButton.Quadruple(
                        ContextCompat.getDrawable(requireContext(), R.drawable.marker_blue),
@@ -656,8 +672,23 @@
        });
    }
    public void closeWaterIntakeDetail() {
    /**
     * 隐藏底部布局的动画效果
     */
    private void hideBottomLayoutWithAnimation() {
        binding.bottomLL.animate()
                .translationY(binding.bottomLL.getHeight())
                .setDuration(300)
                .setInterpolator(new android.view.animation.AccelerateInterpolator())
                .withEndAction(() -> {
        binding.bottomLL.setVisibility(View.GONE);
                    binding.bottomLL.setTranslationY(0);
                })
                .start();
    }
    public void closeWaterIntakeDetail() {
        hideBottomLayoutWithAnimation();
    }
    /**
@@ -1005,7 +1036,30 @@
                        binding.lat.setText(lat);
                        mWebView.evaluateJavascript("javascript:cancelPin()", value -> {
                        });
                        // 更新本地数据库
                        compositeDisposable.add(
                                DaoSingleton.getAsynchInstance(MapFragment.this.getContext())
                                        .markerDao()
                                        .updateMarkerLocation(markerBean.getId(), lng, lat)
                                        .subscribeOn(Schedulers.io())
                                        .observeOn(AndroidSchedulers.mainThread())
                                        .subscribe(
                                                () -> {
                                                    // 更新本地缓存Map中的数据
                                                    MarkerBean cachedMarker = markerBeanSet.get(markerBean.getId());
                                                    if (cachedMarker != null) {
                                                        cachedMarker.setLng(lng);
                                                        cachedMarker.setLat(lat);
                                                    }
                        ToastUtil.showToastLong(MapFragment.this.getContext(), "修改成功!");
                                                },
                                                throwable -> {
                                                    Log.e(TAG, "更新本地数据库失败: ");
                                                    ToastUtil.showToastLong(MapFragment.this.getContext(), "修改成功,但本地数据库更新失败");
                                                }
                                        )
                        );
                    } else {
                        ToastUtil.showToastLong(MapFragment.this.getContext(), t.getMsg());
@@ -1045,6 +1099,7 @@
                    mMarkerBean.setAddress(result.getAddress());
                    mMarkerBean.setBlockName(result.getBlockName());
                    mMarkerBean.setDivideId(result.getDivideId());
                    getDeviceData(result.getName());
                    showMarker(mMarkerBean);
                } else {
                    ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg());
@@ -1055,7 +1110,7 @@
    }
    /**
     * 显示取水口详情
     * 显示分水房详情
     */
    private void getDivideDetail(DivideBean divideBean) {
        ApiManager.getInstance().requestGet(this.getContext(), Constants.BASE_URL + "/project/divide/getone/" + divideBean.getDivideId(), DivideResult.class, null, new SubscriberListener<BaseResponse<DivideResult>>() {
@@ -1063,6 +1118,7 @@
            public void onNext(BaseResponse<DivideResult> t) {
                if (t.isSuccess()) {
                    DivideBean divideBean = getDivideBean(t.getContent());
                    getDeviceData(divideBean.getDivideName());
                    showDivideMarker(divideBean);
                } else {
                    ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg());
@@ -1073,10 +1129,23 @@
    }
    /**
     * 显示底部布局的动画效果
     */
    private void showBottomLayoutWithAnimation() {
        binding.bottomLL.setVisibility(View.VISIBLE);
        binding.bottomLL.setTranslationY(binding.bottomLL.getHeight());
        binding.bottomLL.animate()
                .translationY(0)
                .setDuration(300)
                .setInterpolator(new android.view.animation.DecelerateInterpolator())
                .start();
    }
    /**
     * 显示取水口详情
     */
    private void showMarker(MarkerBean markerBean) {
        binding.bottomLL.setVisibility(View.VISIBLE);
        showBottomLayoutWithAnimation();
        binding.phoneLL.setVisibility(View.GONE);
        binding.headerLL.setVisibility(View.GONE);
        binding.editePoint.setVisibility(View.VISIBLE);
@@ -1120,7 +1189,7 @@
     * @param divideBean
     */
    private void showDivideMarker(DivideBean divideBean) {
        binding.bottomLL.setVisibility(View.VISIBLE);
        showBottomLayoutWithAnimation();
        binding.phoneLL.setVisibility(View.VISIBLE);
        binding.headerLL.setVisibility(View.VISIBLE);
        binding.editePoint.setVisibility(View.GONE);
@@ -1128,6 +1197,11 @@
        binding.markerName.setText(divideBean.getDivideName());
        binding.markerBlockName.setText(divideBean.getBlockName());
        binding.phone.setText(divideBean.getPhone());
        binding.phone.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + divideBean.getPhone()));
            startActivity(intent);
        });
        binding.header.setText(divideBean.getHeader());
        binding.lat.setText(divideBean.getLat());
        binding.lng.setText(divideBean.getLng());
@@ -1384,4 +1458,45 @@
        }
    }
    /**
     * 获取设备相关状态信息
     *
     * @param intakeNum
     */
    private void getDeviceData(String intakeNum) {
        Map<String, Object> params = new HashMap<>();
        params.put("intakeNum", intakeNum);
        ApiManager.getInstance().requestGetHideLoading(MapFragment.this.getContext(), BASE_URL + "/remote/monitor/all_intakes", IntakeListResult.class, params, new SubscriberListener<BaseResponse<IntakeListResult>>() {
            @Override
            public void onNext(BaseResponse<IntakeListResult> t) {
                try {
                    if (t.isSuccess()) {
                        if (t.getContent() != null && t.getContent().getObj().size() > 0) {
                            binding.deviceStateLL.setVisibility(View.VISIBLE);
                            binding.rtuAddressLL.setVisibility(View.VISIBLE);
                            IntakeResult intakeResult = t.getContent().getObj().get(0);
                            if (intakeResult.isOnLine()) {
                                binding.deviceState.setText("在线");
                                binding.deviceState.setTextColor(getResources().getColor(R.color.down_green_up, null));
                            } else {
                                binding.deviceState.setText("离线");
                                binding.deviceState.setTextColor(getResources().getColor(R.color.delete_color, null));
                            }
                            binding.rtuAddress.setText(intakeResult.getRtuAddr());
                        } else {
                            binding.deviceStateLL.setVisibility(View.GONE);
                            binding.rtuAddressLL.setVisibility(View.GONE);
                        }
                    } else {
                        ToastUtil.showToastLong(MapFragment.this.getContext(), t.getMsg());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    CrashReport.postCatchedException(e);
                }
            }
        });
    }
}