Search in sources :

Example 1 with ParallaxTransformer

use of us.koller.cameraroll.util.ParallaxTransformer 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)

Aggregations

ViewPager (android.support.v4.view.ViewPager)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 ImageViewState (com.davemorrissey.labs.subscaleview.ImageViewState)1 ItemAdapter (us.koller.cameraroll.adapter.item.ItemAdapter)1 ViewHolder (us.koller.cameraroll.adapter.item.viewHolder.ViewHolder)1 Photo (us.koller.cameraroll.data.models.Photo)1 ParallaxTransformer (us.koller.cameraroll.util.ParallaxTransformer)1