Coder Social home page Coder Social logo

ybin / ultimaterecyclerview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cymcsg/ultimaterecyclerview

0.0 2.0 0.0 3.64 MB

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

License: Apache License 2.0

Java 100.00%

ultimaterecyclerview's Introduction

UltimateRecyclerView

###Version:0.3.17

####Master branch:Build Status

####Dev branch:Build Status

License

#####Project website:https://github.com/cymcsg/UltimateRecyclerView

###Description UltimateRecyclerView is a RecyclerView(advanced and flexible version of ListView) with pulling to refresh, loading more, swiping to dismiss, draging and drop, animations ,sticky header,show or hide toolbar and FAB when scrolling and many other features.You can use it just like RecyclerView.

Notice that UltimateRecyclerView is a project under development.

Your donations is highly appreciated. Thank you!

###Features:

  • Swipe to refresh(using android.support.v4.widget.SwipeRefreshLayout)
  • Many kinds of animations
  • Swipe to dismiss
  • Parallax or normal head view
  • Drag and drop items
  • Loading more when reach the last item(infinite scrolling)
  • Custom views in loading more
  • Showing or hiding toolbar and floating button when scrolling
  • Scrollbars
  • Colorful styles of swipe to refresh
  • Sticky header like instagram
  • Support different layout in adapter
  • Loading adapter with animation

###Changes in 0.3.17:

  • new style of drag and swipe
  • normal head view
  • add Generics in the UltimateViewAdapter
  • expandable item of recyclerview
  • quick adapter
  • Change attr name from fab_** to urv_fab_**

###Changes in 0.3.8:

  • support different layout in adapter
  • loading adapter with animations
  • support minSdk to 8
  • Upgrade recyclerview to 22.2.0

###Changes in 0.3.2:

  • add a empty view when the adapter do not have data
  • add some colorful styles of swipe to refresh
  • add swapAdapter() ,getAdapter() etc.
  • Custom FAB style
  • add support for scrollbars of RecyclerView
  • add method set background color of recyclerview
  • add method to set default swipe to dismiss color
  • support easy way to use admob

###Upcoming features:

  • More animations
  • Optimise UltimateViewAdapter
  • ...

Upcoming changes in UltiamteRecyclerview 0.4.0:

If you have some good ideas, please tell us. My email is cymcsg # gmail.com.And it is a good idea to put your idea on the issue.

####Welcome to fork and pull request.

###If you want to use a rapid development framework for developing apps,you can try UltimateAndroid Framework.

###Screenshot ultimate_recyclerview ultimate_recyclerview ultimate_recyclerview ultimate_recyclerview ultimate_recyclerview ultimate_recyclerview

###Sample

You can clone the project and compile it yourself (it includes a sample), or you can check it out already compiled at Google Play

Google Play

Notice that it might not be the latest version

###Quick Setup(Basic Usage) ######1.Integration

repositories {
        jcenter()
    }
dependencies {
    ...
    compile 'com.marshalchen.ultimaterecyclerview:library:0.3.17'
}

#####2.Usage:

<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/ultimate_recycler_view"
       >
        </com.marshalchen.ultimaterecyclerview.UltimateRecyclerView>

#####3.Features:
Loading more:

  ultimateRecyclerView.enableLoadmore();
 ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
            @Override
            public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    public void run() {
                        simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    }
                }, 1000);
            }
        });

######Set ParallaxHeader:

 ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
 
ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {
            @Override
            public void onParallaxScroll(float percentage, float offset, View parallax) {
                Drawable c = toolbar.getBackground();
                c.setAlpha(Math.round(127 + percentage * 128));
                toolbar.setBackgroundDrawable(c);
            }
        });

######Set swipe to refresh:

ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        simpleRecyclerViewAdapter.insert(moreNum++ + "  Refresh things", 0);
                        ultimateRecyclerView.setRefreshing(false);
                    }
                }, 1000);
            }
        });

######Set swipe to dismiss:

  ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
        mItemTouchHelper = new ItemTouchHelper(callback);
        mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
Drag and drop:
  simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {
           @Override
           public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
               mItemTouchHelper.startDrag(viewHolder);
           }
       });

Animations:

  ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
  ultimateRecyclerView.getItemAnimator().setAddDuration(300);
  ultimateRecyclerView.getItemAnimator().setRemoveDuration(300);

