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
20b97ab4
authored
Apr 20, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dirty selection implementation
parent
79b07129
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
12 deletions
.idea/caches/build_file_checksums.ser
app/build.gradle
app/src/main/java/com/paktalin/vocabularynotebook/ui/MyItemDetailsLookup.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/ViewHolder.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/res/drawable/selector.xml
app/src/main/res/layout/word_item.xml
.idea/caches/build_file_checksums.ser
View file @
20b97ab4
No preview for this file type
app/build.gradle
View file @
20b97ab4
...
...
@@ -44,7 +44,7 @@ dependencies {
implementation
'com.google.firebase:firebase-auth:16.2.1'
implementation
'com.firebase:firebase-client-android:2.3.1'
implementation
'com.google.firebase:firebase-firestore:18.2.0'
implementation
'com.crashlytics.sdk.android:crashlytics:2.9.9'
//
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation
'androidx.recyclerview:recyclerview-selection:1.0.0'
testImplementation
'junit:junit:4.12'
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MyItemDetailsLookup.kt
0 → 100644
View file @
20b97ab4
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/ViewHolder.kt
View file @
20b97ab4
package
com.paktalin.vocabularynotebook.ui
import
android.graphics.Color
import
androidx.recyclerview.widget.RecyclerView
import
android.view.View
import
android.widget.LinearLayout
import
android.widget.TextView
import
androidx.recyclerview.selection.ItemDetailsLookup
import
androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.Log
import
kotlinx.android.synthetic.main.word_item.view.*
...
...
@@ -20,12 +20,19 @@ class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnCli
private
val
tvTranslation
:
TextView
=
itemView
.
translation
val
layout
:
LinearLayout
=
itemView
.
layout
fun
bind
(
wordPojo
:
WordPojo
,
position
:
Int
,
showPopupMenu
:
(
View
,
Int
)
->
Unit
)
{
fun
bind
(
wordPojo
:
WordPojo
,
position
:
Int
,
isActivated
:
Boolean
,
showPopupMenu
:
(
View
,
Int
)
->
Unit
)
{
tvWord
.
text
=
wordPojo
.
word
tvTranslation
.
text
=
wordPojo
.
translation
itemView
.
setOnClickListener
{
showPopupMenu
(
itemView
,
position
)
}
// itemView.setOnClickListener { showPopupMenu(itemView, position) }
itemView
.
isActivated
=
isActivated
}
fun
getItemDetails
():
ItemDetailsLookup
.
ItemDetails
<
Long
>
=
object
:
ItemDetailsLookup
.
ItemDetails
<
Long
>()
{
override
fun
getPosition
():
Int
=
adapterPosition
override
fun
getSelectionKey
():
Long
?
=
itemId
}
companion
object
{
private
val
TAG
=
"VN/"
+
ViewHolder
::
class
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyAdapter.kt
View file @
20b97ab4
...
...
@@ -3,14 +3,17 @@ package com.paktalin.vocabularynotebook.ui
import
android.annotation.SuppressLint
import
android.os.Build
import
android.os.Bundle
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
android.view.*
import
com.paktalin.vocabularynotebook.OnQueryTextListener
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import
com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
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.shortToast
...
...
@@ -22,6 +25,13 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
viewHolder
:
ViewHolder
var
tracker
:
SelectionTracker
<
Long
>?
=
null
init
{
setHasStableIds
(
true
)
}
override
fun
getItemId
(
position
:
Int
):
Long
=
position
.
toLong
()
var
sort
:
Sort
=
Sort
.
BY_TIME
set
(
value
)
{
...
...
@@ -46,7 +56,9 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override
fun
onBindViewHolder
(
viewHolder
:
ViewHolder
,
position
:
Int
)
{
val
wordItem
=
vocabulary
.
displayedAt
(
position
)
viewHolder
.
bind
(
wordItem
,
position
)
{
view
,
p
->
showPopupMenu
(
view
,
p
)}
tracker
?.
let
{
viewHolder
.
bind
(
wordItem
,
position
,
it
.
isSelected
(
position
.
toLong
()))
{
view
,
p
->
showPopupMenu
(
view
,
p
)
}
}
this
.
viewHolder
=
viewHolder
//todo set click listener to menu
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
20b97ab4
...
...
@@ -2,14 +2,19 @@ package com.paktalin.vocabularynotebook.ui.activities
import
android.app.Activity
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.widget.SearchView
import
android.view.Menu
import
android.view.MenuItem
import
android.view.View
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.MyItemDetailsLookup
import
com.paktalin.vocabularynotebook.ui.VocabularyAdapter
import
com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import
com.paktalin.vocabularynotebook.utils.*
...
...
@@ -17,12 +22,12 @@ 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
java.lang.Exception
class
MainActivity
:
AppCompatActivity
()
{
lateinit
var
searchView
:
SearchView
lateinit
var
vocabularyAdapter
:
VocabularyAdapter
private
var
tracker
:
SelectionTracker
<
Long
>?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -84,13 +89,23 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpVocabularyAdapter
()
{
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_main
)
FirestoreManager
().
extractVocabularyId
({
// recyclerView.adapter = VocabularyAdapter(BasicVocabulary(), this@MainActivity)
recyclerView
.
layoutManager
=
LockableLayoutManager
(
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/res/drawable/selector.xml
0 → 100644
View file @
20b97ab4
<?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"
/>
</selector>
\ No newline at end of file
app/src/main/res/layout/word_item.xml
View file @
20b97ab4
...
...
@@ -33,6 +33,7 @@
android:paddingEnd=
"16dp"
android:paddingRight=
"16dp"
android:paddingBottom=
"8dp"
android:background=
"@drawable/selector"
app:layout_constraintTop_toTopOf=
"parent"
>
<TextView
...
...
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