Search in sources :

Example 1 with FileHolder

use of us.koller.cameraroll.adapter.fileExplorer.viewHolder.FileHolder in project Camera-Roll-Android-App by kollerlukas.

the class FileExplorerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    final File_POJO file = files.getChildren().get(position);
    ((FileHolder) holder).setFile(file);
    ((FileHolder) holder).setSelected(selected_items[position]);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mode == SELECTOR_MODE) {
                onItemSelect(file);
            } else if (file.isMedia) {
                int index = file.getPath().lastIndexOf("/");
                String path = file.getPath().substring(0, index);
                // load Album
                final Album album = new Album().setPath(path);
                AlbumItem albumItem = AlbumItem.getInstance(file.getPath());
                if (albumItem != null) {
                    album.getAlbumItems().add(albumItem);
                }
                if (albumItem != null) {
                    // create intent
                    Intent intent = new Intent(holder.itemView.getContext(), IntentReceiver.class).setAction(Intent.ACTION_VIEW).setData(albumItem.getUri(holder.itemView.getContext()));
                    holder.itemView.getContext().startActivity(intent);
                }
            } else {
                // to keep the ripple animation
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        directoryChangeCallback.changeDir(file.getPath());
                    }
                }, 300);
            }
        }
    });
    holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            onItemSelect(file);
            return true;
        }
    });
    // clicking on folder icons also selects this item
    holder.itemView.findViewById(R.id.folder_indicator).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            onItemSelect(file);
        }
    });
}
Also used : Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Handler(android.os.Handler) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) FileHolder(us.koller.cameraroll.adapter.fileExplorer.viewHolder.FileHolder)

Aggregations

Intent (android.content.Intent)1 Handler (android.os.Handler)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 FileHolder (us.koller.cameraroll.adapter.fileExplorer.viewHolder.FileHolder)1 Album (us.koller.cameraroll.data.models.Album)1 AlbumItem (us.koller.cameraroll.data.models.AlbumItem)1 File_POJO (us.koller.cameraroll.data.models.File_POJO)1