diff --git a/app/app.iml b/app/app.iml
index 8bf2bcf..6df61cc 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -19,7 +19,7 @@
-
+
@@ -97,7 +97,6 @@
-
@@ -109,14 +108,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -146,5 +162,6 @@
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 7627860..f410b80 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -25,6 +25,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.5'
+ implementation 'com.google.firebase:firebase-firestore:17.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
diff --git a/app/src/main/java/in/hackslash/messsy/onboarding/AccountsUtil.java b/app/src/main/java/in/hackslash/messsy/onboarding/AccountsUtil.java
index 4e581ac..39487b3 100644
--- a/app/src/main/java/in/hackslash/messsy/onboarding/AccountsUtil.java
+++ b/app/src/main/java/in/hackslash/messsy/onboarding/AccountsUtil.java
@@ -1,39 +1,136 @@
package in.hackslash.messsy.onboarding;
-public class AccountsUtil {
+import android.util.Log;
+import android.util.Patterns;
- private onCompleteListener onCompleteListener;
+import androidx.annotation.NonNull;
- public AccountsUtil createAccount(User user, String password){
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.Task;
+import com.google.firebase.auth.AuthResult;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseAuthException;
+import com.google.firebase.auth.FirebaseUser;
+import com.google.firebase.firestore.DocumentSnapshot;
+import com.google.firebase.firestore.FirebaseFirestore;
- // TODO Check if a user is logged in and return ALREADY_LOGGED_IN if a logged in user is found
+import java.util.HashMap;
- // TODO Validate user here and return WRONG_INPUT if anything is wrong
+public class AccountsUtil {
- // TODO Check DB if the user exists and return DUPLICATE_USER if user exists
+ private onCompleteListener onCompleteListener;
+
+ public AccountsUtil createAccount(final User user, String password) {
+
+ String email = user.getEmail();
+ final FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
+ final FirebaseFirestore firestore = FirebaseFirestore.getInstance();
+ // Check if a user is logged in and return ALREADY_LOGGED_IN if a logged in user is found
+ if (currentUser != null) {
+ onCompleteListener.onComplete(Status.ALREADY_LOGGED_IN, user);
+ }
+ // Validate user here and return WRONG_INPUT if anything is wrong
+ else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches() || password.length() < 6
+ || user.getName().length()==0 || user.getRoomno().length()==0) {
+ onCompleteListener.onComplete(Status.WRONG_INPUT, user);
+ }
+ // Check DB if the user exists and return DUPLICATE_USER if user exists
+
+ // Create new account using createUserWithEmailAndPassword and return SUCCESS if successful
+ else {
+ FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
+ .addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (task.isSuccessful()) {
+ //user account created
+ String userid=currentUser.getUid();
+ String name=user.getName();
+ String rooomno=user.getRoomno();
+ String email=user.getEmail();
+ HashMap map=new HashMap<>();
+ map.put("name",name);
+ map.put("roomno",rooomno);
+ map.put("email",email);
+ firestore.collection("users").document(userid)
+ .set(map).addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ // user data written on DB
+ onCompleteListener.onComplete(Status.SUCCESS, user);
+ }
+ }
+ });
+ } else {
+ String error_code = ((FirebaseAuthException) task.getException()).getErrorCode();
+ if (error_code.equals("ERROR_EMAIL_ALREADY_IN_USE")) {
+ onCompleteListener.onComplete(Status.DUPLICATE_USER, user);
+ }
+ }
+ }
+ });
+ }
- // TODO Create new account using createUserWithEmailAndPassword and return SUCCESS if successful
// Leave as it is
return this;
}
- public AccountsUtil loginUser(User user, String password) {
-
- // TODO Check if a user is logged in and return ALREADY_LOGGED_IN if a logged in user is found
-
- // TODO Validate user here and return WRONG_INPUT if anything is wrong
-
- // TODO Check DB if the user exists and return USER_DOES_NOT_EXIST if user is not found
-
- // TODO Login using the credentials and return SUCCESS if successful
+ public AccountsUtil loginUser(final User user, final String password) {
+
+ final String email = user.getEmail();
+ FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
+ final FirebaseFirestore firestore = FirebaseFirestore.getInstance();
+ // Check if a user is logged in and return ALREADY_LOGGED_IN if a logged in user is found
+ if (currentUser != null) {
+ onCompleteListener.onComplete(Status.ALREADY_LOGGED_IN, user);
+ }
+ // Validate user here and return WRONG_INPUT if anything is wrong
+ else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches() || password.length() < 6) {
+ onCompleteListener.onComplete(Status.WRONG_INPUT, user);
+ }
+ // Check DB if the user exists and return USER_DOES_NOT_EXIST if user is not found
+
+ // Login using the credentials and return SUCCESS if successful
+
+ else{
+ FirebaseAuth.getInstance().signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ // user logged in
+ // checking user data in DB
+ String user_id=FirebaseAuth.getInstance().getCurrentUser().getUid();
+ firestore.collection("users").document(user_id).get().addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ DocumentSnapshot doc=task.getResult();
+ if(doc.exists()){
+ //user exist
+ onCompleteListener.onComplete(Status.SUCCESS,user);
+ }
+ else{
+ onCompleteListener.onComplete(Status.USER_DOES_NOT_EXIST,user);
+ }
+ }
+ }
+ });
+ }
+ else{
+ Log.d("AccountsUtil", "onComplete: "+"login failed");
+ }
+ }
+ });
+ }
// Leave as it is
return this;
}
- public AccountsUtil updateUser(User user, String password) {
+ public AccountsUtil updateUser(final User user, final String password) {
// TODO Check DB if the user exists and return USER_DOES_NOT_EXIST if user is not found
@@ -42,18 +139,95 @@ public AccountsUtil updateUser(User user, String password) {
// TODO Validate user here and return WRONG_INPUT if anything is wrong
// TODO Update the user data on DB as well as Auth if required and return SUCCESS
-
+ final FirebaseUser currentuser=FirebaseAuth.getInstance().getCurrentUser();
+ final String user_id=currentuser.getUid();
+ final FirebaseFirestore firestore=FirebaseFirestore.getInstance();
+ FirebaseFirestore.getInstance().collection("users").document(user_id).get()
+ .addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ DocumentSnapshot doc=task.getResult();
+ if(doc.exists()){
+ //user exist
+ String name_n=user.getName();
+ String roomno_n=user.getRoomno();
+ String email_n=user.getEmail();
+ String name_old=doc.getString("name");
+ String roomno_old=doc.getString("roomno");
+ String email_old=currentuser.getEmail();
+ if(roomno_n.length()==0 || name_n.length()==0){
+ onCompleteListener.onComplete(Status.WRONG_INPUT,user);
+ }
+ else if(roomno_n.equals(roomno_old) || name_n.equals(name_old)){
+ onCompleteListener.onComplete(Status.DUPLICATE_USER,user);
+ }
+ else{
+ HashMap map=new HashMap<>();
+ map.put("name",name_n);
+ map.put("roomno",roomno_n);
+ firestore.collection("users").document(user_id).update(map);
+ // if new email provided then updating it
+ if(!email_n.equals(email_old)){
+ currentuser.updateEmail(email_n).addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ Log.d("AccountsUtil", "email updated ");
+ }
+ }
+ });
+ }
+ if(password.length()>=6){
+ currentuser.updatePassword(password).addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ Log.d("AccountsUtil", "password updated");
+ }
+ });
+ }
+ onCompleteListener.onComplete(Status.SUCCESS,user);
+ }
+ }
+ else{
+ onCompleteListener.onComplete(Status.USER_DOES_NOT_EXIST,user);
+ }
+ }
+ }
+ });
// Leave as it is
return this;
}
- public AccountsUtil fetchUser(String userID) {
+ public AccountsUtil fetchUser(final String userID) {
// TODO Check DB if the user exists and return USER_DOES_NOT_EXIST if user is not found
// TODO Return the user in a User object if found with a SUCCESS Status
+ FirebaseFirestore.getInstance().collection("users").document(userID).get()
+ .addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if(task.isSuccessful()){
+ DocumentSnapshot doc=task.getResult();
+ if(doc.exists()){
+ //user exist
+ String name=doc.getString("name");
+ String roomno=doc.getString("roomno");
+ String email=doc.getString("email");
+ User user=new User(email,name,roomno,userID);
+ onCompleteListener.onComplete(Status.SUCCESS,user);
+ }
+ else{
+ User user=new User();
+ onCompleteListener.onComplete(Status.USER_DOES_NOT_EXIST,user);
+ }
+ }
+ }
+ });
+
// Leave as it is
return this;
}
diff --git a/app/src/main/java/in/hackslash/messsy/onboarding/CreateAccountActivity.java b/app/src/main/java/in/hackslash/messsy/onboarding/CreateAccountActivity.java
index a0c87f8..60db54a 100644
--- a/app/src/main/java/in/hackslash/messsy/onboarding/CreateAccountActivity.java
+++ b/app/src/main/java/in/hackslash/messsy/onboarding/CreateAccountActivity.java
@@ -2,13 +2,25 @@
import androidx.appcompat.app.AppCompatActivity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
import in.hackslash.messsy.R;
+import in.hackslash.messsy.home.HomeActivity;
public class CreateAccountActivity extends AppCompatActivity {
- // TODO Declare instances for all UI elements
-
+ // Declare instances for all UI elements
+ EditText name,email,roomno,password;
+ TextView login;
+ Button create_account;
+ ProgressBar progress;
+ AccountsUtil accountsUtil;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -20,7 +32,15 @@ protected void onCreate(Bundle savedInstanceState) {
public void assignVariables() {
- // TODO initialize all fields here
+ // initialize all fields here
+ name=findViewById(R.id.ca_name);
+ email=findViewById(R.id.ca_email);
+ roomno=findViewById(R.id.ca_roomno);
+ password=findViewById(R.id.ca_password);
+ login=findViewById(R.id.log_in);
+ create_account=findViewById(R.id.create_acc_button);
+ progress=findViewById(R.id.create_acc_progress);
+ accountsUtil=new AccountsUtil();
}
public void setup(){
@@ -29,18 +49,67 @@ public void setup(){
}
private void handleLogin() {
- // TODO define onclicklistener on Sign in button to navigate to LoginActivity and close this activity
-
+ // define onclicklistener on Sign in button to navigate to LoginActivity and close this activity
+ login.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // navigate to login activity
+ Intent intent=new Intent(CreateAccountActivity.this,LoginActivity.class);
+ startActivity(intent);
+ }
+ });
}
public void handleCreateAccount() {
- // TODO define onclicklistener on Save Details button to collect data from all edittexts and call ComplaintsUtil.createAccount
-
- // TODO Show an indefinite progress bar on the screen as soon as the submit button is clicked to denote that data is being processed
-
- // TODO Pass a callback by createAccount().setOnCompleteListener() to handle the result from the update operation. Show a toast according to the result and also hide the progress bar.
-
- // TODO NOTE: If the result is SUCCESS, then close this activity and navigate to HomeActivity
+ // define onclicklistener on Save Details button to collect data from all edittexts and call ComplaintsUtil.createAccount
+
+ // Show an indefinite progress bar on the screen as soon as the submit button is clicked to denote that data is being processed
+
+ // Pass a callback by createAccount().setOnCompleteListener() to handle the result from the update operation. Show a toast according to the result and also hide the progress bar.
+
+ // NOTE: If the result is SUCCESS, then close this activity and navigate to HomeActivity
+ create_account.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ progress.setVisibility(View.VISIBLE);
+ String username=name.getText().toString();
+ String email_id=email.getText().toString();
+ String room_no=roomno.getText().toString();
+ String password_=password.getText().toString();
+ User user=new User();
+ user.setEmail(email_id);
+ user.setName(username);
+ user.setRoomno(room_no);
+ accountsUtil.createAccount(user,password_).setOnCompleteListener(new AccountsUtil.onCompleteListener() {
+ @Override
+ public void onComplete(AccountsUtil.Status status, User user) {
+ if(status== AccountsUtil.Status.ALREADY_LOGGED_IN){
+ progress.setVisibility(View.INVISIBLE);
+ Toast.makeText(CreateAccountActivity.this, "Already Logged in", Toast.LENGTH_SHORT).show();
+ Intent intent = new Intent(CreateAccountActivity.this, HomeActivity.class);
+ startActivity(intent);
+ finish();
+ }
+ else if(status== AccountsUtil.Status.WRONG_INPUT){
+ //wrong input
+ progress.setVisibility(View.INVISIBLE);
+ Toast.makeText(CreateAccountActivity.this, "wrong input", Toast.LENGTH_SHORT).show();
+ }
+ else if(status== AccountsUtil.Status.DUPLICATE_USER){
+ progress.setVisibility(View.INVISIBLE);
+ Toast.makeText(CreateAccountActivity.this, "User already exist", Toast.LENGTH_SHORT).show();
+ }
+ else if(status== AccountsUtil.Status.SUCCESS){
+ progress.setVisibility(View.INVISIBLE);
+ Toast.makeText(CreateAccountActivity.this, "account created successful", Toast.LENGTH_SHORT).show();
+ Intent intent = new Intent(CreateAccountActivity.this, HomeActivity.class);
+ startActivity(intent);
+ finish();
+ }
+ }
+ });
+ }
+ });
}
}
diff --git a/app/src/main/java/in/hackslash/messsy/onboarding/User.java b/app/src/main/java/in/hackslash/messsy/onboarding/User.java
index b70fd74..13a9bf5 100644
--- a/app/src/main/java/in/hackslash/messsy/onboarding/User.java
+++ b/app/src/main/java/in/hackslash/messsy/onboarding/User.java
@@ -3,17 +3,26 @@
public class User {
// TODO add user fields here
- private String email,name,roomno;
+ private String email,name,roomno,uid;
public User(){
}
- public User(String email, String name, String roomno) {
+
+ public User(String email, String name, String roomno,String uid) {
this.email = email;
this.name = name;
this.roomno = roomno;
+ this.uid=uid;
+ }
+
+ public String getUid() {
+ return uid;
}
+ public void setUid(String uid) {
+ this.uid = uid;
+
public String getEmail() {
return email;
}
diff --git a/app/src/main/res/layout/activity_create_account.xml b/app/src/main/res/layout/activity_create_account.xml
index d27839e..a07ddd8 100644
--- a/app/src/main/res/layout/activity_create_account.xml
+++ b/app/src/main/res/layout/activity_create_account.xml
@@ -6,17 +6,24 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".onboarding.LoginActivity"
+ tools:context=".onboarding.CreateAccountActivity"
app:layout_constraintStart_toStartOf="parent">
+
@@ -44,14 +52,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/breakfast_image"
- android:layout_alignStart="@id/line_1"
+ android:layout_alignStart="@id/ca_name"
android:layout_marginStart="3dp"
+ android:fontFamily="@font/josefin_sans_bold"
android:layout_marginTop="28dp"
android:text="@string/name"
android:textAppearance="@style/name" />
+ android:text="@string/email"
+ android:textAppearance="@style/email" />
-
-
-
+ android:orientation="horizontal"
+ android:layout_below="@id/create_acc_button"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="7dp">
+
+
+
+
diff --git a/app/src/main/res/layout/activity_edit_profile.xml b/app/src/main/res/layout/activity_edit_profile.xml
index 07ac519..a2a290b 100644
--- a/app/src/main/res/layout/activity_edit_profile.xml
+++ b/app/src/main/res/layout/activity_edit_profile.xml
@@ -11,7 +11,7 @@
@@ -23,6 +23,7 @@
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
+ android:fontFamily="@font/josefin_sans_bold"
android:layout_alignStart="@id/line_1"
android:text="@string/edit_your_details"
android:textAppearance="@style/edit_your_details"
@@ -40,6 +41,7 @@
+ android:text="@string/email"
+ android:textAppearance="@style/email" />
@@ -135,8 +140,10 @@
android:layout_height="55dp"
android:layout_below="@id/line_4"
android:layout_centerHorizontal="true"
+ android:fontFamily="@font/josefin_sans_bold"
android:layout_marginTop="32dp"
android:layout_marginBottom="40dp"
+ android:textAllCaps="false"
android:background="@drawable/rectangle_1"
android:elevation="10dp"
android:text="@string/save_details"
diff --git a/app/src/main/res/layout/activity_notice.xml b/app/src/main/res/layout/activity_notice.xml
index 65fb8fa..e3addb6 100644
--- a/app/src/main/res/layout/activity_notice.xml
+++ b/app/src/main/res/layout/activity_notice.xml
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".user.NoticeActivity">
+ tools:context=".complaint.NoticeActivity">
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e028e65..7e161f5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -34,4 +34,13 @@
Meals that you\'ll missOKCancel
+
+ Name
+ Room no
+ Password
+ already have an account?
+ Log in
+
+ Edit your details
+ Save Details
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 2c48dab..3f3b5c9 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -14,12 +14,17 @@
+
+
@@ -29,277 +34,142 @@
-
- 12sp
-
-
-
- #39374D
-
-
+
-
-
- 22sp
-
+
-
- #000000
-
+
+
-
- 16sp
-
-
-
- #3E3C54
-
-
+