Android Open Source - UpcomingMoviesMVP Click Recycler View






From Project

Back to project page UpcomingMoviesMVP.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Defi...

If you think the Android project UpcomingMoviesMVP listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jlmd.android.newfilmsmvp.ui.view;
/*from ww  w. ja  v  a2s  .  c o m*/
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.HapticFeedbackConstants;
import android.view.SoundEffectConstants;
import android.view.View;

/**
 * @author lucasr
 * From https://github.com/lucasr/twoway-view
 */
public class ClickRecyclerView extends RecyclerView {

    private TouchListener mTouchListener;
    private OnItemClickListener mItemClickListener;
    private OnItemLongClickListener mItemLongClickListener;

    public ClickRecyclerView(Context context) {
        super(context);
        init();
    }

    public ClickRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ClickRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        mTouchListener = new TouchListener(this);
        addOnItemTouchListener(mTouchListener);
    }

    /**
     * Register a callback to be invoked when an item in the
     * RecyclerView has been clicked.
     *
     * @param listener The callback that will be invoked.
     */
    public void setOnItemClickListener(OnItemClickListener listener) {
        mItemClickListener = listener;
    }

    /**
     * Register a callback to be invoked when an item in the
     * RecyclerView has been clicked and held.
     *
     * @param listener The callback that will be invoked.
     */
    public void setOnItemLongClickListener(OnItemLongClickListener listener) {
        if (!isLongClickable()) {
            setLongClickable(true);
        }

        mItemLongClickListener = listener;
    }

    /**
     * Interface definition for a callback to be invoked when an item in the
     * RecyclerView has been clicked.
     */
    public interface OnItemClickListener {
        /**
         * Callback method to be invoked when an item in the RecyclerView
         * has been clicked.
         *
         * @param parent   The RecyclerView where the click happened.
         * @param view     The view within the RecyclerView that was clicked
         * @param position The position of the view in the adapter.
         * @param id       The row id of the item that was clicked.
         */
        void onItemClick(RecyclerView parent, View view, int position, long id);
    }

    /**
     * Interface definition for a callback to be invoked when an item in the
     * RecyclerView has been clicked and held.
     */
    public interface OnItemLongClickListener {
        /**
         * Callback method to be invoked when an item in the RecyclerView
         * has been clicked and held.
         *
         * @param parent   The RecyclerView where the click happened
         * @param view     The view within the RecyclerView that was clicked
         * @param position The position of the view in the list
         * @param id       The row id of the item that was clicked
         * @return true if the callback consumed the long click, false otherwise
         */
        boolean onItemLongClick(RecyclerView parent, View view, int position, long id);
    }

    private class TouchListener extends ClickItemTouchListener {
        TouchListener(RecyclerView recyclerView) {
            super(recyclerView);
        }

        @Override
        boolean performItemClick(RecyclerView parent, View view, int position, long id) {
            if (mItemClickListener != null) {
                view.playSoundEffect(SoundEffectConstants.CLICK);
                mItemClickListener.onItemClick(parent, view, position, id);
                return true;
            }

            return false;
        }

        @Override
        boolean performItemLongClick(RecyclerView parent, View view, int position, long id) {
            if (mItemLongClickListener != null) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                return mItemLongClickListener.onItemLongClick(parent, view, position, id);
            }

            return false;
        }
    }
}




Java Source Code List

com.jlmd.android.newfilmsmvp.ApplicationTest.java
com.jlmd.android.newfilmsmvp.api.mapper.Mapper.java
com.jlmd.android.newfilmsmvp.api.mapper.MovieDetailsMapper.java
com.jlmd.android.newfilmsmvp.api.mapper.UpcomingMoviesMapper.java
com.jlmd.android.newfilmsmvp.api.mock.MockedMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.mock.MockedUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.MovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.BelongsToCollection.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.Genre.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.MovieDetailsResult.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCompany.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.ProductionCountry.java
com.jlmd.android.newfilmsmvp.api.moviedetails.model.SpokenLanguage.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.MovieDetailsService.java
com.jlmd.android.newfilmsmvp.api.retrofit.moviedetails.RetrofitMovieDetailsApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.RetrofitUpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.retrofit.upcomingmovies.UpcomingMoviesService.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.UpcomingMoviesApi.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Dates.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.Result.java
com.jlmd.android.newfilmsmvp.api.upcomingmovies.model.UpcomingMoviesResult.java
com.jlmd.android.newfilmsmvp.bus.event.MovieSelectedEvent.java
com.jlmd.android.newfilmsmvp.di.AppApplication.java
com.jlmd.android.newfilmsmvp.di.module.ComparatorModule.java
com.jlmd.android.newfilmsmvp.di.module.PresenterModule.java
com.jlmd.android.newfilmsmvp.di.module.RepositoryModule.java
com.jlmd.android.newfilmsmvp.di.module.RootModule.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieDateComparator.java
com.jlmd.android.newfilmsmvp.domain.comparator.MovieTitleComparator.java
com.jlmd.android.newfilmsmvp.domain.formatter.Formatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.GenresFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.RatingFormatter.java
com.jlmd.android.newfilmsmvp.domain.formatter.ReleaseDateFormatter.java
com.jlmd.android.newfilmsmvp.domain.model.Image.java
com.jlmd.android.newfilmsmvp.domain.model.MovieDetails.java
com.jlmd.android.newfilmsmvp.domain.model.Movie.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MovieDetailsPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenterImp.java
com.jlmd.android.newfilmsmvp.mvp.presenter.MoviesListPresenter.java
com.jlmd.android.newfilmsmvp.mvp.presenter.Presenter.java
com.jlmd.android.newfilmsmvp.mvp.view.MovieDetailsView.java
com.jlmd.android.newfilmsmvp.mvp.view.MoviesListView.java
com.jlmd.android.newfilmsmvp.mvp.view.View.java
com.jlmd.android.newfilmsmvp.ui.activity.BaseActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MainActivity.java
com.jlmd.android.newfilmsmvp.ui.activity.MovieDetailsActivity.java
com.jlmd.android.newfilmsmvp.ui.adapter.BaseRecyclerViewHolder.java
com.jlmd.android.newfilmsmvp.ui.adapter.MoviesListRecyclerAdapter.java
com.jlmd.android.newfilmsmvp.ui.fragment.BaseFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MovieDetailsFragment.java
com.jlmd.android.newfilmsmvp.ui.fragment.MoviesListFragment.java
com.jlmd.android.newfilmsmvp.ui.view.ClickItemTouchListener.java
com.jlmd.android.newfilmsmvp.ui.view.ClickRecyclerView.java
com.jlmd.android.newfilmsmvp.utils.Constants.java
com.jlmd.android.newfilmsmvp.utils.Utils.java