fixed confirming and deleting bookings

This commit is contained in:
IvanaE 2018-12-01 17:42:28 -05:00
parent 8999a149cb
commit 7d3ef3bf92
2 changed files with 77 additions and 23 deletions

View file

@ -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;
}
}

View file

@ -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"
/>