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
Show 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 @@
<activity
android:name=
".ui.MainActivity"
android:windowSoftInputMode=
"adjustResize"
/>
<activity
android:name=
".ui.LogInActivity"
>
<activity
android:name=
".ui.LogInActivity"
android:windowSoftInputMode=
"adjustResize"
>
<intent-filter>
<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
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.ui.LogInActivity
import
com.paktalin.vocabularynotebook.pojo.UserPojo
import
com.paktalin.vocabularynotebook.pojo.Vocabulary
Pojo
import
com.paktalin.vocabularynotebook.pojo.Vocabulary
import
java.util.*
class
UserManager
{
...
...
@@ -23,7 +23,7 @@ class UserManager {
val
db
=
ConfiguredFirestore
.
instance
val
user
=
UserPojo
(
newUser
.
email
)
db
.
collection
(
"vocabularies"
).
add
(
Vocabulary
Pojo
(
))
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/VocabularyAdapter.kt
View file @
54c05326
...
...
@@ -61,12 +61,14 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
fun
addWordItem
(
newWordItem
:
WordItem
)
{
wordItems
.
add
(
0
,
newWordItem
)
this
.
sort
()
this
.
notifyItemInserted
(
0
)
}
fun
updateWordItem
(
updatedWordItem
:
WordItem
)
{
val
updatedItemId
=
wordItems
.
indexOf
(
updatedWordItem
)
wordItems
[
updatedItemId
]
=
updatedWordItem
this
.
sort
()
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() {
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
progress
.
visibility
=
View
.
VISIBLE
showProgressBar
()
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
progress
.
visibility
=
View
.
GONE
}
.
addOnCompleteListener
{
hideProgressBar
()
}
.
addOnSuccessListener
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
startUserActivity
()
...
...
@@ -59,7 +59,9 @@ class LogInActivity : AppCompatActivity() {
if
(
Utils
.
fieldsNotEmpty
(
email
,
password
,
"Please, enter email and password"
,
this
))
{
//todo check if the password is good
// todo verify email
showProgressBar
()
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
hideProgressBar
()
}
.
addOnSuccessListener
{
_
->
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
UserManager
.
addNewUserToDb
(
mAuth
!!
.
currentUser
!!
,
this
)
...
...
@@ -77,6 +79,10 @@ class LogInActivity : AppCompatActivity() {
startActivity
(
userActivityIntent
)
}
private
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
private
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
createRandomUser
()
{
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
import
android.view.MenuItem
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.VocabularyAdapter
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
kotlinx.android.synthetic.main.fragment_vocabulary.*
...
...
@@ -71,11 +72,10 @@ class MainActivity : AppCompatActivity() {
hideProgressBar
()
if
(
task
.
get
(
"vocabularies"
)
!=
null
)
{
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
)
vocabularyId
=
vocabulary
.
id
vocabularyFragment
.
retrieveWordsData
(
vocabularyId
)
}
}
else
{
showToastNoWords
()
}
}
}
...
...
@@ -92,12 +92,13 @@ class MainActivity : AppCompatActivity() {
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
fun
showProgressBar
()
{
progress
.
visibility
=
View
.
VISIBLE
}
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
}
fun
hideProgressBar
()
{
progress
.
visibility
=
View
.
GONE
fun
showToastNoWords
()
{
Toast
.
makeText
(
this
@MainActivity
,
"You don't have any words yet. Add your fist one!"
,
Toast
.
LENGTH_SHORT
).
show
()
}
override
fun
onPause
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
54c05326
...
...
@@ -44,7 +44,10 @@ class VocabularyFragment : Fragment() {
fun
retrieveWordsData
(
vocabularyId
:
String
)
{
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
)
{
...
...
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