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
54c05326
authored
Sep 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Words are sorted after one was added or edited
parent
51f65fec
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
31 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/pojo/Vocabulary.kt
app/src/main/java/com/paktalin/vocabularynotebook/pojo/VocabularyPojo.java
app/src/main/java/com/paktalin/vocabularynotebook/ui/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/AndroidManifest.xml
View file @
54c05326
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
<activity
<activity
android:name=
".ui.MainActivity"
android:name=
".ui.MainActivity"
android:windowSoftInputMode=
"adjustResize"
/>
android:windowSoftInputMode=
"adjustResize"
/>
<activity
android:name=
".ui.LogInActivity"
>
<activity
android:name=
".ui.LogInActivity"
android:windowSoftInputMode=
"adjustResize"
>
<intent-filter>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
...
...
app/src/main/java/com/paktalin/vocabularynotebook/UserManager.kt
View file @
54c05326
...
@@ -5,7 +5,7 @@ import com.google.firebase.auth.FirebaseUser
...
@@ -5,7 +5,7 @@ import com.google.firebase.auth.FirebaseUser
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.pojo.UserPojo
import
com.paktalin.vocabularynotebook.pojo.UserPojo
import
com.paktalin.vocabularynotebook.pojo.Vocabulary
Pojo
import
com.paktalin.vocabularynotebook.pojo.Vocabulary
import
java.util.*
import
java.util.*
class
UserManager
{
class
UserManager
{
...
@@ -23,7 +23,7 @@ class UserManager {
...
@@ -23,7 +23,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
(
))
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/VocabularyAdapter.kt
View file @
54c05326
...
@@ -61,12 +61,14 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
...
@@ -61,12 +61,14 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
fun
addWordItem
(
newWordItem
:
WordItem
)
{
fun
addWordItem
(
newWordItem
:
WordItem
)
{
wordItems
.
add
(
0
,
newWordItem
)
wordItems
.
add
(
0
,
newWordItem
)
this
.
sort
()
this
.
notifyItemInserted
(
0
)
this
.
notifyItemInserted
(
0
)
}
}
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
wordItems
[
updatedItemId
]
=
updatedWordItem
wordItems
[
updatedItemId
]
=
updatedWordItem
this
.
sort
()
this
.
notifyDataSetChanged
()
this
.
notifyDataSetChanged
()
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/pojo/Vocabulary.kt
0 → 100644
View file @
54c05326
package
com.paktalin.vocabularynotebook.pojo
class
Vocabulary
{
var
pojo
:
Pojo
class
Pojo
(
var
title
:
String
?)
{
init
{
if
(
title
==
null
)
title
=
"Untitled vocabulary"
}
}
init
{
pojo
=
Pojo
(
null
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/pojo/VocabularyPojo.java
deleted
100644 → 0
View file @
51f65fec
package
com
.
paktalin
.
vocabularynotebook
.
pojo
;
public
class
VocabularyPojo
{
private
String
title
;
public
VocabularyPojo
()
{
title
=
"First vocabulary"
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/LogInActivity.kt
View file @
54c05326
...
@@ -37,9 +37,9 @@ class LogInActivity : AppCompatActivity() {
...
@@ -37,9 +37,9 @@ class LogInActivity : AppCompatActivity() {
val
password
=
etPassword
!!
.
text
.
toString
()
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
progress
.
visibility
=
View
.
VISIBLE
showProgressBar
()
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
progress
.
visibility
=
View
.
GONE
}
.
addOnCompleteListener
{
hideProgressBar
()
}
.
addOnSuccessListener
{
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
Log
.
d
(
TAG
,
"Successfully signed in"
)
startUserActivity
()
startUserActivity
()
...
@@ -59,7 +59,9 @@ class LogInActivity : AppCompatActivity() {
...
@@ -59,7 +59,9 @@ class LogInActivity : AppCompatActivity() {
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
//todo check if the password is good
//todo check if the password is good
// todo verify email
// todo verify email
showProgressBar
()
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
hideProgressBar
()
}
.
addOnSuccessListener
{
_
->
.
addOnSuccessListener
{
_
->
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
UserManager
.
addNewUserToDb
(
mAuth
!!
.
currentUser
!!
,
this
)
UserManager
.
addNewUserToDb
(
mAuth
!!
.
currentUser
!!
,
this
)
...
@@ -77,6 +79,10 @@ class LogInActivity : AppCompatActivity() {
...
@@ -77,6 +79,10 @@ class LogInActivity : AppCompatActivity() {
startActivity
(
userActivityIntent
)
startActivity
(
userActivityIntent
)
}
}
private
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
private
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
@SuppressLint
(
"SetTextI18n"
)
@SuppressLint
(
"SetTextI18n"
)
private
fun
createRandomUser
()
{
private
fun
createRandomUser
()
{
etEmail
.
setText
(
"random@gmail.com"
)
etEmail
.
setText
(
"random@gmail.com"
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
54c05326
...
@@ -15,6 +15,7 @@ import android.view.Menu
...
@@ -15,6 +15,7 @@ import android.view.Menu
import
android.view.MenuItem
import
android.view.MenuItem
import
android.view.View
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.VocabularyAdapter
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.*
...
@@ -71,11 +72,10 @@ class MainActivity : AppCompatActivity() {
...
@@ -71,11 +72,10 @@ class MainActivity : AppCompatActivity() {
hideProgressBar
()
hideProgressBar
()
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
>
//todo represent specific vocabulary instead of the first one
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
vocabularyId
=
vocabulary
.
id
vocabularyId
=
vocabulary
.
id
vocabularyFragment
.
retrieveWordsData
(
vocabularyId
)
vocabularyFragment
.
retrieveWordsData
(
vocabularyId
)
}
}
else
{
showToastNoWords
()
}
}
}
}
}
...
@@ -92,12 +92,13 @@ class MainActivity : AppCompatActivity() {
...
@@ -92,12 +92,13 @@ class MainActivity : AppCompatActivity() {
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
}
fun
showProgressBar
()
{
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
progress
.
visibility
=
View
.
VISIBLE
}
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
fun
hideProgressBar
()
{
fun
showToastNoWords
()
{
progress
.
visibility
=
View
.
GONE
Toast
.
makeText
(
this
@MainActivity
,
"You don't have any words yet. Add your fist one!"
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
override
fun
onPause
()
{
override
fun
onPause
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
54c05326
...
@@ -44,7 +44,10 @@ class VocabularyFragment : Fragment() {
...
@@ -44,7 +44,10 @@ class VocabularyFragment : Fragment() {
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
).
orderBy
(
"word"
).
get
()
db
.
collection
(
VOCABULARIES
).
document
(
vocabularyId
).
collection
(
WORDS
).
orderBy
(
"word"
).
get
()
.
addOnSuccessListener
{
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
}
.
addOnSuccessListener
{
if
(
it
.
documents
.
size
!=
0
)
setVocabularyAdapter
(
it
.
documents
,
vocabularyId
)
else
(
activity
as
MainActivity
).
showToastNoWords
()}
}
}
private
fun
setVocabularyAdapter
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
private
fun
setVocabularyAdapter
(
documents
:
MutableList
<
DocumentSnapshot
>,
vocabularyId
:
String
)
{
...
...
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