Search in sources :

Example 11 with Album

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

the class StorageRetriever method loadAlbums.

@Override
void loadAlbums(final Activity context, final boolean hiddenFolders) {
    final long startTime = System.currentTimeMillis();
    final ArrayList<Album> albums = new ArrayList<>();
    // handle timeout after 10 seconds
    handler = new Handler();
    timeout = new Runnable() {

        @Override
        public void run() {
            Toast.makeText(context, "timeout", Toast.LENGTH_SHORT).show();
            MediaProvider.OnMediaLoadedCallback callback = getCallback();
            if (callback != null) {
                callback.timeout();
            }
        }
    };
    handler.postDelayed(timeout, 10000);
    // load media from storage
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            searchStorage(context, new StorageSearchCallback() {

                @Override
                public void onThreadResult(ItemLoader.Result result) {
                    if (result != null) {
                        albums.addAll(result.albums);
                    }
                }

                @Override
                public void done() {
                    if (!hiddenFolders) {
                        for (int i = albums.size() - 1; i >= 0; i--) {
                            if (albums.get(i) == null || albums.get(i).isHidden()) {
                                albums.remove(i);
                            }
                        }
                    }
                    // done loading media from storage
                    MediaProvider.OnMediaLoadedCallback callback = getCallback();
                    if (callback != null) {
                        callback.onMediaLoaded(albums);
                    }
                    cancelTimeout();
                    Log.d("StorageRetriever", "onMediaLoaded(" + String.valueOf(THREAD_COUNT) + "): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
                }
            });
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) Handler(android.os.Handler) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider)

Example 12 with Album

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

the class MainAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    final Album album = getData().get(position);
    ((AlbumHolder) holder).setAlbum(album);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(holder.itemView.getContext(), AlbumActivity.class);
            // intent.putExtra(AlbumActivity.ALBUM, album);
            intent.putExtra(AlbumActivity.ALBUM_PATH, album.getPath());
            if (pickPhotos()) {
                Context c = holder.itemView.getContext();
                boolean allowMultiple = false;
                if (c instanceof Activity) {
                    Activity a = (Activity) c;
                    allowMultiple = a.getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
                }
                intent.setAction(MainActivity.PICK_PHOTOS);
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
            } else {
                intent.setAction(AlbumActivity.VIEW_ALBUM);
            }
            ActivityOptionsCompat options;
            Activity context = (Activity) holder.itemView.getContext();
            if (!pickPhotos()) {
                // noinspection unchecked
                options = ActivityOptionsCompat.makeSceneTransitionAnimation(context);
                context.startActivityForResult(intent, MainActivity.REFRESH_PHOTOS_REQUEST_CODE, options.toBundle());
            } else {
                View toolbar = context.findViewById(R.id.toolbar);
                options = ActivityOptionsCompat.makeSceneTransitionAnimation(context, toolbar, context.getString(R.string.toolbar_transition_name));
                context.startActivityForResult(intent, MainActivity.PICK_PHOTOS_REQUEST_CODE, options.toBundle());
            }
        }
    });
}
Also used : Context(android.content.Context) AlbumActivity(us.koller.cameraroll.ui.AlbumActivity) AlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.AlbumHolder) SimpleAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.SimpleAlbumHolder) NestedRecyclerViewAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder) Album(us.koller.cameraroll.data.models.Album) MainActivity(us.koller.cameraroll.ui.MainActivity) AlbumActivity(us.koller.cameraroll.ui.AlbumActivity) ThemeableActivity(us.koller.cameraroll.ui.ThemeableActivity) Activity(android.app.Activity) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat)

Example 13 with Album

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

the class NoFolderRecyclerViewAdapter method setData.

@Override
public AbstractRecyclerViewAdapter<ArrayList<Album>> setData(ArrayList<Album> data) {
    if (data == null) {
        return this;
    }
    Album album = new Album().setPath(MediaProvider.SINGLE_FOLDER_PATH);
    for (int i = 0; i < data.size(); i++) {
        album.getAlbumItems().addAll(data.get(i).getAlbumItems());
    }
    int sortBy = Settings.getInstance(context).sortAlbumsBy();
    SortUtil.sort(album.getAlbumItems(), sortBy);
    albumAdapter.setData(album);
    notifyDataSetChanged();
    return this;
}
Also used : Album(us.koller.cameraroll.data.models.Album)

Example 14 with Album

use of us.koller.cameraroll.data.models.Album 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)

Example 15 with Album

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

the class ItemActivity method renameAlbumItem.

public void renameAlbumItem() {
    File_POJO file = new File_POJO(albumItem.getPath(), true).setName(albumItem.getName());
    Rename.Util.getRenameDialog(this, file, new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    // refresh data
                    final Activity activity = ItemActivity.this;
                    String newFilePath = intent.getStringExtra(Rename.NEW_FILE_PATH);
                    if (newFilePath == null) {
                        return;
                    }
                    int index = newFilePath.lastIndexOf("/");
                    final String albumPath = newFilePath.substring(0, index);
                    getIntent().putExtra(ALBUM_PATH, albumPath);
                    getIntent().putExtra(ITEM_POSITION, album.getAlbumItems().indexOf(albumItem));
                    boolean hiddenFolders = Settings.getInstance(activity).getHiddenFolders();
                    new MediaProvider(activity).loadAlbums(activity, hiddenFolders, new MediaProvider.OnMediaLoadedCallback() {

                        @Override
                        public void onMediaLoaded(ArrayList<Album> albums) {
                            // reload activity
                            MediaProvider.loadAlbum(activity, albumPath, new MediaProvider.OnAlbumLoadedCallback() {

                                @Override
                                public void onAlbumLoaded(Album album) {
                                    ItemActivity.this.albumItem = null;
                                    ItemActivity.this.album = album;
                                    ItemActivity.this.onAlbumLoaded(null);
                                    // notify AlbumActivity
                                    LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(new Intent(AlbumActivity.ALBUM_ITEM_RENAMED));
                                }
                            });
                        }

                        @Override
                        public void timeout() {
                            finish();
                        }

                        @Override
                        public void needPermission() {
                            finish();
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    }).show();
}
Also used : Context(android.content.Context) Activity(android.app.Activity) Album(us.koller.cameraroll.data.models.Album) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) SpannableString(android.text.SpannableString) BroadcastReceiver(android.content.BroadcastReceiver) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider)

Aggregations

Album (us.koller.cameraroll.data.models.Album)21 MediaProvider (us.koller.cameraroll.data.provider.MediaProvider)8 Intent (android.content.Intent)7 RecyclerView (android.support.v7.widget.RecyclerView)7 View (android.view.View)6 ArrayList (java.util.ArrayList)6 VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)5 Context (android.content.Context)4 Settings (us.koller.cameraroll.data.Settings)4 Activity (android.app.Activity)3 BroadcastReceiver (android.content.BroadcastReceiver)3 Uri (android.net.Uri)3 RequiresApi (android.support.annotation.RequiresApi)3 ActionBar (android.support.v7.app.ActionBar)3 SpannableString (android.text.SpannableString)3 AlbumItem (us.koller.cameraroll.data.models.AlbumItem)3 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)3 Cursor (android.database.Cursor)2 Handler (android.os.Handler)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2