| | |
| | | package com.dayu.pipirrapp.fragment; |
| | | |
| | | import static androidx.core.content.ContextCompat.getSystemService; |
| | | |
| | | 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.os.VibrationEffect; |
| | | import android.os.Vibrator; |
| | | import android.text.TextUtils; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | |
| | | 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.MainActivity; |
| | | 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; |
| | |
| | | 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.layout.api.RefreshLayout; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | int page = 1; |
| | | int pageSize = 10; |
| | | int state = 1; |
| | | List<OrderListResult.Data> recordsListDone = new ArrayList<>(); |
| | | List<OrderListResult.Data> recordsList = new ArrayList<>(); |
| | | List<OrderDetailResult> recordsListDone = new ArrayList<>(); |
| | | List<OrderDetailResult> recordsList = new ArrayList<>(); |
| | | RefreshLayout myRefreshLayout; |
| | | //最后刷新的时间 |
| | | long lastRefreshDate; |
| | | //显示红点的时间 |
| | | long showRedlotDate; |
| | | |
| | | |
| | | private ActivityResultLauncher<Intent> activityResultLauncher = |
| | | registerForActivityResult( |
| | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | binding = FragmentOrderBinding.inflate(inflater, container, false); |
| | | initView(); |
| | | //获取定位服务传过来的坐标点 |
| | | LiveEventBus.get(CommonKeyName.MQTTData).observeForever(o -> { |
| | | //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(v -> { |
| | | binding.manageStateProgressRL.setOnClickListener(v -> { |
| | | chooseStateView(true); |
| | | state = STATE_UNDONE;//1 未开始 2 已完成 |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | binding.recyclerView.setAdapter(mAdapter); |
| | | getMarkerData(myRefreshLayout, true, STATE_UNDONE); |
| | | //已完成 |
| | | RefreshLayout myRefreshLayoutDone = (RefreshLayout) binding.refreshLayoutDone; |
| | | RefreshLayout myRefreshLayoutDone = binding.refreshLayoutDone; |
| | | myRefreshLayoutDone.setRefreshHeader(new ClassicsHeader(this.getContext())); |
| | | myRefreshLayoutDone.setRefreshFooter(new ClassicsFooter(this.getContext())); |
| | | myRefreshLayoutDone.setOnRefreshListener(refreshlayout -> { |
| | | // refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败 |
| | | recordsListDone.clear(); |
| | | page = 0; |
| | | getMarkerData(refreshlayout, true, STATE_DONE); |
| | |
| | | |
| | | |
| | | @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"); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void onNext(BaseResponse<OrderListResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | if (t.getContent().getObj() != null && t.getContent().getObj().size() > 0) { |
| | | if (state == STATE_UNDONE) { |
| | | recordsList.addAll(t.getContent().getObj()); |
| | | } else { |
| | | recordsListDone.addAll(t.getContent().getObj()); |
| | | } |
| | | if (t.getContent().getPageTotal() == page) { |
| | | refreshlayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | if (t.getContent().getObj() != null && t.getContent().getObj().size() > 0) { |
| | | if (state == STATE_UNDONE) { |
| | | recordsList.addAll(t.getContent().getObj()); |
| | | } else { |
| | | recordsListDone.addAll(t.getContent().getObj()); |
| | | } |
| | | if (t.getContent().getPageTotal() == page) { |
| | | refreshlayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | } else { |
| | | refreshlayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderFragment.this.getContext(), t.getMsg()); |
| | |
| | | |
| | | 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.manageStateProgressRL.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.manageStateProgressRL.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); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取工单详情 |
| | | */ |
| | | 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 (MainActivity.workerIddata != null) { |
| | | if (!MainActivity.workerIddata.containsKey(workOrderId)) { |
| | | LiveEventBus.get(CommonKeyName.CreateNotification).post(t.getContent()); |
| | | recordsList.add(0, t.getContent()); |
| | | mAdapter.notifyItemInserted(0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |