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
9ebbb31a
authored
Apr 20, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dirty selection implementation is back
parent
a419bbf5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
18 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/MyItemDetailsLookup.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MyItemDetailsLookup.kt
0 → 100644
View file @
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
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
9ebbb31a
...
...
@@ -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
()
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
9ebbb31a
...
...
@@ -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
}
...
...
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