Commit 9ebbb31a by Paktalin

Dirty selection implementation is back

parent a419bbf5
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
......@@ -9,8 +9,12 @@ import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.selection.SelectionPredicates
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StableIdKeyProvider
import androidx.recyclerview.selection.StorageStrategy
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.recycler_view.MyItemDetailsLookup
import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.*
......@@ -84,12 +88,21 @@ class MainActivity : AppCompatActivity() {
addProgressBar(supportFragmentManager, R.id.container_main)
FirestoreManager().extractVocabularyId({
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
recyclerView.adapter = VocabularyAdapter(VocabSet(mutableListOf()), this@MainActivity)
FirestoreManager().extractVocabulary { querySnapshot ->
run {
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()
(recyclerView.adapter as VocabularyAdapter).tracker = tracker
} else showToastNoWords()
}
......
......@@ -7,7 +7,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.recyclerview.selection.Selection
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.widget.RecyclerView
import com.paktalin.vocabularynotebook.R
......@@ -16,18 +15,15 @@ import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import com.paktalin.vocabularynotebook.utils.Log
import com.paktalin.vocabularynotebook.utils.addFragment
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.visible
import com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
import com.paktalin.vocabularynotebook.vocabulary.Sort
import com.paktalin.vocabularynotebook.vocabulary.VocabSet
import kotlinx.android.synthetic.main.content_main.*
class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivity: MainActivity) : RecyclerView.Adapter<ViewHolder>() {
private lateinit var recyclerView: RecyclerView
private lateinit var viewHolder: ViewHolder
private var tracker: SelectionTracker<Long>? = null
var tracker: SelectionTracker<Long>? = null
init {
setHasStableIds(true)
......@@ -44,7 +40,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
this.recyclerView = recyclerView
this.tracker = initializeTracker(recyclerView) { s -> wordsSelected(s) }
mainActivity.searchView.setOnQueryTextListener(OnQueryTextListener(this@VocabularyAdapter))
}
......@@ -134,17 +129,6 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
return vocabulary.getModified()
}
private fun wordsSelected(selection: Selection<Long>) {
if (selection.isEmpty)
gone(mainActivity.btnSubmitLayout)
else {
visible(mainActivity.btnSubmitLayout)
mainActivity.btnSubmit.setOnClickListener {
// TODO add tag to the words
}
}
}
companion object {
private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName
}
......
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