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
115907ef
authored
Sep 22, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved constant strings words and vocabularies under the Vocabulary class
parent
1e099358
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
28 deletions
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
app/src/main/res/values/strings.xml
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
View file @
115907ef
...
@@ -6,6 +6,7 @@ import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
...
@@ -6,6 +6,7 @@ import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
java.util.*
import
java.util.*
class
UserManager
{
class
UserManager
{
...
@@ -23,7 +24,7 @@ class UserManager {
...
@@ -23,7 +24,7 @@ class UserManager {
val
db
=
ConfiguredFirestore
.
instance
val
db
=
ConfiguredFirestore
.
instance
val
user
=
UserPojo
(
newUser
.
email
)
val
user
=
UserPojo
(
newUser
.
email
)
db
.
collection
(
"vocabularies"
).
add
(
Vocabulary
.
Pojo
(
null
))
db
.
collection
(
VOCABULARIES
).
add
(
Vocabulary
.
Pojo
(
null
))
.
addOnSuccessListener
{
firstVocabularyRef
->
.
addOnSuccessListener
{
firstVocabularyRef
->
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
user
.
vocabularies
=
Collections
.
singletonList
(
firstVocabularyRef
)
user
.
vocabularies
=
Collections
.
singletonList
(
firstVocabularyRef
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/Vocabulary.kt
View file @
115907ef
...
@@ -7,6 +7,9 @@ class Vocabulary(words: MutableList<WordItem>) {
...
@@ -7,6 +7,9 @@ class Vocabulary(words: MutableList<WordItem>) {
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_TRANSLATION
=
2
private
const
val
SORT_BY_TRANSLATION
=
2
const
val
WORDS
=
"words"
const
val
VOCABULARIES
=
"vocabularies"
}
}
var
pojo
:
Pojo
var
pojo
:
Pojo
...
...
app/src/main/java/com/paktalin/vocabularynotebook/firestoreitems/WordItem.kt
View file @
115907ef
...
@@ -2,6 +2,8 @@ package com.paktalin.vocabularynotebook.firestoreitems
...
@@ -2,6 +2,8 @@ package com.paktalin.vocabularynotebook.firestoreitems
import
android.util.Log
import
android.util.Log
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
java.io.Serializable
import
java.io.Serializable
import
java.util.Date
import
java.util.Date
...
@@ -19,8 +21,8 @@ class WordItem(word: String, translation: String, time: Date?, var id: String, p
...
@@ -19,8 +21,8 @@ class WordItem(word: String, translation: String, time: Date?, var id: String, p
:
this
(
pojo
.
word
,
pojo
.
translation
,
pojo
.
time
,
id
,
vocabularyId
)
:
this
(
pojo
.
word
,
pojo
.
translation
,
pojo
.
time
,
id
,
vocabularyId
)
fun
delete
()
{
fun
delete
()
{
ConfiguredFirestore
.
instance
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
ConfiguredFirestore
.
instance
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
"words"
).
document
(
id
).
delete
()
.
collection
(
WORDS
).
document
(
id
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
.
addOnFailureListener
{
e
->
Log
.
w
(
TAG
,
"deleteWordWithId $id:failure"
,
e
.
fillInStackTrace
())
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/AddWordFragment.kt
View file @
115907ef
package
com.paktalin.vocabularynotebook.ui
package
com.paktalin.vocabularynotebook.ui
import
android.util.Log
import
android.util.Log
import
android.view.View
import
android.widget.Toast
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
kotlinx.android.synthetic.main.fragment_new_word.*
class
AddWordFragment
:
WordFragment
()
{
class
AddWordFragment
:
WordFragment
()
{
...
@@ -27,5 +31,16 @@ class AddWordFragment : WordFragment() {
...
@@ -27,5 +31,16 @@ class AddWordFragment : WordFragment() {
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
mainActivity
.
vocabularyFragment
.
addWord
(
wordItem
)
}
}
override
fun
updateButtons
()
{
super
.
updateButtons
()
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
()
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
()
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
AddWordFragment
::
class
.
java
.
simpleName
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
115907ef
...
@@ -21,6 +21,7 @@ import com.paktalin.vocabularynotebook.VocabularyAdapter
...
@@ -21,6 +21,7 @@ import com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
android.support.v7.widget.SearchView
import
android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
...
@@ -75,9 +76,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -75,9 +76,9 @@ class MainActivity : AppCompatActivity() {
.
addOnSuccessListener
{
task
->
.
addOnSuccessListener
{
task
->
hideProgressBar
()
hideProgressBar
()
//todo move Firestore logic and collections names to a separate class
//todo move Firestore logic and collections names to a separate class
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
if
(
task
.
get
(
VOCABULARIES
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
val
vocabulary
=
db
.
collection
(
VOCABULARIES
).
document
(
vocabularies
[
0
].
id
)
vocabularyId
=
vocabulary
.
id
vocabularyId
=
vocabulary
.
id
// start VocabularyFragment
// start VocabularyFragment
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
115907ef
...
@@ -14,14 +14,14 @@ import com.google.firebase.firestore.Query
...
@@ -14,14 +14,14 @@ import com.google.firebase.firestore.Query
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
com.paktalin.vocabularynotebook.firestoreitems.WordItem
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
VocabularyFragment
:
Fragment
()
{
class
VocabularyFragment
:
Fragment
()
{
companion
object
{
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
WORDS
=
"words"
}
}
private
val
db
=
ConfiguredFirestore
.
instance
private
val
db
=
ConfiguredFirestore
.
instance
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordFragment.kt
View file @
115907ef
...
@@ -13,17 +13,12 @@ import kotlinx.android.synthetic.main.fragment_new_word.*
...
@@ -13,17 +13,12 @@ import kotlinx.android.synthetic.main.fragment_new_word.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
abstract
class
WordFragment
:
Fragment
()
{
abstract
class
WordFragment
:
Fragment
()
{
companion
object
{
const
val
VOCABULARIES
=
"vocabularies"
const
val
WORDS
=
"words"
}
protected
lateinit
var
mainActivity
:
MainActivity
protected
lateinit
var
mainActivity
:
MainActivity
private
var
wordEmpty
:
Boolean
=
true
internal
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
set
(
value
)
{
field
=
value
;
updateButtons
()
}
private
var
translationEmpty
:
Boolean
=
true
internal
var
translationEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
set
(
value
)
{
field
=
value
;
updateButtons
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
...
@@ -43,15 +38,9 @@ abstract class WordFragment : Fragment() {
...
@@ -43,15 +38,9 @@ abstract class WordFragment : Fragment() {
btnClear
.
setOnClickListener
{
clearFields
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
}
}
private
fun
updateButtons
()
{
open
fun
updateButtons
()
{
if
(!
wordEmpty
||
!
translationEmpty
)
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
()
showClearButton
()
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
()
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
()
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
()
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
()
}
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
...
@@ -68,10 +57,6 @@ abstract class WordFragment : Fragment() {
...
@@ -68,10 +57,6 @@ abstract class WordFragment : Fragment() {
protected
fun
hideSubmitButton
()
{
protected
fun
hideSubmitButton
()
{
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
GONE
}
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
GONE
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
fun
submitWord
()
{
fun
submitWord
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
...
...
app/src/main/res/values/strings.xml
View file @
115907ef
...
@@ -15,4 +15,7 @@
...
@@ -15,4 +15,7 @@
<string
name=
"menu_option_edit"
>
Edit
</string>
<string
name=
"menu_option_edit"
>
Edit
</string>
<string
name=
"option_sort"
>
Sort
</string>
<string
name=
"option_sort"
>
Sort
</string>
<string
name=
"option_search"
>
Search
</string>
<string
name=
"option_search"
>
Search
</string>
<!--Toast messages-->
<string
name=
"toast_no_words"
>
You don\'t have any words yet. Add your fist one!
</string>
</resources>
</resources>
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