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
53ae3ce5
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words can be deleted by long press
parent
0b4e4889
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.java
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
53ae3ce5
...
...
@@ -9,9 +9,16 @@ import android.view.ViewGroup
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class
VocabularyAdapter
(
private
val
wordItems
:
List
<
WordItem
>,
class
VocabularyAdapter
(
private
val
wordItems
:
Mutable
List
<
WordItem
>,
private
val
context
:
Context
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
private
lateinit
var
recyclerView
:
RecyclerView
override
fun
onAttachedToRecyclerView
(
recyclerView
:
RecyclerView
)
{
super
.
onAttachedToRecyclerView
(
recyclerView
)
this
.
recyclerView
=
recyclerView
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
.
inflate
(
R
.
layout
.
word_item
,
parent
,
false
)
...
...
@@ -23,6 +30,7 @@ class VocabularyAdapter(private val wordItems: List<WordItem>,
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
itemView
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
holder
.
itemView
.
setOnLongClickListener
{
deleteWordItem
(
position
);
true
}
}
override
fun
getItemCount
():
Int
{
...
...
@@ -40,5 +48,13 @@ class VocabularyAdapter(private val wordItems: List<WordItem>,
context
.
startActivity
(
intentWordItemInfo
)
}
private
fun
deleteWordItem
(
position
:
Int
)
{
wordItems
[
position
].
delete
()
wordItems
.
removeAt
(
position
)
recyclerView
.
removeViewAt
(
position
)
this
.
notifyItemRemoved
(
position
)
this
.
notifyItemRangeChanged
(
position
,
wordItems
.
size
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.java
View file @
53ae3ce5
package
com
.
paktalin
.
vocabularynotebook
;
import
android.support.annotation.NonNull
;
import
android.util.Log
;
import
com.google.android.gms.tasks.OnFailureListener
;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.firestore.DocumentReference
;
import
com.google.firebase.firestore.FirebaseFirestore
;
import
java.io.Serializable
;
public
class
WordItem
implements
Serializable
{
private
static
final
String
TAG
=
"VN/"
+
WordItem
.
class
.
getSimpleName
();
public
static
class
WordItemPojo
implements
Serializable
{
private
String
word
,
translation
;
...
...
@@ -30,13 +40,31 @@ public class WordItem implements Serializable {
}
private
String
id
;
private
String
vocabularyId
;
private
WordItemPojo
pojo
;
public
WordItem
(
String
word
,
String
translation
,
String
id
)
{
public
WordItem
(
String
word
,
String
translation
,
String
id
,
String
vocabularyId
)
{
this
.
pojo
=
new
WordItemPojo
(
word
,
translation
);
this
.
vocabularyId
=
vocabularyId
;
this
.
id
=
id
;
}
public
void
delete
()
{
FirebaseFirestore
.
getInstance
().
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
document
(
id
).
delete
()
.
addOnSuccessListener
(
new
OnSuccessListener
<
Void
>()
{
@Override
public
void
onSuccess
(
Void
aVoid
)
{
Log
.
i
(
TAG
,
"Successfully deleted word with id "
+
id
);
}
}).
addOnFailureListener
(
new
OnFailureListener
()
{
@Override
public
void
onFailure
(
@NonNull
Exception
e
)
{
Log
.
w
(
TAG
,
"deleteWordWithId "
+
id
+
":failure"
,
e
.
fillInStackTrace
());
}
});
}
public
WordItemPojo
getPojo
()
{
return
pojo
;
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
View file @
53ae3ce5
...
...
@@ -87,8 +87,7 @@ class VocabularyFragment : Fragment() {
for
(
ref
in
documents
)
{
val
word
=
ref
.
get
(
"word"
).
toString
()
val
translation
=
ref
.
get
(
"translation"
).
toString
()
val
wordItemId
=
ref
.
id
wordItems
.
add
(
WordItem
(
word
,
translation
,
wordItemId
))
wordItems
.
add
(
WordItem
(
word
,
translation
,
ref
.
id
,
vocabulary
.
id
))
}
val
adapter
=
VocabularyAdapter
(
wordItems
,
activity
!!
)
...
...
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