From 798128053bb17ed293aa8d5424db3b5ed007d375 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期一, 23 十二月 2024 10:20:57 +0800 Subject: [PATCH] 1.优化订单列表框架,升级为viewPager2,提升性能。 2.添加收到新工单后的红点提醒。 3.修复查询数据为空时报错。 4.优化修改经纬度的流程。 5.修复mqtt的CLIENT_ID一致导致的连接错误。 6.修复收到新工单后点击消息通知栏跳转详情时不更新数据的bug。 --- app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 100 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java b/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java index d2a83e8..92c61ba 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java +++ b/app/src/main/java/com/dayu/pipirrapp/fragment/OrderFragment.java @@ -1,7 +1,13 @@ package com.dayu.pipirrapp.fragment; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; import android.graphics.Typeface; +import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; @@ -12,6 +18,7 @@ import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; import androidx.lifecycle.Observer; import androidx.recyclerview.widget.LinearLayoutManager; @@ -19,6 +26,7 @@ import com.dayu.pipirrapp.R; import com.dayu.pipirrapp.activity.OrderDetailActivity; import com.dayu.pipirrapp.adapter.OrderAdapter; +import com.dayu.pipirrapp.bean.net.OrderDetailResult; import com.dayu.pipirrapp.bean.net.OrderListResult; import com.dayu.pipirrapp.databinding.FragmentOrderBinding; import com.dayu.pipirrapp.net.ApiManager; @@ -26,6 +34,7 @@ import com.dayu.pipirrapp.net.Constants; import com.dayu.pipirrapp.net.subscribers.SubscriberListener; import com.dayu.pipirrapp.utils.CommonKeyName; +import com.dayu.pipirrapp.utils.MyLog; import com.dayu.pipirrapp.utils.ToastUtil; import com.jeremyliao.liveeventbus.LiveEventBus; import com.scwang.smart.refresh.footer.ClassicsFooter; @@ -33,6 +42,7 @@ import com.scwang.smart.refresh.layout.api.RefreshLayout; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -45,7 +55,7 @@ */ public class OrderFragment extends BaseFragment { public static final int RESULT_REFRESH = 1001; - + private static final String CHANNEL_ID = "order_channel"; private final int STATE_DONE = 2; private final int STATE_UNDONE = 1; @@ -58,6 +68,11 @@ List<OrderListResult.Data> recordsListDone = new ArrayList<>(); List<OrderListResult.Data> recordsList = new ArrayList<>(); RefreshLayout myRefreshLayout; + //鏈�鍚庡埛鏂扮殑鏃堕棿 + long lastRefreshDate; + //鏄剧ず绾㈢偣鐨勬椂闂� + long showRedlotDate; + private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult( @@ -98,7 +113,9 @@ LiveEventBus.get(CommonKeyName.MQTTData).observeForever(new Observer<Object>() { @Override public void onChanged(Object o) { - + showRedlotDate = new Date().getTime(); + binding.redDotImg.setVisibility(View.VISIBLE); + getMarkerData((String) o); } }); return binding.getRoot(); @@ -124,6 +141,12 @@ myRefreshLayout.setOnRefreshListener(refreshlayout -> { // refreshlayout.finishRefresh(2000/*,false*/);//浼犲叆false琛ㄧず鍒锋柊澶辫触 + lastRefreshDate = new Date().getTime(); + if (lastRefreshDate > showRedlotDate) { + //娑堥櫎绾㈢偣 + LiveEventBus.get(CommonKeyName.RedLotRefresh).post(true); + binding.redDotImg.setVisibility(View.GONE); + } recordsList.clear(); page = 0; getMarkerData(refreshlayout, true, STATE_UNDONE); @@ -161,8 +184,20 @@ @Override - public void onStart() { - super.onStart(); + public void onResume() { + super.onResume(); + MyLog.d("OrderFragment>>onResume"); + if (showRedlotDate > lastRefreshDate) { + binding.redDotImg.setVisibility(View.VISIBLE); + } else { + binding.redDotImg.setVisibility(View.GONE); + } + } + + @Override + public void onPause() { + super.onPause(); + MyLog.d("OrderFragment>>onPause"); } /** @@ -239,20 +274,20 @@ void chooseStateView(boolean state) { if (state) { - binding.manageStateProgress.setTextColor(getResources().getColor(R.color.title_color,null)); - binding.manageStateProgress.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit,null)); + binding.manageStateProgress.setTextColor(getResources().getColor(R.color.title_color, null)); + binding.manageStateProgress.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit, null)); binding.manageStateProgress.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); - binding.manageStateFinish.setTextColor(getResources().getColor(R.color.black,null)); - binding.manageStateFinish.setBackground(getResources().getDrawable(R.color.title_choose_bg,null)); + binding.manageStateFinish.setTextColor(getResources().getColor(R.color.black, null)); + binding.manageStateFinish.setBackground(getResources().getDrawable(R.color.title_choose_bg, null)); binding.manageStateFinish.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); binding.refreshLayout.setVisibility(View.VISIBLE); binding.refreshLayoutDone.setVisibility(View.GONE); } else { - binding.manageStateFinish.setTextColor(getResources().getColor(R.color.title_color,null)); - binding.manageStateFinish.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit,null)); + binding.manageStateFinish.setTextColor(getResources().getColor(R.color.title_color, null)); + binding.manageStateFinish.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit, null)); binding.manageStateFinish.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); - binding.manageStateProgress.setTextColor(getResources().getColor(R.color.black,null)); - binding.manageStateProgress.setBackground(getResources().getDrawable(R.color.title_choose_bg,null)); + binding.manageStateProgress.setTextColor(getResources().getColor(R.color.black, null)); + binding.manageStateProgress.setBackground(getResources().getDrawable(R.color.title_choose_bg, null)); binding.manageStateProgress.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); binding.refreshLayout.setVisibility(View.GONE); binding.refreshLayoutDone.setVisibility(View.VISIBLE); @@ -260,4 +295,57 @@ } + /** + * 鍒涘缓宸ュ崟鎻愮ず閫氱煡 + * + * @param notifucId + * @param data + */ + private void creatOrderNotification(int notifucId, String data, String workOrderId) { + NotificationManager notificationManager = (NotificationManager) requireContext().getSystemService(Context.NOTIFICATION_SERVICE); + // 鍒涘缓NotificationChannel锛堜粎閽堝Android O鍙婁互涓婄増鏈級 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + CharSequence name = getString(R.string.channel_name); + String description = getString(R.string.channel_description); + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); + channel.setDescription(description); + // 娉ㄥ唽閫氶亾 + notificationManager.createNotificationChannel(channel); + } + + Intent notificationIntent = new Intent(this.getContext(), OrderDetailActivity.class); + notificationIntent.putExtra("workOrderId", workOrderId); + int requestCode = workOrderId.hashCode(); // 浣跨敤workOrderId鐨勫搱甯岀爜浣滀负requestCode + PendingIntent pendingIntent = PendingIntent.getActivity(this.getContext(), requestCode, notificationIntent, PendingIntent.FLAG_MUTABLE); + Notification notification = new NotificationCompat.Builder(this.getContext(), CHANNEL_ID) + .setContentTitle("鏂板伐鍗�") + .setContentText(data) + .setSmallIcon(R.mipmap.ic_launcher) + .setContentIntent(pendingIntent) + .setAutoCancel(true) // 鐐瑰嚮閫氱煡鍚庤嚜鍔ㄦ秷澶� + .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)// 浣跨敤榛樿鐨勯煶鏁堝拰闇囧姩 + .build(); + notificationManager.notify(notifucId, notification); + + } + + /** + * 鑾峰彇宸ュ崟璇︽儏 + */ + private void getMarkerData(String workOrderId) { + Map<String, Object> params = new HashMap<>(); + params.put("workOrderId", workOrderId); + ApiManager.getInstance().requestGetHideLoading(this.getContext(), Constants.BASE_URL + "/app/workOrder/getOneWorkOrder", OrderDetailResult.class, params, new SubscriberListener<BaseResponse<OrderDetailResult>>() { + @Override + public void onNext(BaseResponse<OrderDetailResult> t) { + if (t.isSuccess()) { + if (t.isSuccess()) { + creatOrderNotification(workOrderId.hashCode(), t.getContent().getTaskType(), workOrderId); + } + } + } + }); + } + } -- Gitblit v1.8.0