@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); } } } }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int t = AndroidUtilities.dp(8); attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight()); progressView.layout(0, t, width, t + progressView.getMeasuredHeight()); lineView.layout( 0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight()); int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3; for (int a = 0; a < 8; a++) { int y = AndroidUtilities.dp(105 + 95 * (a / 4)); int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff); views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight()); } }
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 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(); }
public ChatAttachView(Context context) { super(context); NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded); if (MediaController.allPhotosAlbumEntry == null) { if (Build.VERSION.SDK_INT >= 21) { MediaController.loadGalleryPhotosAlbums(0); } loading = true; } views[8] = attachPhotoRecyclerView = new RecyclerListView(context); attachPhotoRecyclerView.setVerticalScrollBarEnabled(true); attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context)); attachPhotoRecyclerView.setClipToPadding(false); attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0); attachPhotoRecyclerView.setItemAnimator(null); attachPhotoRecyclerView.setLayoutAnimation(null); if (Build.VERSION.SDK_INT >= 9) { attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); } addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager); photoAttachAdapter.setDelegate( new PhotoAttachAdapter.PhotoAttachAdapterDelegate() { @Override public void selectedPhotosChanged() { updatePhotosButton(); } }); attachPhotoRecyclerView.setOnItemClickListener( new RecyclerListView.OnItemClickListener() { @SuppressWarnings("unchecked") @Override public void onItemClick(View view, int position) { if (baseFragment == null || baseFragment.getParentActivity() == null) { return; } ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos; if (position < 0 || position >= arrayList.size()) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); PhotoViewer.getInstance() .openPhotoForSelect(arrayList, position, 0, ChatAttachView.this, baseFragment); AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus()); } }); views[9] = progressView = new EmptyTextProgressView(context); if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { progressView.setText( LocaleController.getString("PermissionStorage", R.string.PermissionStorage)); progressView.setTextSize(16); } else { progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); progressView.setTextSize(20); } addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoRecyclerView.setEmptyView(progressView); views[10] = lineView = new View(getContext()); lineView.setBackgroundColor(0xffd2d2d2); addView( lineView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT)); CharSequence[] items = new CharSequence[] { LocaleController.getString("ChatCamera", R.string.ChatCamera), LocaleController.getString("ChatGallery", R.string.ChatGallery), LocaleController.getString("ChatVideo", R.string.ChatVideo), LocaleController.getString("AttachAudio", R.string.AttachAudio), LocaleController.getString("ChatDocument", R.string.ChatDocument), LocaleController.getString("AttachContact", R.string.AttachContact), LocaleController.getString("ChatLocation", R.string.ChatLocation), "" }; int itemIcons[] = new int[] { R.drawable.attach_camera_states, R.drawable.attach_gallery_states, R.drawable.attach_video_states, R.drawable.attach_audio_states, R.drawable.attach_file_states, R.drawable.attach_contact_states, R.drawable.attach_location_states, R.drawable.attach_hide_states, }; for (int a = 0; a < 8; a++) { AttachButton attachButton = new AttachButton(context); attachButton.setTextAndIcon(items[a], itemIcons[a]); addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP)); attachButton.setTag(a); views[a] = attachButton; if (a == 7) { sendPhotosButton = attachButton; sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0); } attachButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (delegate != null) { delegate.didPressedButton((Integer) v.getTag()); } } }); } setOnTouchListener( new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); if (loading) { progressView.showProgress(); } else { progressView.showTextView(); } }