| | |
| | | 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.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 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; |
| | |
| | | */ |
| | | 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; |
| | | |
| | |
| | | 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; |
| | |
| | | @Override |
| | | public void onChanged(Object o) { |
| | | showRedlotDate = new Date().getTime(); |
| | | binding.redDotImg.setVisibility(View.VISIBLE); |
| | | // binding.redDotImg.setVisibility(View.VISIBLE); |
| | | getMarkerData((String) o); |
| | | } |
| | | }); |
| | |
| | | |
| | | void initView() { |
| | | //未完成 |
| | | binding.manageStateProgress.setOnClickListener(v -> { |
| | | binding.manageStateProgressRL.setOnClickListener(v -> { |
| | | chooseStateView(true); |
| | | state = STATE_UNDONE;//1 未开始 2 已完成 |
| | | |
| | |
| | | if (lastRefreshDate > showRedlotDate) { |
| | | //消除红点 |
| | | LiveEventBus.get(CommonKeyName.RedLotRefresh).post(true); |
| | | binding.redDotImg.setVisibility(View.GONE); |
| | | // binding.redDotImg.setVisibility(View.GONE); |
| | | } |
| | | recordsList.clear(); |
| | | page = 0; |
| | |
| | | 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); |
| | |
| | | public void onResume() { |
| | | super.onResume(); |
| | | MyLog.d("OrderFragment>>onResume"); |
| | | if (showRedlotDate > lastRefreshDate) { |
| | | binding.redDotImg.setVisibility(View.VISIBLE); |
| | | } else { |
| | | binding.redDotImg.setVisibility(View.GONE); |
| | | } |
| | | // if (showRedlotDate > lastRefreshDate) { |
| | | // binding.redDotImg.setVisibility(View.VISIBLE); |
| | | // } else { |
| | | // binding.redDotImg.setVisibility(View.GONE); |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | |
| | | @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 { |
| | | refreshlayout.finishLoadMoreWithNoMoreData(); |
| | | } |
| | | } |
| | | } else { |
| | | ToastUtil.showToast(OrderFragment.this.getContext(), t.getMsg()); |
| | |
| | | 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.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, 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.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.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); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建工单提示通知 |
| | | * |
| | | * @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); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取工单详情 |
| | |
| | | @Override |
| | | public void onNext(BaseResponse<OrderDetailResult> t) { |
| | | if (t.isSuccess()) { |
| | | if (t.isSuccess()) { |
| | | creatOrderNotification(workOrderId.hashCode(), t.getContent().getTaskType(), workOrderId); |
| | | if (MainActivity.workerIddata != null) { |
| | | if (!MainActivity.workerIddata.containsKey(workOrderId)) { |
| | | LiveEventBus.get(CommonKeyName.CreateNotification).post(t.getContent()); |
| | | recordsList.add(0, t.getContent()); |
| | | mAdapter.notifyItemInserted(0); |
| | | } |
| | | } |
| | | } |
| | | } |