xuxiuxi
2017-05-12 e1bcafb39828e18a3605d94aad20376484b56b26
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/adapter/SurveillanceFragment.java
@@ -13,19 +13,22 @@
import com.camnter.easyrecyclerview.adapter.EasyRecyclerViewAdapter;
import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
import java.util.List;
import cn.com.basic.face.base.MainActivity;
import cn.com.basic.face.dialog.SurveillancePhotoDialog;
import cn.com.basic.face.discern.common.CommonVariables;
import cn.com.basic.face.discern.query.item.CheckInQueryItem;
import cn.com.basic.face.discern.query.item.SurveillanceQueryItem;
import cn.com.basic.face.fragment.*;
import cn.com.basic.face.util.AppApi;
import cn.com.basic.face.util.Constant;
import cn.com.basic.face.util.WindowsUtil;
public class SurveillanceFragment {
    public static class SurveillanceBottomListViewAdapter extends EasyRecyclerViewAdapter {
    public static class SurveillanceBottomVisitorListViewAdapter extends EasyRecyclerViewAdapter {
        private Context context;
        public SurveillanceBottomListViewAdapter(Context context) {
        public SurveillanceBottomVisitorListViewAdapter(Context context) {
            this.context = context;
        }
@@ -66,8 +69,8 @@
            RelativeLayout mLayout = holder.findViewById(R.id.fragment_home_bottom_register_cell_relative_layout);
            ViewGroup.LayoutParams layoutParams = mLayout.getLayoutParams();
            layoutParams.height = WindowsUtil.dip2px(context, 127);
            layoutParams.width = WindowsUtil.dip2px(context, 104);
            layoutParams.height = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h127dp);
            layoutParams.width = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h122dp);
            mLayout.setLayoutParams(layoutParams);
            final Object data = this.getItem(position);
@@ -92,9 +95,11 @@
                    @Override
                    public void onClick(View view) {
                        MainActivity.selectPage(1);
                        RegisterFragment.getInstance().setRegisterInfo(getVo(item));
                        RegisterFragment.getInstance().setRegisterInfo(getVo(item));//java.lang.OutOfMemoryError: Failed to allocate a 25338980 byte allocation with 15827186 free bytes and 15MB until OOM
                        if(item.getBitmap() != null) {
                            RegisterFragment.getInstance().setChoosePhoto(item.getBitmap());
                            RegisterFragment.getInstance().setSurveillanceQueryItem_selectPhoto(item);
                            RegisterFragment.selectedSurveillancePhotoId = item.getIdForSelect();
                        }
                    }
                });
@@ -108,8 +113,8 @@
            RelativeLayout mLayout = holder.findViewById(R.id.fragment_supervisory_bottom_visitor_cell_relative_layout);
            ViewGroup.LayoutParams layoutParams = mLayout.getLayoutParams();
            layoutParams.height = WindowsUtil.dip2px(context, 127);
            layoutParams.width = WindowsUtil.dip2px(context, 104);
            layoutParams.height = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h127dp);
            layoutParams.width = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h122dp);
            mLayout.setLayoutParams(layoutParams);
            ImageView fragment_home_bottom_visitor_cell_photo = (ImageView) mLayout.findViewById(R.id.fragment_home_bottom_visitor_cell_photo);
