|
|
@@ -0,0 +1,312 @@
|
|
|
+package com.goldze.mvvmhabit.ui.dialog;
|
|
|
+
|
|
|
+import android.app.Dialog;
|
|
|
+import android.content.res.Configuration;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.goldze.mvvmhabit.R;
|
|
|
+import com.goldze.mvvmhabit.data.source.model.MobileDatumResponseBean;
|
|
|
+import com.goldze.mvvmhabit.data.source.model.SelectTypeBean;
|
|
|
+import com.goldze.mvvmhabit.ui.main.adapter.SelectCameraAdapter;
|
|
|
+import com.goldze.mvvmhabit.ui.main.adapter.SelectTypeAdapter;
|
|
|
+import com.goldze.mvvmhabit.utils.DateUtils;
|
|
|
+import com.goldze.mvvmhabit.utils.picker.PickerListener;
|
|
|
+import com.goldze.mvvmhabit.utils.picker.TimeSelectionPicker;
|
|
|
+import com.google.android.flexbox.FlexDirection;
|
|
|
+import com.google.android.flexbox.FlexWrap;
|
|
|
+import com.google.android.flexbox.FlexboxLayoutManager;
|
|
|
+import com.google.android.flexbox.JustifyContent;
|
|
|
+import com.luck.picture.lib.utils.DensityUtil;
|
|
|
+import com.luck.picture.lib.utils.FullyGridLayoutManager;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.annotation.RequiresApi;
|
|
|
+import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
+import androidx.recyclerview.widget.RecyclerView;
|
|
|
+import androidx.recyclerview.widget.SimpleItemAnimator;
|
|
|
+import butterknife.OnClick;
|
|
|
+import me.goldze.mvvmhabit.base.BaseDialogFragment;
|
|
|
+import me.goldze.mvvmhabit.utils.ToastUtils;
|
|
|
+
|
|
|
+@RequiresApi(api = Build.VERSION_CODES.M)
|
|
|
+public class WarningSelectDialogFragment extends BaseDialogFragment implements PickerListener {
|
|
|
+
|
|
|
+ private List<MobileDatumResponseBean> mList;
|
|
|
+ private SelectCameraAdapter adapter;
|
|
|
+ private SelectTypeAdapter typeAdapter;
|
|
|
+ private List<SelectTypeBean> typeBeanList;
|
|
|
+ private TextView tvStartTime;
|
|
|
+ private TextView tvEndTime;
|
|
|
+ private String startTime;
|
|
|
+ private String endTime;
|
|
|
+ private RecyclerView rvType;
|
|
|
+ private RecyclerView rvCamera;
|
|
|
+ private LinearLayout llTime;
|
|
|
+ private int timeType = STARTDATE;
|
|
|
+ private final static int STARTDATE = 0;
|
|
|
+ private final static int ENDDATE = 1;
|
|
|
+ private TextView tvType;
|
|
|
+ private TextView tvCamera;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public WarningSelectDialogFragment(List<MobileDatumResponseBean> mList, List<SelectTypeBean> typeBeanList, String startTime, String endTime) {
|
|
|
+ this.mList = mList;
|
|
|
+ this.typeBeanList = typeBeanList;
|
|
|
+ this.startTime = startTime;
|
|
|
+ this.endTime = endTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int setLayoutId() {
|
|
|
+ return R.layout.layout_select_warning;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
+ super.onViewCreated(view, savedInstanceState);
|
|
|
+ rvCamera = view.findViewById(R.id.rv_camera);
|
|
|
+ rvType = view.findViewById(R.id.rv_type);
|
|
|
+ tvStartTime = view.findViewById(R.id.tv_start_time);
|
|
|
+ tvEndTime = view.findViewById(R.id.tv_end_time);
|
|
|
+ llTime = view.findViewById(R.id.ll_time);
|
|
|
+ tvType = view.findViewById(R.id.tv_type);
|
|
|
+ tvCamera = view.findViewById(R.id.tv_camera);
|
|
|
+ initAdapter();
|
|
|
+ _initTimePicker();
|
|
|
+ }
|
|
|
+
|
|
|
+ @NonNull
|
|
|
+ @Override
|
|
|
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
+ Dialog dialog = super.onCreateDialog(savedInstanceState);
|
|
|
+
|
|
|
+ // 设置Dialog不可取消
|
|
|
+ setCancelable(false);
|
|
|
+
|
|
|
+ // 设置Dialog的Window特性,使其不遮挡其他Dialog
|
|
|
+ if (dialog.getWindow() != null) {
|
|
|
+ dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
|
|
|
+ WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
|
|
|
+ }
|
|
|
+
|
|
|
+ return dialog;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void _initTimePicker() {
|
|
|
+ TimeSelectionPicker.getInstance().init(getContext());
|
|
|
+ TimeSelectionPicker.getInstance().addListener(this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initAdapter() {
|
|
|
+ //设置布局管理器 流式布局 盒子布局
|
|
|
+ FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(getActivity());
|
|
|
+ //flexDirection 属性决定主轴的方向(即项目的排列方向)。类似 LinearLayout 的 vertical和horizontal。
|
|
|
+ flexboxLayoutManager.setFlexDirection(FlexDirection.ROW); //主轴为水平方向,起点在左端。
|
|
|
+ //flexWrap 默认情况下 Flex 跟 LinearLayout 一样,都是不带换行排列的,但是flexWrap属性可以支持换行排列。
|
|
|
+ flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP); //按正常方向换行
|
|
|
+ //justifyContent 属性定义了项目在主轴上的对齐方式。
|
|
|
+ flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START); //交叉轴的起点对齐。
|
|
|
+ //设置布局管理器
|
|
|
+ rvCamera.setLayoutManager(flexboxLayoutManager);
|
|
|
+ adapter = new SelectCameraAdapter(mList, mActivity);
|
|
|
+ rvCamera.setAdapter(adapter);
|
|
|
+ adapter.setOnItemClickListener(new SelectCameraAdapter.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(int position) {
|
|
|
+ if (mList.get(position).isSelect()) {
|
|
|
+ mList.get(position).setSelect(false);
|
|
|
+ } else {
|
|
|
+ mList.get(position).setSelect(true);
|
|
|
+ }
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ FullyGridLayoutManager managerOther = new FullyGridLayoutManager(getContext(),
|
|
|
+ 4, GridLayoutManager.VERTICAL, false);
|
|
|
+ RecyclerView.ItemAnimator itemAnimatorOther = rvType.getItemAnimator();
|
|
|
+ if (itemAnimatorOther != null) {
|
|
|
+ ((SimpleItemAnimator) itemAnimatorOther).setSupportsChangeAnimations(false);
|
|
|
+ }
|
|
|
+ rvType.setLayoutManager(managerOther);
|
|
|
+ typeAdapter = new SelectTypeAdapter(typeBeanList, getActivity());
|
|
|
+ rvType.setAdapter(typeAdapter);
|
|
|
+ typeAdapter.setOnItemClickListener(new SelectTypeAdapter.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(int position) {
|
|
|
+ for (int i = 0; i < typeBeanList.size(); i++) {
|
|
|
+ if (i==position){
|
|
|
+ if (typeBeanList.get(position).isSelect()) {
|
|
|
+ typeBeanList.get(position).setSelect(false);
|
|
|
+ } else {
|
|
|
+ typeBeanList.get(position).setSelect(true);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ typeBeanList.get(i).setSelect(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ typeAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!TextUtils.isEmpty(startTime)) {
|
|
|
+ tvStartTime.setText(startTime);
|
|
|
+ tvStartTime.setBackgroundResource(R.drawable.shape_blue_18);
|
|
|
+ tvStartTime.setTextColor(getContext().getColor(R.color.white));
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(endTime)) {
|
|
|
+ tvEndTime.setText(endTime);
|
|
|
+ tvEndTime.setBackgroundResource(R.drawable.shape_blue_18);
|
|
|
+ tvEndTime.setTextColor(getContext().getColor(R.color.white));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ super.onStart();
|
|
|
+ mWindow.setGravity(Gravity.BOTTOM);
|
|
|
+ mWindow.setWindowAnimations(R.style.BottomAnimation);
|
|
|
+ mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) (DensityUtil.getScreenHeight(mActivity) * 0.8));
|
|
|
+ mWindow.setSoftInputMode(
|
|
|
+ WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onConfigurationChanged(Configuration newConfig) {
|
|
|
+ super.onConfigurationChanged(newConfig);
|
|
|
+ mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean isImmersionBarEnabled() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private OnSuccessListener onSuccessListener;
|
|
|
+
|
|
|
+ public void setOnSuccessListener(OnSuccessListener onSuccessListener) {
|
|
|
+ this.onSuccessListener = onSuccessListener;
|
|
|
+ }
|
|
|
+
|
|
|
+ @OnClick({R.id.tv_next, R.id.tv_cancel, R.id.tv_return, R.id.tv_camera, R.id.tv_type, R.id.tv_start_time, R.id.tv_end_time})
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.tv_next:
|
|
|
+ if (getDialog() != null) {
|
|
|
+ getDialog().dismiss();
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(endTime)){
|
|
|
+ if (TextUtils.isEmpty(startTime)){
|
|
|
+ ToastUtils.showShort("请选择开始时间");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(startTime)){
|
|
|
+ if (TextUtils.isEmpty(endTime)){
|
|
|
+ ToastUtils.showShort("请选择结束时间");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onSuccessListener.onClick(mList, typeBeanList, startTime, endTime);
|
|
|
+ break;
|
|
|
+ case R.id.tv_cancel:
|
|
|
+ if (getDialog() != null) {
|
|
|
+ getDialog().dismiss();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case R.id.tv_return:
|
|
|
+ reset();
|
|
|
+ break;
|
|
|
+ case R.id.tv_camera:
|
|
|
+ rvCamera.setVisibility(View.VISIBLE);
|
|
|
+ llTime.setVisibility(View.GONE);
|
|
|
+ rvType.setVisibility(View.GONE);
|
|
|
+ tvType.setTextColor(getContext().getColor(R.color.editTextColor));
|
|
|
+ tvCamera.setTextColor(getContext().getColor(R.color.action_sheet_blue));
|
|
|
+ break;
|
|
|
+ case R.id.tv_type:
|
|
|
+ rvCamera.setVisibility(View.GONE);
|
|
|
+ rvType.setVisibility(View.VISIBLE);
|
|
|
+ llTime.setVisibility(View.VISIBLE);
|
|
|
+ tvType.setTextColor(getContext().getColor(R.color.action_sheet_blue));
|
|
|
+ tvCamera.setTextColor(getContext().getColor(R.color.editTextColor));
|
|
|
+ break;
|
|
|
+ case R.id.tv_start_time:
|
|
|
+ timeType = STARTDATE;
|
|
|
+ TimeSelectionPicker.getInstance().show();
|
|
|
+ break;
|
|
|
+ case R.id.tv_end_time:
|
|
|
+ timeType = ENDDATE;
|
|
|
+ TimeSelectionPicker.getInstance().show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ TimeSelectionPicker.getInstance().removeListener(this);
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.M)
|
|
|
+ @Override
|
|
|
+ public void onTimeSelect(Date date) {
|
|
|
+ String time = DateUtils.DateToString(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (timeType == STARTDATE) {
|
|
|
+ startTime = time;
|
|
|
+ tvStartTime.setBackgroundResource(R.drawable.shape_blue_18);
|
|
|
+ tvStartTime.setTextColor(getContext().getColor(R.color.white));
|
|
|
+ tvStartTime.setText(time);
|
|
|
+ } else if (timeType == ENDDATE) {
|
|
|
+ tvEndTime.setBackgroundResource(R.drawable.shape_blue_18);
|
|
|
+ tvEndTime.setTextColor(getContext().getColor(R.color.white));
|
|
|
+ endTime = time;
|
|
|
+ tvEndTime.setText(time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public interface OnSuccessListener {
|
|
|
+ void onClick(List<MobileDatumResponseBean> camera, List<SelectTypeBean> type, String star, String end);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void reset() {
|
|
|
+ for (int i = 0; i < mList.size(); i++) {
|
|
|
+ mList.get(i).setSelect(false);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < typeBeanList.size(); i++) {
|
|
|
+ typeBeanList.get(i).setSelect(false);
|
|
|
+ }
|
|
|
+ startTime = "";
|
|
|
+ endTime = "";
|
|
|
+ tvStartTime.setText("");
|
|
|
+ tvEndTime.setText("");
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ typeAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setData(List<MobileDatumResponseBean> mList, List<SelectTypeBean> typeBeanList, String startTime, String endTime) {
|
|
|
+ this.mList = mList;
|
|
|
+ this.typeBeanList = typeBeanList;
|
|
|
+ this.startTime = startTime;
|
|
|
+ this.endTime = endTime;
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ typeAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|