Search in sources :

Example 1 with PhotoViewHolder

use of com.example.android.unsplash.ui.grid.PhotoViewHolder in project atlas by alibaba.

the class MainActivity method populateGrid.

private void populateGrid() {
    grid.setAdapter(new PhotoAdapter(this, relevantPhotos));
    grid.addOnItemTouchListener(new OnItemSelectedListener(MainActivity.this) {

        public void onItemSelected(RecyclerView.ViewHolder holder, int position) {
            if (!(holder instanceof PhotoViewHolder)) {
                return;
            }
            MainActivity activity = MainActivity.this;
            PhotoViewHolder pvh = (PhotoViewHolder) holder;
            final Intent intent = getDetailActivityStartIntent(activity, position, pvh);
            final ActivityOptions activityOptions = getActivityOptions(pvh);
            activity.startActivityForResult(intent, IntentUtil.INSTANCE.getREQUEST_CODE(), activityOptions.toBundle());
        }
    });
    empty.setVisibility(View.GONE);
}
Also used : PhotoAdapter(com.example.android.unsplash.ui.grid.PhotoAdapter) OnItemSelectedListener(com.example.android.unsplash.ui.grid.OnItemSelectedListener) RecyclerView(android.support.v7.widget.RecyclerView) Intent(android.content.Intent) PhotoViewHolder(com.example.android.unsplash.ui.grid.PhotoViewHolder) ActivityOptions(android.app.ActivityOptions)

Example 2 with PhotoViewHolder

use of com.example.android.unsplash.ui.grid.PhotoViewHolder in project atlas by alibaba.

the class MainActivity method onActivityReenter.

@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });
    if (data == null) {
        return;
    }
    final int selectedItem = data.getIntExtra(IntentUtil.INSTANCE.getSELECTED_ITEM_POSITION(), 0);
    grid.scrollToPosition(selectedItem);
    PhotoViewHolder holder = (PhotoViewHolder) grid.findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }
    DetailSharedElementEnterCallback callback = new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);
}
Also used : DetailSharedElementEnterCallback(com.example.android.unsplash.ui.DetailSharedElementEnterCallback) PhotoViewHolder(com.example.android.unsplash.ui.grid.PhotoViewHolder) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

PhotoViewHolder (com.example.android.unsplash.ui.grid.PhotoViewHolder)2 ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewTreeObserver (android.view.ViewTreeObserver)1 DetailSharedElementEnterCallback (com.example.android.unsplash.ui.DetailSharedElementEnterCallback)1 OnItemSelectedListener (com.example.android.unsplash.ui.grid.OnItemSelectedListener)1 PhotoAdapter (com.example.android.unsplash.ui.grid.PhotoAdapter)1