@@ -199,4 +204,134 @@
        }
    }
    public static class SurveillanceBottomAttendanceListViewAdapter extends EasyRecyclerViewAdapter {
        private Context context;
        public SurveillanceBottomAttendanceListViewAdapter(Context context) {
            this.context = context;
        }
        @Override
        public int[] getItemLayouts() {
            return new int[]{R.layout.fragment_surveillance_bottom_attendance_cell, R.layout.fragment_surveillance_bottom_attendance_blank_cell};
        }
        @Override
        public void onBindRecycleViewHolder(EasyRecyclerViewHolder viewHolder, int position) {
            RelativeLayout mLayout = viewHolder.findViewById(R.id.fragment_supervisory_bottom_attendance_cell_relative_layout);
            ViewGroup.LayoutParams layoutParams = mLayout.getLayoutParams();
            layoutParams.height = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h127dp);
            layoutParams.width = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h122dp);
            mLayout.setLayoutParams(layoutParams);
            ImageView fragment_home_bottom_attendance_cell_photo = (ImageView) mLayout.findViewById(R.id.fragment_home_bottom_attendance_cell_photo);
            TextView fragment_home_bottom_attendance_cell_name = (TextView) mLayout.findViewById(R.id.fragment_home_bottom_attendance_cell_name);
            TextView fragment_home_bottom_attendance_cell_status = (TextView) mLayout.findViewById(R.id.fragment_home_bottom_attendance_cell_status);
            Object data = this.getItem(position);
            fragment_home_bottom_attendance_cell_name.setText("");
            if (data instanceof SurveillanceQueryItem) {
                final SurveillanceQueryItem item = (SurveillanceQueryItem)data;
                fragment_home_bottom_attendance_cell_name.setText(item.getUsername());
                if (item.getImagePath() != null && !item.getImagePath().equals("")) {
                    fragment_home_bottom_attendance_cell_photo.setImageURI(Uri.parse(AppApi.IMAGE_URL_BASE +item.getImagePath()));
                } else {
                    if (item.getBitmap() != null) {
                        fragment_home_bottom_attendance_cell_photo.setImageBitmap(item.getBitmap());
                    } else {
                        fragment_home_bottom_attendance_cell_photo.setImageResource(R.drawable.u45);
                    }
                }
                fragment_home_bottom_attendance_cell_status.setText(item.getStatus());
            }
        }
        @Override
        public int getRecycleViewItemType(int position) {
            return 0;
        }
        private CheckInQueryItem getVo(SurveillanceQueryItem item) {
            return JSON.parseObject(JSON.toJSONString(item), CheckInQueryItem.class);
        }
    }
    public static class SurveillancePhotoSelectListViewAdapter extends EasyRecyclerViewAdapter {
        private Context context;
        public SurveillancePhotoSelectListViewAdapter(Context context) {
            this.context = context;
        }
        public static int selectPhotoOrUploadPhoto;
        @Override
        public int[] getItemLayouts() {
            return new int[]{R.layout.fragment_surveillance_photo_cell, R.layout.fragment_surveillance_photo_blank_cell};
        }
        @Override
        public void onBindRecycleViewHolder(EasyRecyclerViewHolder viewHolder, int position) {
            RelativeLayout mLayout = viewHolder.findViewById(R.id.fragment_surveillance_photo_cell_relative_layout);
            ViewGroup.LayoutParams layoutParams = mLayout.getLayoutParams();
            layoutParams.height = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h127dp);
            layoutParams.width = (int)MainActivity.getInstance().getResources().getDimension(R.dimen.h122dp);
            mLayout.setLayoutParams(layoutParams);
            if (((SurveillanceQueryItem)getList().get(position)).getRegisterOrCheckIn() != Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
                return;
            }
            ImageView fragment_surveillance_photo_cell_photo = (ImageView) mLayout.findViewById(R.id.fragment_surveillance_photo_cell_photo);
            final View fragment_surveillance_photo_cell_select = mLayout.findViewById(R.id.fragment_surveillance_photo_cell_select);
            Object data = this.getItem(position);
            if (data instanceof SurveillanceQueryItem) {
                final SurveillanceQueryItem item = (SurveillanceQueryItem)data;
                fragment_surveillance_photo_cell_select.setVisibility(item.isSurveillancePhotoSelected()
                        ? View.VISIBLE : View.INVISIBLE
                );
                fragment_surveillance_photo_cell_photo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (selectPhotoOrUploadPhoto == CommonVariables.SelectPhotoType.SELECT_PHOTO) {
                            RegisterFragment.getInstance().set_fragment_register_surveillance_photo(item);
                            RegisterFragment.selectedSurveillancePhotoId = item.getIdForSelect();
                        }
                        if (selectPhotoOrUploadPhoto == CommonVariables.SelectPhotoType.UPLOAD_PHOTO) {
                            RegisterFragment.getInstance().set_fragment_register_upload_custom_photo(item);
                            RegisterFragment.selectedCustomPhotoId = item.getIdForSelect();
                        }
                        for (SurveillanceQueryItem queryItem : (List<SurveillanceQueryItem>)getList()) {
                            queryItem.setSurveillancePhotoSelected(false);
                        }
                        item.setSurveillancePhotoSelected(true);
                        notifyDataSetChanged();
                    }
                });
                if (item.getImagePath() != null && !item.getImagePath().equals("")) {
                    fragment_surveillance_photo_cell_photo.setImageURI(Uri.parse(AppApi.IMAGE_URL_BASE +item.getImagePath()));
                } else {
                    if (item.getBitmap() != null) {
                        fragment_surveillance_photo_cell_photo.setImageBitmap(item.getBitmap());
                    } else {
                        fragment_surveillance_photo_cell_photo.setImageResource(R.drawable.u45);
                    }
                }
            }
        }
        @Override
        public int getRecycleViewItemType(int position) {
            if (((SurveillanceQueryItem)getList().get(position)).getRegisterOrCheckIn() != Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
                return 1;
            }
            return 0;
        }
        private CheckInQueryItem getVo(SurveillanceQueryItem item) {
            return JSON.parseObject(JSON.toJSONString(item), CheckInQueryItem.class);
        }
    }
}