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
cd16c2cd
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Popup menu is added to every vocabulary item
parent
9b0bdf06
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
3 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
app/src/main/res/layout/word_item.xml
app/src/main/res/menu/word_item_menu.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
cd16c2cd
package
com.paktalin.vocabularynotebook
package
com.paktalin.vocabularynotebook
import
android.
content.Context
import
android.
app.Activity
import
android.content.Intent
import
android.content.Intent
import
android.support.v7.widget.PopupMenu
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.RecyclerView
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.ImageButton
import
android.widget.TextView
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
class
VocabularyAdapter
(
private
val
wordItems
:
MutableList
<
WordItem
>,
private
val
context
:
Context
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
val
context
:
Activity
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
private
lateinit
var
recyclerView
:
RecyclerView
...
@@ -31,6 +33,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
...
@@ -31,6 +33,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
holder
.
itemView
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
itemView
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
itemView
.
setOnLongClickListener
{
deleteWordItem
(
position
);
true
}
holder
.
itemView
.
setOnLongClickListener
{
deleteWordItem
(
position
);
true
}
holder
.
btnPopupMenu
.
setOnClickListener
{
showPopupMenu
(
holder
.
btnPopupMenu
)
}
}
}
override
fun
getItemCount
():
Int
{
override
fun
getItemCount
():
Int
{
...
@@ -40,6 +43,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
...
@@ -40,6 +43,7 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvWord
)
val
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvWord
)
val
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvTranslation
)
val
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvTranslation
)
val
btnPopupMenu
:
ImageButton
=
itemView
.
findViewById
(
R
.
id
.
btnContextMenu
)
}
}
private
fun
openWordItemInfo
(
wordItem
:
WordItem
)
{
private
fun
openWordItemInfo
(
wordItem
:
WordItem
)
{
...
@@ -48,6 +52,13 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
...
@@ -48,6 +52,13 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
context
.
startActivity
(
intentWordItemInfo
)
context
.
startActivity
(
intentWordItemInfo
)
}
}
private
fun
showPopupMenu
(
v
:
View
)
{
val
popup
=
PopupMenu
(
context
,
v
)
val
inflater
=
popup
.
menuInflater
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
popup
.
show
()
}
private
fun
deleteWordItem
(
position
:
Int
)
{
private
fun
deleteWordItem
(
position
:
Int
)
{
wordItems
[
position
].
delete
()
wordItems
[
position
].
delete
()
wordItems
.
removeAt
(
position
)
wordItems
.
removeAt
(
position
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
View file @
cd16c2cd
...
@@ -38,6 +38,7 @@ class AddWordActivity : AppCompatActivity() {
...
@@ -38,6 +38,7 @@ class AddWordActivity : AppCompatActivity() {
.
collection
(
WORDS
).
add
(
WordItemPojo
(
word
,
translation
)).
addOnSuccessListener
{
.
collection
(
WORDS
).
add
(
WordItemPojo
(
word
,
translation
)).
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word $word"
)
Log
.
i
(
TAG
,
"Successfully added a new word $word"
)
clearFields
()
clearFields
()
cancel
()
}
}
.
addOnFailureListener
{
.
addOnFailureListener
{
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
Log
.
w
(
TAG
,
"addNewWordToDb:failure"
,
it
.
fillInStackTrace
())
...
...
app/src/main/res/layout/word_item.xml
View file @
cd16c2cd
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
<TableLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:stretchColumns=
"0, 1"
>
android:stretchColumns=
"0, 1
, 2
"
>
<TableRow
android:padding=
"8dp"
>
<TableRow
android:padding=
"8dp"
>
...
@@ -20,5 +21,12 @@
...
@@ -20,5 +21,12 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"translation"
android:text=
"translation"
android:textSize=
"22sp"
/>
android:textSize=
"22sp"
/>
<ImageButton
android:id=
"@+id/btnContextMenu"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@android:drawable/ic_menu_edit"
/>
</TableRow>
</TableRow>
</TableLayout>
</TableLayout>
\ No newline at end of file
app/src/main/res/menu/word_item_menu.xml
0 → 100644
View file @
cd16c2cd
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:title=
"Item"
/>
<item
android:title=
"Item2"
/>
</menu>
\ 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