OmegaRecyclerView
Custom RecyclerView with additional functionality. Allow you add divider, itemSpace, emptyView, sticky header and some other features.
Installation
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.Omega-R:OmegaRecyclerView:1.6.12@aar'
}
Usage
Example of usage in xml layout
com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
android:id="@+id/custom_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#888"
android:dividerHeight="1dp"
app:itemSpace="12dp"
app:showDivider="middle"/>
StickyHeader
To add sticky header into project you need implements StickyHeaderAdapter in adapters class
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder>
implements StickyHeaderAdapter<TestAdapter.HeaderHolder>
Proper appearence of sticky header when using space item
stickyHeaderDecoration.setItemSpace(omegaRecyclerView.getItemSpace());
You can use findViewById without itemView
nameTextView = findViewById(R.id.text_contact_name);
messageButton = findViewById(R.id.button_message);
For array use BaseArrayAdapter
getItemCount()
getItem(position)
set(array)
add(array)
SwipeMenu
To add swipe menu into project you need to use SwipeViewHolder or create your own ViewHolder.
public class ViewHolder extends SwipeViewHolder {
public ViewHolder(ViewGroup parent) {
super(parent,
R.layout.item_swipe_content,
R.layout.item_left_swipe_menu,
R.layout.item_right_swipe_menu);
}
Also you can use constructor only with left menu, or only with right menu.
public ViewHolder(ViewGroup parent) {
super(parent,
R.layout.item_swipe_content,
R.layout.item_left_swipe_menu,
SwipeViewHolder.NO_ID);
}
Also you can use one layout for left menu and right menu.
public ViewHolder(ViewGroup parent) {
super(parent,
R.layout.item_swipe_content,
R.layout.swipe_menu);
}
You can use following methods for controlling swipe menu state:
public void setSwipeFractionListener(@Nullable SwipeFractionListener listener);
public void setSwipeListener(@Nullable SwipeSwitchListener listener);
public void smoothCloseMenu(int duration);
public void smoothCloseMenu();
public void smoothOpenBeginMenu();
public void smoothOpenEndMenu();
public void setSwipeEnable(boolean enable);
public boolean isSwipeEnable();
Pagination
To add pagination into project you just need to setPaginationCallback to OmegaRecyclerView.
mRecyclerView.setPaginationCallback(new OnPageRequestListener() {
@Override
public void onPageRequest(int page) {
// You can load data inside this callback
}
@Override
public int getPagePreventionForEnd() {
return PREVENTION_VALUE; // PREVENTION_VALUE - for how many positions until the end you want to be informed
}
});
How to control pagination:
mRecyclerView.showProgressPagination(); // show progress
mRecyclerView.hidePagination(); // hide pagination
mRecyclerView.showErrorPagination(); // show error
You have two ways to add your custom pagination layout and error layout.
First way:
<com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:paginationLayout="@layout/item_progress"
app:paginationErrorLayout="@layout/item_error_loading"/>
You can implement PaginationView in your Adapter class.
Second:
public class RecyclerAdapter extends OmegaRecyclerView.Adapter<RecyclerView.ViewHolder> implements PaginationViewCreator {
....
@Nullable
@Override
public View createPaginationView(ViewGroup parent, LayoutInflater inflater) {
return inflater.inflate(R.layout.item_progress, parent, false);
}
@Nullable
@Override
public View createPaginationErrorView(ViewGroup parent, LayoutInflater inflater) {
View view = inflater.inflate(R.layout.item_error_loading, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// on error clicked....
}
});
return view;
}
Sections (Header, Footer)
For usage just add you Views inside OmegaRecyclerView and add "app:layout_section" parameter.
<?xml version="1.0" encoding="utf-8"?>
<com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Header"
app:layout_section="header"/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Footer"
app:layout_section="footer"/>
</com.omega_r.libs.omegarecyclerview.OmegaRecyclerView>
For controll
OmegaRecyclerView.setHeadersVisibility(true);
OmegaRecyclerView.setFootersVisibility(false);
ViewPager
For usage just add OmegaPagerRecyclerView
<?xml version="1.0" encoding="utf-8"?>
<com.omega_r.libs.omegarecyclerview.viewpager.OmegaPagerRecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
// Supported features
app:infinite="true" // Infinite scroll
app:elementSize="0.8" // set element size 80% of screen
app:transitionTime="2100"/>
You could use your owner transformation.
recyclerView.setItemTransformer(new ScaleTransformer.Builder()
.setMaxScale(1.1f)
.setMinScale(0.8f)
.build());