Skip to content
Snippets Groups Projects
Commit 174b7f54 authored by darshanxyz's avatar darshanxyz
Browse files

Added Roll Number Activity

parent 39811aaf
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.android.gms:play-services-auth:10.2.1'
testCompile 'junit:junit:4.12'
}
......
......@@ -15,7 +15,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
<activity android:name=".MainActivity" />
<activity android:name=".RollNumber"></activity>
</application>
</manifest>
\ No newline at end of file
package com.darshanbshah.odsystem;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
......@@ -26,14 +28,22 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private ProgressDialog dialog;
private static int RC_SIGN_IN = 0;
private static String TAG = "MAIN_ACTIVITY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
startActivity(new Intent(getApplicationContext(), RollNumber.class));
finish();
}
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
......@@ -50,9 +60,13 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, options).build();
findViewById(R.id.sign_in_button).setOnClickListener(this);
dialog = new ProgressDialog(this);
}
public void login() {
dialog.setMessage("Logging in. Please wait.");
dialog.show();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
......@@ -93,7 +107,7 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("AUTH", "signInWithCredential: onComplete: " + task.isSuccessful());
startActivity(new Intent(getApplicationContext(), MainActivity.class));
startActivity(new Intent(getApplicationContext(), RollNumber.class));
}
});
}
......
......@@ -4,17 +4,21 @@ import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private TextView welcomeText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
welcomeText = (TextView)findViewById(R.id.welcomeText);
welcomeText.setText("Welcome " + mAuth.getCurrentUser().getEmail());
}
public void signOut(View view) {
......
package com.darshanbshah.odsystem;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.MainThread;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
public class RollNumber extends AppCompatActivity {
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private EditText rollNumber;
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference root = database.getReference();
DatabaseReference user = root.child(mAuth.getCurrentUser().getUid());
DatabaseReference roll_no = user.child("RollNumber");
DatabaseReference email = user.child("Email");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_roll_number);
rollNumber = (EditText)findViewById(R.id.rollNumberEditText);
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
if(pref.getBoolean("activity_executed", false)){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
else {
SharedPreferences.Editor ed = pref.edit();
ed.putBoolean("activity_executed", true);
ed.commit();
}
}
public void nextAct(View view) {
if (TextUtils.isEmpty(rollNumber.getText().toString())) {
Toast.makeText(this, "Enter Roll Number", Toast.LENGTH_SHORT).show();
}
else {
roll_no.setValue(rollNumber.getText().toString());
email.setValue(mAuth.getCurrentUser().getEmail());
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
public void signOut(View view) {
mAuth.signOut();
startActivity(new Intent(this, Login.class));
finish();
}
}
......@@ -12,7 +12,17 @@
android:layout_height="wrap_content"
android:id="@+id/sign_out_button"
android:onClick="signOut"
style="@android:style/Widget.Material.Button.ButtonBar.AlertDialog"
style="@style/Widget.AppCompat.Button.Borderless"
android:textColor="@color/colorAccent"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sign_out_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="66dp"
android:id="@+id/welcomeText"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_roll_number"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.darshanbshah.odsystem.RollNumber">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:id="@+id/rollNumberEditText"
android:hint="Amrita Roll Number"
android:textAlignment="center" />
<Button
android:text="Sign Out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:onClick="signOut" />
<Button
android:text="Continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:id="@+id/continueButton"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_below="@+id/rollNumberEditText"
android:layout_centerHorizontal="true"
android:onClick="nextAct" />
</RelativeLayout>
......@@ -2,5 +2,5 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorAccent">#ff4081</color>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment