Skip to content
Snippets Groups Projects
Commit 943433b4 authored by darshanxyz's avatar darshanxyz
Browse files

Modified Roll Number Activity

parent 174b7f54
Branches
No related tags found
No related merge requests found
......@@ -64,19 +64,6 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
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);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d(TAG, "Connection failed");
}
@Override
public void onClick(View v) {
switch (v.getId()) {
......@@ -86,6 +73,21 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
}
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
......@@ -108,21 +110,20 @@ public class Login extends AppCompatActivity implements GoogleApiClient.OnConnec
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("AUTH", "signInWithCredential: onComplete: " + task.isSuccessful());
startActivity(new Intent(getApplicationContext(), RollNumber.class));
dialog.hide();
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d(TAG, "Connection failed");
}
@Override
protected void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
public void login() {
dialog.setMessage("Logging in. Please wait.");
dialog.show();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
}
\ No newline at end of file
......@@ -9,7 +9,11 @@ import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
......@@ -17,10 +21,11 @@ import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
public class RollNumber extends AppCompatActivity {
public class RollNumber extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
private EditText rollNumber;
private Spinner advisors;
FirebaseDatabase database = FirebaseDatabase.getInstance();
......@@ -34,19 +39,38 @@ public class RollNumber extends AppCompatActivity {
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)){
advisors = (Spinner)findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.advisors, android.R.layout.simple_spinner_dropdown_item);
advisors.setAdapter(adapter);
advisors.setOnItemSelectedListener(this);
SharedPreferences preferences = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
if(preferences.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();
SharedPreferences.Editor edit = preferences.edit();
edit.putBoolean("activity_executed", true);
edit.commit();
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView textView = (TextView)view;
Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void nextAct(View view) {
if (TextUtils.isEmpty(rollNumber.getText().toString())) {
Toast.makeText(this, "Enter Roll Number", Toast.LENGTH_SHORT).show();
......
......@@ -10,18 +10,6 @@
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"
......@@ -32,14 +20,34 @@
android:layout_alignParentEnd="true"
android:onClick="signOut" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="51dp"
android:id="@+id/rollNumberEditText"
android:hint="Amrita Roll Number"
android:textAlignment="center"
android:layout_below="@+id/button3"
android:layout_alignParentStart="true" />
<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:onClick="nextAct"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="67dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rollNumberEditText"
android:layout_centerHorizontal="true"
android:onClick="nextAct" />
android:layout_marginTop="81dp"
android:id="@+id/spinner" />
</RelativeLayout>
<resources>
<string name="app_name">OD System</string>
<string-array name="advisors">
<item>One</item>
<item>Two</item>
<item>Three</item>
<item>Four</item>
<item>Five</item>
</string-array>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment