Merge branch 'master' of https://github.com/ebivibe/SEG2105-Olympus into DBBranch

This commit is contained in:
Mary Tran 2018-12-01 21:57:17 -05:00
commit 4d25a0c460
4 changed files with 112 additions and 25 deletions

View file

@ -9,9 +9,11 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
@ -54,6 +56,27 @@ public class Bookings extends AppCompatActivity {
mAdapter = new MyAdapter(bookings, this); mAdapter = new MyAdapter(bookings, this);
mRecyclerView.setAdapter(mAdapter); 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> booking = (List<Booking>)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> booking = (List<Booking>)dbhelper.findNonCancelledBookings(username);
Booking[] bookings = new Booking[booking.size()];
bookings = booking.toArray(bookings);
mAdapter = new MyAdapter(bookings, Bookings.this);
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
}
});
} }
/** /**
@ -128,6 +151,8 @@ public class Bookings extends AppCompatActivity {
holder.start.setText(formatTime(booking.getStarth(), booking.getStartmin())); holder.start.setText(formatTime(booking.getStarth(), booking.getStartmin()));
holder.end.setText(formatTime(booking.getEndh(), booking.getEndmin())); holder.end.setText(formatTime(booking.getEndh(), booking.getEndmin()));
holder.status.setText(booking.getStatus().toString()); holder.status.setText(booking.getStatus().toString());
holder.ho = booking.getHomeowner().getUsername();
holder.sp = booking.getServiceprovider().getUsername();
} }
@ -147,6 +172,8 @@ public class Bookings extends AppCompatActivity {
TextView start; TextView start;
TextView end; TextView end;
TextView status; TextView status;
String ho;
String sp;
int starth; int starth;
int startmin; int startmin;
int endh; int endh;
@ -165,6 +192,7 @@ public class Bookings extends AppCompatActivity {
end = row.findViewById(R.id.EndTime); end = row.findViewById(R.id.EndTime);
status = row.findViewById(R.id.StatusName); status = row.findViewById(R.id.StatusName);
row.setOnClickListener(this); row.setOnClickListener(this);
} }
@Override @Override
@ -176,10 +204,18 @@ public class Bookings extends AppCompatActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface arg0, int arg1) { public void onClick(DialogInterface arg0, int arg1) {
if(dbhelper.confirmBooking(new Booking(starth, startmin, endh, endmin, day, month, int[] times = parseTime(start.getText().toString(), end.getText().toString());
year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), starth = times[0];
(HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), startmin = times[1];
dbhelper.findService(service.getText().toString())))){ 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(); Toast.makeText(Bookings.this,"Booking is confirmed",Toast.LENGTH_LONG).show();
Bookings.this.recreate(); Bookings.this.recreate();
@ -195,10 +231,18 @@ public class Bookings extends AppCompatActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(dbhelper.cancelBooking(new Booking(starth, startmin, endh, endmin, day, month, int[] times = parseTime(start.getText().toString(), end.getText().toString());
year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), starth = times[0];
(HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), startmin = times[1];
dbhelper.findService(service.getText().toString())))){ 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(); Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show();
Bookings.this.recreate(); Bookings.this.recreate();
} }
@ -218,6 +262,15 @@ public class Bookings extends AppCompatActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface arg0, int arg1) { 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); RadioGroup ratingselect = ((AlertDialog) arg0).findViewById(R.id.RatingSelect);
int selectedId = ratingselect.getCheckedRadioButtonId(); int selectedId = ratingselect.getCheckedRadioButtonId();
RadioButton ratingpicked; RadioButton ratingpicked;
@ -225,17 +278,12 @@ public class Bookings extends AppCompatActivity {
if(selectedId!=-1 && !comment.getText().toString().equals("")){ if(selectedId!=-1 && !comment.getText().toString().equals("")){
ratingpicked = (RadioButton)((AlertDialog) arg0).findViewById(selectedId); ratingpicked = (RadioButton)((AlertDialog) arg0).findViewById(selectedId);
double rating = Double.parseDouble(ratingpicked.getText().toString()); double rating = Double.parseDouble(ratingpicked.getText().toString());
/*Booking booking = new Booking(starth, startmin, endh, endmin, day, month,
year, (ServiceProvider)dbhelper.findUserByUsername(serviceprovider.getText().toString()), Booking booking = new Booking(starth, startmin, endh, endmin, day, month, year, (ServiceProvider)dbhelper.findUserByUsername(sp),
(HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), (HomeOwner)dbhelper.findUserByUsername(ho),
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(), "", "", ""),
new Service(service.getText().toString(), 5)); new Service(service.getText().toString(), 5));
if(!dbhelper.addRating(booking, rating, comment.getText().toString())){ 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{ else{
Bookings.this.recreate(); Bookings.this.recreate();
@ -253,10 +301,19 @@ public class Bookings extends AppCompatActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { 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()), int[] times = parseTime(start.getText().toString(), end.getText().toString());
(HomeOwner)dbhelper.findUserByUsername(homeowner.getText().toString()), starth = times[0];
dbhelper.findService(service.getText().toString())))){ 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(); Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show();
Bookings.this.recreate(); Bookings.this.recreate();
} }
@ -294,4 +351,24 @@ public class Bookings extends AppCompatActivity {
} }
return time; 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

@ -12,11 +12,20 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background" android:background="@drawable/background"
tools:context=".Bookings"> tools:context=".Bookings">
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show cancelled bookings"
android:id="@+id/Switch"
android:checked="true"
android:theme="@style/Switch"
android:layout_marginBottom="10dp"
android:textColor="@color/colorWhite"/>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/Bookings" android:id="@+id/Bookings"
android:scrollbars="vertical" android:scrollbars="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="500dp"/> android:layout_height="450dp"/>
</LinearLayout> </LinearLayout>

View file

@ -142,7 +142,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="Start" android:text=""
android:textColor="@color/colorBlack" android:textColor="@color/colorBlack"
android:textSize="15sp" android:textSize="15sp"
/> />
@ -163,7 +163,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="End" android:text=""
android:textColor="@color/colorBlack" android:textColor="@color/colorBlack"
android:textSize="15sp" android:textSize="15sp"
/> />

View file

@ -13,10 +13,11 @@
<item name="android:textColor">@color/colorBlack</item> <item name="android:textColor">@color/colorBlack</item>
</style> </style>
<style name="RatingBar" parent="Theme.AppCompat"> <style name="Switch" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/colorWhite</item> <item name="colorControlNormal">@color/colorWhite</item>
<item name="colorControlActivated">@color/colorWhite</item> <item name="colorControlActivated">@color/colorWhite</item>
</style> </style>
</resources> </resources>