From fbc434c60bed4c60b75c057596cffe7350273e85 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Sun, 11 Nov 2018 15:52:55 -0500 Subject: [PATCH] deliverable 3 ui, methods to be filled in --- .../.idea/caches/build_file_checksums.ser | Bin 537 -> 537 bytes .../app/src/main/AndroidManifest.xml | 29 +- ...rvicesList.java => AdminServicesList.java} | 7 +- .../olympus/olympusservices/AdminWelcome.java | 2 +- .../DeleteServiceDialogFragment.java | 64 ++++ .../olympus/olympusservices/EditProfile.java | 54 +++ .../olympus/olympusservices/LogIn.java | 6 + .../ServiceProviderAvailabilities.java | 65 ++++ .../ServiceProviderServicesList.java | 234 ++++++++++++ .../ServiceProviderWelcome.java | 71 ++++ ...t.xml => activity_admin_services_list.xml} | 2 +- .../main/res/layout/activity_edit_profile.xml | 92 +++++ .../src/main/res/layout/activity_log_in.xml | 3 +- ...tivity_service_provider_availabilities.xml | 350 ++++++++++++++++++ ...ctivity_service_provider_services_list.xml | 98 +++++ .../activity_service_provider_welcome.xml | 64 +++- .../src/main/res/layout/activity_sign_up.xml | 15 +- .../main/res/layout/dialog_service_delete.xml | 23 ++ 18 files changed, 1153 insertions(+), 26 deletions(-) rename OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/{ServicesList.java => AdminServicesList.java} (95%) create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DeleteServiceDialogFragment.java create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderAvailabilities.java create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderServicesList.java rename OlympusServices/app/src/main/res/layout/{activity_services_list.xml => activity_admin_services_list.xml} (98%) create mode 100644 OlympusServices/app/src/main/res/layout/activity_edit_profile.xml create mode 100644 OlympusServices/app/src/main/res/layout/activity_service_provider_availabilities.xml create mode 100644 OlympusServices/app/src/main/res/layout/activity_service_provider_services_list.xml create mode 100644 OlympusServices/app/src/main/res/layout/dialog_service_delete.xml diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index ff3e6921c1fd501e659389e339f1100b4146646a..337928fd1a0d640376eea1d52e26e87c0dbab978 100644 GIT binary patch delta 60 zcmV-C0K@;81epYom;?k%h!2sRiIZvpa3LZ7bRrr+^B Sb6iPwVQyiQGyyh~>;WyA)D^@4 delta 66 zcmV-I0KNa21epYom;?ie%s-Kwi4Q14I$TwAWpZ;|VqtW3Xp^=9Hj^a*a1%vRB!PEt Y68uG + android:label="List of Users" + android:screenOrientation="portrait"/> + android:name=".AdminServicesList" + android:label="List of Services" + android:screenOrientation="portrait"/> + + + + + \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminServicesList.java similarity index 95% rename from OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java rename to OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminServicesList.java index 247d81b..b54eaa4 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminServicesList.java @@ -10,9 +10,6 @@ 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 android.widget.Toast; @@ -24,7 +21,7 @@ import java.util.List; * which the admin can view and manipulate. * */ -public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ +public class AdminServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ //field for RecyclerView private RecyclerView mRecyclerView; @@ -42,7 +39,7 @@ public class ServicesList extends AppCompatActivity implements NewServiceDialogF @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_services_list); + setContentView(R.layout.activity_admin_services_list); DBHelper dbHelper = new DBHelper(this); List serviceslist = dbHelper.getAllServices(); Service[] services = new Service[(serviceslist.size())]; 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 index ed3a54c..f8e2861 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java @@ -70,7 +70,7 @@ public class AdminWelcome extends AppCompatActivity { * @param view */ public void goToServices(View view){ - Intent intent = new Intent(getApplicationContext(), ServicesList.class); + Intent intent = new Intent(getApplicationContext(), AdminServicesList.class); startActivity(intent); } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DeleteServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DeleteServiceDialogFragment.java new file mode 100644 index 0000000..5427179 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DeleteServiceDialogFragment.java @@ -0,0 +1,64 @@ +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; +import android.widget.EditText; +import android.widget.Toast; + +public class DeleteServiceDialogFragment extends DialogFragment{ + public interface NoticeDialogListener { + public void onDialogDelete(DialogFragment dialog); + public void onDialogNevermind(DialogFragment dialog); + } + DeleteServiceDialogFragment.NoticeDialogListener mListener; + + @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 = (DeleteServiceDialogFragment.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_delete, null)) + // Add action buttons + .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + args.putString("name", (String)getArguments().get("name")); + DeleteServiceDialogFragment.this.setArguments(args); + mListener.onDialogDelete(DeleteServiceDialogFragment.this); + + + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + args.putString("name", (String)getArguments().get("name")); + mListener.onDialogNevermind(DeleteServiceDialogFragment.this); + } + }) + .setTitle((String)getArguments().get("name")); + return builder.create(); + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java new file mode 100644 index 0000000..1175604 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditProfile.java @@ -0,0 +1,54 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +public class EditProfile extends AppCompatActivity { + String username; + DBHelper dbHelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_profile); + Bundle bundle = getIntent().getExtras(); + username = bundle.getString("username"); + dbHelper = new DBHelper(this); + UserType user; + user = dbHelper.findUserByUsername(username); + TextView firstname = findViewById(R.id.FirstNameInput); + TextView lastname = findViewById(R.id.LastNameInput); + TextView password = findViewById(R.id.PasswordInput); + firstname.setText(user.getFirstname()); + lastname.setText(user.getLastname()); + password.setText(user.getPassword()); + + + } + + /** + * Override so that previous screen refreshes when pressing the + * back button on this activity of the app. + * + */ + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + public void Save(View view){ + TextView firstname = findViewById(R.id.FirstNameInput); + TextView lastname = findViewById(R.id.LastNameInput); + TextView password = findViewById(R.id.PasswordInput); + dbHelper.updateUserInfo(username, password.getText().toString(), firstname.getText().toString(), lastname.getText().toString()); + Toast.makeText(this, "Profile has been updated", Toast.LENGTH_LONG).show(); + } + + +} 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 a147710..4fb387a 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 @@ -50,6 +50,12 @@ public class LogIn extends AppCompatActivity { startActivity(intent); finish(); } + else if(user.getRole()=="ServiceProvider"){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } else { Intent intent = new Intent(getApplicationContext(),Welcome.class); intent.putExtra("username", username); diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderAvailabilities.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderAvailabilities.java new file mode 100644 index 0000000..07b0252 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderAvailabilities.java @@ -0,0 +1,65 @@ +package com.uottawa.olympus.olympusservices; + +import android.app.TimePickerDialog; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TimePicker; + +import java.util.Calendar; + +public class ServiceProviderAvailabilities extends AppCompatActivity { + private String username; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_service_provider_availabilities); + Bundle bundle = getIntent().getExtras(); + username = bundle.getString("username"); + } + + + public void onClick(View v) { + // Get Current Time + final Calendar c = Calendar.getInstance(); + int hour = c.get(Calendar.HOUR_OF_DAY); + int minute = c.get(Calendar.MINUTE); + + final Button button = (Button)v; + + // Launch Time Picker Dialog + TimePickerDialog timePickerDialog = new TimePickerDialog(this, + new TimePickerDialog.OnTimeSetListener() { + + @Override + public void onTimeSet(TimePicker view, int hourOfDay, + int minute) { + button.setText(hourOfDay + ":" + minute); + + //set availibility for service provider and check start time is less than finish + } + + }, hour, minute, false); + timePickerDialog.show(); + } + + public void onRemove(View view){ + //set time to Start/End, set availibility for start and end to null + } + + /** + * Override so that previous screen refreshes when pressing the + * back button on this activity of the app. + * + */ + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderServicesList.java new file mode 100644 index 0000000..3ca7aa4 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderServicesList.java @@ -0,0 +1,234 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.design.widget.Snackbar; +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.ArrayAdapter; +import android.widget.ListAdapter; +import android.widget.TextView; +import android.widget.Toast; + +import com.jaredrummler.materialspinner.MaterialSpinner; + +import java.util.Iterator; +import java.util.List; + +/** + * Creates the view and dialog listener for List of services + * which the admin can view and manipulate. + * + */ +public class ServiceProviderServicesList extends AppCompatActivity implements DeleteServiceDialogFragment.NoticeDialogListener{ + + //field for RecyclerView + private RecyclerView mRecyclerView; + //field for adapter of Recycler view + private RecyclerView.Adapter mAdapter; + //field for layout manager of Recyler view. + private RecyclerView.LayoutManager mLayoutManager; + + private String username; + + /** + * On creation loads up the xml, and generates the services list, + * and fillsout the recylerView fields. + * + * @param savedInstanceState Bundle to transfer information. + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_service_provider_services_list); + + Bundle bundle = getIntent().getExtras(); + username = bundle.getString("username"); + DBHelper dbHelper = new DBHelper(this); + + //grid + List serviceslist2 = dbHelper.getAllServices(); + Service[] services2 = new Service[(serviceslist2.size())]; + Iterator iter2 = serviceslist2.iterator(); + for (int i=0; i serviceslist = dbHelper.getAllServices(); + String[] services = new String[(serviceslist.size())]; + Iterator iter = serviceslist.iterator(); + for (int i=0; i servicesadapter = new ArrayAdapter + (this, android.R.layout.simple_spinner_item, services); + + servicesadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + spinner.setAdapter(servicesadapter); + + 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(); + } + }); + + } + + + /** + * Override so that previous screen refreshes when pressing the + * back button on this activity of the app. + * + */ + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + + /** + * Deletes services from the list. + * + * @param view View object contains the generated list and buttons + */ + public void deleteService(View view, String name) { + DialogFragment newFragment = new DeleteServiceDialogFragment(); + newFragment.show(getSupportFragmentManager(), "addService"); + Bundle args = new Bundle(); + args.putString("name", name); + newFragment.setArguments(args); + } + + /** + * Adds service to the list. + * + * @param view View object contains the generated list and buttons + */ + public void addService(View view, String name) { + MaterialSpinner spinner = findViewById(R.id.RoleInput); + String servicename = spinner.getText().toString(); + //add service to service provider if doesn't already exist + } + + + + /** + * Uses Dialog to delete a service from the serviceList. + * + * @param dialog DialogFragment that contains the delete service button. + */ + + @Override + public void onDialogDelete(DialogFragment dialog) { + DBHelper dbHelper = new DBHelper(this); + String name = (String)dialog.getArguments().get("name"); + //remove service from service provider + + + + dialog.dismiss(); + this.recreate(); + } + + /** + * Does nothing + * + * @param dialog DialogFragment that contains the cancel button. + */ + @Override + public void onDialogNevermind(DialogFragment dialog) { + + } + + public class MyAdapter extends RecyclerView.Adapter { + + 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(String.format("$%,.2f", 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(); + deleteService(view, name); + + } + + + } + + + } + +} \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java index 07acb75..efa2570 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java @@ -2,12 +2,83 @@ 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; +/** + * Welcome class creates the welcome screen for the HomeOwners and ServiceProviders + * as a temporary screen until full functionality of those two a classes are + * implemented. + * + */ public class ServiceProviderWelcome extends AppCompatActivity { + String username; + /** + * On creation of this object the app will display the xml file for + * the welcome page which gets the role and username of the UserType + * object and welcomes the user with a message. + * + * @param savedInstanceState Bundle to transfer data + */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_service_provider_welcome); + Bundle bundle = getIntent().getExtras(); + username = bundle.getString("username"); + DBHelper dbHelper = new DBHelper(this); + UserType user; + user = dbHelper.findUserByUsername(username); + TextView welcome = findViewById(R.id.Welcome); + welcome.setText("Welcome "+user.getFirstname()+ " you are logged in as a Service Provider"); + + + } + + /** + * Override so that nothing occurs when pressing the + * back button on this activity of the app. + * + */ + @Override + public void onBackPressed(){ + } + + /** + * Logs out the user and returns them back to + * main activity. End all current user activity + * for security purposes. + * + * @param view View object of current activity. + */ + public void LogOut(View view){ + Intent intent = new Intent(getApplicationContext(), Main.class); + startActivity(intent); + finish(); + } + + public void EditProfile(View view){ + Intent intent = new Intent(getApplicationContext(),EditProfile.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + + public void EditServices(View view){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderServicesList.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + public void EditAvailabilities(View view){ + Intent intent = new Intent(getApplicationContext(),ServiceProviderAvailabilities.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + + } diff --git a/OlympusServices/app/src/main/res/layout/activity_services_list.xml b/OlympusServices/app/src/main/res/layout/activity_admin_services_list.xml similarity index 98% rename from OlympusServices/app/src/main/res/layout/activity_services_list.xml rename to OlympusServices/app/src/main/res/layout/activity_admin_services_list.xml index d0060b7..2c19a56 100644 --- a/OlympusServices/app/src/main/res/layout/activity_services_list.xml +++ b/OlympusServices/app/src/main/res/layout/activity_admin_services_list.xml @@ -11,7 +11,7 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/background" - tools:context=".ServicesList"> + tools:context=".AdminServicesList"> + + + + + + + + //component used from https://github.com/rengwuxian/MaterialEditText + + + + //component used from https://github.com/rengwuxian/MaterialEditText + + //component used from https://github.com/rengwuxian/MaterialEditText + + + +