Commit 8a981912 by Paktalin

Fixed naming issues

parent 81792b36
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paktalin.vocabularynotebook"> package="com.paktalin.vocabularynotebook">
<!-- To auto-complete the email text field in the login form with the user's emails --> <!-- To auto-complete the email text field in the mLogIn form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
......
...@@ -2,9 +2,8 @@ package com.paktalin.vocabularynotebook.firestoreitems ...@@ -2,9 +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.utils.FirestoreManager.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.WORDS import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.WORDS
import java.io.Serializable import java.io.Serializable
import java.util.Date import java.util.Date
......
package com.paktalin.vocabularynotebook.ui.activities package com.paktalin.vocabularynotebook.ui.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
...@@ -24,19 +23,19 @@ class LogInActivity : AppCompatActivity() { ...@@ -24,19 +23,19 @@ class LogInActivity : AppCompatActivity() {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
if (userLoggedIn()) { startUserActivity() } if (mUserLoggedIn()) { startUserActivity() }
} }
fun login() { fun login() {
processUser { processUser {
com.paktalin.vocabularynotebook.utils.login( mLogIn(
{ removeProgressBar() }, { removeProgressBar() },
{ startUserActivity() }, { startUserActivity() },
{ showToastFailure() }, { showToastFailure() },
email!!, password!!) email!!, password!!)
} } } }
private fun signUp() { processUser { signUp(this, email!!, password!!) } } private fun signUp() { processUser { mSignUp(this, email!!, password!!) } }
private fun processUser(authAction: () -> Unit) { private fun processUser(authAction: () -> Unit) {
email = etEmail!!.text.toString() email = etEmail!!.text.toString()
...@@ -67,7 +66,7 @@ class LogInActivity : AppCompatActivity() { ...@@ -67,7 +66,7 @@ class LogInActivity : AppCompatActivity() {
private fun createRandomUser() { private fun createRandomUser() {
etEmail.setText("random@gmail.com") etEmail.setText("random@gmail.com")
etPassword.setText("123456") etPassword.setText("123456")
processUser { signUp(this@LogInActivity, email!!, password!!) } processUser { mSignUp(this@LogInActivity, email!!, password!!) }
} }
companion object { private val TAG = "VN/" + LogInActivity::class.simpleName } companion object { private val TAG = "VN/" + LogInActivity::class.simpleName }
......
...@@ -18,7 +18,6 @@ import com.paktalin.vocabularynotebook.utils.* ...@@ -18,7 +18,6 @@ import com.paktalin.vocabularynotebook.utils.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
lateinit var vocabularyId: String
lateinit var vocabularyFragment: VocabularyFragment lateinit var vocabularyFragment: VocabularyFragment
lateinit var searchView: SearchView lateinit var searchView: SearchView
...@@ -43,7 +42,7 @@ class MainActivity : AppCompatActivity() { ...@@ -43,7 +42,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun logOut() { private fun logOut() {
logOut() mLogOut()
startActivity(this@MainActivity, LogInActivity::class.java) startActivity(this@MainActivity, LogInActivity::class.java)
} }
...@@ -67,7 +66,6 @@ class MainActivity : AppCompatActivity() { ...@@ -67,7 +66,6 @@ class MainActivity : AppCompatActivity() {
} }
private fun addVocabularyFragment(vocabularyId: String) { private fun addVocabularyFragment(vocabularyId: String) {
this.vocabularyId = vocabularyId
vocabularyFragment = VocabularyFragment() vocabularyFragment = VocabularyFragment()
val arguments = Bundle() val arguments = Bundle()
arguments.putString("vocabularyId", vocabularyId) arguments.putString("vocabularyId", vocabularyId)
......
...@@ -4,9 +4,9 @@ import android.util.Log ...@@ -4,9 +4,9 @@ import android.util.Log
import android.view.View import android.view.View
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
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 com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.WORDS
import com.paktalin.vocabularynotebook.utils.shortToast import com.paktalin.vocabularynotebook.utils.shortToast
import kotlinx.android.synthetic.main.fragment_editable_word.* import kotlinx.android.synthetic.main.fragment_editable_word.*
......
...@@ -10,9 +10,9 @@ import android.view.inputmethod.InputMethodManager ...@@ -10,9 +10,9 @@ import android.view.inputmethod.InputMethodManager
import com.paktalin.vocabularynotebook.* import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
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.ui.activities.MainActivity import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.WORDS
import com.paktalin.vocabularynotebook.utils.disableScrolling import com.paktalin.vocabularynotebook.utils.disableScrolling
import com.paktalin.vocabularynotebook.utils.enableScrolling import com.paktalin.vocabularynotebook.utils.enableScrolling
import com.paktalin.vocabularynotebook.utils.removeFragment import com.paktalin.vocabularynotebook.utils.removeFragment
......
...@@ -12,11 +12,11 @@ import com.google.firebase.firestore.Query ...@@ -12,11 +12,11 @@ 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 com.paktalin.vocabularynotebook.ui.activities.MainActivity import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.VOCABULARIES
import com.paktalin.vocabularynotebook.utils.FirestoreManager.Companion.WORDS
import kotlinx.android.synthetic.main.fragment_vocabulary.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
class VocabularyFragment : Fragment() { class VocabularyFragment : Fragment() {
......
...@@ -10,6 +10,7 @@ import android.view.ViewGroup ...@@ -10,6 +10,7 @@ import android.view.ViewGroup
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.firestoreitems.WordItem import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.ui.activities.MainActivity import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.FirestoreManager
import kotlinx.android.synthetic.main.fragment_editable_word.* import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.* import kotlinx.android.synthetic.main.content_main.*
...@@ -63,7 +64,7 @@ abstract class WordFragment : Fragment() { ...@@ -63,7 +64,7 @@ abstract class WordFragment : Fragment() {
val word = word.text.toString() val word = word.text.toString()
val translation = translation.text.toString() val translation = translation.text.toString()
val vocabularyId = mainActivity.vocabularyId val vocabularyId = FirestoreManager.vocabularyId
mainActivity.addProgressBar() mainActivity.addProgressBar()
saveToFirestore(word, translation, vocabularyId) saveToFirestore(word, translation, vocabularyId)
return return
......
...@@ -23,7 +23,7 @@ class FirestoreManager { ...@@ -23,7 +23,7 @@ class FirestoreManager {
.addOnSuccessListener { task -> .addOnSuccessListener { task ->
removeProgressBar() removeProgressBar()
if (task.get(VOCABULARIES) != null) { if (task.get(VOCABULARIES) != null) {
val vocabularyId = retrieveVocabularyID(task, db) setVocabularyID(task, db)
onSuccess(vocabularyId) onSuccess(vocabularyId)
} else { } else {
Log.w(TAG, "There's no collection \"vocabularies\"") Log.w(TAG, "There's no collection \"vocabularies\"")
...@@ -39,7 +39,7 @@ class FirestoreManager { ...@@ -39,7 +39,7 @@ class FirestoreManager {
} }
.addOnFailureListener { .addOnFailureListener {
Log.w(TAG, "Couldn't add user to the database", it.cause) Log.w(TAG, "Couldn't add user to the database", it.cause)
deleteUser(firebaseUser) mDeleteUser(firebaseUser)
} }
} }
...@@ -62,16 +62,18 @@ class FirestoreManager { ...@@ -62,16 +62,18 @@ class FirestoreManager {
} }
} }
private fun retrieveVocabularyID(task: DocumentSnapshot, db: FirebaseFirestore): String { private fun setVocabularyID(task: DocumentSnapshot, db: FirebaseFirestore) {
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)
return vocabulary.id vocabularyId = vocabulary.id
} }
companion object { companion object {
private const val USERS = "users" const val USERS = "users"
private const val WORDS = "words" const val WORDS = "words"
private const val VOCABULARIES = "vocabularies" const val VOCABULARIES = "vocabularies"
private const val TAG = "VN/FirestoreManager" private const val TAG = "VN/FirestoreManager"
lateinit var vocabularyId: String
} }
} }
\ No newline at end of file
...@@ -8,13 +8,13 @@ import com.paktalin.vocabularynotebook.ui.activities.LogInActivity ...@@ -8,13 +8,13 @@ import com.paktalin.vocabularynotebook.ui.activities.LogInActivity
private const val TAG = "VN/UserManager" private const val TAG = "VN/UserManager"
private var mAuth: FirebaseAuth? = FirebaseAuth.getInstance() private var mAuth: FirebaseAuth? = FirebaseAuth.getInstance()
fun deleteUser(user: FirebaseUser) { fun mDeleteUser(user: FirebaseUser) {
user.delete() user.delete()
.addOnSuccessListener { Log.i(TAG, "UserPojo was successfully deleted") } .addOnSuccessListener { Log.i(TAG, "UserPojo was successfully deleted") }
.addOnFailureListener { Log.i(TAG, "deleteUser:failure", it.cause)} .addOnFailureListener { Log.i(TAG, "mDeleteUser:failure", it.cause)}
} }
fun login(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit, fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
email: String, password: String) { email: String, password: String) {
mAuth!!.signInWithEmailAndPassword(email, password) mAuth!!.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { onComplete() } .addOnCompleteListener { onComplete() }
...@@ -28,7 +28,7 @@ fun login(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit, ...@@ -28,7 +28,7 @@ fun login(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
} }
} }
fun signUp(activity: LogInActivity, email: String, password: String) { fun mSignUp(activity: LogInActivity, email: String, password: String) {
mAuth!!.createUserWithEmailAndPassword(email, password) mAuth!!.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener { removeProgressBar(activity.supportFragmentManager) } .addOnCompleteListener { removeProgressBar(activity.supportFragmentManager) }
.addOnSuccessListener { .addOnSuccessListener {
...@@ -41,11 +41,11 @@ fun signUp(activity: LogInActivity, email: String, password: String) { ...@@ -41,11 +41,11 @@ fun signUp(activity: LogInActivity, email: String, password: String) {
shortToast(activity, it.message!!) shortToast(activity, it.message!!)
} } } }
fun userLoggedIn(): Boolean { fun mUserLoggedIn(): Boolean {
return mAuth!!.currentUser != null return mAuth!!.currentUser != null
} }
fun logOut() { fun mLogOut() {
mAuth!!.signOut() mAuth!!.signOut()
Log.i(TAG, "User logged out") Log.i(TAG, "User logged out")
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment