Search in sources :

Example 1 with ViewHolder

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

the class ItemActivity method onAlbumLoaded.

private void onAlbumLoaded(Bundle savedInstanceState) {
    if (albumItem == null) {
        if (savedInstanceState == null) {
            int position = getIntent().getIntExtra(ITEM_POSITION, 0);
            if (album != null && position >= 0 && position < album.getAlbumItems().size()) {
                albumItem = album.getAlbumItems().get(position);
                albumItem.isSharedElement = true;
            }
        } else {
            albumItem = savedInstanceState.getParcelable(ALBUM_ITEM);
            if (albumItem != null && albumItem instanceof Photo) {
                Photo photo = (Photo) albumItem;
                ImageViewState imageViewState = (ImageViewState) savedInstanceState.getSerializable(IMAGE_VIEW_SAVED_STATE);
                photo.putImageViewSavedState(imageViewState);
            }
            if (savedInstanceState.getBoolean(INFO_DIALOG_SHOWN, false)) {
                showInfoDialog();
            }
        }
    }
    if (albumItem == null) {
        return;
    }
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(albumItem.getName());
    }
    viewPager = findViewById(R.id.view_pager);
    viewPager.setAdapter(new ItemAdapter(album));
    int currentItem = album.getAlbumItems().indexOf(albumItem);
    viewPager.setCurrentItem(currentItem >= 0 ? currentItem : 0, false);
    if (showAnimations()) {
        viewPager.setPageTransformer(false, new ParallaxTransformer());
    }
    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        private final int color = ContextCompat.getColor(ItemActivity.this, R.color.white);

        @Override
        public void onPageSelected(int position) {
            // set new AlbumItem
            albumItem = album.getAlbumItems().get(position);
            ColorFade.fadeToolbarTitleColor(toolbar, color, new ColorFade.ToolbarTitleFadeCallback() {

                @Override
                public void setTitle(Toolbar toolbar) {
                    toolbar.setTitle(albumItem.getName() != null ? albumItem.getName() : "");
                }
            });
            ViewHolder viewHolder = ((ItemAdapter) viewPager.getAdapter()).findViewHolderByTag(albumItem.getPath());
            if (viewHolder != null) {
                onShowViewHolder(viewHolder);
            }
        }
    });
    if (!enterTransitionPostponed()) {
        albumItem.isSharedElement = false;
        // there is no sharedElementTransition
        ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter();
        ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath());
        if (viewHolder != null) {
            onShowViewHolder(viewHolder);
        } else {
            ((ItemAdapter) viewPager.getAdapter()).addOnInstantiateItemCallback(new ViewPagerOnInstantiateItemCallback() {

                @Override
                public boolean onInstantiateItem(ViewHolder viewHolder) {
                    if (viewHolder.albumItem.getPath().equals(albumItem.getPath())) {
                        onShowViewHolder(viewHolder);
                        return false;
                    }
                    return true;
                }
            });
        }
    }
}
Also used : Photo(us.koller.cameraroll.data.models.Photo) ImageViewState(com.davemorrissey.labs.subscaleview.ImageViewState) ViewPager(android.support.v4.view.ViewPager) ParallaxTransformer(us.koller.cameraroll.util.ParallaxTransformer) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) ActionBar(android.support.v7.app.ActionBar) ItemAdapter(us.koller.cameraroll.adapter.item.ItemAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with ViewHolder

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

the class ItemAdapter method instantiateItem.

@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, int position) {
    AlbumItem albumItem = album.getAlbumItems().get(position);
    ViewHolder viewHolder;
    if (albumItem instanceof Video) {
        viewHolder = new VideoViewHolder(albumItem, position);
    } else if (albumItem instanceof Gif) {
        viewHolder = new GifViewHolder(albumItem, position);
    } else if (albumItem instanceof RAWImage) {
        viewHolder = new RAWImageViewHolder(albumItem, position);
    } else {
        viewHolder = new PhotoViewHolder(albumItem, position);
    }
    viewHolders.add(viewHolder);
    View v = viewHolder.getView(container);
    container.addView(v);
    if (callback != null) {
        boolean b = callback.onInstantiateItem(viewHolder);
        if (!b) {
            callback = null;
        }
    }
    return v;
}
Also used : RAWImage(us.koller.cameraroll.data.models.RAWImage) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) Gif(us.koller.cameraroll.data.models.Gif) Video(us.koller.cameraroll.data.models.Video) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) View(android.view.View) NonNull(android.support.annotation.NonNull)

Example 3 with ViewHolder

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

the class ItemAdapter method destroyItem.

@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    container.removeView((View) object);
    ViewHolder viewHolder = findViewHolderByPosition(position);
    if (viewHolder != null) {
        viewHolder.onDestroy();
        viewHolders.remove(viewHolder);
    }
}
Also used : PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder)

Example 4 with ViewHolder

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

the class ItemActivity method deletePhoto.