######Showing and hiding toolbar and floating button:

  ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {           
             }
            @Override
            public void onDownMotionEvent() {
            }
            @Override
            public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
                if (observableScrollState == ObservableScrollState.DOWN) {
                     ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView,getScreenHeight());
                } else if (observableScrollState == ObservableScrollState.UP) {
                      ultimateRecyclerView.hideToolbar(toolbar,ultimateRecyclerView,getScreenHeight());
                } else if (observableScrollState == ObservableScrollState.STOP) {
                }
            }
        });        

######Show empty view when the adapter is null:

<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
...
app:recyclerviewEmptyView="@layout/empty_view"/>

OR

ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));

ultimateRecyclerView.showEmptyView();

######Show custom FloatingView(Both menu and button are fine. It is easy to set click event on them) when the adapter is null:

<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
...
 app:recyclerviewFloatingActionView="@layout/floating_view"/>

######Set custom colorful style of pull to refresh:

 <com.marshalchen.ultimaterecyclerview.CustomUltimateRecyclerview
 .../>

######Using CustomUltimateRecyclerview instead of UltimateRecyclerView ultimateRecyclerView.setCustomSwipeToRefresh();

######Set scrollbars of RecyclerView by set attributes of UltimateRecyclerView in xml layout:

<com.marshalchen.ultimaterecyclerview.UltimateRecyclerView
        app:recyclerviewScrollbars="vertical" />                

Note that set scrollbars of RecyclerView dynamically by code is NOT SUPPORTED refer to this

######Add sticky header:

In MainActivity:

   StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
  ultimateRecyclerView.addItemDecoration(headersDecor);

In the adapter:

 @Override
    public long generateHeaderId(int position) {
        if (getItem(position).length() > 0)
            return getItem(position).charAt(0);
        else return -1;
    }
    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup viewGroup) {
        View view = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.stick_header_item, viewGroup, false);
        return new RecyclerView.ViewHolder(view) {
        };
    }

Refresh adapter:

mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
      @Override public void onChanged() {
        headersDecor.invalidateHeaders();
      }
    });

######Using different layout in an adapter: You should define a MultiViewAdapter which extends UltimateDiffernetViewTypeAdapter and then your custom differnt view adapters.

public class MultiViewTypesRecyclerViewAdapter extends UltimateDifferentViewTypeAdapter{
    @Override
    public Enum getEnumFromPosition(int position) {
        if (position % 2 == 1) {
            return SampleViewType.SAMPLE1;
        } else {
            return SampleViewType.SAMPLE2;
        }
    }
    
    public MultiViewTypesRecyclerViewAdapter(List<String> dataSet) {
      putBinder(SampleViewType.SAMPLE1, new Sample1Binder(this,dataSet));
      putBinder(SampleViewType.SAMPLE2, new Sample2Binder(this,dataSet));
      ...
    }
    ...
}
public class Sample1Binder extends DataBinder<Sample1Binder.ViewHolder> {
   
    @Override
    public ViewHolder newViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.simple_binder1, parent, false);
        return new ViewHolder(view);
    }
    ...
}
    

######Admob implementation

 private AdView createadmob() {
        AdView mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
        mAdView.setAdUnitId("__GOOGLE_AD_UNIT__ID__");
        mAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        // Create an ad request.
        AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

        if (admob_test_mode)
            // Optionally populate the ad request builder.
            adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

        // Start loading the ad.
        mAdView.loadAd(adRequestBuilder.build());
        return mAdView;
    }
       simpleRecyclerViewAdapter = new admobdfpadapter(createadmob(), 5, stringList, new AdmobAdapter.AdviewListener() {
            @Override
            public AdView onGenerateAdview() {
                return createadmob();
            }
        });

######Loading adapter with animations :

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       ...
        if (!isFirstOnly || position > mLastPosition) {
            for (Animator anim : getAdapterAnimations(holder.itemView, AdapterAnimationType.ScaleIn)) {
                anim.setDuration(mDuration).start();
                anim.setInterpolator(mInterpolator);
            }
            mLastPosition = position;
        } else {
            ViewHelper.clear(holder.itemView);
        }

    }

####If you want to see more details,you can check the demo.

###Thanks

If there are someone who I do not mention here,please accept my sincerely appologies and tell me.

Donations:

Donate $9.99: $9.99

Donate $19.99: $19.99

Donate $39.99: $39.99

Donate $59.99: $59.99

Alipay:donate

License

Copyright 2015 Marshal Chen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

ultimaterecyclerview's People

Contributors

cymcsg avatar jjhesk avatar sevanjoe avatar lyuku avatar swisyn avatar drindt avatar

Watchers

ybin avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.