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
Show 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
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import
java.util.*
class
UserManager
{
...
...
@@ -23,7 +24,7 @@ class UserManager {
val
db
=
ConfiguredFirestore
.
instance
val
user
=
UserPojo
(
newUser
.
email
)
db
.
collection
(
"vocabularies"
).
add
(
Vocabulary
.
Pojo
(
null
))
db
.
collection
(
VOCABULARIES
).
add
(
Vocabulary
.
Pojo
(
null
))
.
addOnSuccessListener
{
firstVocabularyRef
->
Log
.
d
(
TAG
,
"VocabularyPojo successfully created: "
+
firstVocabularyRef
.
path
)
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>) {
private
const
val
SORT_BY_TIME
=
0
private
const
val
SORT_BY_WORD
=
1
private
const
val
SORT_BY_TRANSLATION
=
2
const
val
WORDS
=
"words"
const
val
VOCABULARIES
=
"vocabularies"
}
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
import
android.util.Log
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.util.Date
...
...
@@ -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
)
fun
delete
()
{
ConfiguredFirestore
.
instance
.
collection
(
"vocabularies"
).
document
(
vocabularyId
)
.
collection
(
"words"
).
document
(
id
).
delete
()
ConfiguredFirestore
.
instance
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
)
.
collection
(
WORDS
).
document
(
id
).
delete
()
.
addOnSuccessListener
{
Log
.
i
(
TAG
,
"Successfully deleted word with id $id"
)
}
.
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
import
android.util.Log
import
android.view.View
import
android.widget.Toast
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
kotlinx.android.synthetic.main.fragment_new_word.*
class
AddWordFragment
:
WordFragment
()
{
...
...
@@ -27,5 +31,16 @@ class AddWordFragment : WordFragment() {
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
}
}
\ 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
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
import
android.support.v7.widget.SearchView
import
com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -75,9 +76,9 @@ class MainActivity : AppCompatActivity() {
.
addOnSuccessListener
{
task
->
hideProgressBar
()
//todo move Firestore logic and collections names to a separate class
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
"vocabularies"
)
as
List
<
DocumentReference
>
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
if
(
task
.
get
(
VOCABULARIES
)
!=
null
)
{
val
vocabularies
:
List
<
DocumentReference
>
=
task
.
get
(
VOCABULARIES
)
as
List
<
DocumentReference
>
val
vocabulary
=
db
.
collection
(
VOCABULARIES
).
document
(
vocabularies
[
0
].
id
)
vocabularyId
=
vocabulary
.
id
// 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
import
com.paktalin.vocabularynotebook.*
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
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
kotlinx.android.synthetic.main.fragment_vocabulary.*
class
VocabularyFragment
:
Fragment
()
{
companion
object
{
private
val
TAG
=
"VN/"
+
VocabularyFragment
::
class
.
simpleName
private
const
val
VOCABULARIES
=
"vocabularies"
private
const
val
WORDS
=
"words"
}
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.*
import
kotlinx.android.synthetic.main.notebook_sheet.*
abstract
class
WordFragment
:
Fragment
()
{
companion
object
{
const
val
VOCABULARIES
=
"vocabularies"
const
val
WORDS
=
"words"
}
protected
lateinit
var
mainActivity
:
MainActivity
private
var
wordEmpty
:
Boolean
=
true
internal
var
wordEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
private
var
translationEmpty
:
Boolean
=
true
internal
var
translationEmpty
:
Boolean
=
true
set
(
value
)
{
field
=
value
;
updateButtons
()
}
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
...
...
@@ -43,15 +38,9 @@ abstract class WordFragment : Fragment() {
btnClear
.
setOnClickListener
{
clearFields
()
}
}
private
fun
updateButtons
()
{
if
(!
wordEmpty
||
!
translationEmpty
)
showClearButton
()
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
()
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
()
if
(
wordEmpty
&&
translationEmpty
)
hideClearButton
()
open
fun
updateButtons
()
{
if
(!
wordEmpty
&&
!
translationEmpty
)
showSubmitButton
()
if
(
wordEmpty
||
translationEmpty
)
hideSubmitButton
()
}
private
fun
textWatcher
(
setEmpty
:
()
->
Unit
):
TextWatcher
{
...
...
@@ -68,10 +57,6 @@ abstract class WordFragment : Fragment() {
protected
fun
hideSubmitButton
()
{
mainActivity
.
btnSubmitLayout
.
visibility
=
View
.
GONE
}
private
fun
hideClearButton
()
{
btnClear
.
visibility
=
View
.
INVISIBLE
}
private
fun
showClearButton
()
{
btnClear
.
visibility
=
View
.
VISIBLE
}
fun
submitWord
()
{
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
...
...
app/src/main/res/values/strings.xml
View file @
115907ef
...
...
@@ -15,4 +15,7 @@
<string
name=
"menu_option_edit"
>
Edit
</string>
<string
name=
"option_sort"
>
Sort
</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>
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