From 6d32b64e901ad20b9c5c5aeafc833adedfea4758 Mon Sep 17 00:00:00 2001 From: Anshu Sharma Date: Fri, 19 Oct 2018 16:45:18 -0400 Subject: [PATCH] Logic --- .../.idea/caches/build_file_checksums.ser | Bin 537 -> 541 bytes OlympusServices/.idea/misc.xml | 10 ++--- OlympusServices/.idea/vcs.xml | 6 --- OlympusServices/app/build.gradle | 2 +- .../app/src/main/AndroidManifest.xml | 13 +++--- .../olympus/olympusservices/Admin.java | 2 + .../olympus/olympusservices/LogIn.java | 29 +++++++++++++ .../uottawa/olympus/olympusservices/Main.java | 17 +++++++- .../olympusservices/ServiceProvider.java | 3 ++ .../olympus/olympusservices/SignUp.java | 40 +++++++++++++++++- .../uottawa/olympus/olympusservices/User.java | 2 + .../olympus/olympusservices/UserType.java | 18 +++++++- .../olympus/olympusservices/Welcome.java | 16 +++++++ .../src/main/res/layout/activity_log_in.xml | 7 ++- .../app/src/main/res/layout/activity_main.xml | 10 +++-- .../src/main/res/layout/activity_sign_up.xml | 5 ++- OlympusServices/build.gradle | 9 +--- 17 files changed, 146 insertions(+), 43 deletions(-) delete mode 100644 OlympusServices/.idea/vcs.xml diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index 73af276a35eb0a7bf35435e70bcd09123bfbc0ed..a8e3b6923237f7b5958e9bf40496fc34876403e5 100644 GIT binary patch delta 235 zcmbQqGM8n-43?(5yMIiapdF2TTkM z6$K0o33peW+Rb zlWiGw83lo)w4K22vVik%HGf#FayVGKIB=Z{XD;~ylDSWpm?RGOKSqL*Hjn39uPTExH2z_zyOYkOxc* z3>5_o3=9Ho>#Iy8jq94WT)dyy*~R&~gh9jEDkiizwWv5IDY2w9BL=EJX7V&f-C+LW z)RL0Sy!2w2sf7%63~V5S=G{!#XLFxDPd7nND%|Pt!V(4^6zky%Z+e{6yfyhl#j!`f zj@>-@^}%FsMp*%ieGjY8tiDs!5?8)u$-CV8$p;zb1V8sOuiBHa)Nhk*n(?!<0!bAB D`lwtw diff --git a/OlympusServices/.idea/misc.xml b/OlympusServices/.idea/misc.xml index b0c7b20..dc34569 100644 --- a/OlympusServices/.idea/misc.xml +++ b/OlympusServices/.idea/misc.xml @@ -5,31 +5,27 @@ - + diff --git a/OlympusServices/.idea/vcs.xml b/OlympusServices/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/OlympusServices/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/OlympusServices/app/build.gradle b/OlympusServices/app/build.gradle index 481e4c8..51596d7 100644 --- a/OlympusServices/app/build.gradle +++ b/OlympusServices/app/build.gradle @@ -39,4 +39,4 @@ dependencies { repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots" } -} \ No newline at end of file +} diff --git a/OlympusServices/app/src/main/AndroidManifest.xml b/OlympusServices/app/src/main/AndroidManifest.xml index 167ae5c..d2cfb1f 100644 --- a/OlympusServices/app/src/main/AndroidManifest.xml +++ b/OlympusServices/app/src/main/AndroidManifest.xml @@ -14,7 +14,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - @@ -29,13 +28,15 @@ android:name="preloaded_fonts" android:resource="@array/preloaded_fonts" /> - - + + - + \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Admin.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Admin.java index 55fd6bf..4d2938b 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Admin.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Admin.java @@ -5,4 +5,6 @@ public class Admin extends UserType { Admin(){ super("admin", "admin", "Admin", "Admin"); } + + public String getRole(){ return "Admin"; } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java index 02ed1f3..beb8681 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/LogIn.java @@ -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,29 @@ 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).getUsername().equals(username)&& + dbHelper.findUserByUsername(username).getPassword().equals(password)){ + //TODO send the welcome message the user information + intent.putExtra("username",username); + startActivity(intent); + + + }else{ + //TODO program incorrect username or password message + Toast.makeText(this,"error",Toast.LENGTH_LONG).show(); + } + + + + } + + + + } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java index f5722d9..052038a 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Main.java @@ -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); + } + +} \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProvider.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProvider.java index 3931dfb..086ccf0 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProvider.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProvider.java @@ -6,4 +6,7 @@ public class ServiceProvider extends UserType { super(username, password, firstname, lastname); } + public String getRole(){ return "ServiceProvider"; } + + } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java index 770795e..4df5844 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/SignUp.java @@ -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 @@ -11,7 +15,7 @@ public class SignUp extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_up); MaterialSpinner spinner = findViewById(R.id.RoleInput); - spinner.setItems("Ice Cream Sandwich", "Jelly Bean", "KitKat", "Lollipop", "Marshmallow"); + spinner.setItems("User", "ServiceProvider"); spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) { @@ -19,7 +23,39 @@ 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 "ServiceProvider": + 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,"error",Toast.LENGTH_LONG).show(); + //TODO add reaction is username is already taken + } } + + + } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/User.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/User.java index ca8cf71..4d14c6c 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/User.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/User.java @@ -6,4 +6,6 @@ public class User extends UserType { super(username, password, firstname, lastname); } + public String getRole(){ return "User"; } + } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UserType.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UserType.java index 550b4e7..8c8cbeb 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UserType.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UserType.java @@ -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; + } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java index 8cf6848..08054ef 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java @@ -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 = (TextView) findViewById(R.id.Role); + TextView name = (TextView) findViewById(R.id.name); + role.setText(user.getRole()); + name.setText(user.getFirstname()); + + } + + } diff --git a/OlympusServices/app/src/main/res/layout/activity_log_in.xml b/OlympusServices/app/src/main/res/layout/activity_log_in.xml index 17ce1f3..729bb27 100644 --- a/OlympusServices/app/src/main/res/layout/activity_log_in.xml +++ b/OlympusServices/app/src/main/res/layout/activity_log_in.xml @@ -52,15 +52,14 @@ app:met_singleLineEllipsis="true" /> -