public void deletePhoto() {
    if (!MediaProvider.checkPermission(this)) {
        return;
    }
    if (albumItem == null) {
        return;
    }
    final File_POJO[] files = new File_POJO[] { new File_POJO(albumItem.getPath(), true) };
    registerLocalBroadcastReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            unregisterLocalBroadcastReceiver(this);
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    String path = albumItem.getPath();
                    Intent i = new Intent(AlbumActivity.ALBUM_ITEM_REMOVED).putExtra(ALBUM_ITEM_PATH, path);
                    // notify AlbumActivity
                    LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(i);
                    /*ItemActivity.this.setResult(RESULT_OK);
                        finish();*/
                    album.getAlbumItems().remove(albumItem);
                    viewPager.getAdapter().notifyDataSetChanged();
                    if (album.getAlbumItems().size() == 0) {
                        ItemActivity.this.setResult(RESULT_OK);
                        finish();
                        return;
                    }
                    albumItem = album.getAlbumItems().get(viewPager.getCurrentItem());
                    ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter();
                    ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath());
                    onShowViewHolder(viewHolder);
                    break;
                case FileOperation.FAILED:
                    // onBackPressed();
                    break;
                default:
                    break;
            }
        }
    });
    startService(FileOperation.getDefaultIntent(this, FileOperation.DELETE, files));
}
Also used : Context(android.content.Context) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) Intent(android.content.Intent) File_POJO(us.koller.cameraroll.data.models.File_POJO) SpannableString(android.text.SpannableString) BroadcastReceiver(android.content.BroadcastReceiver) ItemAdapter(us.koller.cameraroll.adapter.item.ItemAdapter)

Example 5 with ViewHolder

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

the class ItemActivity method getDefaultLocalBroadcastReceiver.

@Override
public BroadcastReceiver getDefaultLocalBroadcastReceiver() {
    return new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            switch(intent.getAction()) {
                case FileOperation.RESULT_DONE:
                    int type = intent.getIntExtra(FileOperation.TYPE, FileOperation.EMPTY);
                    if (type == FileOperation.MOVE) {
                        ArrayList<String> movedFilesPaths = intent.getStringArrayListExtra(Move.MOVED_FILES_PATHS);
                        for (int i = 0; i < movedFilesPaths.size(); i++) {
                            String path = movedFilesPaths.get(i);
                            // notify AlbumActivity
                            LocalBroadcastManager.getInstance(ItemActivity.this).sendBroadcast(new Intent(AlbumActivity.ALBUM_ITEM_REMOVED).putExtra(ALBUM_ITEM_PATH, path));
                            ItemActivity.this.setResult(RESULT_OK);
                            finish();
                        }
                    }
                    break;
                case DATA_CHANGED:
                    final int albumItemIndex = album.getAlbumItems().indexOf(albumItem);
                    String albumPath = getIntent().getStringExtra(ALBUM_PATH);
                    MediaProvider.loadAlbum(ItemActivity.this, albumPath, new MediaProvider.OnAlbumLoadedCallback() {

                        @Override
                        public void onAlbumLoaded(Album album) {
                            if (album == null) {
                                Toast.makeText(ItemActivity.this, "Error: Album null", Toast.LENGTH_SHORT).show();
                                finish();
                                return;
                            }
                            int index = albumItemIndex;
                            ItemActivity.this.album = album;
                            if (index >= album.getAlbumItems().size()) {
                                index = album.getAlbumItems().size() - 1;
                            }
                            if (index >= 0) {
                                ((ItemAdapter) viewPager.getAdapter()).setAlbum(album);
                                albumItem = album.getAlbumItems().get(index);
                                viewPager.getAdapter().notifyDataSetChanged();
                                viewPager.setCurrentItem(index);
                                final ActionBar actionBar = getSupportActionBar();
                                if (actionBar != null) {
                                    actionBar.setTitle(albumItem.getName());
                                }
                                ItemAdapter adapter = (ItemAdapter) viewPager.getAdapter();
                                ViewHolder viewHolder = adapter.findViewHolderByTag(albumItem.getPath());
                                if (viewHolder != null) {
                                    onShowViewHolder(viewHolder);
                                } else {
                                    ((ItemAdapter) viewPager.getAdapter()).addOnInstantiateItemCallback(new ViewPagerOnInstantiateItemCallback() {

                                        @Override
                                        public boolean onInstantiateItem(ViewHolder viewHolder) {
                                            if (viewHolder.albumItem.getPath().equals(albumItem.getPath())) {
                                                onShowViewHolder(viewHolder);
                                                return false;
                                            }
                                            return true;
                                        }
                                    });
                                }
                            } else {
                                finish();
                            }
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    };
}
Also used : Context(android.content.Context) Album(us.koller.cameraroll.data.models.Album) Intent(android.content.Intent) SpannableString(android.text.SpannableString) BroadcastReceiver(android.content.BroadcastReceiver) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) MediaProvider(us.koller.cameraroll.data.provider.MediaProvider) ActionBar(android.support.v7.app.ActionBar) ItemAdapter(us.koller.cameraroll.adapter.item.ItemAdapter)

Aggregations

ViewHolder (us.koller.cameraroll.adapter.item.viewHolder.ViewHolder)5 ItemAdapter (us.koller.cameraroll.adapter.item.ItemAdapter)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 ActionBar (android.support.v7.app.ActionBar)2 SpannableString (android.text.SpannableString)2 GifViewHolder (us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder)2 PhotoViewHolder (us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder)2 RAWImageViewHolder (us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder)2 VideoViewHolder (us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder)2 NonNull (android.support.annotation.NonNull)1 ViewPager (android.support.v4.view.ViewPager)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageViewState (com.davemorrissey.labs.subscaleview.ImageViewState)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 Gif (us.koller.cameraroll.data.models.Gif)1