From 11e8fa677f9dfea4a6b85a21bb32f12a1252dd85 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Sat, 1 Dec 2018 17:42:28 -0500 Subject: [PATCH 1/2] fixed confirming and deleting bookings --- .../olympus/olympusservices/Bookings.java | 96 +++++++++++++++---- .../src/main/res/layout/booking_list_item.xml | 4 +- 2 files changed, 77 insertions(+), 23 deletions(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java index c7b38ca..033e8b4 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java @@ -128,6 +128,8 @@ public class Bookings extends AppCompatActivity { holder.start.setText(formatTime(booking.getStarth(), booking.getStartmin())); holder.end.setText(formatTime(booking.getEndh(), booking.getEndmin())); holder.status.setText(booking.getStatus().toString()); + holder.ho = booking.getHomeowner().getUsername(); + holder.sp = booking.getServiceprovider().getUsername(); } @@ -147,6 +149,8 @@ public class Bookings extends AppCompatActivity { TextView start; TextView end; TextView status; + String ho; + String sp; int starth; int startmin; int endh; @@ -165,6 +169,7 @@ public class Bookings extends AppCompatActivity { end = row.findViewById(R.id.EndTime); status = row.findViewById(R.id.StatusName); + row.setOnClickListener(this); } @Override @@ -176,10 +181,18 @@ public class Bookings extends AppCompatActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { - if(dbhelper.confirmBooking(new Booking(starth, startmin, endh, endmin, day, month, - year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), - (HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), - dbhelper.findService(service.getText().toString())))){ + int[] times = parseTime(start.getText().toString(), end.getText().toString()); + starth = times[0]; + startmin = times[1]; + endh = times[2]; + endmin = times[3]; + String[] dates = date.getText().toString().split("/"); + month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + year = Integer.parseInt(dates[2].replaceAll("\\s+","")); + if(dbhelper.confirmBooking(new Booking(starth, startmin, endh, endmin, day, month, year, (ServiceProvider)dbhelper.findUserByUsername(sp), + (HomeOwner)dbhelper.findUserByUsername(ho), + new Service(service.getText().toString(), 5)))){ Toast.makeText(Bookings.this,"Booking is confirmed",Toast.LENGTH_LONG).show(); Bookings.this.recreate(); @@ -195,10 +208,18 @@ public class Bookings extends AppCompatActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(dbhelper.cancelBooking(new Booking(starth, startmin, endh, endmin, day, month, - year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), - (HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), - dbhelper.findService(service.getText().toString())))){ + int[] times = parseTime(start.getText().toString(), end.getText().toString()); + starth = times[0]; + startmin = times[1]; + endh = times[2]; + endmin = times[3]; + String[] dates = date.getText().toString().split("/"); + month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + year = Integer.parseInt(dates[2].replaceAll("\\s+","")); + if(dbhelper.cancelBooking(new Booking(starth, startmin, endh, endmin, day, month, year, (ServiceProvider)dbhelper.findUserByUsername(sp), + (HomeOwner)dbhelper.findUserByUsername(ho), + new Service(service.getText().toString(), 5)))){ Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show(); Bookings.this.recreate(); } @@ -218,6 +239,15 @@ public class Bookings extends AppCompatActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { + int[] times = parseTime(start.getText().toString(), end.getText().toString()); + starth = times[0]; + startmin = times[1]; + endh = times[2]; + endmin = times[3]; + String[] dates = date.getText().toString().split("/"); + month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + year = Integer.parseInt(dates[2].replaceAll("\\s+","")); RadioGroup ratingselect = ((AlertDialog) arg0).findViewById(R.id.RatingSelect); int selectedId = ratingselect.getCheckedRadioButtonId(); RadioButton ratingpicked; @@ -225,17 +255,12 @@ public class Bookings extends AppCompatActivity { if(selectedId!=-1 && !comment.getText().toString().equals("")){ ratingpicked = (RadioButton)((AlertDialog) arg0).findViewById(selectedId); double rating = Double.parseDouble(ratingpicked.getText().toString()); - /*Booking booking = new Booking(starth, startmin, endh, endmin, day, month, - year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), - (HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), - dbhelper.findService(service.getText().toString())); - */ - Booking booking = new Booking(starth, startmin, endh, endmin, day, month, year, new ServiceProvider(serviceprovider.getText().toString(), - "", "", "", "", "", "", true), - new HomeOwner(homeowner.getText().toString(), "", "", ""), + + Booking booking = new Booking(starth, startmin, endh, endmin, day, month, year, (ServiceProvider)dbhelper.findUserByUsername(sp), + (HomeOwner)dbhelper.findUserByUsername(ho), new Service(service.getText().toString(), 5)); if(!dbhelper.addRating(booking, rating, comment.getText().toString())){ - Toast.makeText(Bookings.this, "Rating could not be added", Toast.LENGTH_SHORT).show(); + Toast.makeText(Bookings.this, "Rating cannot be added before the appointment", Toast.LENGTH_SHORT).show(); } else{ Bookings.this.recreate(); @@ -253,10 +278,19 @@ public class Bookings extends AppCompatActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(dbhelper.cancelBooking(new Booking(starth, startmin, endh, endmin, day, month, - year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), - (HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), - dbhelper.findService(service.getText().toString())))){ + + int[] times = parseTime(start.getText().toString(), end.getText().toString()); + starth = times[0]; + startmin = times[1]; + endh = times[2]; + endmin = times[3]; + String[] dates = date.getText().toString().split("/"); + month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + year = Integer.parseInt(dates[2].replaceAll("\\s+","")); + if(dbhelper.cancelBooking(new Booking(starth, startmin, endh, endmin, day, month, year, (ServiceProvider)dbhelper.findUserByUsername(sp), + (HomeOwner)dbhelper.findUserByUsername(ho), + new Service(service.getText().toString(), 5)))){ Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show(); Bookings.this.recreate(); } @@ -294,4 +328,24 @@ public class Bookings extends AppCompatActivity { } return time; } + + + private int[] parseTime(String startTime, String endTime){ + int[] times = new int[4]; + if(startTime.equals("START")){ + times[0]=0; + times[1]=0; + }else{ + times[0] = Integer.parseInt(startTime.substring(0,2)); + times[1] = Integer.parseInt(startTime.substring(3)); + } + if(endTime.equals("END")){ + times[2]=0; + times[3]=0; + }else{ + times[2] = Integer.parseInt(endTime.substring(0,2)); + times[3] = Integer.parseInt(endTime.substring(3)); + } + return times; + } } diff --git a/OlympusServices/app/src/main/res/layout/booking_list_item.xml b/OlympusServices/app/src/main/res/layout/booking_list_item.xml index 07a4451..3ce86bb 100644 --- a/OlympusServices/app/src/main/res/layout/booking_list_item.xml +++ b/OlympusServices/app/src/main/res/layout/booking_list_item.xml @@ -142,7 +142,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:text="Start" + android:text="" android:textColor="@color/colorBlack" android:textSize="15sp" /> @@ -163,7 +163,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:text="End" + android:text="" android:textColor="@color/colorBlack" android:textSize="15sp" /> From b2c33cea8e900571ae9892a5a3a1fa63d50f2c9c Mon Sep 17 00:00:00 2001 From: IvanaE Date: Sat, 1 Dec 2018 18:09:28 -0500 Subject: [PATCH 2/2] added show cancelled optional --- .../olympus/olympusservices/Bookings.java | 23 +++++++++++++++++++ .../src/main/res/layout/activity_bookings.xml | 11 ++++++++- .../app/src/main/res/values/styles.xml | 3 ++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java index 033e8b4..5c79c9d 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java @@ -9,9 +9,11 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SwitchCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; @@ -54,6 +56,27 @@ public class Bookings extends AppCompatActivity { mAdapter = new MyAdapter(bookings, this); mRecyclerView.setAdapter(mAdapter); + SwitchCompat toggle = findViewById(R.id.Switch); + toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List booking = (List)dbhelper.findBookings(username); + Booking[] bookings = new Booking[booking.size()]; + bookings = booking.toArray(bookings); + mAdapter = new MyAdapter(bookings, Bookings.this); + mRecyclerView.setAdapter(mAdapter); + mAdapter.notifyDataSetChanged(); + } else { + List booking = (List)dbhelper.findNonCancelledBookings(username); + Booking[] bookings = new Booking[booking.size()]; + bookings = booking.toArray(bookings); + mAdapter = new MyAdapter(bookings, Bookings.this); + mRecyclerView.setAdapter(mAdapter); + mAdapter.notifyDataSetChanged(); + } + } + }); + } /** diff --git a/OlympusServices/app/src/main/res/layout/activity_bookings.xml b/OlympusServices/app/src/main/res/layout/activity_bookings.xml index eb704f7..334eb60 100644 --- a/OlympusServices/app/src/main/res/layout/activity_bookings.xml +++ b/OlympusServices/app/src/main/res/layout/activity_bookings.xml @@ -12,11 +12,20 @@ android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/background" tools:context=".Bookings"> + + android:layout_height="450dp"/> \ No newline at end of file diff --git a/OlympusServices/app/src/main/res/values/styles.xml b/OlympusServices/app/src/main/res/values/styles.xml index 4b78444..be9729a 100644 --- a/OlympusServices/app/src/main/res/values/styles.xml +++ b/OlympusServices/app/src/main/res/values/styles.xml @@ -13,10 +13,11 @@ @color/colorBlack - +