| | |
| | | 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.bean.net.WeatherResponse; |
| | | import com.dayu.pipirrapp.databinding.FragmentOrderBinding; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | 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; |
| | |
| | | * 备注:首页 |
| | | */ |
| | | 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(); |
| | | } |
| | | }); |
| | | |
| | | /** |
| | | * 设置天气相关信息 |
| | |
| | | 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); |
| | |
| | | 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"); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 |
| | |
| | | } else { |
| | | recordsListDone.addAll(t.getContent().getObj()); |
| | | } |
| | | if (t.getContent().getObj().size() < pageSize) { |
| | | if (t.getContent().getPageTotal() == page) { |
| | | refreshlayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | } else { |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建工单提示通知 |
| | | * |
| | | * @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); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |