Search in sources :

Example 6 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method loadAlbums.

@Override
void loadAlbums(final Activity context, boolean hiddenFolders) {
    final long startTime = System.currentTimeMillis();
    final ArrayList<Album> albums = new ArrayList<>();
    // Return only video and image metadata.
    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
    Uri queryUri = MediaStore.Files.getContentUri("external");
    CursorLoader cursorLoader = new CursorLoader(context, queryUri, projection, selection, // Selection args (none).
    null, MediaStore.Files.FileColumns.DATE_ADDED);
    final Cursor cursor = cursorLoader.loadInBackground();
    if (cursor == null) {
        return;
    }
    // search hiddenFolders
    if (hiddenFolders) {
        ArrayList<Album> hiddenAlbums = checkHiddenFolders(context);
        albums.addAll(hiddenAlbums);
    }
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            if (cursor.moveToFirst()) {
                String path;
                long dateTaken, id;
                int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
                int idColumn = cursor.getColumnIndex(BaseColumns._ID);
                do {
                    path = cursor.getString(pathColumn);
                    AlbumItem albumItem = AlbumItem.getInstance(context, path);
                    if (albumItem != null) {
                        // set dateTaken
                        int dateTakenColumn = cursor.getColumnIndex(!(albumItem instanceof Video) ? MediaStore.Images.ImageColumns.DATE_TAKEN : MediaStore.Video.VideoColumns.DATE_TAKEN);
                        dateTaken = cursor.getLong(dateTakenColumn);
                        albumItem.setDate(dateTaken);
                        id = cursor.getLong(idColumn);
                        Uri uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id);
                        albumItem.setUri(uri);
                        // search bucket
                        boolean foundBucket = false;
                        for (int i = 0; i < albums.size(); i++) {
                            if (albums.get(i).getPath().equals(FileOperation.Util.getParentPath(path))) {
                                albums.get(i).getAlbumItems().add(0, albumItem);
                                foundBucket = true;
                                break;
                            }
                        }
                        if (!foundBucket) {
                            // no bucket found
                            String bucketPath = FileOperation.Util.getParentPath(path);
                            if (bucketPath != null) {
                                albums.add(new Album().setPath(bucketPath));
                                albums.get(albums.size() - 1).getAlbumItems().add(0, albumItem);
                            }
                        }
                    }
                } while (cursor.moveToNext());
            }
            cursor.close();
            // done loading media with content resolver
            MediaProvider.OnMediaLoadedCallback callback = getCallback();
            if (callback != null) {
                callback.onMediaLoaded(albums);
            }
            Log.d("MediaStoreRetriever", "onMediaLoaded(): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) Uri(android.net.Uri) CursorLoader(android.support.v4.content.CursorLoader) Video(us.koller.cameraroll.data.models.Video)

Example 7 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class AlbumHolder method loadImage.

void loadImage(final ImageView image) {
    if (album.getAlbumItems().size() == 0) {
        Glide.with(getContext()).load(R.drawable.error_placeholder).apply(new RequestOptions().skipMemoryCache(true)).into(image);
        return;
    }
    final AlbumItem coverImage = album.getAlbumItems().get(0);
    Glide.with(getContext()).asBitmap().load(coverImage.getPath()).listener(new RequestListener<Bitmap>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
            coverImage.error = true;
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }

        @Override
        public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
            if (!coverImage.hasFadedIn) {
                coverImage.hasFadedIn = true;
                ColorFade.fadeSaturation(image);
            }
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }
    }).apply(coverImage.getGlideRequestOptions(getContext())).into(image);
}
Also used : Bitmap(android.graphics.Bitmap) RequestOptions(com.bumptech.glide.request.RequestOptions) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) GlideException(com.bumptech.glide.load.engine.GlideException) DataSource(com.bumptech.glide.load.DataSource)

Example 8 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
    final AlbumItem albumItem = getData().getAlbumItems().get(position);
    if (!albumItem.equals(((AlbumItemHolder) holder).getAlbumItem())) {
        ((AlbumItemHolder) holder).setAlbumItem(albumItem);
    }
    boolean selected = getSelectorManager().isItemSelected(albumItem.getPath());
    ((AlbumItemHolder) holder).setSelected(selected);
    holder.itemView.setTag(albumItem.getPath());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (getSelectorMode()) {
                onItemSelected((AlbumItemHolder) holder);
            } else {
                Log.d("AlbumAdapter", "onClick: " + getData().getPath());
                Context context = holder.itemView.getContext();
                Intent intent = new Intent(context, ItemActivity.class);
                intent.putExtra(ItemActivity.ALBUM_ITEM, albumItem);
                intent.putExtra(ItemActivity.ALBUM_PATH, getData().getPath());
                intent.putExtra(ItemActivity.ITEM_POSITION, getData().getAlbumItems().indexOf(albumItem));
                if (Settings.getInstance(context).showAnimations()) {
                    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context, holder.itemView.findViewById(R.id.image), albumItem.getPath());
                    ActivityCompat.startActivityForResult((Activity) context, intent, ItemActivity.VIEW_IMAGE, options.toBundle());
                } else {
                    ActivityCompat.startActivityForResult((Activity) context, intent, ItemActivity.VIEW_IMAGE, null);
                }
            }
        }
    });
    if (getSelectorManager().callbacksAttached()) {
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!getSelectorMode()) {
                    setSelectorMode(true);
                    clearSelectedItemsList();
                }
                onItemSelected((AlbumItemHolder) holder);
                if (dragSelectEnabled()) {
                    // notify DragSelectTouchListener
                    boolean selected = getSelectorManager().isItemSelected(albumItem.getPath());
                    if (selected) {
                        int position = getData().getAlbumItems().indexOf(albumItem);
                        dragSelectTouchListener.startDragSelection(position);
                    }
                }
                return true;
            }
        });
    }
}
Also used : Context(android.content.Context) AlbumItemHolder(us.koller.cameraroll.adapter.album.viewHolder.AlbumItemHolder) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) ItemActivity(us.koller.cameraroll.ui.ItemActivity) AlbumActivity(us.koller.cameraroll.ui.AlbumActivity) Activity(android.app.Activity) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) ItemActivity(us.koller.cameraroll.ui.ItemActivity)

