Merge branch 'lBranch'

# Conflicts:
#	OlympusServices/.idea/caches/build_file_checksums.ser
#	OlympusServices/.idea/vcs.xml
#	OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java
#	OlympusServices/app/src/main/res/layout/activity_main.xml
#	OlympusServices/app/src/main/res/layout/activity_sign_up.xml
#	OlympusServices/build.gradle
This commit is contained in:
IvanaE 2018-10-19 19:02:28 -04:00
commit d740cf72d3
15 changed files with 142 additions and 27 deletions

View file

@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -39,4 +39,4 @@ dependencies {
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}

View file

@ -14,7 +14,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".Main"
android:label="@string/app_name">
@ -29,13 +28,15 @@
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<activity android:name=".SignUp" android:parentActivityName=".Main">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main" />
<activity
android:name=".SignUp"
android:parentActivityName=".Main">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main" />
</activity>
<activity android:name=".LogIn" />
<activity android:name=".Welcome"/>
<activity android:name=".Welcome" />
</application>
</manifest>

View file

@ -5,4 +5,6 @@ public class Admin extends UserType {
Admin(){
super("admin", "admin", "Admin", "Admin");
}
public String getRole(){ return "Admin"; }
}

View file

@ -2,6 +2,10 @@ package com.uottawa.olympus.olympusservices;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;
public class LogIn extends AppCompatActivity {
@ -10,4 +14,32 @@ public class LogIn extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
}
public void onClickLogIn(View view){
String username = ((EditText) findViewById(R.id.UsernameInput)).getText().toString();
String password = ((EditText) findViewById(R.id.PasswordInput)).getText().toString();
DBHelper dbHelper = new DBHelper(this);
Intent intent = new Intent(getApplicationContext(),Welcome.class);
if(dbHelper.findUserByUsername(username)!=null) {
if (dbHelper.findUserByUsername(username).getUsername().equals(username) &&
dbHelper.findUserByUsername(username).getPassword().equals(password)) {
intent.putExtra("username", username);
startActivity(intent);
} else {
Toast.makeText(this, "Wrong Password", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "Account does not exist", Toast.LENGTH_LONG).show();
}
}
}

View file

@ -11,7 +11,22 @@ public class Main extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UserType admin = new Admin();
DBHelper dbHelper = new DBHelper(this);
dbHelper.addUser(admin);
}
}
public void onClickSignUp(View view){
Intent intent = new Intent(getApplicationContext(),SignUp.class);
startActivityForResult(intent,0);
}
public void onClickLogIn(View view){
Intent intent = new Intent(getApplicationContext(),LogIn.class);
startActivityForResult(intent,0);
}
}

View file

@ -6,4 +6,7 @@ public class ServiceProvider extends UserType {
super(username, password, firstname, lastname);
}
public String getRole(){ return "ServiceProvider"; }
}

View file

@ -4,6 +4,10 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.jaredrummler.materialspinner.MaterialSpinner;
import android.support.design.widget.Snackbar;
import android.content.Intent;
import android.widget.EditText;
import android.view.View;
import android.widget.Toast;
public class SignUp extends AppCompatActivity {
@Override
@ -19,7 +23,38 @@ public class SignUp extends AppCompatActivity {
}
});
}
public static void main(String[] args){
public void onClickSignUp(View view){
UserType newUser;
String username = ((EditText) findViewById(R.id.UsernameInput)).getText().toString();
String password = ((EditText) findViewById(R.id.PasswordInput)).getText().toString();
String firstname = ((EditText) findViewById(R.id.FirstNameInput)).getText().toString();
String lastname = ((EditText) findViewById(R.id.LastNameInput)).getText().toString();
MaterialSpinner spinner = findViewById(R.id.RoleInput);
//TODO add message conditional to check if every EditText is filled up to standards
switch(spinner.getText().toString()){
case "User":
newUser = new User(username,password,firstname,lastname);
break;
case "Service Provider":
newUser = new ServiceProvider(username,password,firstname,lastname);
break;
default:
newUser = new User(username,password,firstname,lastname); //if nothing is enter then defaults to user role.
break;
}
DBHelper dbHelper = new DBHelper(this);
Intent intent = new Intent(getApplicationContext(),LogIn.class); //TODO check if signup should take to the login page or automatically login
if(dbHelper.addUser(newUser)){
startActivityForResult(intent,0);
}else{
Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show();
}
}
}

View file

@ -7,4 +7,6 @@ public class User extends UserType {
super(username, password, firstname, lastname);
}
public String getRole(){ return "User"; }
}

View file

@ -1,16 +1,17 @@
package com.uottawa.olympus.olympusservices;
import java.io.Serializable;
public abstract class UserType {
String username;
String password;
String firstname;
String lastname;
UserType(){
}
UserType(String username, String password, String firstname, String lastname){
this.username = username;
@ -19,6 +20,8 @@ public abstract class UserType {
this.lastname = lastname;
}
public abstract String getRole();
public String getUsername() {
return username;
}
@ -64,4 +67,15 @@ public abstract class UserType {
//so cannot be initialized in this class
this.lastname = lastname;
}
public boolean equals(UserType other){
if(this.username.equals(other.username)&&this.password.equals(other.password)&&
this.firstname.equals(other.firstname)&&this.lastname.equals(other.lastname)){
return true;
}
return false;
}
}

View file

@ -2,6 +2,9 @@ package com.uottawa.olympus.olympusservices;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.content.Intent;
public class Welcome extends AppCompatActivity {
@ -9,5 +12,18 @@ public class Welcome extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
Bundle bundle = getIntent().getExtras();
String username = bundle.getString("username");
DBHelper dbHelper = new DBHelper(this);
UserType user;
user = dbHelper.findUserByUsername(username);
TextView role = findViewById(R.id.Role);
TextView name = findViewById(R.id.name);
role.setText(user.getRole());
name.setText(user.getFirstname());
}
}

View file

@ -57,15 +57,14 @@
android:textCursorDrawable="@color/colorWhite"/>
<Button
android:theme="@style/AppTheme.Button"
android:id="@+id/LogIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:layout_marginTop="40dp"
/>
android:onClick="onClickLogIn"
android:text="@string/login"
android:theme="@style/AppTheme.Button" />

View file

@ -26,20 +26,20 @@
app:fontFamily="@font/julius_sans_one" />
<Button
android:theme="@style/AppTheme.Button"
android:id="@+id/SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:onClick="onClickSignUp"
android:text="@string/signup"
android:onClick="SignUp"/>
android:theme="@style/AppTheme.Button" />
<Button
android:theme="@style/AppTheme.Button"
android:id="@+id/LogIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickLogIn"
android:text="@string/login"
android:onClick="LogIn"/>
android:theme="@style/AppTheme.Button" />
</LinearLayout>

View file

@ -98,15 +98,11 @@
android:textCursorDrawable="@color/colorWhite"/>
<Button
android:theme="@style/AppTheme.Button"
android:id="@+id/SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/signup"/>
android:onClick="onClickSignUp"
android:text="@string/signup"
android:theme="@style/AppTheme.Button" />
</LinearLayout>