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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
23 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,17 +121,18 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpSelectionTracker
()
{
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
init
(
recyclerView
)
addObserver
{
selection
->
run
{
if
(!
selection
.
isEmpty
)
{
// TODO disable popup menu
Log
.
d
(
TAG
,
"selection ${selection.toList()}"
)
visible
(
tagLayout
)
}
else
{
gone
(
tagLayout
)
}
}
}
addObserver
{
selection
->
whenSelectionChanges
(
selection
)
}
}
}
private
fun
whenSelectionChanges
(
selection
:
Selection
<
Long
>)
{
if
(!
selection
.
isEmpty
)
{
vocabularyAdapter
.
showPopupMenu
=
false
Log
.
d
(
TAG
,
"selection ${selection.toList()}"
)
visible
(
tagLayout
)
}
else
{
vocabularyAdapter
.
showPopupMenu
=
true
gone
(
tagLayout
)
}
}
...
...
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,20 +63,22 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
option_delete
)
{
deleteWord
(
vocabulary
.
displayedAt
(
position
),
position
)
if
(
showPopupMenu
)
{
val
popup
=
PopupMenu
(
mainActivity
,
v
)
popup
.
menuInflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
option_delete
)
{
deleteWord
(
vocabulary
.
displayedAt
(
position
),
position
)
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
startEditFragment
(
v
,
vocabulary
.
displayedAt
(
position
))
}
true
}
if
(
it
.
itemId
==
R
.
id
.
option_edit
)
{
startEditFragment
(
v
,
vocabulary
.
displayedAt
(
position
))
}
true
// if not edit mode, then start EditFragment
if
(
mainActivity
.
supportFragmentManager
.
findFragmentByTag
(
"edit_fragment"
)
==
null
)
popup
.
show
()
}
// if not edit mode, then start EditFragment
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