Example 9 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class NestedRecyclerViewAlbumHolder method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    final String[] paths = ((NestedAdapter) nestedRecyclerView.getAdapter()).cancelSelectorMode((Activity) getContext());
    cancelSelectorMode();
    Activity a;
    if (getContext() instanceof Activity) {
        a = ((Activity) getContext());
    } else {
        Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show();
        return false;
    }
    Intent intent;
    switch(item.getItemId()) {
        case R.id.share:
            // share multiple items
            ArrayList<Uri> uris = new ArrayList<>();
            for (int i = 0; i < paths.length; i++) {
                uris.add(StorageUtil.getContentUri(getContext(), paths[i]));
            }
            intent = new Intent();
            intent.setAction(Intent.ACTION_SEND_MULTIPLE).setType(MediaType.getMimeType(getContext(), uris.get(0))).putExtra(Intent.EXTRA_STREAM, uris);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (intent.resolveActivity(getContext().getPackageManager()) != null) {
                a.startActivity(Intent.createChooser(intent, getContext().getString(R.string.share)));
            }
            break;
        case R.id.copy:
        case R.id.move:
            intent = new Intent(getContext(), FileOperationDialogActivity.class);
            intent.setAction(item.getItemId() == R.id.copy ? FileOperationDialogActivity.ACTION_COPY : FileOperationDialogActivity.ACTION_MOVE);
            intent.putExtra(FileOperationDialogActivity.FILES, paths);
            a.startActivityForResult(intent, AlbumActivity.FILE_OP_DIALOG_REQUEST);
            break;
        case R.id.delete:
            Context c = getContext();
            String title;
            if (paths.length == 1) {
                AlbumItem albumItem = AlbumItem.getInstance(paths[0]);
                title = getContext().getString(R.string.delete_item, albumItem.getType(getContext()));
            } else {
                title = getContext().getString(R.string.delete_files, paths.length);
            }
            new AlertDialog.Builder(c, theme.getDialogThemeRes()).setTitle(title).setNegativeButton(c.getString(R.string.no), null).setPositiveButton(c.getString(R.string.delete), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    deleteItems(paths);
                }
            }).create().show();
            break;
        default:
            break;
    }
    return false;
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AlbumActivity(us.koller.cameraroll.ui.AlbumActivity) Activity(android.app.Activity) FileOperationDialogActivity(us.koller.cameraroll.ui.FileOperationDialogActivity) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Intent(android.content.Intent) Uri(android.net.Uri) FileOperationDialogActivity(us.koller.cameraroll.ui.FileOperationDialogActivity)

Example 10 with AlbumItem

use of us.koller.cameraroll.data.models.AlbumItem in project Camera-Roll-Android-App by kollerlukas.

the class IntentReceiver method view.

private void view(Intent intent) {
    Uri uri = intent.getData();
    if (uri == null) {
        Toast.makeText(this, getString(R.string.error) + ": Uri = null", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, MainActivity.class));
        this.finish();
        return;
    }
    Album album = new Album().setPath("");
    AlbumItem albumItem;
    String mimeType = intent.getType();
    if (mimeType != null) {
        albumItem = AlbumItem.getInstance(this, uri, mimeType);
    } else {
        albumItem = AlbumItem.getInstance(this, uri);
    }
    if (albumItem == null) {
        Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show();
        this.finish();
        return;
    }
    album.getAlbumItems().add(albumItem);
    if (albumItem instanceof Video) {
        Intent view_video = new Intent(this, VideoPlayerActivity.class).setData(uri);
        startActivity(view_video);
    } else {
        Intent view_photo = new Intent(this, ItemActivity.class).setData(uri).putExtra(ItemActivity.ALBUM_ITEM, albumItem).putExtra(ItemActivity.VIEW_ONLY, true).putExtra(ItemActivity.ALBUM, album).putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem)).addFlags(intent.getFlags());
        startActivity(view_photo);
    }
    this.finish();
}
Also used : Video(us.koller.cameraroll.data.models.Video) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Intent(android.content.Intent) MainActivity(us.koller.cameraroll.ui.MainActivity) Uri(android.net.Uri) VideoPlayerActivity(us.koller.cameraroll.ui.VideoPlayerActivity)

Aggregations

AlbumItem (us.koller.cameraroll.data.models.AlbumItem)13 View (android.view.View)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 Album (us.koller.cameraroll.data.models.Album)4 Uri (android.net.Uri)3 ArrayList (java.util.ArrayList)3 Video (us.koller.cameraroll.data.models.Video)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 RequiresApi (android.support.annotation.RequiresApi)2 AlbumActivity (us.koller.cameraroll.ui.AlbumActivity)2 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)2 ClipData (android.content.ClipData)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1