Commit daa4eff2 by Paktalin

Added selectionTracker observer

parent 8683cc3b
......@@ -93,9 +93,7 @@ class MainActivity : AppCompatActivity() {
if (querySnapshot != null && !querySnapshot.isEmpty) {
vocabularyAdapter = VocabularyAdapter(VocabSet.createFromSnapshot(querySnapshot), this@MainActivity)
recyclerView.adapter = vocabularyAdapter
setSelectionTracker()
(recyclerView.adapter as VocabularyAdapter).tracker = tracker
setUpSelectionTracker()
} else showToastNoWords()
}
}
......@@ -121,7 +119,7 @@ class MainActivity : AppCompatActivity() {
shortToast(this, getString(R.string.toast_empty_vocabulary))
}
private fun setSelectionTracker() {
private fun setUpSelectionTracker() {
tracker = SelectionTracker.Builder<Long>(
"mySelection",
recyclerView,
......@@ -131,6 +129,18 @@ class MainActivity : AppCompatActivity() {
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
tracker?.addObserver(
object : SelectionTracker.SelectionObserver<Long>() {
override fun onSelectionChanged() {
super.onSelectionChanged()
if (tracker?.hasSelection()!!) {
Log.d(TAG, "selection ${tracker?.selection?.toList().toString()}")
}
//TODO my implementation
}
})
(recyclerView.adapter as VocabularyAdapter).tracker = tracker
}
override fun onPause() {
......
<?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="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical">
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="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>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment