Commit f3574940 by Paktalin

Isolated logOut and startActivity functions

parent 757b3b59
...@@ -7,10 +7,7 @@ import android.os.Bundle ...@@ -7,10 +7,7 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import com.paktalin.vocabularynotebook.* import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.utils.fieldsNotEmpty import com.paktalin.vocabularynotebook.utils.*
import com.paktalin.vocabularynotebook.utils.shortToast
import com.paktalin.vocabularynotebook.utils.signUp
import com.paktalin.vocabularynotebook.utils.userLoggedIn
import kotlinx.android.synthetic.main.activity_log_in.* import kotlinx.android.synthetic.main.activity_log_in.*
class LogInActivity : AppCompatActivity() { class LogInActivity : AppCompatActivity() {
...@@ -53,8 +50,7 @@ class LogInActivity : AppCompatActivity() { ...@@ -53,8 +50,7 @@ class LogInActivity : AppCompatActivity() {
fun startUserActivity() { fun startUserActivity() {
Log.d(TAG, "Logged in successfully") Log.d(TAG, "Logged in successfully")
val userActivityIntent = Intent(this@LogInActivity, MainActivity::class.java) startActivity(this@LogInActivity, MainActivity::class.java)
startActivity(userActivityIntent)
} }
private fun addProgressBar() { private fun addProgressBar() {
......
package com.paktalin.vocabularynotebook.ui.activities package com.paktalin.vocabularynotebook.ui.activities
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.util.Log import android.util.Log
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import android.view.WindowManager import android.view.WindowManager
...@@ -20,6 +18,7 @@ import com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment ...@@ -20,6 +18,7 @@ import com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
import com.paktalin.vocabularynotebook.utils.addFragment import com.paktalin.vocabularynotebook.utils.addFragment
import com.paktalin.vocabularynotebook.utils.extractVocabularyData import com.paktalin.vocabularynotebook.utils.extractVocabularyData
import com.paktalin.vocabularynotebook.utils.shortToast import com.paktalin.vocabularynotebook.utils.shortToast
import com.paktalin.vocabularynotebook.utils.startActivity
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
...@@ -48,10 +47,8 @@ class MainActivity : AppCompatActivity() { ...@@ -48,10 +47,8 @@ class MainActivity : AppCompatActivity() {
} }
private fun logOut() { private fun logOut() {
Log.i(TAG, "User logged out") logOut()
FirebaseAuth.getInstance()!!.signOut() startActivity(this@MainActivity, LogInActivity::class.java)
val intentLogInActivity = Intent(this@MainActivity, LogInActivity::class.java)
startActivity(intentLogInActivity)
} }
private fun setUpNavigationView() { private fun setUpNavigationView() {
......
package com.paktalin.vocabularynotebook.utils package com.paktalin.vocabularynotebook.utils
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentManager
...@@ -48,3 +49,7 @@ fun enableScrolling(mainActivity: MainActivity) { ...@@ -48,3 +49,7 @@ fun enableScrolling(mainActivity: MainActivity) {
fun shortToast(context: Context, text: String) { fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show() Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
} }
fun startActivity(context: Context, cls: Class<*>) {
context.startActivity(Intent(context, cls))
}
\ No newline at end of file
...@@ -3,12 +3,7 @@ package com.paktalin.vocabularynotebook.utils ...@@ -3,12 +3,7 @@ package com.paktalin.vocabularynotebook.utils
import android.util.Log import android.util.Log
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.FirebaseUser
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.ui.activities.LogInActivity import com.paktalin.vocabularynotebook.ui.activities.LogInActivity
import com.paktalin.vocabularynotebook.firestoreitems.UserPojo
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary
import com.paktalin.vocabularynotebook.firestoreitems.Vocabulary.Companion.VOCABULARIES
import java.util.*
private const val TAG = "VN/UserManager" private const val TAG = "VN/UserManager"
private var mAuth: FirebaseAuth? = FirebaseAuth.getInstance() private var mAuth: FirebaseAuth? = FirebaseAuth.getInstance()
...@@ -49,3 +44,8 @@ fun signUp(activity: LogInActivity, email: String, password: String) { ...@@ -49,3 +44,8 @@ fun signUp(activity: LogInActivity, email: String, password: String) {
fun userLoggedIn(): Boolean { fun userLoggedIn(): Boolean {
return mAuth!!.currentUser != null return mAuth!!.currentUser != null
} }
fun logOut() {
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