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
6dbccfca
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enables/disables popup menu according to the tag selection
parent
1473c257
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
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/activities/MainActivity.kt
View file @
6dbccfca
...
...
@@ -9,6 +9,7 @@ import android.view.WindowManager
import
android.view.inputmethod.InputMethodManager
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.widget.SearchView
import
androidx.recyclerview.selection.Selection
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker.MySelectionTracker
...
...
@@ -120,19 +121,20 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpSelectionTracker
()
{
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
init
(
recyclerView
)
addObserver
{
selection
->
run
{
addObserver
{
selection
->
whenSelectionChanges
(
selection
)
}
}
}
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
)
{
// TODO disable popup menu
vocabularyAdapter
.
showPopupMenu
=
false
Log
.
d
(
TAG
,
"selection ${selection.toList()}"
)
visible
(
tagLayout
)
}
else
{
vocabularyAdapter
.
showPopupMenu
=
true
gone
(
tagLayout
)
}
}
}
}
}
override
fun
onPause
()
{
super
.
onPause
()
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/VocabularyAdapter.kt
View file @
6dbccfca
...
...
@@ -24,6 +24,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
viewHolder
:
ViewHolder
lateinit
var
selectionTracker
:
MySelectionTracker
var
showPopupMenu
=
true
init
{
setHasStableIds
(
true
)
...
...
@@ -62,6 +63,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
if
(
showPopupMenu
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
...
...
@@ -77,6 +79,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
if
(
mainActivity
.
supportFragmentManager
.
findFragmentByTag
(
"edit_fragment"
)
==
null
)
popup
.
show
()
}
}
fun
refresh
()
{}
...
...
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