Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.loopeer:itemtouchhelper-extension:1.0.4'
}
dependencies {
implementation("com.github.loopeer:itemtouchhelper-extension:1.0.4")
}
<dependency>
<groupId>com.github.loopeer</groupId>
<artifactId>itemtouchhelper-extension</artifactId>
<version>1.0.4</version>
</dependency>
libraryDependencies += "com.github.loopeer" % "itemtouchhelper-extension" % "1.0.4"
:dependencies [[com.github.loopeer/itemtouchhelper-extension "1.0.4"]]
This library add something for swipe item settling, recover base on the Itemtouchhelper.
This used in the repo code-reader
dependencies {
compile 'com.loopeer.library:itemtouchhelperextension:1.0.6'
}
mCallback = new ItemTouchHelperCallback();
mItemTouchHelper = new ItemTouchHelperExtension(mCallback);
mItemTouchHelper.attachToRecyclerView(mRecyclerView);
ItemTouchHelperCallback just set as Itemtouchhelper. Set your swipe content view translationX by moving in method onChildDraw
public class ItemTouchHelperCallback extends ItemTouchHelperExtension.Callback {
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
return makeMovementFlags(0, ItemTouchHelper.START);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
...
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
MainRecyclerAdapter.ItemBaseViewHolder holder = (MainRecyclerAdapter.ItemBaseViewHolder) viewHolder;
holder.mViewContent.setTranslationX(dX);
}
}
At last you can let your viewholder implements Extension to set swipe settling width
@Override
public float getActionWidth() {
return mActionContainer.getWidth();
}
This will use whole recyclerview width when you do not add the width
If you want to add drag item feature.You just do super.onChildDraw in method onChildDraw of the class ItemTouchHelperCallback. Just like bottom:
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (dY != 0 && dX == 0) super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
...
}
If you want to close item after click action btn in the swipe item. You show add
mItemTouchHelperExtension.closeOpened();