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
9d2a7e51
authored
Sep 08, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set up RecyclerView
parent
fc1ee8d4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
14 deletions
app/build.gradle
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.java
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/pojo/WordPojo.java → app/src/main/java/com/paktalin/vocabularynotebook/pojo/WordItemPojo.java
app/src/main/res/layout/fragment_vocabulary.xml
app/src/main/res/layout/list_item.xml
app/build.gradle
View file @
9d2a7e51
...
@@ -23,6 +23,9 @@ dependencies {
...
@@ -23,6 +23,9 @@ dependencies {
implementation
'com.android.support:appcompat-v7:28.0.0-rc02'
implementation
'com.android.support:appcompat-v7:28.0.0-rc02'
implementation
'com.android.support:design:27.1.1'
implementation
'com.android.support:design:27.1.1'
implementation
'com.android.support.constraint:constraint-layout:1.1.3'
implementation
'com.android.support.constraint:constraint-layout:1.1.3'
implementation
'com.android.support:recyclerview-v7:27.1.0'
implementation
'com.android.support:support-annotations:28.0.0-rc02'
implementation
"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation
"org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation
'com.google.firebase:firebase-core:16.0.3'
implementation
'com.google.firebase:firebase-core:16.0.3'
...
@@ -31,7 +34,6 @@ dependencies {
...
@@ -31,7 +34,6 @@ dependencies {
implementation
'com.firebase:firebase-client-android:2.3.1'
implementation
'com.firebase:firebase-client-android:2.3.1'
implementation
'com.google.firebase:firebase-firestore:17.1.0'
implementation
'com.google.firebase:firebase-firestore:17.1.0'
implementation
'com.android.support:support-annotations:28.0.0-rc02'
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
...
...
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.java
0 → 100644
View file @
9d2a7e51
package
com
.
paktalin
.
vocabularynotebook
;
import
android.support.annotation.NonNull
;
import
android.support.v7.widget.RecyclerView
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
com.paktalin.vocabularynotebook.pojo.WordItemPojo
;
import
java.util.List
;
public
class
VocabularyAdapter
extends
RecyclerView
.
Adapter
<
VocabularyAdapter
.
ViewHolder
>
{
private
static
final
String
TAG
=
"VN/"
+
VocabularyAdapter
.
class
.
getSimpleName
();
private
List
<
WordItemPojo
>
wordItems
;
public
VocabularyAdapter
(
List
<
WordItemPojo
>
wordItems
)
{
this
.
wordItems
=
wordItems
;
Log
.
d
(
TAG
,
"wordItems: "
+
wordItems
);
}
@NonNull
@Override
public
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
view
=
LayoutInflater
.
from
(
parent
.
getContext
())
.
inflate
(
R
.
layout
.
list_item
,
parent
,
false
);
return
new
ViewHolder
(
view
);
}
@Override
public
void
onBindViewHolder
(
@NonNull
ViewHolder
holder
,
int
position
)
{
WordItemPojo
item
=
wordItems
.
get
(
position
);
Log
.
d
(
TAG
,
"bind item: "
+
item
);
holder
.
tvWord
.
setText
(
item
.
getWord
());
holder
.
tvTranslation
.
setText
(
item
.
getTranslation
());
}
@Override
public
int
getItemCount
()
{
return
wordItems
.
size
();
}
class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
TextView
tvWord
,
tvTranslation
;
ViewHolder
(
View
itemView
)
{
super
(
itemView
);
tvWord
=
itemView
.
findViewById
(
R
.
id
.
tvWord
);
tvTranslation
=
itemView
.
findViewById
(
R
.
id
.
tvTranslation
);
}
}
}
app/src/main/java/com/paktalin/vocabularynotebook/activities/AddWordActivity.kt
View file @
9d2a7e51
...
@@ -9,7 +9,7 @@ import com.google.firebase.firestore.FirebaseFirestore
...
@@ -9,7 +9,7 @@ import com.google.firebase.firestore.FirebaseFirestore
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.Utils
import
com.paktalin.vocabularynotebook.pojo.WordPojo
import
com.paktalin.vocabularynotebook.pojo.Word
Item
Pojo
import
kotlinx.android.synthetic.main.activity_add_word.*
import
kotlinx.android.synthetic.main.activity_add_word.*
class
AddWordActivity
:
AppCompatActivity
()
{
class
AddWordActivity
:
AppCompatActivity
()
{
...
@@ -35,7 +35,7 @@ class AddWordActivity : AppCompatActivity() {
...
@@ -35,7 +35,7 @@ class AddWordActivity : AppCompatActivity() {
val
translation
=
etTranslation
.
text
.
toString
()
val
translation
=
etTranslation
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
word
,
translation
,
"Please, enter word and translation"
,
this
))
{
if
(
Utils
.
fieldsNotEmpty
(
word
,
translation
,
"Please, enter word and translation"
,
this
))
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
WORDS
).
add
(
WordPojo
(
word
,
translation
)).
addOnSuccessListener
{
.
collection
(
WORDS
).
add
(
Word
Item
Pojo
(
word
,
translation
)).
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully added a new word $word"
)
Log
.
i
(
TAG
,
"Successfully added a new word $word"
)
clearFields
()
clearFields
()
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/activities/VocabularyFragment.kt
View file @
9d2a7e51
...
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
...
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import
android.content.Intent
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
import
android.support.v7.widget.LinearLayoutManager
import
android.util.Log
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
...
@@ -13,13 +14,21 @@ import com.google.firebase.firestore.DocumentReference
...
@@ -13,13 +14,21 @@ import com.google.firebase.firestore.DocumentReference
import
com.google.firebase.firestore.DocumentSnapshot
import
com.google.firebase.firestore.DocumentSnapshot
import
com.google.firebase.firestore.FirebaseFirestore
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.pojo.WordItemPojo
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
java.util.*
class
VocabularyFragment
:
Fragment
()
{
class
VocabularyFragment
:
Fragment
()
{
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
WORDS
=
"words"
}
private
lateinit
var
userDocument
:
DocumentReference
private
lateinit
var
userDocument
:
DocumentReference
private
val
db
=
FirebaseFirestore
.
getInstance
()
private
val
db
=
FirebaseFirestore
.
getInstance
()
private
lateinit
var
vocabulary
Id
:
String
private
lateinit
var
vocabulary
:
DocumentReference
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
return
inflater
.
inflate
(
R
.
layout
.
fragment_vocabulary
,
container
,
false
)
return
inflater
.
inflate
(
R
.
layout
.
fragment_vocabulary
,
container
,
false
)
...
@@ -46,7 +55,7 @@ class VocabularyFragment : Fragment() {
...
@@ -46,7 +55,7 @@ class VocabularyFragment : Fragment() {
private
fun
setVocabularyId
(
task
:
DocumentSnapshot
)
{
private
fun
setVocabularyId
(
task
:
DocumentSnapshot
)
{
//todo if only one vocabulary exists, open it
//todo if only one vocabulary exists, open it
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
vocabulary
Id
=
vocabularies
[
0
].
id
vocabulary
=
db
.
collection
(
VOCABULARIES
).
document
(
vocabularies
[
0
].
id
)
}
}
@SuppressLint
(
"SetTextI18n"
)
@SuppressLint
(
"SetTextI18n"
)
...
@@ -62,18 +71,35 @@ class VocabularyFragment : Fragment() {
...
@@ -62,18 +71,35 @@ 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
db
.
collection
(
"vocabularies"
).
document
(
vocabularyId
).
get
().
addOnSuccessListener
{
task
->
vocabulary
.
get
().
addOnSuccessListener
{
task
->
val
vocabTitle
=
task
.
get
(
"title"
).
toString
()
val
vocabularyTitle
=
task
.
get
(
"title"
).
toString
()
tvUserData
.
append
(
"\n\nvocabularies:\n$vocabTitle"
)
tvUserData
.
append
(
"\n\nvocabularies:\n$vocabularyTitle"
)
}
}
val
mLayoutManager
=
LinearLayoutManager
(
activity
)
recyclerView
.
layoutManager
=
mLayoutManager
recyclerView
.
setHasFixedSize
(
true
)
val
items
:
List
<
WordItemPojo
>
=
Arrays
.
asList
(
WordItemPojo
(
"uno"
,
"one"
),
WordItemPojo
(
"due"
,
"two"
),
WordItemPojo
(
"tre"
,
"three"
))
val
adapter
=
VocabularyAdapter
(
items
)
recyclerView
.
adapter
=
adapter
/*vocabulary.collection(WORDS).get().addOnSuccessListener {
val items: List<String> = Arrays.asList("one", "two", "three")
val adapter = VocabularyAdapter(items)
recyclerView.adapter = adapter
}*/
}
}
private
fun
addWord
()
{
private
fun
addWord
()
{
val
addWordIntent
=
Intent
(
activity
,
AddWordActivity
::
class
.
java
)
val
addWordIntent
=
Intent
(
activity
,
AddWordActivity
::
class
.
java
)
addWordIntent
.
putExtra
(
"vocabularyId"
,
vocabulary
I
d
)
addWordIntent
.
putExtra
(
"vocabularyId"
,
vocabulary
.
i
d
)
startActivity
(
addWordIntent
)
startActivity
(
addWordIntent
)
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
}
private
fun
retrieveWordsFromVocabulary
()
{
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/pojo/WordPojo.java
→
app/src/main/java/com/paktalin/vocabularynotebook/pojo/Word
Item
Pojo.java
View file @
9d2a7e51
package
com
.
paktalin
.
vocabularynotebook
.
pojo
;
package
com
.
paktalin
.
vocabularynotebook
.
pojo
;
public
class
WordPojo
{
public
class
Word
Item
Pojo
{
private
String
word
,
translation
;
private
String
word
,
translation
;
public
WordPojo
(
String
word
,
String
translation
)
{
public
Word
Item
Pojo
(
String
word
,
String
translation
)
{
this
.
word
=
word
;
this
.
word
=
word
;
this
.
translation
=
translation
;
this
.
translation
=
translation
;
}
}
...
...
app/src/main/res/layout/fragment_vocabulary.xml
View file @
9d2a7e51
...
@@ -36,8 +36,9 @@
...
@@ -36,8 +36,9 @@
app:layout_constraintTop_toBottomOf=
"@+id/tvCongrats"
/>
app:layout_constraintTop_toBottomOf=
"@+id/tvCongrats"
/>
<android.support.v7.widget.RecyclerView
<android.support.v7.widget.RecyclerView
android:id=
"@+id/recyclerView"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"
wrap_content
"
android:layout_height=
"
200dp
"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
app:layout_constraintTop_toBottomOf=
"@+id/tvUserData"
/>
app:layout_constraintTop_toBottomOf=
"@+id/tvUserData"
/>
...
...
app/src/main/res/layout/list_item.xml
0 → 100644
View file @
9d2a7e51
<?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=
"wrap_content"
>
<TextView
android:id=
"@+id/tvWord"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"word"
/>
<TextView
android:id=
"@+id/tvTranslation"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dp"
android:layout_marginStart=
"8dp"
android:text=
"translation"
app:layout_constraintStart_toEndOf=
"@+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