Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
12b51fb5
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrapped selectionTracker
parent
ede577cb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
67 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyTracker.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/OnQueryTextListener.kt → app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/SearchQueryTextListener.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyItemDetailsLookup.kt → app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MyItemDetailsLookup.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyItemKeyProvider.kt → app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MyItemKeyProvider.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
12b51fb5
...
...
@@ -9,26 +9,20 @@ 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.StorageStrategy
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.recycler_view.MyItemDetailsLookup
import
com.paktalin.vocabularynotebook.ui.recycler_view.MyItemKeyProvider
import
com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import
com.paktalin.vocabularynotebook.utils.*
import
com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.tag.*
class
MainActivity
:
AppCompatActivity
()
{
var
searchView
:
SearchView
?
=
null
lateinit
var
vocabularyAdapter
:
VocabularyAdapter
private
var
tracker
:
SelectionTracker
<
Long
>?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -123,29 +117,10 @@ class MainActivity : AppCompatActivity() {
}
private
fun
setUpSelectionTracker
()
{
tracker
=
SelectionTracker
.
Builder
<
Long
>(
"mySelection"
,
recyclerView
,
MyItemKeyProvider
(
recyclerView
),
MyItemDetailsLookup
(
recyclerView
),
StorageStrategy
.
createLongStorage
()
).
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()}"
)
visible
(
tagLayout
)
}
else
{
gone
(
tagLayout
)
}
}
})
(
recyclerView
.
adapter
as
VocabularyAdapter
).
tracker
=
tracker
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
init
(
recyclerView
)
addObserver
(
this
@MainActivity
)
}
}
override
fun
onPause
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyTracker.kt
deleted
100644 → 0
View file @
ede577cb
package
com.paktalin.vocabularynotebook.ui.recycler_view
import
androidx.recyclerview.selection.*
import
androidx.recyclerview.widget.RecyclerView
fun
initializeTracker
(
recyclerView
:
RecyclerView
,
onSelection
:
(
Selection
<
Long
>)
->
Unit
):
SelectionTracker
<
Long
>?
{
val
tracker
=
SelectionTracker
.
Builder
<
Long
>(
"mySelection"
,
recyclerView
,
StableIdKeyProvider
(
recyclerView
),
MyItemDetailsLookup
(
recyclerView
),
StorageStrategy
.
createLongStorage
()
).
withSelectionPredicate
(
SelectionPredicates
.
createSelectAnything
()
).
build
()
tracker
.
addObserver
(
object
:
SelectionTracker
.
SelectionObserver
<
Long
>()
{
override
fun
onSelectionChanged
()
{
super
.
onSelectionChanged
()
onSelection
(
tracker
?.
selection
!!
)
}
})
return
tracker
}
private
val
TAG
=
"VN/MyTracker"
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/
On
QueryTextListener.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/
Search
QueryTextListener.kt
View file @
12b51fb5
...
...
@@ -2,7 +2,7 @@ package com.paktalin.vocabularynotebook.ui.recycler_view
import
androidx.appcompat.widget.SearchView
class
On
QueryTextListener
(
var
adapter
:
VocabularyAdapter
)
:
SearchView
.
OnQueryTextListener
{
class
Search
QueryTextListener
(
var
adapter
:
VocabularyAdapter
)
:
SearchView
.
OnQueryTextListener
{
override
fun
onQueryTextSubmit
(
query
:
String
):
Boolean
{
adapter
.
filter
(
query
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
12b51fb5
...
...
@@ -7,12 +7,12 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.appcompat.widget.PopupMenu
import
androidx.recyclerview.selection.SelectionTracker
import
androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.addFragment
import
com.paktalin.vocabularynotebook.vocabulary.ModifiedVocabulary
...
...
@@ -23,7 +23,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
viewHolder
:
ViewHolder
var
tracker
:
SelectionTracker
<
Long
>?
=
null
lateinit
var
selectionTracker
:
MySelectionTracker
init
{
setHasStableIds
(
true
)
...
...
@@ -40,7 +40,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
this
.
recyclerView
=
recyclerView
mainActivity
.
searchView
?.
setOnQueryTextListener
(
On
QueryTextListener
(
this
@VocabularyAdapter
))
mainActivity
.
searchView
?.
setOnQueryTextListener
(
Search
QueryTextListener
(
this
@VocabularyAdapter
))
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
...
...
@@ -54,8 +54,8 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
displayedAt
(
position
)
tracker
?
.
let
{
viewHolder
.
bind
(
wordItem
,
position
,
it
.
isS
elected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
selectionTracker
.
let
{
viewHolder
.
bind
(
wordItem
,
position
,
it
.
s
elected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
}
this
.
viewHolder
=
viewHolder
//todo set click listener to menu
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyItemDetailsLookup.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/
selection_tracker/
MyItemDetailsLookup.kt
View file @
12b51fb5
package
com.paktalin.vocabularynotebook.ui.recycler_view
package
com.paktalin.vocabularynotebook.ui.recycler_view
.selection_tracker
import
android.view.MotionEvent
import
androidx.recyclerview.selection.ItemDetailsLookup
import
androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.ui.recycler_view.ViewHolder
class
MyItemDetailsLookup
(
private
val
recyclerView
:
RecyclerView
)
:
ItemDetailsLookup
<
Long
>()
{
override
fun
getItemDetails
(
event
:
MotionEvent
):
ItemDetails
<
Long
>?
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/MyItemKeyProvider.kt
→
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/
selection_tracker/
MyItemKeyProvider.kt
View file @
12b51fb5
package
com.paktalin.vocabularynotebook.ui.recycler_view
package
com.paktalin.vocabularynotebook.ui.recycler_view
.selection_tracker
import
androidx.recyclerview.selection.ItemKeyProvider
import
androidx.recyclerview.widget.RecyclerView
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
0 → 100644
View file @
12b51fb5
package
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker
import
androidx.recyclerview.selection.SelectionPredicates
import
androidx.recyclerview.selection.SelectionTracker
import
androidx.recyclerview.selection.StorageStrategy
import
androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.tag.*
class
MySelectionTracker
{
private
var
tracker
:
SelectionTracker
<
Long
>?
=
null
fun
init
(
recyclerView
:
RecyclerView
)
{
tracker
=
SelectionTracker
.
Builder
<
Long
>(
"mySelection"
,
recyclerView
,
MyItemKeyProvider
(
recyclerView
),
MyItemDetailsLookup
(
recyclerView
),
StorageStrategy
.
createLongStorage
()
).
withSelectionPredicate
(
SelectionPredicates
.
createSelectAnything
()
).
build
()
}
fun
addObserver
(
mainActivity
:
MainActivity
)
{
tracker
?.
addObserver
(
object
:
SelectionTracker
.
SelectionObserver
<
Long
>()
{
override
fun
onSelectionChanged
()
{
super
.
onSelectionChanged
()
if
(
tracker
?.
hasSelection
()
!!
)
{
// TODO disable popup menu
Log
.
d
(
TAG
,
"selection ${tracker?.selection?.toList().toString()}"
)
visible
(
mainActivity
.
tagLayout
)
}
else
{
gone
(
mainActivity
.
tagLayout
)
}
}
})
}
fun
selected
(
position
:
Long
):
Boolean
{
tracker
?.
let
{
return
it
.
isSelected
(
position
)
}
return
false
}
companion
object
{
private
val
TAG
=
"VN/"
+
MySelectionTracker
::
class
.
simpleName
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment