Commit 8683cc3b by Paktalin

Minor refactoring

parent 9ebbb31a
package com.paktalin.vocabularynotebook.ui
import android.view.MotionEvent
import androidx.recyclerview.selection.ItemDetailsLookup
import androidx.recyclerview.widget.RecyclerView
class MyItemDetailsLookup(private val recyclerView: RecyclerView) :
ItemDetailsLookup<Long>() {
override fun getItemDetails(event: MotionEvent): ItemDetails<Long>? {
val view = recyclerView.findChildViewUnder(event.x, event.y)
if (view != null) {
return (recyclerView.getChildViewHolder(view) as ViewHolder)
.getItemDetails()
}
return null
}
}
\ No newline at end of file
......@@ -93,15 +93,7 @@ class MainActivity : AppCompatActivity() {
if (querySnapshot != null && !querySnapshot.isEmpty) {
vocabularyAdapter = VocabularyAdapter(VocabSet.createFromSnapshot(querySnapshot), this@MainActivity)
recyclerView.adapter = vocabularyAdapter
tracker = SelectionTracker.Builder<Long>(
"mySelection",
recyclerView,
StableIdKeyProvider(recyclerView),
MyItemDetailsLookup(recyclerView),
StorageStrategy.createLongStorage()
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
setSelectionTracker()
(recyclerView.adapter as VocabularyAdapter).tracker = tracker
} else showToastNoWords()
......@@ -129,6 +121,18 @@ class MainActivity : AppCompatActivity() {
shortToast(this, getString(R.string.toast_empty_vocabulary))
}
private fun setSelectionTracker() {
tracker = SelectionTracker.Builder<Long>(
"mySelection",
recyclerView,
StableIdKeyProvider(recyclerView),
MyItemDetailsLookup(recyclerView),
StorageStrategy.createLongStorage()
).withSelectionPredicate(
SelectionPredicates.createSelectAnything()
).build()
}
override fun onPause() {
super.onPause()
hideKeyboard()
......@@ -141,6 +145,4 @@ class MainActivity : AppCompatActivity() {
companion object {
private val TAG = "VN/" + MainActivity::class.simpleName
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/holo_blue_light" android:state_activated="true" />
<item android:drawable="@android:color/white" />
<item android:drawable="@android:color/transparent" />
</selector>
\ 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