Commit 1622b5ca by Paktalin

Moved vocabulary logic to a fragment

parent 5bbf1a85
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".activities.UserActivity" /> <activity android:name=".activities.MainActivity" />
<activity android:name=".activities.LogInActivity"> <activity android:name=".activities.LogInActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -78,8 +78,8 @@ class LogInActivity : AppCompatActivity() { ...@@ -78,8 +78,8 @@ class LogInActivity : AppCompatActivity() {
} }
fun startUserActivity() { fun startUserActivity() {
Log.d(TAG, "Signed in successfully") Log.d(TAG, "Logged in successfully")
val userActivityIntent = Intent(this@LogInActivity, UserActivity::class.java) val userActivityIntent = Intent(this@LogInActivity, MainActivity::class.java)
startActivity(userActivityIntent) startActivity(userActivityIntent)
} }
......
package com.paktalin.vocabularynotebook.activities
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.paktalin.vocabularynotebook.R
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navigationView.setNavigationItemSelectedListener { menuItem ->
menuItem.isChecked = true
drawerLayout!!.closeDrawers()
true
}
}
companion object {
private val TAG = "VN/" + MainActivity::class.simpleName
}
}
...@@ -2,42 +2,33 @@ package com.paktalin.vocabularynotebook.activities ...@@ -2,42 +2,33 @@ package com.paktalin.vocabularynotebook.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.support.design.widget.NavigationView import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.DocumentReference import com.google.firebase.firestore.DocumentReference
import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.DocumentSnapshot
import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.FirebaseFirestore
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
import kotlinx.android.synthetic.main.activity_vocabulary.*
class UserActivity : AppCompatActivity() { class VocabularyFragment : Fragment() {
private lateinit var userDocument: DocumentReference private lateinit var userDocument: DocumentReference
private val db = FirebaseFirestore.getInstance() private val db = FirebaseFirestore.getInstance()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreate(savedInstanceState) return inflater.inflate(R.layout.fragment_vocabulary, container, false)
setContentView(R.layout.activity_main) }
navigationView.setNavigationItemSelectedListener { menuItem ->
menuItem.isChecked = true
drawerLayout!!.closeDrawers()
true
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
extractUserDocument() extractUserDocument()
printUserData() printUserData()
} }
override fun onDestroy() {
super.onDestroy()
FirebaseAuth.getInstance().signOut()
}
private fun extractUserDocument() { private fun extractUserDocument() {
val userId = FirebaseAuth.getInstance().currentUser!!.uid val userId = FirebaseAuth.getInstance().currentUser!!.uid
Log.d(TAG, "retrieved userId: $userId") Log.d(TAG, "retrieved userId: $userId")
...@@ -65,7 +56,12 @@ class UserActivity : AppCompatActivity() { ...@@ -65,7 +56,12 @@ class UserActivity : AppCompatActivity() {
} }
} }
override fun onDestroy() {
super.onDestroy()
FirebaseAuth.getInstance().signOut()
}
companion object { companion object {
private val TAG = "VN/" + UserActivity::class.simpleName private val TAG = "VN/" + VocabularyFragment::class.simpleName
} }
} }
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:openDrawer="start"> tools:openDrawer="start">
<include <fragment
layout="@layout/activity_vocabulary"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:name="com.paktalin.vocabularynotebook.activities.VocabularyFragment"
android:id="@+id/fragment_vocabulary" />
<android.support.design.widget.NavigationView <android.support.design.widget.NavigationView
android:id="@+id/navigationView" android:id="@+id/navigationView"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/transparent" android:background="@android:color/transparent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.paktalin.vocabularynotebook.activities.UserActivity"> tools:context="com.paktalin.vocabularynotebook.activities.VocabularyFragment">
<TextView <TextView
android:id="@+id/tvCongrats" android:id="@+id/tvCongrats"
...@@ -41,4 +41,15 @@ ...@@ -41,4 +41,15 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/tvUserData" /> app:layout_constraintTop_toBottomOf="@+id/tvUserData" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@android:drawable/ic_input_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
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