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
548c2ee9
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VocabularyFragment is started from MainActivity after retrieving Firestore data
parent
6a28bf07
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
16 deletions
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/res/layout/notebook_sheet.xml
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
548c2ee9
...
...
@@ -2,6 +2,7 @@ package com.paktalin.vocabularynotebook.firestoreitems
class
Vocabulary
{
var
pojo
:
Pojo
private
lateinit
var
words
:
MutableList
<
WordItem
>
class
Pojo
(
var
title
:
String
?)
{
init
{
...
...
@@ -12,4 +13,6 @@ class Vocabulary {
init
{
pojo
=
Pojo
(
null
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
548c2ee9
...
...
@@ -34,9 +34,7 @@ class AddWordFragment : WordFragment() {
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
mainActivity
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
addWordItem
(
wordItem
)
mainActivity
.
vocabularyFragment
.
addWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/EditWordFragment.kt
View file @
548c2ee9
...
...
@@ -66,9 +66,7 @@ class EditWordFragment : WordFragment() {
Toast
.
makeText
(
mainActivity
,
"Couldn't update the word"
,
Toast
.
LENGTH_SHORT
).
show
()}
}
override
fun
updateRecycleView
(
wordItem
:
WordItem
)
{
val
vocabularyFragment
=
mainActivity
.
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
vocabularyFragment
.
updateWordItem
(
wordItem
)
mainActivity
.
vocabularyFragment
.
updateWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
EditWordFragment
::
class
.
java
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
548c2ee9
...
...
@@ -23,14 +23,13 @@ import kotlinx.android.synthetic.main.fragment_vocabulary.*
class
MainActivity
:
AppCompatActivity
()
{
lateinit
var
vocabularyId
:
String
private
lateinit
var
vocabularyFragment
:
VocabularyFragment
lateinit
var
vocabularyFragment
:
VocabularyFragment
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
hideKeyboard
()
setUpNavigationView
()
vocabularyFragment
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
extractVocabularyData
()
}
...
...
@@ -74,7 +73,13 @@ class MainActivity : AppCompatActivity() {
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
vocabularyId
=
vocabulary
.
id
vocabularyFragment
.
retrieveWordsData
(
vocabularyId
)
// start VocabularyFragment
vocabularyFragment
=
VocabularyFragment
()
val
arguments
=
Bundle
()
arguments
.
putString
(
"vocabularyId"
,
vocabularyId
)
vocabularyFragment
.
arguments
=
arguments
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
fragment_container
,
vocabularyFragment
).
commitNowAllowingStateLoss
()
}
else
{
showToastNoWords
()
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
548c2ee9
...
...
@@ -3,6 +3,7 @@ package com.paktalin.vocabularynotebook.ui
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v7.widget.LinearLayoutManager
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
...
...
@@ -27,9 +28,11 @@ class VocabularyFragment : Fragment() {
return
inflater
.
inflate
(
R
.
layout
.
fragment_vocabulary
,
container
,
false
)
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
setEmptyAdapter
()
retrieveWordsData
(
arguments
!!
[
"vocabularyId"
]
as
String
)
}
override
fun
onDestroy
()
{
...
...
@@ -44,14 +47,17 @@ class VocabularyFragment : Fragment() {
recyclerView
.
layoutManager
=
mLayoutManager
}
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
private
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
)
.
orderBy
(
"time"
,
Query
.
Direction
.
DESCENDING
)
.
get
()
.
addOnSuccessListener
{
if
(
it
.
documents
.
size
!=
0
)
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
else
(
activity
as
MainActivity
).
showToastNoWords
()}
else
{
Log
.
i
(
TAG
,
"There are no documents in collection \"words\""
)
(
activity
as
MainActivity
).
showToastNoWords
()
}}
}
private
fun
setVocabularyAdapter
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
...
...
app/src/main/res/layout/notebook_sheet.xml
View file @
548c2ee9
...
...
@@ -17,6 +17,7 @@
android:layout_margin=
"8dp"
>
<LinearLayout
android:id=
"@+id/fragment_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:padding=
"8dp"
...
...
@@ -30,11 +31,6 @@
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
/>
<fragment
android:id=
"@+id/fragment_vocabulary"
android:name=
"com.paktalin.vocabularynotebook.ui.VocabularyFragment"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
</ScrollView>
...
...
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