Skip to content

Commit dbbed6a

Browse files
authored
Merge pull request #15 from MosheSheena/develop
This is the ALPHA
2 parents 3257159 + ce013d8 commit dbbed6a

74 files changed

Lines changed: 3898 additions & 28 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

add-24px.svg

Lines changed: 1 addition & 0 deletions
Loading

app/build.gradle

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ android {
55
buildToolsVersion "29.0.2"
66
defaultConfig {
77
applicationId "com.example.phasetwo"
8-
minSdkVersion 21
9-
targetSdkVersion 29
8+
minSdkVersion 26
9+
targetSdkVersion 26
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -23,7 +23,20 @@ dependencies {
2323
implementation fileTree(dir: 'libs', include: ['*.jar'])
2424
implementation 'androidx.appcompat:appcompat:1.1.0'
2525
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
26+
implementation 'com.google.android.material:material:1.0.0'
27+
implementation 'androidx.annotation:annotation:1.1.0'
28+
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
29+
30+
implementation 'com.google.firebase:firebase-analytics:17.2.0'
31+
implementation 'com.google.firebase:firebase-firestore:21.2.0'
32+
implementation 'com.google.firebase:firebase-auth:19.1.0'
33+
2634
testImplementation 'junit:junit:4.12'
2735
androidTestImplementation 'androidx.test:runner:1.2.0'
2836
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
37+
implementation 'androidx.recyclerview:recyclerview:1.0.0'
2938
}
39+
40+
// Add the following line to the bottom of the file:
41+
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
42+

app/google-services.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"project_info": {
3+
"project_number": "258754643169",
4+
"firebase_url": "https://phasetwo.firebaseio.com",
5+
"project_id": "phasetwo",
6+
"storage_bucket": "phasetwo.appspot.com"
7+
},
8+
"client": [
9+
{
10+
"client_info": {
11+
"mobilesdk_app_id": "1:258754643169:android:67e4a8e6efa4e85b1a23a0",
12+
"android_client_info": {
13+
"package_name": "com.example.phasetwo"
14+
}
15+
},
16+
"oauth_client": [
17+
{
18+
"client_id": "258754643169-87husf6794p80gqru03vrhavf03h4kat.apps.googleusercontent.com",
19+
"client_type": 3
20+
}
21+
],
22+
"api_key": [
23+
{
24+
"current_key": "AIzaSyDoFhK2MlD1q-FtQhh2qLfvlnGGHnVBDAU"
25+
}
26+
],
27+
"services": {
28+
"appinvite_service": {
29+
"other_platform_oauth_client": [
30+
{
31+
"client_id": "258754643169-87husf6794p80gqru03vrhavf03h4kat.apps.googleusercontent.com",
32+
"client_type": 3
33+
}
34+
]
35+
}
36+
}
37+
}
38+
],
39+
"configuration_version": "1"
40+
}

app/proguard-rules.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22+
23+
-keepattributes Signature
24+
25+
-keepclassmembers class com.yourcompany.models.** {
26+
*;
27+
}

app/src/main/AndroidManifest.xml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,48 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.example.phasetwo">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@mipmap/ic_launcher"
810
android:label="@string/app_name"
911
android:roundIcon="@mipmap/ic_launcher_round"
1012
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
13+
android:theme="@style/Theme.AppCompat.Light">
14+
<activity
15+
android:name=".activities.ui.consumer.ConsumerBookingActivity"
16+
android:parentActivityName=".activities.ui.consumer.ConsumerMenuActivity">
17+
<meta-data
18+
android:name="android.support.PARENT_ACTIVITY"
19+
android:value=".activities.ui.consumer.ConsumerMenuActivity" />
20+
</activity>
21+
<activity
22+
android:name=".activities.ui.producer.ProducerMakeTimeActivity"
23+
android:parentActivityName=".activities.ui.producer.ProducerMenuActivity" />
24+
25+
<meta-data
26+
android:name="android.support.PARENT_ACTIVITY"
27+
android:value=".activities.ui.producer.ProducerMenuActivity" />
28+
29+
<activity
30+
android:name=".activities.ui.login.LoginActivity"
31+
android:label="@string/title_activity_login">
1332
<intent-filter>
1433
<action android:name="android.intent.action.MAIN" />
1534

1635
<category android:name="android.intent.category.LAUNCHER" />
1736
</intent-filter>
1837
</activity>
38+
<activity android:name=".activities.ui.consumer.ConsumerMenuActivity" />
39+
<activity android:name=".activities.ui.producer.ProducerMenuActivity" />
40+
<activity
41+
android:name=".activities.CreateAccountActivity"
42+
android:parentActivityName=".activities.MainActivity">
43+
<meta-data
44+
android:name="android.support.PARENT_ACTIVITY"
45+
android:value=".activities.MainActivity" />
46+
</activity>
47+
<activity android:name=".activities.MainActivity" />
1948
</application>
20-
2149
</manifest>

app/src/main/java/com/example/phasetwo/MainActivity.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.example.phasetwo.activities;
2+
3+
import android.content.Context;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.Button;
7+
import android.widget.EditText;
8+
import android.widget.RadioButton;
9+
import android.widget.Toast;
10+
11+
import androidx.appcompat.app.AppCompatActivity;
12+
13+
import com.example.phasetwo.R;
14+
import com.example.phasetwo.common.UserType;
15+
import com.example.phasetwo.logic.UserEntity;
16+
17+
public class CreateAccountActivity extends AppCompatActivity {
18+
19+
private EditText nameInput;
20+
private EditText emailInput;
21+
private EditText passwordInput;
22+
private EditText passwordVerifyInput;
23+
private RadioButton typeConsumerRadioButton;
24+
private RadioButton typeProducerRadioButton;
25+
private Button createAccountButton;
26+
27+
@Override
28+
protected void onCreate(Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_create_account);
31+
32+
nameInput = (EditText) findViewById(R.id.create_account_name_input);
33+
emailInput = (EditText) findViewById(R.id.create_account_email_input);
34+
passwordInput = (EditText) findViewById(R.id.create_account_password_input);
35+
passwordVerifyInput = (EditText) findViewById(R.id.create_account_password_verify_input);
36+
typeConsumerRadioButton = (RadioButton) findViewById(R.id.create_account_consumer_type_radio_button);
37+
typeProducerRadioButton = (RadioButton) findViewById(R.id.create_account_producer_type_radio_button);
38+
createAccountButton = (Button) findViewById(R.id.create_account_create_button);
39+
40+
createAccountButton.setOnClickListener(new View.OnClickListener() {
41+
@Override
42+
public void onClick(View view) {
43+
boolean inputIsValid = verifyInput();
44+
if(!inputIsValid) {
45+
return;
46+
}
47+
48+
//TODO: check if a user with this email exists and handle accordingly
49+
50+
UserType checkedUserType = typeConsumerRadioButton.isChecked() ? UserType.CONSUMER
51+
: UserType.PRODUCER;
52+
53+
UserEntity user = new UserEntity(
54+
nameInput.getText().toString(),
55+
emailInput.getText().toString(),
56+
passwordInput.getText().toString(),
57+
checkedUserType
58+
);
59+
60+
//TODO: create a new user
61+
}
62+
});
63+
}
64+
65+
private boolean verifyInput() {
66+
67+
Context context = getApplicationContext();
68+
CharSequence text;
69+
StringBuilder message = new StringBuilder("please fill in");
70+
int duration = Toast.LENGTH_SHORT;
71+
Toast toast;
72+
73+
if(nameInput.getText().toString().isEmpty()) {
74+
message.append(" name");
75+
toast = Toast.makeText(context, message.toString(), duration);
76+
toast.show();
77+
return false;
78+
}
79+
if(emailInput.getText().toString().isEmpty()) {
80+
message.append(" email");
81+
toast = Toast.makeText(context, message.toString(), duration);
82+
toast.show();
83+
return false;
84+
}
85+
if(passwordInput.getText().toString().isEmpty()) {
86+
message.append(" password");
87+
toast = Toast.makeText(context, message.toString(), duration);
88+
toast.show();
89+
return false;
90+
}
91+
if(passwordVerifyInput.getText().toString().isEmpty()) {
92+
message.append(" password verification");
93+
toast = Toast.makeText(context, message.toString(), duration);
94+
toast.show();
95+
return false;
96+
}
97+
if(!passwordInput.getText().toString().equals(
98+
passwordVerifyInput.getText().toString())) {
99+
CharSequence passwordMismatchMessage = "passwords do not match!";
100+
toast = Toast.makeText(context, passwordMismatchMessage, duration);
101+
toast.show();
102+
return false;
103+
}
104+
if(!typeConsumerRadioButton.isChecked() && !typeProducerRadioButton.isChecked()) {
105+
message.append(" type");
106+
toast = Toast.makeText(context, message.toString(), duration);
107+
toast.show();
108+
return false;
109+
}
110+
return true;
111+
}
112+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.example.phasetwo.activities;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.EditText;
10+
11+
import com.example.phasetwo.R;
12+
import com.example.phasetwo.activities.ui.consumer.ConsumerMenuActivity;
13+
import com.example.phasetwo.activities.ui.producer.ProducerMenuActivity;
14+
import com.example.phasetwo.common.UserType;
15+
16+
public class MainActivity extends AppCompatActivity {
17+
18+
public static final String EXTRA_USERNAME = "com.example.phasetwo.activities.MainActivity.EXTRA_USERNAME";
19+
20+
EditText usernameInput;
21+
EditText userPasswordInput;
22+
Button submitCredentialsButton;
23+
Button createNewAccountButton;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_main);
29+
30+
usernameInput = (EditText) findViewById(R.id.userNameInput);
31+
userPasswordInput = (EditText) findViewById(R.id.userPasswordInput);
32+
submitCredentialsButton = (Button) findViewById(R.id.submitUserCredentialsButton);
33+
createNewAccountButton = (Button) findViewById(R.id.createAccountButton);
34+
35+
submitCredentialsButton.setOnClickListener(new View.OnClickListener() {
36+
@Override
37+
public void onClick(View view) {
38+
login(view);
39+
}
40+
});
41+
42+
createNewAccountButton.setOnClickListener(new View.OnClickListener() {
43+
@Override
44+
public void onClick(View view) {
45+
createAccount(view);
46+
}
47+
});
48+
}
49+
50+
private void createAccount(View view) {
51+
Intent intent = new Intent(this, CreateAccountActivity.class);
52+
startActivity(intent);
53+
}
54+
55+
private void login(View view) {
56+
String username = usernameInput.getText().toString();
57+
String password = userPasswordInput.getText().toString();
58+
59+
//TODO: check if the user exists
60+
//TODO: validate password
61+
//TODO: if the user exists log him in according to his type
62+
//TODO: if the user does not exist notify him
63+
64+
65+
//TODO: check which type is the user (PRODUCER / CONSUMER)
66+
UserType userType = UserType.PRODUCER;
67+
Class<?> activityToMoveTo = userType.equals(UserType.PRODUCER) ?
68+
ProducerMenuActivity.class : ConsumerMenuActivity.class;
69+
Intent intent = new Intent(this, activityToMoveTo);
70+
intent.putExtra(EXTRA_USERNAME, username);
71+
startActivity(intent);
72+
}
73+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.example.phasetwo.activities.data;
2+
3+
/**
4+
* A generic class that holds a result success w/ data or an error exception.
5+
*/
6+
public class Result<T> {
7+
// hide the private constructor to limit subclass types (Success, Error)
8+
private Result() {
9+
}
10+
11+
@Override
12+
public String toString() {
13+
if (this instanceof Result.Success) {
14+
Result.Success success = (Result.Success) this;
15+
return "Success[data=" + success.getData().toString() + "]";
16+
} else if (this instanceof Result.Error) {
17+
Result.Error error = (Result.Error) this;
18+
return "Error[exception=" + error.getError().toString() + "]";
19+
}
20+
return "";
21+
}
22+
23+
// Success sub-class
24+
public final static class Success<T> extends Result {
25+
private T data;
26+
27+
public Success(T data) {
28+
this.data = data;
29+
}
30+
31+
public T getData() {
32+
return this.data;
33+
}
34+
}
35+
36+
// Error sub-class
37+
public final static class Error extends Result {
38+
private Exception error;
39+
40+
public Error(Exception error) {
41+
this.error = error;
42+
}
43+
44+
public Exception getError() {
45+
return this.error;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)