├── jitpack.yml
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── readme
├── drag-drop-swipe-list-demo.gif
├── drag-drop-swipe-list-demo2.gif
└── drag-drop-swipe-item-customization.jpg
├── .gitignore
├── drag-drop-swipe-recyclerview-sample
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── drawable-hdpi
│ │ │ └── ice_cream_photo.png
│ │ ├── drawable-xhdpi
│ │ │ └── ice_cream_photo.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ice_cream_photo.png
│ │ ├── drawable
│ │ │ ├── divider_horizontal_list.xml
│ │ │ ├── divider_vertical_list.xml
│ │ │ ├── divider_grid_list.xml
│ │ │ ├── ic_list_horizontal.xml
│ │ │ ├── ic_clear_items.xml
│ │ │ ├── ic_new_item.xml
│ │ │ ├── ic_list_vertical.xml
│ │ │ ├── ic_list_grid.xml
│ │ │ ├── ic_remove_item.xml
│ │ │ ├── ic_ice_cream.xml
│ │ │ ├── ic_drag.xml
│ │ │ └── ic_archive_item.xml
│ │ ├── values
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ └── strings.xml
│ │ ├── menu
│ │ │ ├── bottom_navigation.xml
│ │ │ ├── fragment_horizontal_list_options.xml
│ │ │ ├── fragment_vertical_list_options.xml
│ │ │ └── fragment_grid_list_options.xml
│ │ └── layout
│ │ │ ├── fragment_log.xml
│ │ │ ├── fragment_grid_list.xml
│ │ │ ├── fragment_horizontal_list.xml
│ │ │ ├── fragment_vertical_list.xml
│ │ │ ├── behind_swiped_grid_list.xml
│ │ │ ├── behind_swiped_horizontal_list.xml
│ │ │ ├── behind_swiped_grid_list_secondary.xml
│ │ │ ├── behind_swiped_horizontal_list_secondary.xml
│ │ │ ├── behind_swiped_vertical_list.xml
│ │ │ ├── behind_swiped_vertical_list_secondary.xml
│ │ │ ├── list_item_grid_list.xml
│ │ │ ├── list_item_horizontal_list.xml
│ │ │ ├── list_item_vertical_list.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── list_item_grid_list_cardview.xml
│ │ │ ├── list_item_horizontal_list_cardview.xml
│ │ │ └── list_item_vertical_list_cardview.xml
│ │ ├── java
│ │ └── com
│ │ │ └── infomaniak
│ │ │ └── dragdropswiperecyclerviewsample
│ │ │ ├── data
│ │ │ ├── model
│ │ │ │ └── IceCream.kt
│ │ │ └── source
│ │ │ │ ├── base
│ │ │ │ └── BaseRepository.kt
│ │ │ │ └── IceCreamRepository.kt
│ │ │ ├── config
│ │ │ └── local
│ │ │ │ └── AppConfig.kt
│ │ │ ├── util
│ │ │ └── Logger.kt
│ │ │ ├── feature
│ │ │ ├── managelog
│ │ │ │ └── view
│ │ │ │ │ └── LogFragment.kt
│ │ │ └── managelists
│ │ │ │ ├── IceCreamListAdapter.kt
│ │ │ │ └── view
│ │ │ │ ├── VerticalListFragment.kt
│ │ │ │ ├── HorizontalListFragment.kt
│ │ │ │ └── GridListFragment.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── gradle.properties
├── .github
├── workflows
│ ├── auto-author-assign.yml
│ ├── dependent-issues.yml
│ ├── android.yml
│ ├── publish.yml
│ └── rebase-default-branch.yml
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
├── drag-drop-swipe-recyclerview
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── attrs.xml
│ │ └── java
│ │ └── com
│ │ └── infomaniak
│ │ └── dragdropswiperecyclerview
│ │ ├── listener
│ │ ├── OnListScrollListener.kt
│ │ ├── OnItemDragListener.kt
│ │ └── OnItemSwipeListener.kt
│ │ ├── ScrollAwareRecyclerView.kt
│ │ └── util
│ │ ├── DividerDrawingHelper.kt
│ │ ├── DragDropSwipeItemDecoration.kt
│ │ └── DragDropSwipeTouchHelper.kt
└── build.gradle
├── gradlew.bat
├── gradlew
└── LICENSE
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':drag-drop-swipe-recyclerview-sample', ':drag-drop-swipe-recyclerview'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/readme/drag-drop-swipe-list-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/readme/drag-drop-swipe-list-demo.gif
--------------------------------------------------------------------------------
/readme/drag-drop-swipe-list-demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/readme/drag-drop-swipe-list-demo2.gif
--------------------------------------------------------------------------------
/readme/drag-drop-swipe-item-customization.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/readme/drag-drop-swipe-item-customization.jpg
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 | .idea/
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-hdpi/ice_cream_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-hdpi/ice_cream_photo.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-xhdpi/ice_cream_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-xhdpi/ice_cream_photo.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-xxhdpi/ice_cream_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/drawable-xxhdpi/ice_cream_photo.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Infomaniak/DragDropSwipeRecyclerview/HEAD/drag-drop-swipe-recyclerview-sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.defaults.buildfeatures.buildconfig=true
2 | android.enableJetifier=true
3 | android.nonFinalResIds=false
4 | android.nonTransitiveRClass=false
5 | android.useAndroidX=true
6 | org.gradle.jvmargs=-Xmx1536m
7 | systemProp.org.gradle.internal.publish.checksums.insecure=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 02 20:44:28 GMT 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
7 |
--------------------------------------------------------------------------------
/.github/workflows/auto-author-assign.yml:
--------------------------------------------------------------------------------
1 | name: Auto Author Assign
2 |
3 | on:
4 | pull_request_target:
5 | types: [ opened, reopened ]
6 |
7 | permissions:
8 | pull-requests: write
9 |
10 | jobs:
11 | assign-author:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: toshimaru/auto-author-assign@v2.1.0
15 |
--------------------------------------------------------------------------------
/.github/workflows/dependent-issues.yml:
--------------------------------------------------------------------------------
1 | name: Dependent Issues
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - edited
8 | - closed
9 | - reopened
10 | pull_request_target:
11 | types:
12 | - opened
13 | - edited
14 | - closed
15 | - reopened
16 | # Makes sure we always add status check for PRs. Useful only if
17 | # this action is required to pass before merging. Otherwise, it
18 | # can be removed.
19 | - synchronize
20 |
21 | jobs:
22 | check:
23 | runs-on: ubuntu-latest
24 | steps:
25 | - uses: z0al/dependent-issues@v1.5.2
26 | env:
27 | # (Required) The token to use to make API calls to GitHub.
28 | GITHUB_TOKEN: ${{ github.token }}
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | *Note: Please write your issue only in english*
11 |
12 | **Is your feature request related to a problem? Please describe.**
13 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
14 |
15 | **Describe the solution you'd like**
16 | A clear and concise description of what you want to happen.
17 |
18 | **Describe alternatives you've considered**
19 | A clear and concise description of any alternative solutions or features you've considered.
20 |
21 | **Additional context**
22 | Add any other context or screenshots about the feature request here.
23 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | *Note: Please write your issue only in english*
11 |
12 | **Description**
13 | A clear and concise description of what the bug is.
14 |
15 | **Steps to reproduce**
16 | Steps to reproduce the behavior:
17 | 1. Go to '...'
18 | 2. Click on '....'
19 | 3. Scroll down to '....'
20 | 4. See error
21 |
22 | **Expected behavior**
23 | A clear and concise description of what you expected to happen.
24 |
25 | **Screenshots**
26 | If applicable, add screenshots to help explain your problem.
27 |
28 | **Smartphone (please complete the following information):**
29 | - Device: [e.g. Samsung S20 Ultra 5G]
30 | - Android version: [e.g. Android 11]
31 | - Lib version: [e.g. 4.0.1]
32 |
33 | **Additional context**
34 | Add any other context about the problem here.
35 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | Drag-Drop-Swipe-RecyclerView
20 |
21 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | pull_request:
5 |
6 | concurrency:
7 | group: ${{ github.head_ref }}
8 | cancel-in-progress: true
9 |
10 | jobs:
11 |
12 | instrumentation-tests:
13 | if: github.event.pull_request.draft == false
14 | runs-on: [ self-hosted, Android ]
15 | strategy:
16 | matrix:
17 | api-level: [ 34 ]
18 | target: [ google_apis ]
19 |
20 | steps:
21 | - name: Cancel Previous Runs
22 | uses: styfle/cancel-workflow-action@0.12.1
23 | with:
24 | access_token: ${{ github.token }}
25 |
26 | - name: Checkout the code
27 | uses: actions/checkout@v4.1.1
28 | with:
29 | token: ${{ github.token }}
30 | submodules: recursive
31 |
32 | # Setup Gradle and run Build
33 | - name: Grant execute permission for gradlew
34 | run: chmod +x gradlew
35 | - name: Build with Gradle
36 | run: ./gradlew build
37 |
38 | # Run tests
39 | - name: Run Unit tests
40 | run: ./gradlew testDebugUnitTest --stacktrace
41 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/divider_horizontal_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/divider_vertical_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/divider_grid_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_list_horizontal.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/data/model/IceCream.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.data.model
19 |
20 | import java.util.UUID
21 |
22 | class IceCream(
23 | val uuid: UUID,
24 | val name: String,
25 | val price: Float,
26 | val colorRed: Float,
27 | val colorGreen: Float,
28 | val colorBlue: Float,
29 | ) {
30 | override fun toString() = name
31 | }
32 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_clear_items.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_new_item.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_list_vertical.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_list_grid.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_remove_item.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_ice_cream.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_drag.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | 4dp
20 | 6dp
21 | 8dp
22 | 12dp
23 | 16dp
24 | 24dp
25 | 32dp
26 | 48dp
27 | 64dp
28 | 72dp
29 |
30 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/drawable/ic_archive_item.xml:
--------------------------------------------------------------------------------
1 |
18 |
23 |
26 |
27 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdk 35
6 |
7 | defaultConfig {
8 | applicationId "com.infomaniak.dragdropswiperecyclerviewsample"
9 | minSdkVersion rootProject.ext.minSdk
10 | targetSdkVersion rootProject.ext.targetSdk
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | buildFeatures {
23 | viewBinding true
24 | }
25 |
26 | compileOptions {
27 | sourceCompatibility rootProject.ext.javaVersion
28 | targetCompatibility rootProject.ext.javaVersion
29 | }
30 |
31 | kotlinOptions { jvmTarget = rootProject.ext.javaVersion }
32 |
33 | namespace 'com.infomaniak.dragdropswiperecyclerviewsample'
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | implementation 'com.google.android.material:material:1.12.0'
40 | implementation 'androidx.appcompat:appcompat:1.7.0'
41 | implementation 'androidx.vectordrawable:vectordrawable:1.2.0'
42 | implementation 'androidx.cardview:cardview:1.0.0'
43 |
44 | implementation project(path: ':drag-drop-swipe-recyclerview')
45 | }
46 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | #e91d63
20 | #c1185b
21 | #11edf5
22 | #ebebeb
23 | #fafafa
24 | #ffffff
25 | #e1e1e1
26 | #d0184c
27 | #17af98
28 | #ffffff
29 |
30 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'maven-publish'
4 |
5 | android {
6 | compileSdk 35
7 |
8 | defaultConfig {
9 | minSdkVersion rootProject.ext.minSdk
10 | targetSdkVersion rootProject.ext.targetSdk
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | compileOptions {
21 | sourceCompatibility rootProject.ext.javaVersion
22 | targetCompatibility rootProject.ext.javaVersion
23 | }
24 |
25 | kotlinOptions { jvmTarget = rootProject.ext.javaVersion }
26 |
27 | publishing {
28 | singleVariant("release") {
29 | withSourcesJar()
30 | withJavadocJar()
31 | }
32 | }
33 |
34 | namespace 'com.infomaniak.dragdropswiperecyclerview'
35 | }
36 |
37 | dependencies {
38 | implementation 'androidx.appcompat:appcompat:1.7.0'
39 | api 'androidx.recyclerview:recyclerview:1.4.0'
40 | }
41 |
42 | afterEvaluate {
43 | publishing {
44 | publications {
45 | maven(MavenPublication) {
46 | from components.findByName('release')
47 | groupId = 'com.github.infomaniak'
48 | artifactId = 'DragDropSwipeRecyclerview'
49 | version = '1.0.0'
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/menu/bottom_navigation.xml:
--------------------------------------------------------------------------------
1 |
18 |
36 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | release:
5 | types: [released]
6 |
7 | jobs:
8 | publish:
9 | name: Release build and publish
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: Check out code
13 | uses: actions/checkout@v3
14 |
15 | - name: Set up JDK
16 | uses: actions/setup-java@v3
17 | with:
18 | java-version: 17
19 | distribution: 'zulu'
20 |
21 | - name: Create GPG file
22 | env:
23 | GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
24 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
25 | run: |
26 | git fetch --unshallow
27 | sudo bash -c "echo '$GPG_KEY_CONTENTS' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'"
28 |
29 | - name: Make gradlew executable
30 | run: chmod +x ./gradlew
31 |
32 | - name: Release build
33 | run: ./gradlew :drag-drop-swipe-recyclerview:assembleRelease
34 |
35 | - name: Publish to MavenCentral
36 | run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
37 | env:
38 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
39 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
40 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
41 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
42 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
43 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
44 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/menu/fragment_horizontal_list_options.xml:
--------------------------------------------------------------------------------
1 |
18 |
42 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/menu/fragment_vertical_list_options.xml:
--------------------------------------------------------------------------------
1 |
18 |
42 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/menu/fragment_grid_list_options.xml:
--------------------------------------------------------------------------------
1 |
18 |
43 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/fragment_log.xml:
--------------------------------------------------------------------------------
1 |
18 |
26 |
27 |
32 |
33 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/listener/OnListScrollListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.listener
19 |
20 | /**
21 | * Listener for the scroll events on the list.
22 | */
23 | interface OnListScrollListener {
24 |
25 | /**
26 | * Indicates the direction in which the scroll action is performed.
27 | */
28 | enum class ScrollDirection {
29 | UP,
30 | DOWN,
31 | LEFT,
32 | RIGHT
33 | }
34 |
35 | /**
36 | * Indicates the state of the scroll.
37 | */
38 | enum class ScrollState {
39 | IDLE,
40 | DRAGGING,
41 | SETTLING
42 | }
43 |
44 | /**
45 | * Callback for whenever the list has been scrolled.
46 | *
47 | * @param scrollDirection The direction in which the list has been scrolled.
48 | * @param distance The distance in pixels that the list has been scrolled.
49 | */
50 | fun onListScrolled(scrollDirection: ScrollDirection, distance: Int)
51 |
52 | /**
53 | * Callback for whenever the scroll state of the list changes.
54 | *
55 | * @param scrollState The scroll state of the list.
56 | */
57 | fun onListScrollStateChanged(scrollState: ScrollState)
58 | }
59 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/listener/OnItemDragListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.listener
19 |
20 | /**
21 | * Listener for the dragging events of list items.
22 | */
23 | interface OnItemDragListener {
24 |
25 | /**
26 | * Callback for whenever an item that is being dragged exchanges positions with another one.
27 | * It will be called every time an exchange occurs, no matter if the user is still dragging
28 | * the item or not.
29 | *
30 | * @param previousPosition The old position of the item that has just been exchanged with the
31 | * dragged one.
32 | * @param newPosition The new position of the dragged item.
33 | * @param item The dragged item.
34 | */
35 | fun onItemDragged(previousPosition: Int, newPosition: Int, item: T)
36 |
37 | /**
38 | * Callback for when the drag & drop event has completed because the user has dropped the item.
39 | *
40 | * @param initialPosition The position of the item before the user started dragging it.
41 | * @param finalPosition The position in which the user has dropped the item.
42 | * @param item The dropped item.
43 | */
44 | fun onItemDropped(initialPosition: Int, finalPosition: Int, item: T)
45 | }
46 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/fragment_grid_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
25 |
34 |
35 |
44 |
45 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/fragment_horizontal_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
25 |
34 |
35 |
44 |
45 |
--------------------------------------------------------------------------------
/.github/workflows/rebase-default-branch.yml:
--------------------------------------------------------------------------------
1 | # Rebases a pull request on the repo's default branch when the "rebase" label is added
2 | # Link: https://github.com/Infomaniak/.github/blob/main/workflow-templates/rebase-default-branch.yml
3 |
4 | name: Rebase Pull Request
5 |
6 | on:
7 | pull_request:
8 | types: [ labeled ]
9 |
10 | concurrency:
11 | group: ${{ github.workflow }}-${{ github.ref }}
12 | cancel-in-progress: true
13 |
14 | env:
15 | DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
16 |
17 | jobs:
18 | main:
19 | if: ${{ contains(github.event.*.labels.*.name, 'rebase') }}
20 | name: Rebase
21 | runs-on: ubuntu-latest
22 | steps:
23 | - name: Checkout
24 | uses: actions/checkout@v5.0.0
25 | with:
26 | ref: ${{ github.event.pull_request.head.ref }}
27 | fetch-depth: 0
28 |
29 | # Context: https://httgp.com/signing-commits-in-github-actions
30 | # Link: https://github.com/crazy-max/ghaction-import-gpg/releases
31 | - name: Import bot's GPG key for signing commits
32 | id: import-gpg
33 | uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0
34 | with:
35 | gpg_private_key: ${{ secrets.BOT_MOBILE_GPG_PRIVATE_KEY }}
36 | passphrase: ${{ secrets.BOT_MOBILE_GPG_PASSPHRASE }}
37 | git_config_global: true
38 | git_user_signingkey: true
39 | git_commit_gpgsign: true
40 |
41 | - name: perform rebase
42 | run: |
43 | git config --global user.name "dev-mobile-bot"
44 | git config --global user.email "mobile+github-bot@infomaniak-dev.ch"
45 | git status
46 | git pull
47 | git checkout "$DEFAULT_BRANCH"
48 | git status
49 | git pull
50 | git checkout "$GITHUB_HEAD_REF"
51 | git rebase "$DEFAULT_BRANCH"
52 | git push --force-with-lease
53 | git status
54 |
55 | # Context: https://github.com/marketplace/actions/actions-ecosystem-remove-labels
56 | # Link: https://github.com/actions-ecosystem/action-remove-labels/releases
57 | - name: remove label
58 | if: always()
59 | uses: actions-ecosystem/action-remove-labels@2ce5d41b4b6aa8503e285553f75ed56e0a40bae0 # v1.3.0
60 | with:
61 | labels: rebase
62 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | Drag-Drop-Swipe-RecyclerView Sample
20 | Vertical
21 | Horizontal
22 | Grid
23 | $%1$.2f
24 | UNDO
25 | %1$s was removed.
26 | %1$s was archived.
27 | See Log Messages (%1$d)
28 | The log is empty
29 | Use default item layout
30 | Use card view item layout
31 | Draw behind swiped items
32 | Don\'t draw behind swiped items
33 | Reduce alpha on swiping
34 | Don\'t reduce alpha on swiping
35 | Restrict dragging
36 | Don\'t restrict dragging
37 | Delete
38 | Archive
39 |
40 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/listener/OnItemSwipeListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.listener
19 |
20 | /**
21 | * Listener for the swiping events of list items.
22 | */
23 | interface OnItemSwipeListener {
24 |
25 | /**
26 | * Indicates the direction in which the swipe action is performed.
27 | */
28 | enum class SwipeDirection {
29 | RIGHT_TO_LEFT,
30 | LEFT_TO_RIGHT,
31 | DOWN_TO_UP,
32 | UP_TO_DOWN
33 | }
34 |
35 | /**
36 | * Callback for whenever an item has been swiped.
37 | * If it returns false, this event will be considered as not handled and the swiped item will be
38 | * removed from the adapter's data set. This is the standard behaviour.
39 | * If it returns true, this event will be considered as handled and the adapter's data set will
40 | * not be changed. In this case, it is your responsibility to apply the necessary changes to the
41 | * adapter's data set.
42 | *
43 | * @param position The position of the swiped item.
44 | * @param direction The direction in which the item has been swiped.
45 | * @param item The item that has been swiped.
46 | * @return True if the event was handled (i.e., if the necessary changes were applied to the
47 | * adapter's data set within the callback); false otherwise. If false, the swiped item will be
48 | * removed from the adapter's data set automatically.
49 | */
50 | fun onItemSwiped(position: Int, direction: SwipeDirection, item: T): Boolean
51 | }
52 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/fragment_vertical_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
24 |
25 |
38 |
39 |
48 |
49 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/config/local/AppConfig.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.config.local
19 |
20 | enum class ListFragmentType(val index: Int, val tag: String) {
21 | VERTICAL(0, "VerticalFragment"),
22 | HORIZONTAL(1, "HorizontalFragment"),
23 | GRID(2, "GridFragment"),
24 | }
25 |
26 | data class ListFragmentConfig(
27 | var isUsingStandardItemLayout: Boolean,
28 | var isRestrictingDraggingDirections: Boolean,
29 | var isDrawingBehindSwipedItems: Boolean,
30 | var isUsingFadeOnSwipedItems: Boolean,
31 | )
32 |
33 | private val listFragmentConfigurations = listOf(
34 |
35 | // Initial state of the vertical-list fragment
36 | ListFragmentConfig(
37 | isUsingStandardItemLayout = true,
38 | isRestrictingDraggingDirections = true,
39 | isDrawingBehindSwipedItems = true,
40 | isUsingFadeOnSwipedItems = false,
41 | ),
42 |
43 | // Initial state of the horizontal-list fragment
44 | ListFragmentConfig(
45 | isUsingStandardItemLayout = false,
46 | isRestrictingDraggingDirections = false,
47 | isDrawingBehindSwipedItems = true,
48 | isUsingFadeOnSwipedItems = true,
49 | ),
50 |
51 | // Initial state of the grid-list fragment
52 | ListFragmentConfig(
53 | isUsingStandardItemLayout = false,
54 | isRestrictingDraggingDirections = false,
55 | isDrawingBehindSwipedItems = true,
56 | isUsingFadeOnSwipedItems = true,
57 | )
58 | )
59 |
60 | var currentListFragmentType = ListFragmentType.VERTICAL
61 | val currentListFragmentConfig
62 | get() = listFragmentConfigurations[currentListFragmentType.index]
63 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_grid_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
36 |
37 |
45 |
46 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_horizontal_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
36 |
37 |
45 |
46 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_grid_list_secondary.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
36 |
37 |
45 |
46 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/util/Logger.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.util
19 |
20 | /**
21 | * Dummy logger created to keep track of all the events that occur in this sample app.
22 | */
23 | class Logger(listener: OnLogUpdateListener) {
24 |
25 | interface OnLogUpdateListener {
26 | fun onLogUpdated()
27 | }
28 |
29 | private val _messages = mutableListOf()
30 | val messages: List
31 | get() = _messages.toList()
32 |
33 | private val listeners = mutableListOf(listener)
34 |
35 | companion object {
36 | var instance: Logger? = null
37 | private set
38 |
39 | fun init(listener: OnLogUpdateListener) {
40 | if (instance == null)
41 | instance = Logger(listener)
42 | else {
43 | instance?.listeners?.clear()
44 | addListener(listener)
45 | }
46 | }
47 |
48 | fun addListener(listener: OnLogUpdateListener) {
49 | if (instance?.listeners?.contains(listener) == false)
50 | instance?.listeners?.add(listener)
51 | }
52 |
53 | fun removeListener(listener: OnLogUpdateListener) {
54 | if (instance?.listeners?.contains(listener) == true)
55 | instance?.listeners?.remove(listener)
56 | }
57 |
58 | fun reset() {
59 | instance?._messages?.clear()
60 | instance?.listeners?.forEach { it.onLogUpdated() }
61 | }
62 |
63 | fun log(message: String) {
64 | instance?._messages?.add(message)
65 | instance?.listeners?.forEach { it.onLogUpdated() }
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_horizontal_list_secondary.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
36 |
37 |
45 |
46 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_vertical_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
37 |
38 |
46 |
47 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/behind_swiped_vertical_list_secondary.xml:
--------------------------------------------------------------------------------
1 |
18 |
27 |
28 |
37 |
38 |
46 |
47 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/data/source/base/BaseRepository.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.data.source.base
19 |
20 | /**
21 | * This is a dummy implementation of a repository to be used by the app to add and retrieve items.
22 | * It is abstract and generic, so it can be used to implement repositories of different kinds.
23 | */
24 | abstract class BaseRepository {
25 |
26 | interface OnItemAdditionListener {
27 | fun onItemAdded(item: T, position: Int)
28 | }
29 |
30 | private val items = mutableListOf()
31 | private val listeners = mutableListOf>()
32 |
33 | fun getAllItems() = items.toList()
34 |
35 | abstract fun generateNewItem(): T
36 |
37 | fun addItem(item: T): Boolean {
38 | if (!items.contains(item)) {
39 | items.add(item)
40 | notifyItemAddition(item)
41 |
42 | return true
43 | }
44 |
45 | return false
46 | }
47 |
48 | fun insertItem(item: T, position: Int): Boolean {
49 | if (!items.contains(item)) {
50 | items.add(position, item)
51 | notifyItemAddition(item)
52 |
53 | return true
54 | }
55 |
56 | return false
57 | }
58 |
59 | fun removeItem(item: T): Boolean {
60 | if (items.contains(item)) {
61 | items.remove(item)
62 |
63 | return true
64 | }
65 |
66 | return false
67 | }
68 |
69 | fun addOnItemAdditionListener(listener: OnItemAdditionListener) {
70 | if (!listeners.contains(listener))
71 | listeners.add(listener)
72 | }
73 |
74 | fun removeOnItemAdditionListener(listener: OnItemAdditionListener) {
75 | if (listeners.contains(listener))
76 | listeners.remove(listener)
77 | }
78 |
79 | private fun notifyItemAddition(item: T) {
80 | val position = items.indexOf(item)
81 | listeners.forEach { it.onItemAdded(item, position) }
82 | }
83 | }
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_grid_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
30 |
31 |
41 |
42 |
49 |
50 |
57 |
58 |
64 |
65 |
66 |
67 |
76 |
77 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_horizontal_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
30 |
31 |
41 |
42 |
49 |
50 |
57 |
58 |
64 |
65 |
66 |
67 |
76 |
77 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_vertical_list.xml:
--------------------------------------------------------------------------------
1 |
18 |
30 |
31 |
41 |
42 |
49 |
50 |
57 |
58 |
64 |
65 |
66 |
67 |
76 |
77 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/feature/managelog/view/LogFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.feature.managelog.view
19 |
20 | import android.os.Bundle
21 | import android.view.LayoutInflater
22 | import android.view.View
23 | import android.view.ViewGroup
24 | import android.widget.ScrollView
25 | import android.widget.TextView
26 | import androidx.fragment.app.Fragment
27 | import com.infomaniak.dragdropswiperecyclerviewsample.R
28 | import com.infomaniak.dragdropswiperecyclerviewsample.util.Logger
29 |
30 | /**
31 | * This fragment shows all the logged messages.
32 | */
33 | class LogFragment : Fragment() {
34 |
35 | private var messagesViewContainerContainer: ScrollView? = null
36 | private var messagesView: TextView? = null
37 |
38 | private val onLogUpdateListener = object : Logger.OnLogUpdateListener {
39 | override fun onLogUpdated() {
40 | loadLogMessages()
41 | }
42 | }
43 |
44 | override fun onCreate(savedInstanceState: Bundle?) {
45 | super.onCreate(savedInstanceState)
46 |
47 | setHasOptionsMenu(false)
48 | }
49 |
50 | override fun onCreateView(
51 | inflater: LayoutInflater,
52 | container: ViewGroup?,
53 | savedInstanceState: Bundle?
54 | ): View? {
55 |
56 | val rootView = inflater.inflate(R.layout.fragment_log, container, false)
57 | messagesViewContainerContainer = rootView.findViewById(R.id.messages_container_container)
58 | messagesView = rootView.findViewById(R.id.messages)
59 |
60 | loadLogMessages()
61 |
62 | return rootView
63 | }
64 |
65 | override fun onResume() {
66 | super.onResume()
67 |
68 | Logger.addListener(onLogUpdateListener)
69 | }
70 |
71 | override fun onPause() {
72 | super.onPause()
73 |
74 | Logger.removeListener(onLogUpdateListener)
75 | }
76 |
77 | private fun loadLogMessages() {
78 | messagesView?.text = getString(R.string.empty_log)
79 |
80 | if (Logger.instance?.messages?.isNotEmpty() == true) {
81 | messagesView?.text = ""
82 | Logger.instance?.messages?.forEachIndexed { index, message -> messagesView?.append("${index + 1}. $message\n\n") }
83 | messagesViewContainerContainer?.post { messagesViewContainerContainer?.fullScroll(View.FOCUS_DOWN) }
84 | }
85 | }
86 |
87 | companion object {
88 | const val TAG = "LogFragment"
89 |
90 | fun newInstance() = LogFragment()
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/ScrollAwareRecyclerView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview
19 |
20 | import android.content.Context
21 | import android.util.AttributeSet
22 | import androidx.recyclerview.widget.RecyclerView
23 | import com.infomaniak.dragdropswiperecyclerview.listener.OnListScrollListener
24 |
25 | /**
26 | * Extension of RecyclerView that detects when the user scrolls.
27 | */
28 | open class ScrollAwareRecyclerView @JvmOverloads constructor(
29 | context: Context,
30 | attrs: AttributeSet? = null,
31 | defStyleAttr: Int = 0
32 | ) : RecyclerView(context, attrs, defStyleAttr) {
33 |
34 | /**
35 | * Listener for the scrolling events.
36 | */
37 | var scrollListener: OnListScrollListener? = null
38 |
39 | private val internalListScrollListener = object : OnScrollListener() {
40 | override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
41 | super.onScrollStateChanged(recyclerView, newState)
42 |
43 | when (newState) {
44 | SCROLL_STATE_IDLE ->
45 | scrollListener?.onListScrollStateChanged(OnListScrollListener.ScrollState.IDLE)
46 |
47 | SCROLL_STATE_DRAGGING ->
48 | scrollListener?.onListScrollStateChanged(OnListScrollListener.ScrollState.DRAGGING)
49 |
50 | SCROLL_STATE_SETTLING ->
51 | scrollListener?.onListScrollStateChanged(OnListScrollListener.ScrollState.SETTLING)
52 | }
53 | }
54 |
55 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
56 | super.onScrolled(recyclerView, dx, dy)
57 |
58 | when {
59 | dy > 0 ->
60 | scrollListener?.onListScrolled(OnListScrollListener.ScrollDirection.DOWN, dy)
61 |
62 | dy < 0 ->
63 | scrollListener?.onListScrolled(OnListScrollListener.ScrollDirection.UP, -dy)
64 |
65 | dx > 0 ->
66 | scrollListener?.onListScrolled(OnListScrollListener.ScrollDirection.RIGHT, dx)
67 |
68 | dx < 0 ->
69 | scrollListener?.onListScrolled(OnListScrollListener.ScrollDirection.LEFT, -dx)
70 | }
71 | }
72 | }
73 |
74 | init {
75 | super.addOnScrollListener(internalListScrollListener)
76 | }
77 |
78 | @Deprecated("Use the property scrollListener instead.", ReplaceWith("scrollListener"))
79 | override fun addOnScrollListener(listener: OnScrollListener) {
80 | throw UnsupportedOperationException(
81 | "Only the property scrollListener can be used to add a scroll listener here."
82 | )
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/util/DividerDrawingHelper.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.util
19 |
20 | import android.graphics.Canvas
21 | import android.graphics.drawable.Drawable
22 | import android.view.View
23 | import androidx.recyclerview.widget.RecyclerView
24 |
25 | internal fun drawHorizontalDividers(
26 | itemLayout: View,
27 | canvas: Canvas,
28 | divider: Drawable,
29 | left: Int? = null,
30 | right: Int? = null,
31 | alpha: Float? = null
32 | ) {
33 | val itemParams = itemLayout.layoutParams as RecyclerView.LayoutParams
34 | val dividerLeft =
35 | (left ?: itemLayout.left + itemLayout.translationX.toInt()) - itemParams.leftMargin
36 | val dividerRight =
37 | (right ?: itemLayout.right + itemLayout.translationX.toInt()) + itemParams.rightMargin
38 |
39 | // Restore alpha to normal and then set it to a different value if required
40 | divider.alpha = 255
41 | if (alpha != null)
42 | divider.alpha = (alpha * 255).toInt()
43 |
44 | // Draw the bottom divider
45 | val bottomDividerTop =
46 | itemLayout.bottom + itemParams.bottomMargin + itemLayout.translationY.toInt()
47 | val bottomDividerBottom = bottomDividerTop + divider.intrinsicHeight
48 | divider.setBounds(dividerLeft, bottomDividerTop, dividerRight, bottomDividerBottom)
49 | divider.draw(canvas)
50 |
51 | // Draw the top divider
52 | val topDividerBottom = itemLayout.top - itemParams.topMargin + itemLayout.translationY.toInt()
53 | val topDividerTop = topDividerBottom - divider.intrinsicHeight
54 | divider.setBounds(dividerLeft, topDividerTop, dividerRight, topDividerBottom)
55 | divider.draw(canvas)
56 | }
57 |
58 | internal fun drawVerticalDividers(
59 | itemLayout: View,
60 | canvas: Canvas,
61 | divider: Drawable,
62 | top: Int? = null,
63 | bottom: Int? = null,
64 | alpha: Float? = null
65 | ) {
66 | val itemParams = itemLayout.layoutParams as RecyclerView.LayoutParams
67 | val dividerTop =
68 | (top ?: itemLayout.top + itemLayout.translationY.toInt()) - itemParams.topMargin
69 | val dividerBottom =
70 | (bottom ?: itemLayout.bottom + itemLayout.translationY.toInt()) + itemParams.bottomMargin
71 |
72 | // Restore alpha to normal and then set it to a different value if required
73 | divider.alpha = 255
74 | if (alpha != null)
75 | divider.alpha = (alpha * 255).toInt()
76 |
77 | // Draw the right divider
78 | val rightDividerLeft =
79 | itemLayout.right + itemParams.rightMargin + itemLayout.translationX.toInt()
80 | val rightDividerRight = rightDividerLeft + divider.intrinsicWidth
81 | divider.setBounds(rightDividerLeft, dividerTop, rightDividerRight, dividerBottom)
82 | divider.draw(canvas)
83 |
84 | // Draw the left divider
85 | val leftDividerRight = itemLayout.left - itemParams.leftMargin + itemLayout.translationX.toInt()
86 | val leftDividerLeft = leftDividerRight - divider.intrinsicWidth
87 | divider.setBounds(leftDividerLeft, dividerTop, leftDividerRight, dividerBottom)
88 | divider.draw(canvas)
89 | }
90 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
18 |
26 |
27 |
36 |
37 |
45 |
46 |
47 |
48 |
52 |
53 |
59 |
60 |
73 |
74 |
75 |
76 |
82 |
83 |
91 |
92 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_grid_list_cardview.xml:
--------------------------------------------------------------------------------
1 |
18 |
33 |
34 |
41 |
42 |
47 |
48 |
56 |
57 |
62 |
63 |
64 |
65 |
78 |
79 |
86 |
87 |
96 |
97 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_horizontal_list_cardview.xml:
--------------------------------------------------------------------------------
1 |
18 |
38 |
39 |
46 |
47 |
52 |
53 |
61 |
62 |
67 |
68 |
69 |
70 |
83 |
84 |
91 |
92 |
101 |
102 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/res/layout/list_item_vertical_list_cardview.xml:
--------------------------------------------------------------------------------
1 |
18 |
38 |
39 |
46 |
47 |
52 |
53 |
61 |
62 |
67 |
68 |
69 |
70 |
78 |
79 |
88 |
89 |
97 |
98 |
104 |
105 |
106 |
107 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/util/DragDropSwipeItemDecoration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.util
19 |
20 | import android.graphics.Canvas
21 | import android.graphics.Rect
22 | import android.graphics.drawable.Drawable
23 | import android.view.View
24 | import androidx.recyclerview.widget.RecyclerView
25 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeAdapter
26 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView
27 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView.ListOrientation
28 |
29 | internal class DragDropSwipeItemDecoration(var divider: Drawable) : RecyclerView.ItemDecoration() {
30 |
31 | override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
32 | if (parent is DragDropSwipeRecyclerView) {
33 | for (index in 0 until parent.childCount) {
34 | val child = parent.getChildAt(index)
35 |
36 | // We only draw dividers for items that are not being moved (moving ones will draw their own).
37 | // The reason why we need to do it this way is because this method is not called as often on
38 | // items that are being moved, so if we use it to draw the dividers, some frames will be lost
39 | // and even some spacing may appear between the divider and the item layout that is moving.
40 | // Luckily, some of the methods that are called by the system on moving items include a canvas
41 | // as a parameter and are called often enough to allow us to draw the dividers without lag.
42 | // The joys of programming for Android!
43 | if (!itemIsBeingMoved(parent, child))
44 | when (parent.orientation) {
45 | ListOrientation.VERTICAL_LIST_WITH_VERTICAL_DRAGGING,
46 | ListOrientation.VERTICAL_LIST_WITH_UNCONSTRAINED_DRAGGING ->
47 | drawHorizontalDividers(child, c, divider)
48 |
49 | ListOrientation.HORIZONTAL_LIST_WITH_UNCONSTRAINED_DRAGGING,
50 | ListOrientation.HORIZONTAL_LIST_WITH_HORIZONTAL_DRAGGING ->
51 | drawVerticalDividers(child, c, divider)
52 |
53 | ListOrientation.GRID_LIST_WITH_HORIZONTAL_SWIPING,
54 | ListOrientation.GRID_LIST_WITH_VERTICAL_SWIPING -> {
55 | drawHorizontalDividers(child, c, divider)
56 | drawVerticalDividers(child, c, divider)
57 | }
58 |
59 | null -> {}
60 | }
61 | }
62 | } else throw TypeCastException("The recycler view must be an extension of DragDropSwipeRecyclerView.")
63 | }
64 |
65 | override fun getItemOffsets(
66 | outRect: Rect,
67 | view: View,
68 | parent: RecyclerView,
69 | state: RecyclerView.State
70 | ) {
71 | super.getItemOffsets(outRect, view, parent, state)
72 |
73 | if (parent is DragDropSwipeRecyclerView) {
74 |
75 | val position = parent.getChildAdapterPosition(view)
76 | if (position != 0) {
77 | when (parent.orientation) {
78 | ListOrientation.VERTICAL_LIST_WITH_VERTICAL_DRAGGING,
79 | ListOrientation.VERTICAL_LIST_WITH_UNCONSTRAINED_DRAGGING ->
80 | outRect.top = divider.intrinsicHeight
81 |
82 | ListOrientation.HORIZONTAL_LIST_WITH_UNCONSTRAINED_DRAGGING,
83 | ListOrientation.HORIZONTAL_LIST_WITH_HORIZONTAL_DRAGGING ->
84 | outRect.left = divider.intrinsicWidth
85 |
86 | ListOrientation.GRID_LIST_WITH_HORIZONTAL_SWIPING,
87 | ListOrientation.GRID_LIST_WITH_VERTICAL_SWIPING -> {
88 | if (position >= parent.numOfColumnsPerRowInGridList)
89 | outRect.top = divider.intrinsicHeight
90 |
91 | if (position >= parent.numOfRowsPerColumnInGridList)
92 | outRect.left = divider.intrinsicWidth
93 | }
94 |
95 | null -> {}
96 | }
97 | }
98 | } else throw TypeCastException("The recycler view must be an extension of AsyncSwipeRecyclerView.")
99 | }
100 |
101 | private fun itemIsBeingMoved(parent: RecyclerView, child: View): Boolean {
102 | val viewHolder = parent.getChildViewHolder(child) as DragDropSwipeAdapter.ViewHolder
103 |
104 | return viewHolder.isBeingDragged || viewHolder.isBeingSwiped
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/feature/managelists/IceCreamListAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists
19 |
20 | import android.content.res.ColorStateList
21 | import android.graphics.Canvas
22 | import android.graphics.Color
23 | import android.view.View
24 | import android.widget.ImageView
25 | import android.widget.TextView
26 | import androidx.core.widget.ImageViewCompat
27 | import androidx.recyclerview.widget.AsyncListDiffer
28 | import androidx.recyclerview.widget.DiffUtil
29 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeAdapter
30 | import com.infomaniak.dragdropswiperecyclerviewsample.R
31 | import com.infomaniak.dragdropswiperecyclerviewsample.data.model.IceCream
32 | import com.infomaniak.dragdropswiperecyclerviewsample.util.Logger
33 |
34 | /**
35 | * Adapter for a list of ice creams.
36 | */
37 | class IceCreamListAdapter(
38 | dataSet: List = emptyList(),
39 | ) : DragDropSwipeAdapter(dataSet) {
40 |
41 | class IceCreamDiffUtil : DiffUtil.ItemCallback() {
42 |
43 | override fun areItemsTheSame(oldItem: IceCream, newItem: IceCream): Boolean {
44 | return oldItem.uuid == newItem.uuid
45 | }
46 |
47 | override fun areContentsTheSame(oldItem: IceCream, newItem: IceCream): Boolean {
48 | val isColorIdentical = oldItem.colorRed == newItem.colorRed &&
49 | oldItem.colorGreen == newItem.colorGreen &&
50 | oldItem.colorBlue == newItem.colorBlue
51 |
52 | return oldItem.name == newItem.name &&
53 | oldItem.price == newItem.price &&
54 | isColorIdentical
55 | }
56 | }
57 |
58 | override val asyncListDiffer: AsyncListDiffer = AsyncListDiffer(this, IceCreamDiffUtil())
59 |
60 | class ViewHolder(iceCreamLayout: View) : DragDropSwipeAdapter.ViewHolder(iceCreamLayout) {
61 | val iceCreamNameView: TextView = itemView.findViewById(R.id.ice_cream_name)
62 | val iceCreamPriceView: TextView = itemView.findViewById(R.id.ice_cream_price)
63 | val dragIcon: ImageView = itemView.findViewById(R.id.drag_icon)
64 | val iceCreamIcon: ImageView? = itemView.findViewById(R.id.ice_cream_icon)
65 | val iceCreamPhotoFilter: View? = itemView.findViewById(R.id.ice_cream_photo_filter)
66 | }
67 |
68 | override fun getViewHolder(itemView: View): ViewHolder {
69 | return ViewHolder(itemView)
70 | }
71 |
72 | override fun onBindViewHolder(item: IceCream, viewHolder: ViewHolder, position: Int) = with(viewHolder) {
73 | val context = itemView.context
74 |
75 | // Set ice cream name and price
76 | iceCreamNameView.text = item.name
77 | iceCreamPriceView.text = context.getString(R.string.priceFormat, item.price)
78 |
79 | // Set ice cream icon color
80 | val red = (item.colorRed * 255).toInt()
81 | val green = (item.colorGreen * 255).toInt()
82 | val blue = (item.colorBlue * 255).toInt()
83 |
84 | // Set the icon/image color
85 | when {
86 | iceCreamIcon != null -> {
87 | val iceCreamIconColor = Color.rgb(red, green, blue)
88 | ImageViewCompat.setImageTintList(iceCreamIcon, ColorStateList.valueOf(iceCreamIconColor))
89 | }
90 | iceCreamPhotoFilter != null -> {
91 | val iceCreamPhotoFilterColor = Color.argb(128, red, green, blue)
92 | iceCreamPhotoFilter.setBackgroundColor(iceCreamPhotoFilterColor)
93 | }
94 | }
95 | }
96 |
97 | override fun getViewToTouchToStartDraggingItem(item: IceCream, viewHolder: ViewHolder, position: Int) = viewHolder.dragIcon
98 |
99 | override fun onDragStarted(item: IceCream, viewHolder: ViewHolder) {
100 | Logger.log("Dragging started on ${item.name}")
101 | }
102 |
103 | override fun onSwipeStarted(item: IceCream, viewHolder: ViewHolder) {
104 | Logger.log("Swiping started on ${item.name}")
105 | }
106 |
107 | override fun onIsDragging(
108 | item: IceCream?,
109 | viewHolder: ViewHolder,
110 | offsetX: Int,
111 | offsetY: Int,
112 | canvasUnder: Canvas?,
113 | canvasOver: Canvas?,
114 | isUserControlled: Boolean,
115 | ) {
116 | // Call commented out to avoid saturating the log
117 | // Logger.log("The ${if (isUserControlled) "User" else "System"} is dragging ${item.name} (offset X: $offsetX, offset Y: $offsetY)")
118 | }
119 |
120 | override fun onIsSwiping(
121 | item: IceCream?,
122 | viewHolder: ViewHolder,
123 | offsetX: Int,
124 | offsetY: Int,
125 | canvasUnder: Canvas?,
126 | canvasOver: Canvas?,
127 | isUserControlled: Boolean,
128 | ) {
129 | // Call commented out to avoid saturating the log
130 | // Logger.log("The ${if (isUserControlled) "User" else "System"} is swiping ${item?.name} (offset X: $offsetX, offset Y: $offsetY)")
131 | }
132 |
133 | override fun onDragFinished(item: IceCream, viewHolder: ViewHolder) {
134 | Logger.log("Dragging finished on ${item.name} (the item was dropped)")
135 | }
136 |
137 | override fun onSwipeAnimationFinished(viewHolder: ViewHolder) {
138 | Logger.log("Swiping animation finished")
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/feature/managelists/view/VerticalListFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view
19 |
20 | import android.view.LayoutInflater
21 | import android.view.ViewGroup
22 | import androidx.core.content.ContextCompat
23 | import androidx.recyclerview.widget.LinearLayoutManager
24 | import androidx.viewbinding.ViewBinding
25 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView
26 | import com.infomaniak.dragdropswiperecyclerviewsample.R
27 | import com.infomaniak.dragdropswiperecyclerviewsample.config.local.currentListFragmentConfig
28 | import com.infomaniak.dragdropswiperecyclerviewsample.databinding.FragmentVerticalListBinding
29 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.base.BaseListFragment
30 |
31 | /**
32 | * This fragment shows a vertical list of ice creams.
33 | */
34 | class VerticalListFragment : BaseListFragment() {
35 |
36 | override val optionsMenuId = R.menu.fragment_vertical_list_options
37 |
38 | override fun inflateViewBinding(inflater: LayoutInflater, container: ViewGroup?): ViewBinding {
39 | return FragmentVerticalListBinding.inflate(inflater, container, false)
40 | }
41 |
42 | override fun setupListLayoutManager(list: DragDropSwipeRecyclerView) {
43 | // Set vertical linear layout manager
44 | list.layoutManager = LinearLayoutManager(activity)
45 | }
46 |
47 | override fun setupListOrientation(list: DragDropSwipeRecyclerView) {
48 | // It is necessary to set the orientation in code so the list can work correctly
49 | list.orientation = if (currentListFragmentConfig.isRestrictingDraggingDirections)
50 | DragDropSwipeRecyclerView.ListOrientation.VERTICAL_LIST_WITH_VERTICAL_DRAGGING
51 | else
52 | DragDropSwipeRecyclerView.ListOrientation.VERTICAL_LIST_WITH_UNCONSTRAINED_DRAGGING
53 | }
54 |
55 | override fun setupListItemLayout(list: DragDropSwipeRecyclerView) {
56 | if (currentListFragmentConfig.isUsingStandardItemLayout)
57 | setStandardItemLayoutAndDivider(list)
58 | else
59 | setCardViewItemLayoutAndNoDivider(list)
60 | }
61 |
62 | private fun setStandardItemLayoutAndDivider(list: DragDropSwipeRecyclerView) {
63 | // In XML: app:item_layout="@layout/list_item_vertical_list"
64 | list.itemLayoutId = R.layout.list_item_vertical_list
65 |
66 | // In XML: app:divider="@drawable/divider_vertical_list"
67 | list.dividerDrawableId = R.drawable.divider_vertical_list
68 | }
69 |
70 | private fun setCardViewItemLayoutAndNoDivider(list: DragDropSwipeRecyclerView) {
71 | // In XML: app:item_layout="@layout/list_item_vertical_list_cardview"
72 | list.itemLayoutId = R.layout.list_item_vertical_list_cardview
73 |
74 | // In XML: app:divider="@null"
75 | list.dividerDrawableId = null
76 | }
77 |
78 | override fun setupLayoutBehindItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
79 | // We set to null all the properties that can be used to display something behind swiped items
80 | // In XML: app:behind_swiped_item_bg_color="@null"
81 | list.behindSwipedItemBackgroundColor = null
82 |
83 | // In XML: app:behind_swiped_item_bg_color_secondary="@null"
84 | list.behindSwipedItemBackgroundSecondaryColor = null
85 |
86 | // In XML: app:behind_swiped_item_icon="@null"
87 | list.behindSwipedItemIconDrawableId = null
88 |
89 | // In XML: app:behind_swiped_item_icon_secondary="@null"
90 | list.behindSwipedItemIconSecondaryDrawableId = null
91 |
92 | // In XML: app:behind_swiped_item_custom_layout="@null"
93 | list.behindSwipedItemLayoutId = null
94 |
95 | // In XML: app:behind_swiped_item_custom_layout_secondary="@null"
96 | list.behindSwipedItemSecondaryLayoutId = null
97 |
98 | val currentContext = context
99 | if (currentListFragmentConfig.isDrawingBehindSwipedItems && currentContext != null)
100 | if (currentListFragmentConfig.isUsingStandardItemLayout) {
101 | // We set certain properties to show an icon and a background colour behind swiped items
102 | // In XML: app:behind_swiped_item_icon="@drawable/ic_remove_item"
103 | list.behindSwipedItemIconDrawableId = R.drawable.ic_remove_item
104 |
105 | // In XML: app:behind_swiped_item_icon_secondary="@drawable/ic_archive_item"
106 | list.behindSwipedItemIconSecondaryDrawableId = R.drawable.ic_archive_item
107 |
108 | // In XML: app:behind_swiped_item_bg_color="@color/swipeBehindBackground"
109 | list.behindSwipedItemBackgroundColor =
110 | ContextCompat.getColor(currentContext, R.color.swipeBehindBackground)
111 |
112 | // In XML: app:behind_swiped_item_bg_color_secondary="@color/swipeBehindBackgroundSecondary"
113 | list.behindSwipedItemBackgroundSecondaryColor =
114 | ContextCompat.getColor(currentContext, R.color.swipeBehindBackgroundSecondary)
115 |
116 | // In XML: app:behind_swiped_item_icon_margin="@dimen/spacing_normal"
117 | list.behindSwipedItemIconMargin = resources.getDimension(R.dimen.spacing_normal)
118 | } else {
119 | // We set our custom layouts to be displayed behind swiped items
120 | // In XML: app:behind_swiped_item_custom_layout="@layout/behind_swiped_vertical_list"
121 | list.behindSwipedItemLayoutId = R.layout.behind_swiped_vertical_list
122 |
123 | // In XML: app:behind_swiped_item_custom_layout_secondary="@layout/behind_swiped_vertical_list_secondary"
124 | list.behindSwipedItemSecondaryLayoutId =
125 | R.layout.behind_swiped_vertical_list_secondary
126 | }
127 | }
128 |
129 | override fun setupFadeItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
130 | // In XML: app:swiped_item_opacity_fades_on_swiping="true/false"
131 | list.reduceItemAlphaOnSwiping = currentListFragmentConfig.isUsingFadeOnSwipedItems
132 | }
133 |
134 | companion object {
135 | fun newInstance() = VerticalListFragment()
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/feature/managelists/view/HorizontalListFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view
19 |
20 | import android.view.LayoutInflater
21 | import android.view.ViewGroup
22 | import androidx.core.content.ContextCompat
23 | import androidx.recyclerview.widget.LinearLayoutManager
24 | import androidx.recyclerview.widget.RecyclerView
25 | import androidx.viewbinding.ViewBinding
26 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView
27 | import com.infomaniak.dragdropswiperecyclerviewsample.R
28 | import com.infomaniak.dragdropswiperecyclerviewsample.config.local.currentListFragmentConfig
29 | import com.infomaniak.dragdropswiperecyclerviewsample.databinding.FragmentHorizontalListBinding
30 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.base.BaseListFragment
31 |
32 | /**
33 | * This fragment shows a horizontal list of ice creams.
34 | */
35 | class HorizontalListFragment : BaseListFragment() {
36 |
37 | override val optionsMenuId = R.menu.fragment_horizontal_list_options
38 |
39 | override fun inflateViewBinding(inflater: LayoutInflater, container: ViewGroup?): ViewBinding {
40 | return FragmentHorizontalListBinding.inflate(inflater, container, false)
41 | }
42 |
43 | override fun setupListLayoutManager(list: DragDropSwipeRecyclerView) {
44 | // Set horizontal linear layout manager
45 | list.layoutManager = LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false)
46 | }
47 |
48 | override fun setupListOrientation(list: DragDropSwipeRecyclerView) {
49 | // It is necessary to set the orientation in code so the list can work correctly
50 | list.orientation = if (currentListFragmentConfig.isRestrictingDraggingDirections)
51 | DragDropSwipeRecyclerView.ListOrientation.HORIZONTAL_LIST_WITH_HORIZONTAL_DRAGGING
52 | else
53 | DragDropSwipeRecyclerView.ListOrientation.HORIZONTAL_LIST_WITH_UNCONSTRAINED_DRAGGING
54 | }
55 |
56 | override fun setupListItemLayout(list: DragDropSwipeRecyclerView) {
57 | if (currentListFragmentConfig.isUsingStandardItemLayout)
58 | setStandardItemLayoutAndDivider(list)
59 | else
60 | setCardViewItemLayoutAndNoDivider(list)
61 | }
62 |
63 | private fun setStandardItemLayoutAndDivider(list: DragDropSwipeRecyclerView) {
64 | // In XML: app:item_layout="@layout/list_item_horizontal_list"
65 | list.itemLayoutId = R.layout.list_item_horizontal_list
66 |
67 | // In XML: app:divider="@drawable/divider_horizontal_list"
68 | list.dividerDrawableId = R.drawable.divider_horizontal_list
69 | }
70 |
71 | private fun setCardViewItemLayoutAndNoDivider(list: DragDropSwipeRecyclerView) {
72 | // In XML: app:item_layout="@layout/list_item_horizontal_list_cardview"
73 | list.itemLayoutId = R.layout.list_item_horizontal_list_cardview
74 |
75 | // In XML: app:divider="@null"
76 | list.dividerDrawableId = null
77 | }
78 |
79 | override fun setupLayoutBehindItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
80 | // We set to null all the properties that can be used to display something behind swiped items
81 | // In XML: app:behind_swiped_item_bg_color="@null"
82 | list.behindSwipedItemBackgroundColor = null
83 |
84 | // In XML: app:behind_swiped_item_bg_color_secondary="@null"
85 | list.behindSwipedItemBackgroundSecondaryColor = null
86 |
87 | // In XML: app:behind_swiped_item_icon="@null"
88 | list.behindSwipedItemIconDrawableId = null
89 |
90 | // In XML: app:behind_swiped_item_icon_secondary="@null"
91 | list.behindSwipedItemIconSecondaryDrawableId = null
92 |
93 | // In XML: app:behind_swiped_item_custom_layout="@null"
94 | list.behindSwipedItemLayoutId = null
95 |
96 | // In XML: app:behind_swiped_item_custom_layout_secondary="@null"
97 | list.behindSwipedItemSecondaryLayoutId = null
98 |
99 | val currentContext = context
100 | if (currentListFragmentConfig.isDrawingBehindSwipedItems && currentContext != null)
101 | if (currentListFragmentConfig.isUsingStandardItemLayout) {
102 | // We set certain properties to show an icon and a background colour behind swiped items
103 | // In XML: app:behind_swiped_item_icon="@drawable/ic_remove_item"
104 | list.behindSwipedItemIconDrawableId = R.drawable.ic_remove_item
105 |
106 | // In XML: app:behind_swiped_item_icon_secondary="@drawable/ic_archive_item"
107 | list.behindSwipedItemIconSecondaryDrawableId = R.drawable.ic_archive_item
108 |
109 | // In XML: app:behind_swiped_item_bg_color="@color/swipeBehindBackground"
110 | list.behindSwipedItemBackgroundColor = ContextCompat.getColor(currentContext, R.color.swipeBehindBackground)
111 |
112 | // In XML: app:behind_swiped_item_bg_color_secondary="@color/swipeBehindBackgroundSecondary"
113 | list.behindSwipedItemBackgroundSecondaryColor =
114 | ContextCompat.getColor(currentContext, R.color.swipeBehindBackgroundSecondary)
115 |
116 | // In XML: app:behind_swiped_item_icon_centered="true"
117 | list.behindSwipedItemCenterIcon = true
118 | } else {
119 | // We set our custom layouts to be displayed behind swiped items
120 | // In XML: app:behind_swiped_item_custom_layout="@layout/behind_swiped_horizontal_list"
121 | list.behindSwipedItemLayoutId = R.layout.behind_swiped_horizontal_list
122 |
123 | // In XML: app:behind_swiped_item_custom_layout_secondary="@layout/behind_swiped_horizontal_list_secondary"
124 | list.behindSwipedItemSecondaryLayoutId = R.layout.behind_swiped_horizontal_list_secondary
125 | }
126 | }
127 |
128 | override fun setupFadeItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
129 | // In XML: app:swiped_item_opacity_fades_on_swiping="true/false"
130 | list.reduceItemAlphaOnSwiping = currentListFragmentConfig.isUsingFadeOnSwipedItems
131 | }
132 |
133 | companion object {
134 | fun newInstance() = HorizontalListFragment()
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/data/source/IceCreamRepository.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.data.source
19 |
20 | import com.infomaniak.dragdropswiperecyclerviewsample.data.model.IceCream
21 | import com.infomaniak.dragdropswiperecyclerviewsample.data.source.base.BaseRepository
22 | import java.util.Random
23 | import java.util.UUID
24 |
25 | /**
26 | * A dummy repository with ice creams.
27 | */
28 | class IceCreamRepository : BaseRepository() {
29 |
30 | private val adjectives: List = arrayListOf(
31 | "Acidic",
32 | "Bitter",
33 | "Cool",
34 | "Creamy",
35 | "Delicious",
36 | "Gooey",
37 | "Hot",
38 | "Juicy",
39 | "Mild",
40 | "Nutty",
41 | "Peppery",
42 | "Ripe",
43 | "Salty",
44 | "Savory",
45 | "Sour",
46 | "Spicy",
47 | "Sticky",
48 | "Strong",
49 | "Sweet",
50 | "Tangy",
51 | "Tart",
52 | "Tasteless",
53 | "Tasty",
54 | )
55 |
56 | private val names: List = arrayListOf(
57 | "Apple",
58 | "Apricot",
59 | "Avocado",
60 | "Banana",
61 | "Bilberry",
62 | "Blackberry",
63 | "Blackcurrant",
64 | "Blueberry",
65 | "Boysenberry",
66 | "Currant",
67 | "Cherry",
68 | "Coconut",
69 | "Cranberry",
70 | "Cucumber",
71 | "Custard apple",
72 | "Damson",
73 | "Date",
74 | "Dragon Fruit",
75 | "Elderberry",
76 | "Fig",
77 | "Gooseberry",
78 | "Grape",
79 | "Raisin",
80 | "Grapefruit",
81 | "Guava",
82 | "Huckleberry",
83 | "Jack Fruit",
84 | "Jujube",
85 | "Juniper berry",
86 | "Kiwi",
87 | "Kumquat",
88 | "Lemon",
89 | "Lime",
90 | "Mango",
91 | "Melon",
92 | "Cantaloupe",
93 | "Honeydew",
94 | "Watermelon",
95 | "Miracle fruit",
96 | "Mulberry",
97 | "Nectarine",
98 | "Nance",
99 | "Olive",
100 | "Orange",
101 | "Blood orange",
102 | "Clementine",
103 | "Tangerine",
104 | "Papaya",
105 | "Peach",
106 | "Pear",
107 | "Persimmon",
108 | "Plantain",
109 | "Plum",
110 | "Pineapple",
111 | "Pomegranate",
112 | "Quince",
113 | "Raspberry",
114 | "Redcurrant",
115 | "Satsuma",
116 | "Star fruit",
117 | "Strawberry",
118 | "Tamarind",
119 | "After Eight",
120 | "Altoids",
121 | "Aniseed ball",
122 | "Aniseed twist",
123 | "Apple drops",
124 | "Banjo",
125 | "Barley sugar",
126 | "Black Jack",
127 | "Bonfire toffee",
128 | "Bounty",
129 | "Butterscotch",
130 | "Coconut ice",
131 | "Dolly mixture",
132 | "Double Decker",
133 | "Drops",
134 | "Flake",
135 | "Flying saucer",
136 | "Fruit Salad",
137 | "Fudge",
138 | "Fudge",
139 | "Fuse",
140 | "Galaxy",
141 | "Galaxy Bubbles",
142 | "Gobstopper",
143 | "Halls",
144 | "Humbug",
145 | "Jelly Babies",
146 | "Kit Kat",
147 | "Lion Bar",
148 | "Liquorice",
149 | "Mars",
150 | "Midget Gems",
151 | "Mingles",
152 | "Mini Eggs",
153 | "Galaxy Minstrels",
154 | "Pear drop",
155 | "Polo",
156 | "Quality Street",
157 | "Revels",
158 | "Rock",
159 | "Sherbet",
160 | "Smarties",
161 | "Snickers",
162 | "Sports Mixture",
163 | "Toffee Crisp",
164 | "Topic",
165 | "Trio",
166 | "Twirl",
167 | "Victory V",
168 | "Wham Bar",
169 | "Wine gum",
170 | "Yorkie",
171 | )
172 |
173 | override fun generateNewItem(): IceCream {
174 | val iceCreamName = generateIceCreamName()
175 | val iceCreamPrice = generateIceCreamPrice()
176 | val red = generateIceCreamBasicColor()
177 | val green = generateIceCreamBasicColor()
178 | val blue = generateIceCreamBasicColor()
179 | val (enhancedRed, enhancedGreen, enhancedBlue) = enhanceColorIntensity(red, green, blue)
180 |
181 | val iceCream = IceCream(UUID.randomUUID(), iceCreamName, iceCreamPrice, enhancedRed, enhancedGreen, enhancedBlue)
182 |
183 | addItem(iceCream)
184 |
185 | return iceCream
186 | }
187 |
188 | private fun enhanceColorIntensity(
189 | red: Float,
190 | green: Float,
191 | blue: Float,
192 | ): Triple {
193 | var enhancedRed = red
194 | var enhancedGreen = green
195 | var enhancedBlue = blue
196 |
197 | // Make the strongest color stronger and the weakest weaker to get more intense colors
198 | when {
199 | enhancedRed > enhancedGreen && enhancedRed > enhancedBlue -> enhancedRed += 0.1f
200 | enhancedGreen > enhancedRed && enhancedGreen > enhancedBlue -> enhancedGreen += 0.1f
201 | enhancedBlue > enhancedRed && enhancedBlue > enhancedGreen -> enhancedBlue += 0.1f
202 | enhancedRed < enhancedGreen && enhancedRed < enhancedBlue -> enhancedRed -= 0.1f
203 | enhancedGreen < enhancedRed && enhancedGreen < enhancedBlue -> enhancedGreen -= 0.1f
204 | enhancedBlue < enhancedRed && enhancedBlue < enhancedGreen -> enhancedBlue -= 0.1f
205 | }
206 |
207 | return Triple(enhancedRed, enhancedGreen, enhancedBlue)
208 | }
209 |
210 | private fun generateIceCreamName() = "${adjectives.shuffled().take(1)[0]} ${names.shuffled().take(1)[0]}"
211 |
212 | private fun generateIceCreamPrice() = (80..500).random().toFloat() / 100.0f
213 |
214 | private fun generateIceCreamBasicColor() = (80..210).random().toFloat() / 255.0f
215 |
216 | private fun ClosedRange.random() = Random().nextInt((endInclusive + 1) - start) + start
217 |
218 | companion object {
219 | private var instance: IceCreamRepository? = null
220 |
221 | fun getInstance(): IceCreamRepository {
222 | if (instance == null) instance = IceCreamRepository()
223 |
224 | return instance as IceCreamRepository
225 | }
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/feature/managelists/view/GridListFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view
19 |
20 | import android.view.LayoutInflater
21 | import android.view.ViewGroup
22 | import androidx.core.content.ContextCompat
23 | import androidx.recyclerview.widget.GridLayoutManager
24 | import androidx.viewbinding.ViewBinding
25 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView
26 | import com.infomaniak.dragdropswiperecyclerviewsample.R
27 | import com.infomaniak.dragdropswiperecyclerviewsample.config.local.currentListFragmentConfig
28 | import com.infomaniak.dragdropswiperecyclerviewsample.databinding.FragmentGridListBinding
29 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.base.BaseListFragment
30 |
31 | /**
32 | * This fragment shows a grid-arranged list of ice creams.
33 | */
34 | class GridListFragment : BaseListFragment() {
35 |
36 | private val numberOfColumns = 2
37 |
38 | override val optionsMenuId = R.menu.fragment_grid_list_options
39 |
40 | override fun inflateViewBinding(inflater: LayoutInflater, container: ViewGroup?): ViewBinding {
41 | return FragmentGridListBinding.inflate(inflater, container, false)
42 | }
43 |
44 | override fun setupListLayoutManager(list: DragDropSwipeRecyclerView) {
45 | // Set grid linear layout manager
46 | list.layoutManager = GridLayoutManager(activity, numberOfColumns)
47 | }
48 |
49 | override fun setupListOrientation(list: DragDropSwipeRecyclerView) {
50 | // It is necessary to set the orientation in code so the list can work correctly.
51 | // Horizontal swiping is specified because this grid list is vertically scrollable.
52 | // For horizontally scrollable grid lists, vertical swiping should be used instead.
53 | list.orientation =
54 | DragDropSwipeRecyclerView.ListOrientation.GRID_LIST_WITH_HORIZONTAL_SWIPING
55 |
56 | // We set this property to stop the grid list from drawing top dividers in the first row
57 | list.numOfColumnsPerRowInGridList = numberOfColumns
58 | }
59 |
60 | override fun setupListItemLayout(list: DragDropSwipeRecyclerView) {
61 | if (currentListFragmentConfig.isUsingStandardItemLayout)
62 | setStandardItemLayoutAndDivider(list)
63 | else
64 | setCardViewItemLayoutAndNoDivider(list)
65 | }
66 |
67 | private fun setStandardItemLayoutAndDivider(list: DragDropSwipeRecyclerView) {
68 | // In XML: app:item_layout="@layout/list_item_grid_list"
69 | list.itemLayoutId = R.layout.list_item_grid_list
70 |
71 | // In XML: app:divider="@drawable/divider_grid_list"
72 | list.dividerDrawableId = R.drawable.divider_grid_list
73 | }
74 |
75 | private fun setCardViewItemLayoutAndNoDivider(list: DragDropSwipeRecyclerView) {
76 | // In XML: app:item_layout="@layout/list_item_grid_list_cardview"
77 | list.itemLayoutId = R.layout.list_item_grid_list_cardview
78 |
79 | // In XML: app:divider="@null"
80 | list.dividerDrawableId = null
81 | }
82 |
83 | override fun setupLayoutBehindItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
84 | // We set to null all the properties that can be used to display something behind swiped items
85 | // In XML: app:behind_swiped_item_bg_color="@null"
86 | list.behindSwipedItemBackgroundColor = null
87 |
88 | // In XML: app:behind_swiped_item_bg_color_secondary="@null"
89 | list.behindSwipedItemBackgroundSecondaryColor = null
90 |
91 | // In XML: app:behind_swiped_item_icon="@null"
92 | list.behindSwipedItemIconDrawableId = null
93 |
94 | // In XML: app:behind_swiped_item_icon_secondary="@null"
95 | list.behindSwipedItemIconSecondaryDrawableId = null
96 |
97 | // In XML: app:behind_swiped_item_custom_layout="@null"
98 | list.behindSwipedItemLayoutId = null
99 |
100 | // In XML: app:behind_swiped_item_custom_layout_secondary="@null"
101 | list.behindSwipedItemSecondaryLayoutId = null
102 |
103 | val currentContext = context
104 | if (currentListFragmentConfig.isDrawingBehindSwipedItems && currentContext != null)
105 | if (currentListFragmentConfig.isUsingStandardItemLayout) {
106 | // We set certain properties to show an icon and a background colour behind swiped items
107 | // In XML: app:behind_swiped_item_icon="@drawable/ic_remove_item"
108 | list.behindSwipedItemIconDrawableId = R.drawable.ic_remove_item
109 |
110 | // In XML: app:behind_swiped_item_icon_secondary="@drawable/ic_archive_item"
111 | list.behindSwipedItemIconSecondaryDrawableId = R.drawable.ic_archive_item
112 |
113 | // In XML: app:behind_swiped_item_bg_color="@color/swipeBehindBackground"
114 | list.behindSwipedItemBackgroundColor =
115 | ContextCompat.getColor(currentContext, R.color.swipeBehindBackground)
116 |
117 | // In XML: app:behind_swiped_item_bg_color_secondary="@color/swipeBehindBackgroundSecondary"
118 | list.behindSwipedItemBackgroundSecondaryColor =
119 | ContextCompat.getColor(currentContext, R.color.swipeBehindBackgroundSecondary)
120 |
121 | // In XML: app:behind_swiped_item_icon_margin="@dimen/spacing_normal"
122 | list.behindSwipedItemIconMargin = resources.getDimension(R.dimen.spacing_normal)
123 | } else {
124 | // We set our custom layouts to be displayed behind swiped items
125 | // In XML: app:behind_swiped_item_custom_layout="@layout/behind_swiped_grid_list"
126 | list.behindSwipedItemLayoutId = R.layout.behind_swiped_grid_list
127 |
128 | // In XML: app:behind_swiped_item_custom_layout_secondary="@layout/behind_swiped_grid_list_secondary"
129 | list.behindSwipedItemSecondaryLayoutId = R.layout.behind_swiped_grid_list_secondary
130 | }
131 | }
132 |
133 | override fun setupFadeItemLayoutOnSwiping(list: DragDropSwipeRecyclerView) {
134 | // In XML: app:swiped_item_opacity_fades_on_swiping="true/false"
135 | list.reduceItemAlphaOnSwiping = currentListFragmentConfig.isUsingFadeOnSwipedItems
136 | }
137 |
138 | companion object {
139 | fun newInstance() = GridListFragment()
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview-sample/src/main/java/com/infomaniak/dragdropswiperecyclerviewsample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerviewsample
19 |
20 | import android.graphics.Color
21 | import android.os.Bundle
22 | import android.view.MenuItem
23 | import android.view.View
24 | import androidx.appcompat.app.AppCompatActivity
25 | import androidx.appcompat.content.res.AppCompatResources
26 | import androidx.fragment.app.Fragment
27 | import com.google.android.material.navigation.NavigationBarView
28 | import com.infomaniak.dragdropswiperecyclerviewsample.config.local.ListFragmentType
29 | import com.infomaniak.dragdropswiperecyclerviewsample.config.local.currentListFragmentType
30 | import com.infomaniak.dragdropswiperecyclerviewsample.data.source.IceCreamRepository
31 | import com.infomaniak.dragdropswiperecyclerviewsample.databinding.ActivityMainBinding
32 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.GridListFragment
33 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.HorizontalListFragment
34 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.VerticalListFragment
35 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelists.view.base.BaseListFragment
36 | import com.infomaniak.dragdropswiperecyclerviewsample.feature.managelog.view.LogFragment
37 | import com.infomaniak.dragdropswiperecyclerviewsample.util.Logger
38 |
39 | /**
40 | * Main Activity of the app. Handles the navigation to the list sample screens and to the log screen.
41 | */
42 | class MainActivity : AppCompatActivity() {
43 |
44 | private lateinit var binding: ActivityMainBinding
45 |
46 | private val onBottomItemSelectedListener = NavigationBarView.OnItemSelectedListener { item ->
47 | tryNavigateToListFragment(item.itemId)
48 | }
49 |
50 | private val onLogButtonClickedListener = View.OnClickListener {
51 | navigateToLogFragment()
52 | }
53 |
54 | private val onLogUpdatedListener = object : Logger.OnLogUpdateListener {
55 | override fun onLogUpdated() = refreshLogButtonText()
56 | }
57 |
58 | private val onFabClickedListener = View.OnClickListener {
59 | // When in the log fragment, the FAB clears the log; when in a list fragment, it adds an item
60 | if (isLogFragmentOpen())
61 | Logger.reset()
62 | else
63 | IceCreamRepository.getInstance().generateNewItem()
64 | }
65 |
66 | override fun onCreate(savedInstanceState: Bundle?) {
67 | super.onCreate(savedInstanceState)
68 |
69 | binding = ActivityMainBinding.inflate(layoutInflater)
70 | setContentView(binding.root)
71 | supportActionBar?.elevation = 0.0f
72 | window.navigationBarColor = Color.BLACK
73 |
74 | setupLog()
75 | setupBottomNavigation()
76 | setupFab()
77 | refreshLogButtonText()
78 | navigateToListFragment()
79 | }
80 |
81 | private fun setupLog() {
82 | // Initialise log and subscribe to log changes
83 | Logger.init(onLogUpdatedListener)
84 |
85 | // If the user clicks on the log button, we open the log fragment
86 | binding.seeLogButton.setOnClickListener(onLogButtonClickedListener)
87 | }
88 |
89 | private fun setupBottomNavigation() {
90 | binding.navigation.setOnItemSelectedListener(onBottomItemSelectedListener)
91 | }
92 |
93 | private fun setupFab() {
94 | binding.fab.setOnClickListener(onFabClickedListener)
95 | }
96 |
97 | private fun refreshLogButtonText() {
98 | val numItemsOnLog = Logger.instance?.messages?.size ?: 0
99 | binding.seeLogButtonText.text = getString(R.string.seeLogMessagesTitle, numItemsOnLog)
100 | }
101 |
102 | private fun tryNavigateToListFragment(itemId: Int): Boolean {
103 | val listFragmentType: ListFragmentType? = when (itemId) {
104 | R.id.navigation_vertical_list -> ListFragmentType.VERTICAL
105 | R.id.navigation_horizontal_list -> ListFragmentType.HORIZONTAL
106 | R.id.navigation_grid_list -> ListFragmentType.GRID
107 | else -> null
108 | }
109 |
110 | if (listFragmentType != null && (listFragmentType != currentListFragmentType || isLogFragmentOpen())) {
111 | navigateToListFragment(listFragmentType)
112 |
113 | return true
114 | }
115 |
116 | return false
117 | }
118 |
119 | private fun navigateToListFragment(listFragmentType: ListFragmentType = currentListFragmentType) {
120 | currentListFragmentType = listFragmentType
121 |
122 | val fragment: BaseListFragment = when (listFragmentType) {
123 | ListFragmentType.VERTICAL -> VerticalListFragment.newInstance()
124 | ListFragmentType.HORIZONTAL -> HorizontalListFragment.newInstance()
125 | ListFragmentType.GRID -> GridListFragment.newInstance()
126 | }
127 | replaceFragment(fragment, listFragmentType.tag)
128 | onNavigatedToListFragment()
129 | }
130 |
131 | private fun navigateToLogFragment() {
132 | replaceFragment(LogFragment.newInstance(), LogFragment.TAG)
133 | onNavigatedToLogFragment()
134 | }
135 |
136 | private fun onNavigatedToListFragment() {
137 | supportActionBar?.setDisplayHomeAsUpEnabled(false)
138 | supportActionBar?.setHomeButtonEnabled(false)
139 | binding.seeLogButton.visibility = View.VISIBLE
140 | binding.fab.setImageDrawable(
141 | AppCompatResources.getDrawable(applicationContext, R.drawable.ic_new_item)
142 | )
143 | }
144 |
145 | private fun onNavigatedToLogFragment() {
146 | supportActionBar?.setDisplayHomeAsUpEnabled(true)
147 | supportActionBar?.setHomeButtonEnabled(true)
148 | binding.seeLogButton.visibility = View.GONE
149 | binding.fab.setImageDrawable(
150 | AppCompatResources.getDrawable(applicationContext, R.drawable.ic_clear_items)
151 | )
152 | }
153 |
154 | private fun isLogFragmentOpen() = supportFragmentManager.findFragmentByTag(LogFragment.TAG) != null
155 |
156 | private fun replaceFragment(fragment: Fragment, tag: String) {
157 | supportFragmentManager.beginTransaction().apply {
158 | replace(R.id.content_frame, fragment, tag)
159 | }.commit()
160 | }
161 |
162 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
163 | return when (item.itemId) {
164 | android.R.id.home -> {
165 | if (isLogFragmentOpen()) {
166 | navigateToListFragment()
167 | return true
168 | }
169 | super.onOptionsItemSelected(item)
170 | }
171 |
172 | else -> super.onOptionsItemSelected(item)
173 | }
174 | }
175 |
176 | override fun onBackPressed() {
177 | if (isLogFragmentOpen()) navigateToListFragment() else super.onBackPressed()
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/drag-drop-swipe-recyclerview/src/main/java/com/infomaniak/dragdropswiperecyclerview/util/DragDropSwipeTouchHelper.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Drag/Drop/Swipe RecyclerView - Android
3 | * Copyright (C) 2018 Julio Ernesto Rodríguez Cabañas
4 | * Copyright (C) 2025 Infomaniak Network SA
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package com.infomaniak.dragdropswiperecyclerview.util
19 |
20 | import android.graphics.Canvas
21 | import androidx.recyclerview.widget.ItemTouchHelper
22 | import androidx.recyclerview.widget.RecyclerView
23 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeAdapter
24 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView
25 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView.ListOrientation
26 | import com.infomaniak.dragdropswiperecyclerview.DragDropSwipeRecyclerView.ListOrientation.DirectionFlag
27 | import com.infomaniak.dragdropswiperecyclerview.listener.OnItemSwipeListener.SwipeDirection
28 |
29 | internal class DragDropSwipeTouchHelper(
30 | private val itemDragListener: OnItemDragListener,
31 | private val itemSwipeListener: OnItemSwipeListener,
32 | private val itemStateChangeListener: OnItemStateChangeListener,
33 | private val itemLayoutPositionChangeListener: OnItemLayoutPositionChangeListener,
34 | internal var recyclerView: DragDropSwipeRecyclerView?
35 | ) : ItemTouchHelper.Callback() {
36 |
37 | /**
38 | * Similar to the public interface of the library that has the same name, but for internal use only.
39 | * It will help pass the events from this class down to the adapter.
40 | */
41 | interface OnItemDragListener {
42 | fun onItemDragged(previousPosition: Int, newPosition: Int)
43 | fun onItemDropped(initialPosition: Int, finalPosition: Int)
44 | }
45 |
46 | /**
47 | * Similar to the public interface of the library that has the same name, but for internal use only.
48 | * It will help pass the events from this class down to the adapter.
49 | */
50 | interface OnItemSwipeListener {
51 | fun onItemSwiped(position: Int, direction: SwipeDirection)
52 | }
53 |
54 | /**
55 | * Similar to the public interface of the library that has the same name, but for internal use only.
56 | * It will help pass the events from this class down to the adapter.
57 | */
58 | interface OnItemStateChangeListener {
59 |
60 | enum class StateChangeType {
61 | DRAG_STARTED,
62 | DRAG_FINISHED,
63 | SWIPE_STARTED,
64 | SWIPE_FINISHED
65 | }
66 |
67 | fun onStateChanged(newState: StateChangeType, viewHolder: RecyclerView.ViewHolder) {
68 | }
69 | }
70 |
71 | interface OnItemLayoutPositionChangeListener {
72 |
73 | enum class Action {
74 | DRAGGING,
75 | SWIPING
76 | }
77 |
78 | fun onPositionChanged(
79 | action: Action,
80 | viewHolder: RecyclerView.ViewHolder,
81 | offsetX: Int,
82 | offsetY: Int,
83 | canvasUnder: Canvas?,
84 | canvasOver: Canvas?,
85 | isUserControlled: Boolean
86 | ) {
87 | }
88 | }
89 |
90 | internal var orientation: ListOrientation? = null
91 | private val mOrientation: ListOrientation
92 | get() = orientation
93 | ?: throw NullPointerException("The orientation of the DragDropSwipeRecyclerView is not defined.")
94 |
95 | internal var disabledDragFlagsValue: Int = 0
96 | internal var disabledSwipeFlagsValue: Int = 0
97 |
98 | private var isDragging = false
99 | private var isSwiping = false
100 | private var initialItemPositionForOngoingDraggingEvent = -1
101 |
102 | override fun isLongPressDragEnabled() = false
103 |
104 | override fun isItemViewSwipeEnabled() = true
105 |
106 | override fun getSwipeThreshold(viewHolder: RecyclerView.ViewHolder): Float {
107 | var threshold = super.getSwipeThreshold(viewHolder)
108 |
109 | // We have to adjust the threshold to act on the width or height of the item layout
110 | // because by default it applies to the entire width or height or the recycler view
111 | val recyclerViewWidth = recyclerView?.measuredWidth
112 | val recyclerViewHeight = recyclerView?.measuredHeight
113 | val itemWidth = viewHolder.itemView.measuredWidth
114 | val itemHeight = viewHolder.itemView.measuredHeight
115 | if (recyclerViewWidth != null && recyclerViewHeight != null) {
116 | val isSwipingHorizontally =
117 | (mOrientation.swipeFlagsValue and DirectionFlag.RIGHT.value == DirectionFlag.RIGHT.value)
118 | || (mOrientation.swipeFlagsValue and DirectionFlag.LEFT.value == DirectionFlag.LEFT.value)
119 | threshold *= if (isSwipingHorizontally)
120 | (itemWidth.toFloat() / recyclerViewWidth.toFloat())
121 | else
122 | (itemHeight.toFloat() / recyclerViewHeight.toFloat())
123 | }
124 |
125 | return threshold
126 | }
127 |
128 | override fun getMovementFlags(
129 | recyclerView: RecyclerView,
130 | viewHolder: RecyclerView.ViewHolder
131 | ): Int {
132 | return if (viewHolder is DragDropSwipeAdapter.ViewHolder) {
133 | makeMovementFlags(
134 | if (viewHolder.canBeDragged?.invoke() == true) mOrientation.dragFlagsValue xor disabledDragFlagsValue else 0,
135 | if (viewHolder.canBeSwiped?.invoke() == true) mOrientation.swipeFlagsValue xor disabledSwipeFlagsValue else 0,
136 | )
137 | } else {
138 | 0
139 | }
140 | }
141 |
142 | override fun onMove(
143 | recyclerView: RecyclerView,
144 | viewHolder: RecyclerView.ViewHolder,
145 | target: RecyclerView.ViewHolder,
146 | ): Boolean {
147 | itemDragListener.onItemDragged(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition)
148 | return true
149 | }
150 |
151 | override fun canDropOver(
152 | recyclerView: RecyclerView,
153 | current: RecyclerView.ViewHolder,
154 | target: RecyclerView.ViewHolder,
155 | ) = (target as? DragDropSwipeAdapter.ViewHolder)?.canBeDroppedOver?.invoke() == true
156 |
157 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
158 | val position = viewHolder.bindingAdapterPosition
159 | val swipeDirection = when (direction) {
160 | ItemTouchHelper.LEFT -> SwipeDirection.RIGHT_TO_LEFT
161 | ItemTouchHelper.RIGHT -> SwipeDirection.LEFT_TO_RIGHT
162 | ItemTouchHelper.UP -> SwipeDirection.DOWN_TO_UP
163 | else -> SwipeDirection.UP_TO_DOWN
164 | }
165 |
166 | itemSwipeListener.onItemSwiped(position, swipeDirection)
167 | }
168 |
169 | override fun onChildDraw(
170 | c: Canvas,
171 | recyclerView: RecyclerView,
172 | viewHolder: RecyclerView.ViewHolder,
173 | dX: Float,
174 | dY: Float,
175 | actionState: Int,
176 | isCurrentlyActive: Boolean
177 | ) {
178 |
179 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
180 |
181 | onChildDrawImpl(c, null, viewHolder, dX, dY, actionState, isCurrentlyActive)
182 | }
183 |
184 | override fun onChildDrawOver(
185 | c: Canvas,
186 | recyclerView: RecyclerView,
187 | viewHolder: RecyclerView.ViewHolder,
188 | dX: Float,
189 | dY: Float,
190 | actionState: Int,
191 | isCurrentlyActive: Boolean
192 | ) {
193 |
194 | super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
195 |
196 | onChildDrawImpl(null, c, viewHolder, dX, dY, actionState, isCurrentlyActive)
197 | }
198 |
199 | override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
200 | super.onSelectedChanged(viewHolder, actionState)
201 |
202 | if (viewHolder != null) {
203 | when (actionState) {
204 | ItemTouchHelper.ACTION_STATE_DRAG -> onStartedDragging(viewHolder)
205 | ItemTouchHelper.ACTION_STATE_SWIPE -> onStartedSwiping(viewHolder)
206 | }
207 | }
208 | }
209 |
210 | override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
211 | super.clearView(recyclerView, viewHolder)
212 |
213 | onFinishedDraggingOrSwiping(viewHolder)
214 | }
215 |
216 | private fun onChildDrawImpl(
217 | canvasUnder: Canvas?,
218 | canvasOver: Canvas?,
219 | viewHolder: RecyclerView.ViewHolder,
220 | dX: Float,
221 | dY: Float,
222 | actionState: Int,
223 | isCurrentlyActive: Boolean
224 | ) {
225 |
226 | val action = when (actionState) {
227 | ItemTouchHelper.ACTION_STATE_SWIPE -> OnItemLayoutPositionChangeListener.Action.SWIPING
228 | ItemTouchHelper.ACTION_STATE_DRAG -> OnItemLayoutPositionChangeListener.Action.DRAGGING
229 | else -> null
230 | }
231 |
232 | if (action != null) {
233 | val offsetX = dX.toInt()
234 | val offsetY = dY.toInt()
235 | itemLayoutPositionChangeListener.onPositionChanged(
236 | action,
237 | viewHolder,
238 | offsetX,
239 | offsetY,
240 | canvasUnder,
241 | canvasOver,
242 | isCurrentlyActive
243 | )
244 | }
245 | }
246 |
247 | private fun onStartedDragging(viewHolder: RecyclerView.ViewHolder) {
248 | isDragging = true
249 | initialItemPositionForOngoingDraggingEvent = viewHolder.bindingAdapterPosition
250 | itemStateChangeListener.onStateChanged(
251 | OnItemStateChangeListener.StateChangeType.DRAG_STARTED, viewHolder
252 | )
253 | }
254 |
255 | private fun onStartedSwiping(viewHolder: RecyclerView.ViewHolder) {
256 | isSwiping = true
257 | itemStateChangeListener.onStateChanged(
258 | OnItemStateChangeListener.StateChangeType.SWIPE_STARTED, viewHolder
259 | )
260 | }
261 |
262 | private fun onFinishedDraggingOrSwiping(viewHolder: RecyclerView.ViewHolder) {
263 | if (isDragging)
264 | onFinishedDragging(viewHolder)
265 |
266 | if (isSwiping)
267 | onFinishedSwiping(viewHolder)
268 | }
269 |
270 | private fun onFinishedDragging(viewHolder: RecyclerView.ViewHolder) {
271 | // At this point, the user has dropped the item
272 | val initialItemPositionForFinishedDraggingEvent = initialItemPositionForOngoingDraggingEvent
273 | val finalItemPositionForFinishedDraggingEvent = viewHolder.bindingAdapterPosition
274 | isDragging = false
275 | initialItemPositionForOngoingDraggingEvent = -1
276 | itemDragListener.onItemDropped(
277 | initialItemPositionForFinishedDraggingEvent,
278 | finalItemPositionForFinishedDraggingEvent
279 | )
280 | itemStateChangeListener.onStateChanged(
281 | OnItemStateChangeListener.StateChangeType.DRAG_FINISHED, viewHolder
282 | )
283 | }
284 |
285 | private fun onFinishedSwiping(viewHolder: RecyclerView.ViewHolder) {
286 | isSwiping = false
287 | itemStateChangeListener.onStateChanged(
288 | OnItemStateChangeListener.StateChangeType.SWIPE_FINISHED, viewHolder
289 | )
290 | }
291 | }
292 |
--------------------------------------------------------------------------------