From 4f7f99c6ea914bcd38de78bd8371be566026b905 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期三, 26 二月 2025 15:54:14 +0800 Subject: [PATCH] -为按钮和列表项添加波纹效果,以获得更好的视觉反馈 -改进MapFragment中的底部布局动画 -在MapFragment中添加设备状态和RTU地址显示 -更新BaseListResult以支持泛型类型 -为设备数据添加IntakeListResult和IntakeResult -通过数据库支持增强标记位置更新功能 -添加电话拨号意图以分隔标记详细信息 -通过过期检查改进磁贴缓存 -添加问题报告的确认对话框 -更新登录活动以限制用户名长度 -为波纹效果和UI元素添加新颜色 -重构XML布局以使用新的波纹图 -改进MapFragment中的错误处理和用户反馈 --- app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java | 258 ++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 210 insertions(+), 48 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 82ab38e..5591ce1 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java +++ b/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; @@ -72,6 +76,7 @@ import com.jeremyliao.liveeventbus.LiveEventBus; import com.tencent.bugly.crashreport.CrashReport; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -84,6 +89,7 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.schedulers.Schedulers; +import io.reactivex.rxjava3.core.Single; /** * author: zuo @@ -145,10 +151,55 @@ // 娣诲姞鍒锋柊鏁版嵁鐨勭洃鍚� LiveEventBus.get(CommonKeyName.refreshData).observe(this, o -> { - getCenterPoint(); - getMarkerData(); - getDivideList(); - getPipeNetworkList(); + // 鏄剧ず鍔犺浇鍔ㄧ敾 + TipUtil.showLoading(MapFragment.this.getActivity(), "姝e湪鏇存柊鏁版嵁..."); + + // 鍒涘缓澶氫釜Single瀵硅薄鏉ヨ〃绀烘瘡涓綉缁滆姹� + Single<Boolean> centerPointSingle = Single.create(emitter -> { + getCenterPoint(); + emitter.onSuccess(true); + }); + + Single<Boolean> markerDataSingle = Single.create(emitter -> { + getMarkerData(); + emitter.onSuccess(true); + }); + + Single<Boolean> divideListSingle = Single.create(emitter -> { + getDivideList(); + emitter.onSuccess(true); + }); + + Single<Boolean> pipeNetworkListSingle = Single.create(emitter -> { + getPipeNetworkList(); + emitter.onSuccess(true); + }); + + // 缁勫悎鎵�鏈塖ingle + compositeDisposable.add( + Single.zip( + centerPointSingle, + markerDataSingle, + divideListSingle, + pipeNetworkListSingle, + (centerPoint, marker, divide, pipe) -> true + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doFinally(() -> { + // 鏃犺鎴愬姛杩樻槸澶辫触锛岄兘闇�瑕侀殣钘忓姞杞藉姩鐢� + TipUtil.dismissLoading(); + }) + .subscribe( + result -> { + ToastUtil.showToast(MapFragment.this.getContext(), "鏁版嵁鏇存柊瀹屾垚"); + }, + throwable -> { + Log.e(TAG, "鏁版嵁鏇存柊澶辫触: " + throwable.getMessage()); + ToastUtil.showToast(MapFragment.this.getContext(), "鏁版嵁鏇存柊澶辫触"); + } + ) + ); }); } @@ -289,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)) { - try { - // 浠庣紦瀛樺姞杞界摝鐗� - return new WebResourceResponse("image/jpg", "utf-8", new FileInputStream(cachedTile)); - } catch (FileNotFoundException e) { - e.printStackTrace(); + // 妫�鏌ユ枃浠舵槸鍚﹁秴杩�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); } @@ -440,7 +498,7 @@ //宸℃鎸夐挳 binding.inspectButton.setOnClickListener(v -> { if (XXPermissions.isGranted(MapFragment.this.getContext(), Permission.ACCESS_BACKGROUND_LOCATION)) { - new ConfirmDialog(MapFragment.this.getActivity(), "纭寮�濮嬪贰妫�鍚楋紵",(confirmDialog, v1) -> { + new ConfirmDialog(MapFragment.this.getActivity(), "纭寮�濮嬪贰妫�鍚楋紵", (confirmDialog, v1) -> { chageInspecState(InspectionUtils.STAT_INSPECTION_ONCLICK); confirmDialog.dismiss(); }).show(); @@ -469,8 +527,13 @@ }); //涓婃姤闂 binding.putButton.setOnClickListener(v -> { - Intent issue = new Intent(MapFragment.this.getActivity(), AddIssueActivity.class); - MapFragment.this.getActivity().startActivity(issue); + 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), @@ -521,33 +584,33 @@ // } // 璺宠浆鍒伴�夋嫨鐨勪綅缃� mWebView.evaluateJavascript( - String.format("javascript:setCenterAndZoom(\"%s\",\"%s\",\"17\")", - item.getLng(), - item.getLat()), - null + String.format("javascript:setCenterAndZoom(\"%s\",\"%s\",\"17\")", + item.getLng(), + item.getLat()), + null ); }); - + // 鎵ц鎼滅储 compositeDisposable.add( - DaoSingleton.getAsynchInstance(requireContext()) - .divideDao() - .searchAllByKeyword(s) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - results -> { - if (results != null && !results.isEmpty()) { - searchDialog.setData(results); - searchDialog.show(); - } else { - ToastUtil.showToast(requireContext(), "鏈壘鍒扮浉鍏崇粨鏋�"); - } - }, - throwable -> { - ToastUtil.showToast(requireContext(), "鎼滅储澶辫触锛�" + throwable.getMessage()); - } - ) + DaoSingleton.getAsynchInstance(requireContext()) + .divideDao() + .searchAllByKeyword(s) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + results -> { + if (results != null && !results.isEmpty()) { + searchDialog.setData(results); + searchDialog.show(); + } else { + ToastUtil.showToast(requireContext(), "鏈壘鍒扮浉鍏崇粨鏋�"); + } + }, + throwable -> { + ToastUtil.showToast(requireContext(), "鎼滅储澶辫触锛�" + throwable.getMessage()); + } + ) ); } return null; @@ -609,8 +672,23 @@ }); } + /** + * 闅愯棌搴曢儴甯冨眬鐨勫姩鐢绘晥鏋� + */ + 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() { - binding.bottomLL.setVisibility(View.GONE); + hideBottomLayoutWithAnimation(); } /** @@ -844,7 +922,7 @@ boolean isfrist = true; for (PipeNetworkDataCoordinateBean data : pipeNetworkBean.getData().getCoordinates()) { if (!TextUtils.isEmpty(data.getLat()) && !TextUtils.isEmpty(data.getLng())) { - mWebView.evaluateJavascript("javascript:addPipeNetwork(\"" + data.getLng() + "\",\"" + data.getLat() + "\",\"" + isfrist + "\",\"" + isShowPipeNetwork +"\")", new ValueCallback<String>() { + mWebView.evaluateJavascript("javascript:addPipeNetwork(\"" + data.getLng() + "\",\"" + data.getLat() + "\",\"" + isfrist + "\",\"" + isShowPipeNetwork + "\")", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { } @@ -958,7 +1036,30 @@ binding.lat.setText(lat); mWebView.evaluateJavascript("javascript:cancelPin()", value -> { }); - ToastUtil.showToastLong(MapFragment.this.getContext(), "淇敼鎴愬姛锛�"); + + // 鏇存柊鏈湴鏁版嵁搴� + 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()); @@ -998,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()); @@ -1008,7 +1110,7 @@ } /** - * 鏄剧ず鍙栨按鍙h鎯� + * 鏄剧ず鍒嗘按鎴胯鎯� */ 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>>() { @@ -1016,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()); @@ -1026,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(); + } + + /** * 鏄剧ず鍙栨按鍙h鎯� */ 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); @@ -1073,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); @@ -1081,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()); @@ -1337,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); + } + } + + }); + } + } -- Gitblit v1.8.0