Search in sources :

Example 1 with NestedRecyclerViewAlbumHolder

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

the class MainActivity method onActivityReenter.

@Override
public void onActivityReenter(final int resultCode, Intent intent) {
    super.onActivityReenter(resultCode, intent);
    int nestedRecyclerViewValue = getResources().getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE);
    if (intent.getAction() != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && intent.getAction().equals(ItemActivity.SHARED_ELEMENT_RETURN_TRANSITION) && Settings.getInstance(this).getStyle(this, pick_photos) == nestedRecyclerViewValue) {
        // handle shared-element transition, for nested nestedRecyclerView style
        Bundle tmpReenterState = new Bundle(intent.getExtras());
        if (tmpReenterState.containsKey(AlbumActivity.ALBUM_PATH) && tmpReenterState.containsKey(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION)) {
            String albumPath = tmpReenterState.getString(AlbumActivity.ALBUM_PATH);
            final int sharedElementReturnPosition = tmpReenterState.getInt(AlbumActivity.EXTRA_CURRENT_ALBUM_POSITION);
            int index = -1;
            ArrayList<Album> albums = MediaProvider.getAlbumsWithVirtualDirectories(this);
            for (int i = 0; i < albums.size(); i++) {
                if (albums.get(i).getPath().equals(albumPath)) {
                    index = i;
                    break;
                }
            }
            if (index == -1) {
                return;
            }
            // postponing transition until sharedElement is laid out
            postponeEnterTransition();
            setExitSharedElementCallback(mCallback);
            final NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback callback = new NestedRecyclerViewAlbumHolder.StartSharedElementTransitionCallback() {

                @Override
                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                public void startPostponedEnterTransition() {
                    // sharedElement is laid out --> start transition
                    MainActivity.this.startPostponedEnterTransition();
                }
            };
            final int finalIndex = index;
            recyclerView.scrollToPosition(index);
            // wait until ViewHolder is laid out
            recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
                @Override
                public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) {
                    RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(finalIndex);
                    if (viewHolder != null) {
                        recyclerView.removeOnLayoutChangeListener(this);
                    } else {
                        // viewHolder hasn't been laid out yet --> wait
                        recyclerView.scrollToPosition(finalIndex);
                    }
                    if (viewHolder instanceof NestedRecyclerViewAlbumHolder) {
                        // found ViewHolder
                        sharedElementViewHolder = (NestedRecyclerViewAlbumHolder) viewHolder;
                        ((NestedRecyclerViewAlbumHolder) viewHolder).onSharedElement(sharedElementReturnPosition, callback);
                    }
                }
            });
        }
    }
}
Also used : NestedRecyclerViewAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder) Bundle(android.os.Bundle) Album(us.koller.cameraroll.data.models.Album) View(android.view.View) FastScrollerRecyclerView(us.koller.cameraroll.ui.widget.FastScrollerRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) RequiresApi(android.support.annotation.RequiresApi)

Example 2 with NestedRecyclerViewAlbumHolder

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

the class MainAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder;
    Resources res = parent.getContext().getResources();
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    if (viewType == res.getInteger(R.integer.STYLE_PARALLAX_VALUE)) {
        View v = inflater.inflate(R.layout.album_cover_parallax, parent, false);
        viewHolder = new SimpleAlbumHolder(v);
    } else if (viewType == res.getInteger(R.integer.STYLE_CARDS_VALUE)) {
        View v = inflater.inflate(R.layout.album_cover_card, parent, false);
        viewHolder = new SimpleAlbumHolder(v);
    } else if (viewType == res.getInteger(R.integer.STYLE_CARDS_2_VALUE)) {
        View v = inflater.inflate(R.layout.album_cover_card_2, parent, false);
        viewHolder = new SimpleAlbumHolder(v);
    } else /*if (viewType == res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE))*/
    {
        View v = inflater.inflate(R.layout.album_cover_nested_recyclerview, parent, false);
        viewHolder = new NestedRecyclerViewAlbumHolder(v).setSelectorModeManager(getSelectorManager());
    }
    Context context = viewHolder.itemView.getContext();
    Theme theme = Settings.getInstance(context).getThemeInstance(context);
    ThemeableActivity.checkTags((ViewGroup) viewHolder.itemView, theme);
    return viewHolder;
}
Also used : NestedRecyclerViewAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder) Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) Theme(us.koller.cameraroll.themes.Theme) RecyclerView(android.support.v7.widget.RecyclerView) Resources(android.content.res.Resources) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SimpleAlbumHolder(us.koller.cameraroll.adapter.main.viewHolder.SimpleAlbumHolder)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 NestedRecyclerViewAlbumHolder (us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 RequiresApi (android.support.annotation.RequiresApi)1 LayoutInflater (android.view.LayoutInflater)1 SimpleAlbumHolder (us.koller.cameraroll.adapter.main.viewHolder.SimpleAlbumHolder)1 Album (us.koller.cameraroll.data.models.Album)1 Theme (us.koller.cameraroll.themes.Theme)1 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)1 ParallaxImageView (us.koller.cameraroll.ui.widget.ParallaxImageView)1