Commit 6277fd14 by Paktalin

Log out option added

parent 2d0634ca
package com.paktalin.vocabularynotebook.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.paktalin.vocabularynotebook.R;
public class AddWordActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_word);
}
}
package com.paktalin.vocabularynotebook.activities
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.paktalin.vocabularynotebook.R
class AddWordActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_word)
}
}
......@@ -63,16 +63,13 @@ class LogInActivity : AppCompatActivity() {
//todo check if the password is good
// todo verify email
mAuth!!.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
Log.d(TAG, "Successfully signed up a new user")
UserManager.addNewUserToDb(mAuth!!.currentUser!!, this)
}
else {
Log.w(TAG, "createUserWithEmail:failure", task.exception)
Toast.makeText(this@LogInActivity, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
.addOnSuccessListener { _ ->
Log.d(TAG, "Successfully signed up a new user")
UserManager.addNewUserToDb(mAuth!!.currentUser!!, this)
}
.addOnFailureListener {
Log.d(TAG, "createUserWithEmail:failure", it.fillInStackTrace())
Toast.makeText(this@LogInActivity, it.message, Toast.LENGTH_SHORT).show()
}
}
}
......
package com.paktalin.vocabularynotebook.activities
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.google.firebase.auth.FirebaseAuth
import com.paktalin.vocabularynotebook.R
import kotlinx.android.synthetic.main.activity_main.*
......@@ -14,11 +17,21 @@ class MainActivity : AppCompatActivity() {
navigationView.setNavigationItemSelectedListener { menuItem ->
menuItem.isChecked = true
if(menuItem.itemId == R.id.logOut) { logOut() }
drawerLayout!!.closeDrawers()
true
}
}
private fun logOut() {
Log.i(TAG, "User logged out")
FirebaseAuth.getInstance()!!.signOut()
val intentLogInActivity = Intent(this@MainActivity, LogInActivity::class.java)
startActivity(intentLogInActivity)
}
companion object {
private val TAG = "VN/" + MainActivity::class.simpleName
}
......
......@@ -14,9 +14,9 @@
<group android:checkableBehavior="single">
<item
android:id="@+id/map"
android:icon="@drawable/common_google_signin_btn_icon_light"
android:title="Vocabulary" />
android:id="@+id/logOut"
android:icon="@android:drawable/ic_lock_power_off"
android:title="Log out" />
</group>
</menu>
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