Skip to content

Commit

Permalink
Adding the dashboard activity and implementing multiple functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
1HazArd1 committed Feb 28, 2022
1 parent 2236a85 commit 7dd1220
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 16 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Samarpan">
<!--android:theme="@style/splashScreenTheme"--> <!-- this is the logic for the splash screen place it inside the activity tag-->

<activity
android:name=".Main2Activity"
android:exported="false" />
<!-- android:theme="@style/splashScreenTheme" -->
<!-- this is the logic for the splash screen place it inside the activity tag -->
<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -21,6 +24,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/java/com/hazard/samarpan/LoginFragment.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hazard.samarpan

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -25,7 +25,7 @@ class LoginFragment: Fragment() {

private lateinit var ngoSignUp: TextView

private lateinit var registerAuth: FirebaseAuth
private lateinit var loginAuth: FirebaseAuth

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
itemView =layoutInflater.inflate(R.layout.login_fragment,container,false)
Expand All @@ -37,7 +37,7 @@ class LoginFragment: Fragment() {

ngoSignUp = itemView!!.findViewById(R.id.tv_login_registerasngo)

registerAuth= Firebase.auth
loginAuth= Firebase.auth

ngoSignUp.setOnClickListener{
activity?.supportFragmentManager?.beginTransaction()?.replace(R.id.fragment_container1, NgoSignup1Fragment())?.addToBackStack(null)?.commit()
Expand All @@ -60,7 +60,7 @@ class LoginFragment: Fragment() {
}
else{
try {
registerAuth.signInWithEmailAndPassword(mail, pass)
loginAuth.signInWithEmailAndPassword(mail, pass)
.addOnCompleteListener { task ->

if (task.isSuccessful) {
Expand All @@ -72,6 +72,12 @@ class LoginFragment: Fragment() {
"Logged in Successfully",
Toast.LENGTH_SHORT
).show()
activity?.let{
val intent = Intent (it, Main2Activity::class.java)
it.startActivity(intent)
}
activity?.finish()

} else {
Toast.makeText(
activity,
Expand All @@ -89,5 +95,18 @@ class LoginFragment: Fragment() {

return itemView
}

override fun onStart() {
super.onStart()
// check if the user is signed in then don't open login or register page directly send to the required activity
val currentUser = loginAuth.currentUser
if (currentUser != null) {
// write logic to send to the main dashboard of the application
activity?.let{
val intent =Intent(it,Main2Activity::class.java)
startActivity(intent)
}
}
}

}
27 changes: 27 additions & 0 deletions app/src/main/java/com/hazard/samarpan/Main2Activity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hazard.samarpan

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase

class Main2Activity : AppCompatActivity() {
private var btnLogout: Button? =null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)

//this is just for testing the logout functionality remove this while adding the dashboard fragment
btnLogout=findViewById(R.id.btnLogout)

btnLogout?.setOnClickListener{
Firebase.auth.signOut()
val intent=Intent(this,MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
18 changes: 9 additions & 9 deletions app/src/main/java/com/hazard/samarpan/UserRegisterFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hazard.samarpan

import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
Expand Down Expand Up @@ -52,6 +54,7 @@ class UserRegisterFragment : Fragment() {
etAddress = itemView?.findViewById(R.id.registerAddress)
etPinCode = itemView?.findViewById(R.id.registerPinCode)


registerAuth = Firebase.auth


Expand Down Expand Up @@ -133,6 +136,12 @@ class UserRegisterFragment : Fragment() {
if the user presses back after registration they don't go back to the registration page
it basically clears all the previous activities
*/
activity?.let{
val intent = Intent (it, Main2Activity::class.java)
it.startActivity(intent)
}
activity?.finish() /* as the fragment does not have finish function this function finds the
activity to which the fragment is attached and finishes it */
}
// if the registration failed somehow
else {
Expand All @@ -154,15 +163,6 @@ class UserRegisterFragment : Fragment() {
}


override fun onStart() {
super.onStart()
// check if the user is signed in then don't open login or register page directly send to the required activity
val currentUser = registerAuth.currentUser
if (currentUser != null) {
// write logic to send to the main dashboard of the application
}
}

private fun isValidPassword(password: String): Boolean {
val passwordREGEX = Pattern.compile(
"^" +
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_main2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity"
android:orientation="vertical">

<Button
android:id="@+id/btnLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textAllCaps="false"/>

</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.google.gms:google-services:4.3.10'

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 7dd1220

Please sign in to comment.