Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

12 changes: 11 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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'
}
40 changes: 40 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.myapplication;
package com.example.FoodViz;

import android.content.Context;

Expand Down
10 changes: 7 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myapplication">
package="com.example.FoodViz">

<application
android:allowBackup="true"
Expand All @@ -12,7 +12,7 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".Login"
android:name="com.example.FoodViz.Login"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -21,7 +21,11 @@
</intent-filter>
</activity>
<activity
android:name=".Register"
android:name="com.example.FoodViz.Register"
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboard" />
<activity
android:name="com.example.FoodViz.MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboard" />

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +18,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;

public class Login extends AppCompatActivity {

@Override
Expand All @@ -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() {
Expand All @@ -44,6 +67,5 @@ public void onClick(View view) {
finish();
}
});

}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.myapplication;
package com.example.FoodViz;

import androidx.appcompat.app.AppCompatActivity;

Expand Down
119 changes: 119 additions & 0 deletions app/src/main/java/com/example/FoodViz/Register.java
Original file line number Diff line number Diff line change
@@ -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<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.getResult() != null && task.getResult().size() > 0) {
Toast.makeText(Register.this, "Error: Username already exists", Toast.LENGTH_SHORT).show();
}
}
}));
else {
HashMap<String, Object> 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<Void>() {
@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();
}
});

}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/example/FoodViz/User.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
38 changes: 0 additions & 38 deletions app/src/main/java/com/example/myapplication/Register.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.myapplication;
package com.example.FoodViz;

import org.junit.Test;

Expand Down
Loading