Exemplo n.º 1
0
  public void updatePhotosButton() {
    int count = photoAttachAdapter.getSelectedPhotos().size();
    if (count == 0) {
      sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
      sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_hide_states);
      sendPhotosButton.imageView.setImageResource(R.drawable.attach_hide2);
      sendPhotosButton.textView.setText("");
    } else {
      sendPhotosButton.imageView.setPadding(AndroidUtilities.dp(2), 0, 0, 0);
      sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_send_states);
      sendPhotosButton.imageView.setImageResource(R.drawable.attach_send2);
      sendPhotosButton.textView.setText(
          LocaleController.formatString(
              "SendItems", R.string.SendItems, String.format("(%d)", count)));
    }

    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);
    }
  }
Exemplo n.º 2
0
  @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());
    }
  }
Exemplo n.º 3
0
 @Override
 public void didReceivedNotification(int id, Object... args) {
   if (id == NotificationCenter.albumsDidLoaded) {
     if (photoAttachAdapter != null) {
       loading = false;
       progressView.showTextView();
       photoAttachAdapter.notifyDataSetChanged();
     }
   }
 }
Exemplo n.º 4
0
  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();
    }
  }