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 | 216 ++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 152 insertions(+), 64 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 c0efb85..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,20 +1,32 @@
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;
import android.view.View;
import android.view.ViewGroup;
+import androidx.activity.result.ActivityResultLauncher;
+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;
+import com.dayu.pipirrapp.MyApplication;
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;
@@ -22,15 +34,15 @@
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;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
-import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
-import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,18 +54,34 @@
* 澶囨敞锛氶椤�
*/
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;
FragmentOrderBinding binding;
OrderAdapter mAdapter;
+ OrderAdapter mDoneAdapter;
int page = 1;
int pageSize = 10;
int state = 1;
List<OrderListResult.Data> recordsListDone = new ArrayList<>();
List<OrderListResult.Data> recordsList = new ArrayList<>();
+ RefreshLayout myRefreshLayout;
+ //鏈�鍚庡埛鏂扮殑鏃堕棿
+ long lastRefreshDate;
+ //鏄剧ず绾㈢偣鐨勬椂闂�
+ long showRedlotDate;
+
+
+ private ActivityResultLauncher<Intent> activityResultLauncher =
+ registerForActivityResult(
+ new ActivityResultContracts.StartActivityForResult(),
+ result -> {
+ if (result.getResultCode() == RESULT_REFRESH) {
+ myRefreshLayout.autoRefresh();
+ }
+ });
/**
* 璁剧疆澶╂皵鐩稿叧淇℃伅
@@ -81,57 +109,51 @@
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentOrderBinding.inflate(inflater, container, false);
initView();
- //鑾峰彇瀹氫綅鏈嶅姟浼犺繃鏉ョ殑鍧愭爣鐐�
+ //mq浼犳潵鐨勬秷鎭�
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();
}
void initView() {
//鏈畬鎴�
- binding.manageStateProgress.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- chooseStateView(true);
- state = STATE_UNDONE;//1 鏈紑濮� 2 宸插畬鎴�
+ binding.manageStateProgress.setOnClickListener(v -> {
+ chooseStateView(true);
+ state = STATE_UNDONE;//1 鏈紑濮� 2 宸插畬鎴�
- }
});
//宸插畬鎴�
- binding.manageStateFinish.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- chooseStateView(false);
- state = STATE_DONE;//1 鏈紑濮� 2 宸插畬鎴�
- }
+ binding.manageStateFinish.setOnClickListener(v -> {
+ chooseStateView(false);
+ state = STATE_DONE;//1 鏈紑濮� 2 宸插畬鎴�
});
//鏈畬鎴�
- RefreshLayout myRefreshLayout = (RefreshLayout) binding.refreshLayout;
+ myRefreshLayout = (RefreshLayout) binding.refreshLayout;
myRefreshLayout.setRefreshHeader(new ClassicsHeader(this.getContext()));
myRefreshLayout.setRefreshFooter(new ClassicsFooter(this.getContext()));
- myRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
- @Override
- public void onRefresh(RefreshLayout refreshlayout) {
+ myRefreshLayout.setOnRefreshListener(refreshlayout -> {
// refreshlayout.finishRefresh(2000/*,false*/);//浼犲叆false琛ㄧず鍒锋柊澶辫触
- recordsList.clear();
- page = 0;
- getMarkerData(refreshlayout, true, STATE_UNDONE);
+ 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);
});
- myRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
- @Override
- public void onLoadMore(RefreshLayout refreshlayout) {
- page = page + 1;
- getMarkerData(refreshlayout, false, STATE_UNDONE);
- }
+ myRefreshLayout.setOnLoadMoreListener(refreshlayout -> {
+ page = page + 1;
+ getMarkerData(refreshlayout, false, STATE_UNDONE);
});
mAdapter = new OrderAdapter(this.getContext(), recordsList, this);
@@ -143,33 +165,39 @@
RefreshLayout myRefreshLayoutDone = (RefreshLayout) binding.refreshLayoutDone;
myRefreshLayoutDone.setRefreshHeader(new ClassicsHeader(this.getContext()));
myRefreshLayoutDone.setRefreshFooter(new ClassicsFooter(this.getContext()));
- myRefreshLayoutDone.setOnRefreshListener(new OnRefreshListener() {
- @Override
- public void onRefresh(RefreshLayout refreshlayout) {
+ myRefreshLayoutDone.setOnRefreshListener(refreshlayout -> {
// refreshlayout.finishRefresh(2000/*,false*/);//浼犲叆false琛ㄧず鍒锋柊澶辫触
- recordsList.clear();
- page = 0;
- getMarkerData(refreshlayout, true, STATE_DONE);
- }
+ recordsListDone.clear();
+ page = 0;
+ getMarkerData(refreshlayout, true, STATE_DONE);
});
- myRefreshLayoutDone.setOnLoadMoreListener(new OnLoadMoreListener() {
- @Override
- public void onLoadMore(RefreshLayout refreshlayout) {
- page = page + 1;
- getMarkerData(refreshlayout, false, STATE_DONE);
- }
+ myRefreshLayoutDone.setOnLoadMoreListener(refreshlayout -> {
+ page = page + 1;
+ getMarkerData(refreshlayout, false, STATE_DONE);
});
- mAdapter = new OrderAdapter(this.getContext(), recordsListDone, this);
+ mDoneAdapter = new OrderAdapter(this.getContext(), recordsListDone, this);
LinearLayoutManager layoutManagerDone = new LinearLayoutManager(this.getContext());
binding.recyclerViewDone.setLayoutManager(layoutManagerDone);
- binding.recyclerViewDone.setAdapter(mAdapter);
+ binding.recyclerViewDone.setAdapter(mDoneAdapter);
getMarkerData(myRefreshLayoutDone, true, 2);
}
@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");
}
/**
@@ -189,7 +217,7 @@
params.put("pageSize", pageSize);
params.put("pageCurr", page);
params.put("state", state);
-// params.put("inspectorId", MyApplication.myApplication.userId);
+ params.put("inspectorId", MyApplication.myApplication.userId);
ApiManager.getInstance().requestGetHideLoading(this.getContext(), Constants.BASE_URL + "/app/workOrder/getWorkOrders", OrderListResult.class, params, new SubscriberListener<BaseResponse<OrderListResult>>() {
@Override
@@ -202,7 +230,7 @@
} else {
recordsListDone.addAll(t.getContent().getObj());
}
- if (t.getContent().getObj().size() < pageSize) {
+ if (t.getContent().getPageTotal() == page) {
refreshlayout.finishLoadMoreWithNoMoreData();
}
} else {
@@ -218,16 +246,23 @@
public void onCloose() {
super.onCloose();
layoutFinish(refreshlayout, isRefresh);
- mAdapter.notifyDataSetChanged();
+ if (state == STATE_UNDONE) {
+ mAdapter.notifyDataSetChanged();
+ } else {
+ mDoneAdapter.notifyDataSetChanged();
+ }
}
});
}
- public void startDetail(String id) {
+ public void startDetail(String workOrderId, String proResultId) {
Intent intent = new Intent(this.getContext(), OrderDetailActivity.class);
- intent.putExtra("workOrderId", id);
- startActivity(intent);
+ intent.putExtra("workOrderId", workOrderId);
+ if (!TextUtils.isEmpty(proResultId)) {
+ intent.putExtra("proResultId", proResultId);
+ }
+ activityResultLauncher.launch(intent);
}
@@ -239,20 +274,20 @@
void chooseStateView(boolean state) {
if (state) {
- binding.manageStateProgress.setTextColor(getResources().getColor(R.color.title_color));
- binding.manageStateProgress.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit));
+ 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));
- binding.manageStateFinish.setBackground(getResources().getDrawable(R.color.title_choose_bg));
+ 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));
- binding.manageStateFinish.setBackground(getResources().getDrawable(R.drawable.ic_choose_bg_whit));
+ 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));
- binding.manageStateProgress.setBackground(getResources().getDrawable(R.color.title_choose_bg));
+ 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