Commit 8a981912 by Paktalin

Fixed naming issues

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