diff --git a/Deliverable1.zip b/Deliverable1.zip new file mode 100644 index 0000000..fd97b0b Binary files /dev/null and b/Deliverable1.zip differ diff --git a/OlympusServices/.idea/assetWizardSettings.xml b/OlympusServices/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..6b96cf0 --- /dev/null +++ b/OlympusServices/.idea/assetWizardSettings.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index 24e3c6b..279981b 100644 Binary files a/OlympusServices/.idea/caches/build_file_checksums.ser and b/OlympusServices/.idea/caches/build_file_checksums.ser differ diff --git a/OlympusServices/.idea/misc.xml b/OlympusServices/.idea/misc.xml index 99202cc..dc34569 100644 --- a/OlympusServices/.idea/misc.xml +++ b/OlympusServices/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/OlympusServices/.idea/vcs.xml b/OlympusServices/.idea/vcs.xml index 94a25f7..62bd7a0 100644 --- a/OlympusServices/.idea/vcs.xml +++ b/OlympusServices/.idea/vcs.xml @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/OlympusServices/app/build.gradle b/OlympusServices/app/build.gradle index 4a8aefa..7bdef2b 100644 --- a/OlympusServices/app/build.gradle +++ b/OlympusServices/app/build.gradle @@ -16,6 +16,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + testOptions { + unitTests { + includeAndroidResources = true + } + } } dependencies { @@ -24,10 +29,15 @@ dependencies { implementation 'com.android.support:design:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' + testImplementation 'org.robolectric:robolectric:4.0-alpha-3-SNAPSHOT' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.jaredrummler:material-spinner:1.2.5' implementation 'com.android.support:design:28.0.0-alpha3' implementation 'com.rengwuxian.materialedittext:library:2.1.4' - + implementation 'com.android.support:recyclerview-v7:28.0.0' +} + +repositories { + maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } diff --git a/OlympusServices/app/src/main/AndroidManifest.xml b/OlympusServices/app/src/main/AndroidManifest.xml index 167ae5c..f8bc8ab 100644 --- a/OlympusServices/app/src/main/AndroidManifest.xml +++ b/OlympusServices/app/src/main/AndroidManifest.xml @@ -9,15 +9,14 @@ - + android:screenOrientation="portrait"> @@ -29,13 +28,20 @@ android:name="preloaded_fonts" android:resource="@array/preloaded_fonts" /> - - - - - + + + + + + \ No newline at end of file diff --git a/OlympusServices/app/src/main/ic_launcher-web.png b/OlympusServices/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..547c096 Binary files /dev/null and b/OlympusServices/app/src/main/ic_launcher-web.png differ 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 new file mode 100644 index 0000000..4d2938b --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Admin.java @@ -0,0 +1,10 @@ +package com.uottawa.olympus.olympusservices; + +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/AdminWelcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java new file mode 100644 index 0000000..0068236 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java @@ -0,0 +1,33 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; + +public class AdminWelcome extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_admin_welcome); + + } + @Override + public void onBackPressed(){ + } + + public void LogOut(View view){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } + public void goToUsers(View view){ + Intent intent = new Intent(getApplicationContext(), UsersList.class); + startActivity(intent); + } + public void goToServices(View view){ + Intent intent = new Intent(getApplicationContext(), ServicesList.class); + startActivity(intent); + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Appointment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Appointment.java new file mode 100644 index 0000000..93cd7a0 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Appointment.java @@ -0,0 +1,6 @@ +package com.uottawa.olympus.olympusservices; + +public class Appointment { + Service service; + ServiceProvider provider; +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java new file mode 100644 index 0000000..452473d --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java @@ -0,0 +1,385 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.database.Cursor; +import android.content.ContentValues; + +import java.util.LinkedList; +import java.util.List; + +/** + * The class DBHelper allows the Android application to access and perform + * CRUD (Create, Read, Update, Delete) operations on the tables of the SQLite database. + * There is currently one table of all users' login information and names. + * Table of service providers and services to come soon. + * + * To use, create an object of this class with the current activity as context. + * + */ + +public class DBHelper extends SQLiteOpenHelper { + + //version of db used for update method + private static final int DB_VERSION = 2; + //name of db in app data + private static final String DB_NAME = "UsersDB.db"; + + //SQLiteDatabase for reading + private static SQLiteDatabase readDB; + + //SQLiteDatabase for writing + private static SQLiteDatabase writeDB; + + //name of table containing user login information and names + private static final String TABLE_LOGIN = "userInfo"; + //columns of TABLE_LOGIN + private static final String COLUMN_USERNAME = "username"; + private static final String COLUMN_PASSWORD = "password"; + private static final String COLUMN_FIRSTNAME = "firstName"; + private static final String COLUMN_LASTNAME = "lastName"; + private static final String COLUMN_USERTYPE = "userType"; + +// private static final String TABLE_SERVICEPROVIDERS = "serviceProviders"; + + //name of table containing services and rates + private static final String TABLE_SERVICES = "services"; + //columns of TABLE_LOGIN + private static final String COLUMN_SERVICE = "service"; + private static final String COLUMN_RATE = "rate"; + + + /** + * Creates an instance of DBHelper to allow activities to access and + * perform CRUD operations on the database via DBHelper's methods + * + * @param context current activity calling DBHelper + */ + public DBHelper(Context context){ + super(context, DB_NAME, null, DB_VERSION); + //since these methods take a while we will call them once and store the returned dbs + readDB = this.getReadableDatabase(); + writeDB = this.getWritableDatabase(); + //pre-add the admin user + addUser(new Admin()); + } + + @Override + public void onCreate(SQLiteDatabase db){ + + //making the table containing user login information + String CREATE_LOGIN_TABLE = "CREATE TABLE "+ TABLE_LOGIN + "(" + + COLUMN_USERNAME + " TEXT UNIQUE NOT NULL PRIMARY KEY ON CONFLICT ROLLBACK," + + COLUMN_PASSWORD + " TEXT NOT NULL," + + COLUMN_FIRSTNAME + " TEXT DEFAULT 'FirstName'," + + COLUMN_LASTNAME + " TEXT DEFAULT 'LastName'," + + COLUMN_USERTYPE + " TEXT NOT NULL" + ")"; + db.execSQL(CREATE_LOGIN_TABLE); + + //making the table containing services and their rates + String CREATE_SERVICES_TABLE = "CREATE TABLE "+ TABLE_SERVICES + "(" + + COLUMN_SERVICE + " TEXT UNIQUE NOT NULL PRIMARY KEY ON CONFLICT ROLLBACK," + + COLUMN_RATE + " REAL DEFAULT 0.0" + ")"; + db.execSQL(CREATE_SERVICES_TABLE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){ + switch(oldVersion){ + case 1: //going from db version 1 to 2 + //change usertype of Users to Homeowner + ContentValues values = new ContentValues(); + values.put(COLUMN_USERTYPE, "HomeOwner"); + db.update(TABLE_LOGIN, values, COLUMN_USERTYPE + " = ?", new String[]{"User"}); + + //if services table is not created, create it + db.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE_SERVICES + "(" + + COLUMN_SERVICE + " TEXT UNIQUE NOT NULL PRIMARY KEY ON CONFLICT ROLLBACK," + + COLUMN_RATE + " REAL DEFAULT 0.0" + ")"); + } + } + + @Override + public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { + onUpgrade(db, oldVersion, newVersion); + } + + + //methods for table of users + + /** + * Adds a user to the database. Returns false if there is a user already + * existing in the database with the same username. Returns true if + * successful in adding user to database. + * + * @param userType user to be added + * @return whether adding user was successful + */ + public boolean addUser(UserType userType){ + //Check for duplicate username by querying login table + Cursor cursor = writeDB.query(TABLE_LOGIN, + new String[] {COLUMN_USERNAME}, + COLUMN_USERNAME + " = ?", + new String[]{userType.getUsername()}, + null, null, null, + "1"); + //If cursor has 1+ elements in it, username already exists in table + if (cursor != null && cursor.getCount() > 0){ + cursor.close(); + return false; + } + cursor.close(); + + ContentValues values = new ContentValues(); + values.put(COLUMN_USERNAME, userType.getUsername()); + values.put(COLUMN_PASSWORD, userType.getPassword()); + values.put(COLUMN_FIRSTNAME, userType.getFirstname()); + values.put(COLUMN_LASTNAME, userType.getLastname()); + values.put(COLUMN_USERTYPE, userType.getClass().getSimpleName()); + writeDB.insert(TABLE_LOGIN, null, values); + return true; + } + + /** + * Looks in database for user with requested username, and returns an + * object of UserType corresponding to said user's role. + * Returns null if no such user found. + * + * @param username username to look up + * @return object representing user found + */ + public UserType findUserByUsername(String username){ + UserType usertype; + Cursor cursor = readDB.rawQuery("SELECT * FROM " + TABLE_LOGIN + + " WHERE " + COLUMN_USERNAME + " = ?", + new String[]{username}); + + if (cursor.moveToFirst()){ + String password = cursor.getString(1); + String firstname = cursor.getString(2); + String lastname = cursor.getString(3); + if (cursor.getString(4) + .equals("Admin")){ + usertype = new Admin(); + } else if (cursor.getString(4) + .equals("ServiceProvider")){ + usertype = new ServiceProvider(username, password, firstname, lastname); + } else { + usertype = new HomeOwner(username, password, firstname, lastname); + } + } else { + usertype = null; + } + cursor.close(); + return usertype; + } + + /** + * Updates user login information and name for user with requested username. + * Returns true if a user of said username was found and entry updated. + * Returns false if no user was found of said username. + * + * + * @param username username of entry to update + * @param password new password + * @param firstname new first name + * @param lastname new last name + * + * @return whether updating user information was successful + */ + public boolean updateUserInfo(String username, String password, String firstname, String lastname){ + ContentValues values = new ContentValues(); + values.put(COLUMN_PASSWORD, password); + values.put(COLUMN_FIRSTNAME, firstname); + values.put(COLUMN_LASTNAME, lastname); + + return writeDB.update(TABLE_LOGIN, values, COLUMN_USERNAME+" = ?", + new String[]{username}) > 0; + + } + + /** + * Looks in database for user with requested username, and deletes the corresponding + * entry. Returns true if a user was deleted, false otherwise. + * + * @param username username of entry to delete + * @return whether a user was deleted + */ + public boolean deleteUser(String username) { + return writeDB.delete(TABLE_LOGIN, COLUMN_USERNAME+" = ?", + new String[]{username}) > 0; + } + + /** + * Returns a list of String arrays containing the username, first name, + * last name, and user type of every user in TABLE_LOGIN. + * + * @return list of arrays of [username, first name, last name, user type] + */ + public List getAllUsers(){ + return getAll("SELECT " + COLUMN_USERNAME + ", " + + COLUMN_FIRSTNAME + ", " + + COLUMN_LASTNAME + ", " + + COLUMN_USERTYPE + + " FROM "+TABLE_LOGIN); + } + + //methods for table of services + + /** + * Adds a service to the database. Returns false if service already + * exists in the database. + * Returns true if successful in adding service to database. + * + * @param service service to be added + * @return whether adding service was successful + */ + public boolean addService(Service service){ + //Check for duplicate username by querying login table + Cursor cursor = writeDB.query(TABLE_SERVICES, + new String[] {COLUMN_SERVICE}, + COLUMN_SERVICE + " = ?", + new String[]{service.getName()}, + null, null, null, + "1"); + //If cursor has 1+ elements in it, username already exists in table + if (cursor != null && cursor.getCount() > 0){ + cursor.close(); + return false; + } + cursor.close(); + + ContentValues values = new ContentValues(); + values.put(COLUMN_SERVICE, service.getName()); + values.put(COLUMN_RATE, service.getRate()); + writeDB.insert(TABLE_SERVICES, null, values); + return true; + } + + /** + * Looks in database for service with specified, and returns an + * object of Service if found. + * Returns null if no such service found. + * + * @param serviceName service to look up + * @return object representing service found + */ + public Service findService(String serviceName){ + Service service; + Cursor cursor = readDB.rawQuery("SELECT * FROM " + TABLE_SERVICES + + " WHERE " + COLUMN_SERVICE + " = ?", + new String[]{serviceName}); + + if (cursor.moveToFirst()){ + String servName = cursor.getString(0); + double rate = cursor.getDouble(1); + service = new Service(servName, rate); + } else { + service = null; + } + cursor.close(); + return service; + } + + /** + * Updates service rate using a Service object. + * Returns true if a service was found and entry updated. + * Returns false if no service was found. + * + * + * @param service service object containing updated values + * + * @return whether updating service information was successful + */ + public boolean updateService(Service service){ + ContentValues values = new ContentValues(); + values.put(COLUMN_RATE, service.getRate()); + + return writeDB.update(TABLE_SERVICES, values, COLUMN_SERVICE+" = ?", + new String[]{service.getName()}) > 0; + } + + /** + * Updates service rate using input of service name and rate. + * Returns true if a service was found and entry updated. + * Returns false if no service was found. + * + * + * @param name name of service + * @param rate rate of service + * + * @return whether updating service information was successful + */ + public boolean updateService(String name, double rate){ + ContentValues values = new ContentValues(); + if (rate > 0) + values.put(COLUMN_RATE, rate); + + return writeDB.update(TABLE_SERVICES, values, COLUMN_SERVICE+" = ?", + new String[]{name}) > 0; + } + + /** + * Looks in database for a service, and deletes the corresponding + * entry. Returns true if a user was deleted, false otherwise. + * + * @param service service of entry to delete + * @return whether the service was deleted + */ + public boolean deleteService(String service) { + return writeDB.delete(TABLE_SERVICES, COLUMN_SERVICE+" = ?", + new String[]{service}) > 0; + } + + /** + * Returns a list of String arrays containing the service categories, + * names and hourly rates. + * + * @return list of arrays of [service, rate] + */ + public List getAllServices(){ + return getAll("SELECT * FROM " + TABLE_SERVICES); + } + + /** + * Prints all entries of table. One row is printed per line. Columns are + * separated by spaces. + * + * @param tableName name of table to print + */ + void printTable(String tableName){ + Cursor cursor = readDB.rawQuery("SELECT * FROM "+tableName, null); + cursor.moveToFirst(); + for (int i = 0; i getAll(String rawQuery){ + List list = new LinkedList<>(); + String[] infoArray; + Cursor cursor = readDB.rawQuery(rawQuery,null); + + if (cursor.moveToFirst()) { + for (int i = 0; i < cursor.getCount(); i++) { + infoArray = new String[cursor.getColumnNames().length]; + for (int j = 0; j < cursor.getColumnNames().length; j++) { + infoArray[j] = cursor.getString(j); + } + list.add(infoArray); + cursor.moveToNext(); + } + } + cursor.close(); + return list; + } + +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java new file mode 100644 index 0000000..3998964 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java @@ -0,0 +1,68 @@ +package com.uottawa.olympus.olympusservices; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; + +public class EditServiceDialogFragment extends DialogFragment{ + +public interface NoticeDialogListener { + public void onDialogEdit(DialogFragment dialog); + public void onDialogDelete(DialogFragment dialog); + } + EditServiceDialogFragment.NoticeDialogListener mListener; + + // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener + @Override + public void onAttach(Context context) { + super.onAttach(context); + // Verify that the host activity implements the callback interface + try { + // Instantiate the NoticeDialogListener so we can send events to the host + mListener = (EditServiceDialogFragment.NoticeDialogListener) context; + } catch (ClassCastException e) { + // The activity doesn't implement the interface, throw exception + throw new ClassCastException(this.toString() + + " must implement NoticeDialogListener"); + } + } + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + // Get the layout inflater + LayoutInflater inflater = getActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + builder.setView(inflater.inflate(R.layout.dialog_service_edit, null)) + // Add action buttons + .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", (String)getArguments().get("name")); + args.putDouble("rate", 2.5); + // + EditServiceDialogFragment.this.setArguments(args); + mListener.onDialogEdit(EditServiceDialogFragment.this); + } + }) + .setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", (String)getArguments().get("name")); + // + EditServiceDialogFragment.this.setArguments(args); + mListener.onDialogDelete(EditServiceDialogFragment.this); + } + }) + .setTitle((String)getArguments().get("name")); + return builder.create(); + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwner.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwner.java new file mode 100644 index 0000000..4807fa2 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwner.java @@ -0,0 +1,12 @@ +package com.uottawa.olympus.olympusservices; + + +public class HomeOwner extends UserType { + + HomeOwner(String username, String password, String firstname, String lastname){ + super(username, password, firstname, lastname); + } + + public String getRole(){ return "HomeOwner"; } + +} 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..6afde1a 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,54 @@ 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); + if(username.matches("[a-zA-Z0-9]*")&&password.matches("[a-zA-Z0-9]*") + && password.length()>0 && username.length()>0) { + if (dbHelper.findUserByUsername(username) != null) { + UserType user = dbHelper.findUserByUsername(username); + if (user.getUsername().equals(username) && + user.getPassword().equals(password)) { + if(user.getRole()=="Admin"){ + Intent intent = new Intent(getApplicationContext(),AdminWelcome.class); + startActivity(intent); + finish(); + } + else { + Intent intent = new Intent(getApplicationContext(),Welcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + + + } else { + Toast.makeText(this, "Wrong Password", Toast.LENGTH_LONG).show(); + } + } else { + Toast.makeText(this, "Account does not exist", Toast.LENGTH_LONG).show(); + } + } + else if(username.length()==0 || password.length()==0){ + Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show(); + } + else{ + Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show(); + } + + + } + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } + + + + } 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..6245cb1 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,24 @@ 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); + startActivity(intent); + finish(); + + } + + public void onClickLogIn(View view){ + Intent intent = new Intent(getApplicationContext(),LogIn.class); + startActivity(intent); + finish(); + } + +} \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java new file mode 100644 index 0000000..2855872 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java @@ -0,0 +1,10 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java new file mode 100644 index 0000000..7f0496e --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java @@ -0,0 +1,63 @@ +package com.uottawa.olympus.olympusservices; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; + +public class NewServiceDialogFragment extends DialogFragment { + + public interface NoticeDialogListener { + public void onDialogNew(DialogFragment dialog); + public void onDialogNevermind(DialogFragment dialog); + } + NoticeDialogListener mListener; + + // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener + @Override + public void onAttach(Context context) { + super.onAttach(context); + // Verify that the host activity implements the callback interface + try { + // Instantiate the NoticeDialogListener so we can send events to the host + mListener = (NoticeDialogListener) context; + } catch (ClassCastException e) { + // The activity doesn't implement the interface, throw exception + throw new ClassCastException(this.toString() + + " must implement NoticeDialogListener"); + } + } + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + // Get the layout inflater + LayoutInflater inflater = getActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + builder.setView(inflater.inflate(R.layout.dialog_service_new, null)) + // Add action buttons + .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", "test2"); + args.putDouble("rate", 2.5); + /// + NewServiceDialogFragment.this.setArguments(args); + mListener.onDialogNew(NewServiceDialogFragment.this); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + NewServiceDialogFragment.this.getDialog().cancel(); + } + }); + return builder.create(); + } + +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Service.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Service.java new file mode 100644 index 0000000..266115a --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Service.java @@ -0,0 +1,46 @@ +package com.uottawa.olympus.olympusservices; + +import java.util.ArrayList; +import java.util.List; + +public class Service { + private String name; + private double rate; + private List serviceProviders; + + Service(String name, double rate) { + this.name = name; + this.rate = rate; + serviceProviders = new ArrayList(); + } + + public String getName() { + return name; + } + + public double getRate() { + return rate; + } + + public void setName(String name) { + this.name = name; + } + + public void setRate(double rate) { + this.rate = rate; + } + + public boolean addServiceProvider(ServiceProvider user){ + for (ServiceProvider listUser : serviceProviders){ + if (user.getUsername().equals(listUser.getUsername())){ + return false; + } + } + serviceProviders.add(user); + return true; + } + + public List getServiceProviders(){ + return serviceProviders; + } +} 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 new file mode 100644 index 0000000..15bfde4 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProvider.java @@ -0,0 +1,31 @@ +package com.uottawa.olympus.olympusservices; + +import java.util.ArrayList; +import java.util.List; + +public class ServiceProvider extends UserType { + + private List services; + + ServiceProvider(String username, String password, String firstname, String lastname){ + super(username, password, firstname, lastname); + services = new ArrayList<>(); + } + + public String getRole(){ return "ServiceProvider"; } + + public boolean addService(Service service){ + for (Service listService : services){ + if (service.getName().equals(listService.getName())){ + return false; + } + } + services.add(service); + return true; + } + + public List getServices(){ + return services; + } + +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java new file mode 100644 index 0000000..db0cd9e --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java @@ -0,0 +1,164 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.GridView; +import android.widget.TextView; + +import java.util.Iterator; +import java.util.List; + +public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ + + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_services_list); + DBHelper dbHelper = new DBHelper(this); + List serviceslist = dbHelper.getAllServices(); + Service[] services = new Service[(serviceslist.size())]; + Iterator iter = serviceslist.iterator(); + for (int i=0; i { + + private Service[] services; + private Context context; + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // you provide access to all the views for a data item in a view holder + + // Provide a suitable constructor (depends on the kind of dataset) + public MyAdapter(Service[] services, Context context) { + this.services = services; + } + + // Create new views (invoked by the layout manager) + @NonNull + @Override + public ServicesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.list_item, parent, false); + ServicesHolder vh = new ServicesHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ServicesHolder holder, int position) { + Service service = services[position]; + holder.name.setText(service.getName()); + holder.rate.setText(""+service.getRate()); + + + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return services.length; + } + + class ServicesHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + + TextView name; + TextView rate; + + public ServicesHolder(View row){ + super(row); + name = row.findViewById(R.id.Name); + rate = row.findViewById(R.id.Rate); + row.setOnClickListener(this); + } + @Override + public void onClick(View view) { + TextView nameview = (TextView)view.findViewById(R.id.Name); + String name = nameview.getText().toString(); + editService(view, name); + + } + + + } + + + } + +} \ No newline at end of file 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..d4d8e38 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,15 +15,65 @@ 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("Home Owner", "Service Provider"); spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) { Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show(); } }); - } - 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 + if(username.length()>=5 && password.length()>5 && firstname.length()>0 && lastname.length()>0 && username.matches("[a-zA-Z0-9]*") && password.matches("[a-zA-Z0-9]*") + && firstname.matches("[a-zA-Z]*") && lastname.matches("[a-zA-Z]*")){ + switch(spinner.getText().toString()){ + case "Home Owner": + newUser = new HomeOwner(username,password,firstname,lastname); + break; + case "Service Provider": + newUser = new ServiceProvider(username,password,firstname,lastname); + break; + default: + newUser = new HomeOwner(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)){ + startActivity(intent); + finish(); + }else{ + Toast.makeText(this,"Username is taken",Toast.LENGTH_LONG).show(); + } + } + else if(firstname.length()==0 || lastname.length()==0 || username.length()==0 || password.length()==0){ + Toast.makeText(this, "Fields cannot be empty", Toast.LENGTH_LONG).show(); + } + else if (username.length()<=5 || password.length()<=5 ){ + Toast.makeText(this, "Password and username must be longer than 4 characters", Toast.LENGTH_LONG).show(); + } + else{ + Toast.makeText(this, "Fields may only contain alphanumeric values", Toast.LENGTH_LONG).show(); + } + } + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } + + + } 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 new file mode 100644 index 0000000..8c8cbeb --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UserType.java @@ -0,0 +1,81 @@ +package com.uottawa.olympus.olympusservices; + + +import java.io.Serializable; + +public abstract class UserType { + + String username; + String password; + String firstname; + String lastname; + + + + + UserType(String username, String password, String firstname, String lastname){ + this.username = username; + this.password = password; + this.firstname = firstname; + this.lastname = lastname; + } + + public abstract String getRole(); + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getFirstname() { + return firstname; + } + + public String getLastname() { + return lastname; + } + + + public void setUsername(String username) { + //remember to call updateUser(String username, String password, String firstname, String lastname) + //in activity whenever a setter is called. DBHelper requires a Context (Activity) to be initialized + //so cannot be initialized in this class + this.username = username; + + } + + public void setPassword(String password) { + //remember to call updateUser(String username, String password, String firstname, String lastname) + //in activity whenever a setter is called. DBHelper requires a Context (Activity) to be initialized + //so cannot be initialized in this class + this.password = password; + } + + public void setFirstname(String firstname) { + //remember to call updateUser(String username, String password, String firstname, String lastname) + //in activity whenever a setter is called. DBHelper requires a Context (Activity) to be initialized + //so cannot be initialized in this class + this.firstname = firstname; + } + + public void setLastname(String lastname) { + //remember to call updateUser(String username, String password, String firstname, String lastname) + //in activity whenever a setter is called. DBHelper requires a Context (Activity) to be initialized + //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/UsersList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UsersList.java new file mode 100644 index 0000000..4cb5afb --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UsersList.java @@ -0,0 +1,33 @@ +package com.uottawa.olympus.olympusservices; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.ArrayAdapter; +import android.widget.GridView; + +import java.util.Iterator; +import java.util.List; + +public class UsersList extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_users_list); + + DBHelper dbHelper = new DBHelper(this); + List users = dbHelper.getAllUsers(); + String[] usernames = new String[(users.size()+1)*2]; + usernames[0] = "Username"; + usernames[1] = "User Type"; + Iterator iter = users.iterator(); + for (int i=0; i(this, R.layout.simple_list_item_1_customized, usernames); + GridView gridView = findViewById(R.id.Users); + gridView.setAdapter(adapter); + } +} 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..4389f62 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,26 @@ 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()); + + } + @Override + public void onBackPressed(){ + } + public void LogOut(View view){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } + + } diff --git a/OlympusServices/app/src/main/res/drawable/logo.JPG b/OlympusServices/app/src/main/res/drawable/logo.JPG new file mode 100644 index 0000000..65459c1 Binary files /dev/null and b/OlympusServices/app/src/main/res/drawable/logo.JPG differ diff --git a/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml new file mode 100644 index 0000000..49da067 --- /dev/null +++ b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml @@ -0,0 +1,54 @@ + + + + + + +