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
53ad7bb7
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Word info is opened on click
parent
a73ceeb5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
19 deletions
app/src/main/AndroidManifest.xml
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/activities/WordItemInfoActivity.kt
app/src/main/res/layout/activity_word_info.xml
app/src/main/AndroidManifest.xml
View file @
53ad7bb7
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
</intent-filter>
</intent-filter>
</activity>
</activity>
<activity
android:name=
".activities.AddWordActivity"
/>
<activity
android:name=
".activities.AddWordActivity"
/>
<activity
android:name=
".activities.WordItemInfoActivity"
/>
</application>
</application>
</manifest>
</manifest>
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
53ad7bb7
package
com.paktalin.vocabularynotebook
package
com.paktalin.vocabularynotebook
import
android.content.Context
import
android.content.Intent
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.TextView
import
android.widget.TextView
import
com.paktalin.vocabularynotebook.activities.WordItemInfoActivity
class
VocabularyAdapter
(
private
val
wordItems
:
List
<
WordItem
>)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
class
VocabularyAdapter
(
private
val
wordItems
:
List
<
WordItem
>,
private
val
context
:
Context
)
:
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>()
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
...
@@ -15,9 +19,10 @@ class VocabularyAdapter(private val wordItems: List<WordItem>) : RecyclerView.Ad
...
@@ -15,9 +19,10 @@ class VocabularyAdapter(private val wordItems: List<WordItem>) : RecyclerView.Ad
}
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
item
=
wordItems
[
position
]
val
wordItem
=
wordItems
[
position
]
holder
.
tvWord
.
text
=
item
.
pojo
.
word
holder
.
tvWord
.
text
=
wordItem
.
pojo
.
word
holder
.
tvTranslation
.
text
=
item
.
pojo
.
translation
holder
.
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
holder
.
tvWord
.
setOnClickListener
{
openWordItemInfo
(
wordItem
)
}
}
}
override
fun
getItemCount
():
Int
{
override
fun
getItemCount
():
Int
{
...
@@ -25,8 +30,14 @@ class VocabularyAdapter(private val wordItems: List<WordItem>) : RecyclerView.Ad
...
@@ -25,8 +30,14 @@ class VocabularyAdapter(private val wordItems: List<WordItem>) : RecyclerView.Ad
}
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
var
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvWord
)
val
tvWord
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvWord
)
var
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvTranslation
)
val
tvTranslation
:
TextView
=
itemView
.
findViewById
(
R
.
id
.
tvTranslation
)
}
private
fun
openWordItemInfo
(
wordItem
:
WordItem
)
{
val
intentWordItemInfo
=
Intent
(
context
,
WordItemInfoActivity
::
class
.
java
)
intentWordItemInfo
.
putExtra
(
"wordItem"
,
wordItem
)
context
.
startActivity
(
intentWordItemInfo
)
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyAdapter
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/WordItem.java
View file @
53ad7bb7
package
com
.
paktalin
.
vocabularynotebook
;
package
com
.
paktalin
.
vocabularynotebook
;
public
class
WordItem
{
import
java.io.Serializable
;
public
static
class
WordItemPojo
{
public
class
WordItem
implements
Serializable
{
public
static
class
WordItemPojo
implements
Serializable
{
private
String
word
,
translation
;
private
String
word
,
translation
;
...
@@ -27,12 +29,12 @@ public class WordItem {
...
@@ -27,12 +29,12 @@ public class WordItem {
}
}
}
}
private
String
wordItemI
d
;
private
String
i
d
;
private
WordItemPojo
pojo
;
private
WordItemPojo
pojo
;
public
WordItem
(
String
word
,
String
translation
,
String
wordItemI
d
)
{
public
WordItem
(
String
word
,
String
translation
,
String
i
d
)
{
this
.
pojo
=
new
WordItemPojo
(
word
,
translation
);
this
.
pojo
=
new
WordItemPojo
(
word
,
translation
);
this
.
wordItemId
=
wordItemI
d
;
this
.
id
=
i
d
;
}
}
public
WordItemPojo
getPojo
()
{
public
WordItemPojo
getPojo
()
{
...
@@ -42,4 +44,12 @@ public class WordItem {
...
@@ -42,4 +44,12 @@ public class WordItem {
public
void
setPojo
(
WordItemPojo
pojo
)
{
public
void
setPojo
(
WordItemPojo
pojo
)
{
this
.
pojo
=
pojo
;
this
.
pojo
=
pojo
;
}
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
View file @
53ad7bb7
...
@@ -14,7 +14,6 @@ import com.google.firebase.firestore.FirebaseFirestore
...
@@ -14,7 +14,6 @@ import com.google.firebase.firestore.FirebaseFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.WordItem.WordItemPojo
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
VocabularyFragment
:
Fragment
()
{
class
VocabularyFragment
:
Fragment
()
{
...
@@ -37,6 +36,7 @@ class VocabularyFragment : Fragment() {
...
@@ -37,6 +36,7 @@ class VocabularyFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
setEmptyAdapter
()
fabAddWord
.
setOnClickListener
(
{
addWord
()
}
)
fabAddWord
.
setOnClickListener
(
{
addWord
()
}
)
retrieveData
()
retrieveData
()
}
}
...
@@ -46,6 +46,13 @@ class VocabularyFragment : Fragment() {
...
@@ -46,6 +46,13 @@ class VocabularyFragment : Fragment() {
FirebaseAuth
.
getInstance
().
signOut
()
FirebaseAuth
.
getInstance
().
signOut
()
}
}
private
fun
setEmptyAdapter
()
{
val
emptyList
:
MutableList
<
WordItem
>
=
mutableListOf
()
recyclerView
.
adapter
=
VocabularyAdapter
(
emptyList
,
activity
!!
)
val
mLayoutManager
=
LinearLayoutManager
(
activity
)
recyclerView
.
layoutManager
=
mLayoutManager
}
private
fun
retrieveData
()
{
private
fun
retrieveData
()
{
val
userId
=
FirebaseAuth
.
getInstance
().
currentUser
!!
.
uid
val
userId
=
FirebaseAuth
.
getInstance
().
currentUser
!!
.
uid
userDocument
=
db
.
collection
(
USERS
).
document
(
userId
)
userDocument
=
db
.
collection
(
USERS
).
document
(
userId
)
...
@@ -64,9 +71,6 @@ class VocabularyFragment : Fragment() {
...
@@ -64,9 +71,6 @@ class VocabularyFragment : Fragment() {
private
fun
retrieveVocabularyData
()
{
private
fun
retrieveVocabularyData
()
{
//todo if only one vocabulary exists, open it
//todo if only one vocabulary exists, open it
val
mLayoutManager
=
LinearLayoutManager
(
activity
)
recyclerView
.
layoutManager
=
mLayoutManager
vocabulary
.
collection
(
WORDS
).
get
()
vocabulary
.
collection
(
WORDS
).
get
()
.
addOnSuccessListener
{
setVocabularyAdapter
(
it
.
documents
)
}
.
addOnSuccessListener
{
setVocabularyAdapter
(
it
.
documents
)
}
}
}
...
@@ -87,9 +91,7 @@ class VocabularyFragment : Fragment() {
...
@@ -87,9 +91,7 @@ class VocabularyFragment : Fragment() {
wordItems
.
add
(
WordItem
(
word
,
translation
,
wordItemId
))
wordItems
.
add
(
WordItem
(
word
,
translation
,
wordItemId
))
}
}
val
adapter
=
VocabularyAdapter
(
wordItems
)
val
adapter
=
VocabularyAdapter
(
wordItems
,
activity
!!
)
recyclerView
.
adapter
=
adapter
recyclerView
.
adapter
=
adapter
//todo setOnItemClickListener
}
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/activities/WordItemInfoActivity.kt
0 → 100644
View file @
53ad7bb7
package
com.paktalin.vocabularynotebook.activities
import
android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.WordItem
import
kotlinx.android.synthetic.main.activity_word_info.*
class
WordItemInfoActivity
:
AppCompatActivity
()
{
private
lateinit
var
wordItem
:
WordItem
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_word_info
)
wordItem
=
intent
.
getSerializableExtra
(
"wordItem"
)
as
WordItem
updateUi
()
}
private
fun
updateUi
()
{
tvWord
.
text
=
wordItem
.
pojo
.
word
tvTranslation
.
text
=
wordItem
.
pojo
.
translation
}
companion
object
{
private
val
TAG
=
"VN/"
+
WordItemInfoActivity
::
class
.
java
.
simpleName
}
}
\ No newline at end of file
app/src/main/res/layout/activity_word_info.xml
0 → 100644
View file @
53ad7bb7
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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_height=
"match_parent"
>
<TextView
android:id=
"@+id/tvWord"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Word"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:id=
"@+id/tvTranslation"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Translation"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/tvWord"
/>
</android.support.constraint.ConstraintLayout>
\ 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