@Override
 public void willSwitchFromPhoto(
     MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
   PhotoAttachPhotoCell cell = getCellForIndex(index);
   if (cell != null) {
     cell.getCheckBox().setVisibility(View.VISIBLE);
   }
 }
 @Override
 public Bitmap getThumbForPhoto(
     MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
   PhotoAttachPhotoCell cell = getCellForIndex(index);
   if (cell != null) {
     return cell.getImageView().getImageReceiver().getBitmap();
   }
   return null;
 }
 @Override
 public void willHidePhotoViewer() {
   int count = attachPhotoRecyclerView.getChildCount();
   for (int a = 0; a < count; a++) {
     View view = attachPhotoRecyclerView.getChildAt(a);
     if (view instanceof PhotoAttachPhotoCell) {
       PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
       if (cell.getCheckBox().getVisibility() != VISIBLE) {
         cell.getCheckBox().setVisibility(VISIBLE);
       }
     }
   }
 }
 private PhotoAttachPhotoCell getCellForIndex(int index) {
   int count = attachPhotoRecyclerView.getChildCount();
   for (int a = 0; a < count; a++) {
     View view = attachPhotoRecyclerView.getChildAt(a);
     if (view instanceof PhotoAttachPhotoCell) {
       PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
       int num = (Integer) cell.getImageView().getTag();
       if (num < 0 || num >= MediaController.allPhotosAlbumEntry.photos.size()) {
         continue;
       }
       if (num == index) {
         return cell;
       }
     }
   }
   return null;
 }
 @Override
 public PhotoViewer.PlaceProviderObject getPlaceForPhoto(
     MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
   PhotoAttachPhotoCell cell = getCellForIndex(index);
   if (cell != null) {
     int coords[] = new int[2];
     cell.getImageView().getLocationInWindow(coords);
     PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
     object.viewX = coords[0];
     object.viewY =
         coords[1] - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
     object.parentView = attachPhotoRecyclerView;
     object.imageReceiver = cell.getImageView().getImageReceiver();
     object.thumb = object.imageReceiver.getBitmap();
     object.scale = ViewProxy.getScaleX(cell.getImageView());
     object.clipBottomAddition =
         (Build.VERSION.SDK_INT >= 21 ? 0 : -AndroidUtilities.statusBarHeight);
     cell.getCheckBox().setVisibility(View.GONE);
     return object;
   }
   return null;
 }
 @Override
 public void setPhotoChecked(int index) {
   boolean add = true;
   if (index < 0 || index >= MediaController.allPhotosAlbumEntry.photos.size()) {
     return;
   }
   MediaController.PhotoEntry photoEntry = MediaController.allPhotosAlbumEntry.photos.get(index);
   if (photoAttachAdapter.getSelectedPhotos().containsKey(photoEntry.imageId)) {
     photoAttachAdapter.getSelectedPhotos().remove(photoEntry.imageId);
     add = false;
   } else {
     photoAttachAdapter.getSelectedPhotos().put(photoEntry.imageId, photoEntry);
   }
   int count = attachPhotoRecyclerView.getChildCount();
   for (int a = 0; a < count; a++) {
     View view = attachPhotoRecyclerView.getChildAt(a);
     int num = (Integer) view.getTag();
     if (num == index) {
       ((PhotoAttachPhotoCell) view).setChecked(add, false);
       break;
     }
   }
   updatePhotosButton();
 }
 @Override
 public void updatePhotoAtIndex(int index) {
   PhotoAttachPhotoCell cell = getCellForIndex(index);
   if (cell != null) {
     cell.getImageView().setOrientation(0, true);
     MediaController.PhotoEntry photoEntry = MediaController.allPhotosAlbumEntry.photos.get(index);
     if (photoEntry.thumbPath != null) {
       cell.getImageView()
           .setImage(
               photoEntry.thumbPath,
               null,
               cell.getContext().getResources().getDrawable(R.drawable.nophotos));
     } else if (photoEntry.path != null) {
       cell.getImageView().setOrientation(photoEntry.orientation, true);
       cell.getImageView()
           .setImage(
               "thumb://" + photoEntry.imageId + ":" + photoEntry.path,
               null,
               cell.getContext().getResources().getDrawable(R.drawable.nophotos));
     } else {
       cell.getImageView().setImageResource(R.drawable.nophotos);
     }
   }
 }