diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 0888ef6..5f10bc4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,15 +1,17 @@
apply plugin: 'com.android.application'
+apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
- minSdkVersion 15
+ minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ multiDexEnabled true
}
buildTypes {
release {
@@ -23,8 +25,16 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'com.google.firebase:firebase-auth:19.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
+ implementation 'com.google.firebase:firebase-analytics:17.2.0'
+ implementation 'com.google.firebase:firebase-firestore:21.2.1'
+ implementation 'com.firebaseui:firebase-ui-firestore:6.1.0'
implementation 'com.google.android.material:material:1.0.0'
+ implementation 'com.google.firebase:firebase-firestore:21.3.1'
+ implementation 'com.google.firebase:firebase-core:17.2.2'
+ implementation 'com.android.support:multidex:1.0.3'
+ implementation 'com.google.firebase:firebase-analytics:17.2.0'
}
diff --git a/app/google-services.json b/app/google-services.json
new file mode 100644
index 0000000..c056959
--- /dev/null
+++ b/app/google-services.json
@@ -0,0 +1,40 @@
+{
+ "project_info": {
+ "project_number": "641119009055",
+ "firebase_url": "https://hack20-dac97.firebaseio.com",
+ "project_id": "hack20-dac97",
+ "storage_bucket": "hack20-dac97.appspot.com"
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:641119009055:android:a4220326d9fe56d127182a",
+ "android_client_info": {
+ "package_name": "com.example.myapplication"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "641119009055-47kafmm3mn7k2ovq8s0faku1pf4cmr94.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyDlirD7P7DlOBMvzEPfB5kIVBQeX3kCRb4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "641119009055-47kafmm3mn7k2ovq8s0faku1pf4cmr94.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
\ No newline at end of file
diff --git a/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/FoodViz/ExampleInstrumentedTest.java
similarity index 95%
rename from app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java
rename to app/src/androidTest/java/com/example/FoodViz/ExampleInstrumentedTest.java
index af71346..445e480 100644
--- a/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java
+++ b/app/src/androidTest/java/com/example/FoodViz/ExampleInstrumentedTest.java
@@ -1,4 +1,4 @@
-package com.example.myapplication;
+package com.example.FoodViz;
import android.content.Context;
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 324197f..744fa6d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,7 +1,7 @@
+ package="com.example.FoodViz">
@@ -21,7 +21,11 @@
+
diff --git a/app/src/main/java/com/example/myapplication/Login.java b/app/src/main/java/com/example/FoodViz/Login.java
similarity index 53%
rename from app/src/main/java/com/example/myapplication/Login.java
rename to app/src/main/java/com/example/FoodViz/Login.java
index 4fcb00c..334e31f 100644
--- a/app/src/main/java/com/example/myapplication/Login.java
+++ b/app/src/main/java/com/example/FoodViz/Login.java
@@ -1,13 +1,15 @@
-package com.example.myapplication;
+package com.example.FoodViz;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.AppCompatButton;
+import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatTextView;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
-import android.text.Spannable;
+import android.text.Editable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
@@ -16,6 +18,8 @@
import android.widget.TextView;
import android.widget.Toast;
+import com.google.firebase.auth.FirebaseAuth;
+
public class Login extends AppCompatActivity {
@Override
@@ -28,12 +32,31 @@ protected void onCreate(Bundle savedInstanceState) {
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
TextView logo = findViewById(R.id.Logo);
- String logoText = "HackED 2020";
+ String logoText = "Food Viz";
SpannableString modifiedLogoText = new SpannableString(logoText);
ForegroundColorSpan fcsRed = new ForegroundColorSpan(Color.RED);
- modifiedLogoText.setSpan(fcsRed, 4, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ modifiedLogoText.setSpan(fcsRed, 5, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
logo.setText(modifiedLogoText);
+ final AppCompatEditText usernameInfo = findViewById(R.id.username);
+ final Editable usernameParsed = usernameInfo.getText();
+ final AppCompatEditText passwordInfo = findViewById(R.id.password);
+ final Editable pwParsed = passwordInfo.getText();
+
+ final AppCompatButton loginBtn = findViewById(R.id.login_btn);
+ loginBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (pwParsed.toString().length() == 0 || usernameParsed.toString().length() == 0) {
+ Toast.makeText(Login.this, "Error: Please add your information", Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(Login.this, "Successfully Logged In", Toast.LENGTH_SHORT).show();
+ Intent mainActivityIntent = new Intent(Login.this, MainActivity.class);
+ startActivity(mainActivityIntent);
+ finish();
+ }
+ }
+ });
final AppCompatTextView signUpLink = findViewById(R.id.signup_link);
signUpLink.setOnClickListener(new View.OnClickListener() {
@@ -44,6 +67,5 @@ public void onClick(View view) {
finish();
}
});
-
- }
-}
+ }
+ }
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/MainActivity.java b/app/src/main/java/com/example/FoodViz/MainActivity.java
similarity index 89%
rename from app/src/main/java/com/example/myapplication/MainActivity.java
rename to app/src/main/java/com/example/FoodViz/MainActivity.java
index ca37a8a..d3fe5eb 100644
--- a/app/src/main/java/com/example/myapplication/MainActivity.java
+++ b/app/src/main/java/com/example/FoodViz/MainActivity.java
@@ -1,4 +1,4 @@
-package com.example.myapplication;
+package com.example.FoodViz;
import androidx.appcompat.app.AppCompatActivity;
diff --git a/app/src/main/java/com/example/FoodViz/Register.java b/app/src/main/java/com/example/FoodViz/Register.java
new file mode 100644
index 0000000..468c6e4
--- /dev/null
+++ b/app/src/main/java/com/example/FoodViz/Register.java
@@ -0,0 +1,119 @@
+package com.example.FoodViz;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.AppCompatButton;
+import androidx.appcompat.widget.AppCompatEditText;
+import androidx.appcompat.widget.AppCompatTextView;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.Editable;
+import android.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.OnFailureListener;
+import com.google.android.gms.tasks.OnSuccessListener;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.AppCompatButton;
+import androidx.appcompat.widget.AppCompatEditText;
+import androidx.appcompat.widget.AppCompatTextView;
+
+import com.google.android.gms.tasks.Task;
+import com.google.firebase.auth.FirebaseAuth;
+import com.google.firebase.auth.FirebaseUser;
+import com.google.firebase.firestore.CollectionReference;
+import com.google.firebase.firestore.FirebaseFirestore;
+import com.google.firebase.firestore.Query;
+import com.google.firebase.firestore.QuerySnapshot;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Register extends AppCompatActivity {
+ private FirebaseAuth mAuth;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ mAuth = FirebaseAuth.getInstance();
+ final FirebaseFirestore db;
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_register);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
+ WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+ // instance of database
+ db = FirebaseFirestore.getInstance();
+
+ final CollectionReference collectionReference = db.collection("User");
+ final AppCompatEditText usernameInfo = findViewById(R.id.username);
+ final Editable usernameParsed = usernameInfo.getText();
+ final AppCompatEditText passwordInfo = findViewById(R.id.password);
+ final Editable pwParsed = passwordInfo.getText();
+ final EditText confirmPW = findViewById(R.id.password_veri);
+ final Editable pwVeriParsed = confirmPW.getText();
+
+ final AppCompatButton registerBtn = findViewById(R.id.signup_btn);
+ registerBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ User newUser = new User(usernameParsed.toString(), pwParsed.toString());
+ if (pwParsed.toString().isEmpty() || usernameParsed.toString().isEmpty() || pwVeriParsed.toString().isEmpty()) {
+ Toast.makeText(Register.this, "Error: Please add information", Toast.LENGTH_SHORT).show();
+ } else if (!(pwParsed.toString().equals(pwVeriParsed.toString()))) {
+ Toast.makeText(Register.this, "Passwords Do not Match", Toast.LENGTH_SHORT).show();
+ }
+
+ Query query = db.collection("users").whereEqualTo("username", newUser.getUsername());
+ query.get().addOnCompleteListener(new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (task.getResult() != null && task.getResult().size() > 0) {
+ Toast.makeText(Register.this, "Error: Username already exists", Toast.LENGTH_SHORT).show();
+ }
+ }
+ }));
+ else {
+ HashMap user = new HashMap<>();
+ user.put("username", newUser.getUsername());
+ user.put("password", newUser.getPassword());
+
+ final CollectionReference collectionReference = db.collection("User");
+ collectionReference.document(newUser.getUsername())
+ .set(user)
+ .addOnSuccessListener(new OnSuccessListener() {
+ @Override
+ public void onSuccess(Void aVoid) {
+ Log.d("thisActivity", "DocumentSnapshot successfully written!");
+ }
+ })
+ .addOnFailureListener(new OnFailureListener() {
+ @Override
+ public void onFailure(@NonNull Exception e) {
+ Log.w("Failed to add user", "Error writing document", e);
+ }
+ });
+ Toast.makeText(Register.this, "Successfully Signed Up", Toast.LENGTH_SHORT).show();
+ Intent mainActivityIntent = new Intent(Register.this, MainActivity.class);
+ startActivity(mainActivityIntent);
+ finish();
+ }
+ }
+ });
+
+ final AppCompatTextView signUpLink = findViewById(R.id.login_link);
+ signUpLink.setOnClickListener(new View.OnClickListener() {
+ public void onClick (View view){
+ Intent signUpScreen = new Intent(Register.this, Login.class);
+ startActivity(signUpScreen);
+ finish();
+ }
+ });
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/FoodViz/User.java b/app/src/main/java/com/example/FoodViz/User.java
new file mode 100644
index 0000000..934f2ae
--- /dev/null
+++ b/app/src/main/java/com/example/FoodViz/User.java
@@ -0,0 +1,27 @@
+package com.example.FoodViz;
+
+public class User {
+ private String username;
+ private String password;
+
+ public User(String username, String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ public String getUsername() {
+ return this.username;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/app/src/main/java/com/example/myapplication/Register.java b/app/src/main/java/com/example/myapplication/Register.java
deleted file mode 100644
index 74deea1..0000000
--- a/app/src/main/java/com/example/myapplication/Register.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.example.myapplication;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.AppCompatTextView;
-
-import android.content.Intent;
-import android.graphics.Color;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.style.ForegroundColorSpan;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.TextView;
-
-public class Register extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
- WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- }
-
- final AppCompatTextView signUpLink = findViewById(R.id.login_link);
- signUpLink.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent loginScreen = new Intent(Register.this, Login.class);
- startActivity(loginScreen);
- finish();
- }
- });
- }
-}
diff --git a/app/src/test/java/com/example/myapplication/ExampleUnitTest.java b/app/src/test/java/com/example/FoodViz/ExampleUnitTest.java
similarity index 90%
rename from app/src/test/java/com/example/myapplication/ExampleUnitTest.java
rename to app/src/test/java/com/example/FoodViz/ExampleUnitTest.java
index bf43ee5..baf04d3 100644
--- a/app/src/test/java/com/example/myapplication/ExampleUnitTest.java
+++ b/app/src/test/java/com/example/FoodViz/ExampleUnitTest.java
@@ -1,4 +1,4 @@
-package com.example.myapplication;
+package com.example.FoodViz;
import org.junit.Test;
diff --git a/build.gradle b/build.gradle
index f5fb2cc..d6e3744 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
-
+ classpath 'com.google.gms:google-services:4.3.2'
+
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
diff --git a/google-services.json b/google-services.json
new file mode 100644
index 0000000..6f4d07f
--- /dev/null
+++ b/google-services.json
@@ -0,0 +1,48 @@
+{
+ "project_info": {
+ "project_number": "641119009055",
+ "firebase_url": "https://hack20-dac97.firebaseio.com",
+ "project_id": "hack20-dac97",
+ "storage_bucket": "hack20-dac97.appspot.com"
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:641119009055:android:9cd3d2ff3ef93e6b27182a",
+ "android_client_info": {
+ "package_name": "com.example.myapplication"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "641119009055-8g20o5rkqvh4c8i8j0k8hubhvkms89d9.apps.googleusercontent.com",
+ "client_type": 1,
+ "android_info": {
+ "package_name": "com.example.myapplication",
+ "certificate_hash": "56e49f280a63ab8e10a27e1662414f6613d6167a"
+ }
+ },
+ {
+ "client_id": "641119009055-47kafmm3mn7k2ovq8s0faku1pf4cmr94.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyDlirD7P7DlOBMvzEPfB5kIVBQeX3kCRb4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "641119009055-47kafmm3mn7k2ovq8s0faku1pf4cmr94.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
\ No newline at end of file