-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: added the two functions for adding and deleting an element.
- Loading branch information
Showing
5 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sample/src/main/java/com/devrapid/example/DeletableActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.devrapid.example | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.ItemTouchHelper | ||
import androidx.recyclerview.widget.ItemTouchHelper.DOWN | ||
import androidx.recyclerview.widget.ItemTouchHelper.LEFT | ||
import androidx.recyclerview.widget.ItemTouchHelper.RIGHT | ||
import androidx.recyclerview.widget.ItemTouchHelper.UP | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.devrapid.example.model.Person | ||
import kotlinx.android.synthetic.main.activity_deletable.recyclerView | ||
|
||
class DeletableActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_deletable) | ||
|
||
val itemList: MutableList<IExpandVisitor> = mutableListOf(Person("Google"), | ||
Person("Facebook"), | ||
Person("Apple"), | ||
Person("Amazon"), | ||
Person("HTC"), | ||
Person("Banana"), | ||
Person("Grape"), | ||
Person("Airbnb"), | ||
Person("Jieyi")) | ||
val adapter = ExpandAdapter(itemList) | ||
|
||
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(UP or DOWN, LEFT or RIGHT) { | ||
override fun onMove( | ||
recyclerView: RecyclerView, | ||
viewHolder: RecyclerView.ViewHolder, | ||
target: RecyclerView.ViewHolder | ||
) = true | ||
|
||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | ||
val position = viewHolder.layoutPosition | ||
adapter.dropList(position, position) | ||
} | ||
}).attachToRecyclerView(recyclerView) | ||
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) | ||
recyclerView.adapter = adapter | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recyclerView" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |