added comments

This commit is contained in:
IvanaE 2018-12-04 20:27:25 -05:00
parent b562598f3c
commit add1965308
3 changed files with 99 additions and 15 deletions

View file

@ -44,6 +44,7 @@ public class Bookings extends AppCompatActivity {
username = bundle.getString("username");
dbhelper = new DBHelper(this);
//get the list of bookings
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
Collections.reverse(booking);
Booking[] bookings = new Booking[booking.size()];
@ -54,17 +55,21 @@ public class Bookings extends AppCompatActivity {
Booking[] bookings = {new Booking(5, 5, 6, 6, 2, 3, 2019, (ServiceProvider)dbhelper.findUserByUsername("testing"),
(HomeOwner)dbhelper.findUserByUsername("tester"), dbhelper.findService("service1"))};
*/
//Make the recycler view show the bookings
mRecyclerView = (RecyclerView) findViewById(R.id.Bookings);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MyAdapter(bookings, this);
mRecyclerView.setAdapter(mAdapter);
//remove or add cancelled booking depending on the switch position
SwitchCompat toggle = findViewById(R.id.Switch);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
Collections.reverse(booking);
Booking[] bookings = new Booking[booking.size()];
bookings = booking.toArray(bookings);
mAdapter = new MyAdapter(bookings, Bookings.this);
@ -72,6 +77,7 @@ public class Bookings extends AppCompatActivity {
mAdapter.notifyDataSetChanged();
} else {
List<Booking> booking = (List<Booking>)dbhelper.findNonCancelledBookings(username);
Collections.reverse(booking);
Booking[] bookings = new Booking[booking.size()];
bookings = booking.toArray(bookings);
mAdapter = new MyAdapter(bookings, Bookings.this);
@ -90,6 +96,7 @@ public class Bookings extends AppCompatActivity {
*/
@Override
public void onBackPressed(){
//goes back to the appropriate screen depending on the type of user
Intent intent;
if(dbhelper.findUserByUsername(username).getRole().equals("ServiceProvider")){
intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class);
@ -201,6 +208,8 @@ public class Bookings extends AppCompatActivity {
}
@Override
public void onClick(View view) {
//show different dialogs depending on the type of user
//Service Provider can confirm or cancel while Home Owner can rate and comment, or cancel
if(dbhelper.findUserByUsername(username).getRole()=="ServiceProvider"){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
alertDialogBuilder.setMessage("Cancel or Confirm your booking");
@ -259,7 +268,7 @@ public class Bookings extends AppCompatActivity {
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
else{
else{ //if user is a Home Owner
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
alertDialogBuilder.setView(R.layout.rating_item);
alertDialogBuilder.setPositiveButton("Rate Booking",
@ -275,9 +284,12 @@ public class Bookings extends AppCompatActivity {
month = Integer.parseInt(dates[0].replaceAll("\\s+",""));
day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
//rating bar
RadioGroup ratingselect = ((AlertDialog) arg0).findViewById(R.id.RatingSelect);
int selectedId = ratingselect.getCheckedRadioButtonId();
RadioButton ratingpicked;
//comment field
EditText comment = ((AlertDialog) arg0).findViewById(R.id.Comment);
if(selectedId!=-1 && !comment.getText().toString().equals("")){
ratingpicked = (RadioButton)((AlertDialog) arg0).findViewById(selectedId);
@ -340,6 +352,13 @@ public class Bookings extends AppCompatActivity {
}
/**
* formats the time into a string
* @param hours
* @param minutes
* @return
*/
private String formatTime(int hours, int minutes){
String time = "";
if(hours<10){
@ -356,7 +375,12 @@ public class Bookings extends AppCompatActivity {
return time;
}
/**
* Parses a string into an array of ints representing times
* @param startTime
* @param endTime
* @return
*/
private int[] parseTime(String startTime, String endTime){
int[] times = new int[4];
if(startTime.equals("START")){

View file

@ -54,6 +54,7 @@ public class FindServiceProvider extends AppCompatActivity {
dbHelper = new DBHelper(this);
MaterialSpinner spinner2 = findViewById(R.id.ServicesInput);
//populate the list of services
List<String[]> serviceslist = dbHelper.getAllServices();
String[] services = new String[(serviceslist.size())];
Iterator iter = serviceslist.iterator();
@ -74,7 +75,11 @@ public class FindServiceProvider extends AppCompatActivity {
//
}
/**
* 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(),Welcome.class);
@ -83,8 +88,11 @@ public class FindServiceProvider extends AppCompatActivity {
finish();
}
/**
* Reset the filter fields
* @param view
*/
public void Reset(View view){
Button button = findViewById(R.id.Start);
Button button2 = findViewById(R.id.End);
Button button3 = findViewById(R.id.Date);
@ -116,9 +124,9 @@ public class FindServiceProvider extends AppCompatActivity {
String date;
double rating;
List<String[]> providers;
//time and date picked
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
&& !button3.getText().toString().equals("Date")){
System.out.println(button.getText().toString()+":"+button2.getText().toString()+":"+button3.getText().toString());
start = button.getText().toString();
end = button2.getText().toString();
date = button3.getText().toString();
@ -137,16 +145,19 @@ public class FindServiceProvider extends AppCompatActivity {
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
int[] times = {starth, startmin, endh, endmin};
//rating picked and time valid
if(selectedId!=-1 && validateTime(times)){
ratingpicked = (RadioButton) findViewById(selectedId);
rating = Double.parseDouble(ratingpicked.getText().toString());
providers = dbHelper.getProvidersByTimeAndRating(service, rating, year, month, day,
starth, startmin, endh, endmin);
}
//rating not picked and time valid
else if(validateTime(times)){
providers = dbHelper.getProvidersByTime(service, year, month, day,
starth, startmin, endh, endmin);
}
//rating picked
else if(selectedId!=-1){
Toast.makeText(this, "Times are invalid, only searching by service and rating"+starth+";"+startmin+","+endh+";"+endmin, Toast.LENGTH_SHORT).show();
ratingpicked = (RadioButton) findViewById(selectedId);
@ -154,12 +165,14 @@ public class FindServiceProvider extends AppCompatActivity {
providers = dbHelper.getProvidersAboveRating(service, rating);
}
//no rating & time not valid
else{
Toast.makeText(this, "Times are invalid, only searching by service", Toast.LENGTH_SHORT).show();
providers = dbHelper.getAllProvidersByService(service);
}
}
//time and date not picked
else{
if(selectedId!=-1){
ratingpicked = (RadioButton) findViewById(selectedId);
@ -184,6 +197,10 @@ public class FindServiceProvider extends AppCompatActivity {
}
/**
* Go to the MakeBooking activity with the booking info
* @param serviceprovider
*/
public void makeBooking(String serviceprovider){
MaterialSpinner spinner = findViewById(R.id.ServicesInput);
String service = spinner.getText().toString();
@ -198,6 +215,10 @@ public class FindServiceProvider extends AppCompatActivity {
}
/**
* Show the DatePicker dialog
* @param view
*/
public void onClickDate(View view){
final Button button = (Button)view;
@ -236,7 +257,10 @@ public class FindServiceProvider extends AppCompatActivity {
}
/**
* Show the TimePicker dialog
* @param view
*/
public void onClickTime(View view){
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
@ -262,6 +286,12 @@ public class FindServiceProvider extends AppCompatActivity {
}
/**
* Format time into a string
* @param hours
* @param minutes
* @return
*/
private String formatTime(int hours, int minutes){
String time = "";
if(hours<10){
@ -278,6 +308,12 @@ public class FindServiceProvider extends AppCompatActivity {
return time;
}
/**
* Parse time into an array of ints
* @param startTime
* @param endTime
* @return
*/
private int[] parseTime(String startTime, String endTime){
int[] times = new int[4];
if(startTime.equals("START")){
@ -297,6 +333,11 @@ public class FindServiceProvider extends AppCompatActivity {
return times;
}
/**
* Validate times
* @param time
* @return
*/
private boolean validateTime(int[] time){
if(time[0]==0&&time[1]==0&&time[2]==0&&time[3]==0){
return true;
@ -312,7 +353,7 @@ public class FindServiceProvider extends AppCompatActivity {
}
}
//adapter for the recycler view
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ProviderHolder> {
private String[][] serviceProviders;
@ -372,11 +413,8 @@ public class FindServiceProvider extends AppCompatActivity {
final String name = nameview.getText().toString();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FindServiceProvider.this);
//show service provider info
alertDialogBuilder.setView(R.layout.sp_info_item);
alertDialogBuilder.setPositiveButton("Make Booking",
new DialogInterface.OnClickListener() {
@Override
@ -394,6 +432,8 @@ public class FindServiceProvider extends AppCompatActivity {
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
//set the service provider info
ServiceProvider sp = (ServiceProvider)dbHelper.findUserByUsername(name);
TextView spname = alertDialog.findViewById(R.id.NameName);
spname.setText(sp.getFirstname()+" "+sp.getLastname());
@ -438,7 +478,7 @@ public class FindServiceProvider extends AppCompatActivity {
ArrayAdapter adapter = new ArrayAdapter<String>(FindServiceProvider.this, R.layout.simple_list_item_1_customized, ratings);
//list of comments and ratings
ListView listView = (ListView) alertDialog.findViewById(R.id.RatingList);
listView.setAdapter(adapter);

View file

@ -39,7 +39,11 @@ public class MakeBooking extends AppCompatActivity {
serv.setText("Service: \n"+service);
}
/**
* 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(),Welcome.class);
@ -56,6 +60,7 @@ public class MakeBooking extends AppCompatActivity {
Button button2 = findViewById(R.id.End);
Button button3 = findViewById(R.id.Date);
//check that fields are filled in
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
&& !button3.getText().toString().equals("Date")){
String[] dates = button3.getText().toString().split("/");
@ -63,6 +68,7 @@ public class MakeBooking extends AppCompatActivity {
int day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
int year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
//parse times
String[] starttimes = button.getText().toString().split(":");
int starth = Integer.parseInt(starttimes[0].replaceAll("\\s+",""));
int startmin = Integer.parseInt(starttimes[1].replaceAll("\\s+",""));
@ -71,6 +77,7 @@ public class MakeBooking extends AppCompatActivity {
int endh = Integer.parseInt(endtimes[0].replaceAll("\\s+",""));
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
//check date is valid
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
@ -79,6 +86,7 @@ public class MakeBooking extends AppCompatActivity {
Toast.makeText(this, "Date must be a future date", Toast.LENGTH_SHORT).show();
}
else{
//check time is valid
if (starth<endh || (starth==endh && startmin<endmin)){
DBHelper dbHelper = new DBHelper(this);
@ -116,7 +124,7 @@ public class MakeBooking extends AppCompatActivity {
final Button button = (Button)view;
final Calendar c = Calendar.getInstance();
//show the date picker
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@ -173,6 +181,12 @@ public class MakeBooking extends AppCompatActivity {
}
/**
* formats the time into a string
* @param hours
* @param minutes
* @return
*/
private String formatTime(int hours, int minutes){
String time = "";
if(hours<10){
@ -189,6 +203,12 @@ public class MakeBooking extends AppCompatActivity {
return time;
}
/**
* Parses a string into an array of ints representing times
* @param startTime
* @param endTime
* @return
*/
private int[] parseTime(String startTime, String endTime){
int[] times = new int[4];
if(startTime.equals("START")){