Merge branch 'master' of https://github.com/ebivibe/SEG2105-Olympus into DBBranch
This commit is contained in:
commit
4d25a0c460
4 changed files with 112 additions and 25 deletions
|
@ -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> 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.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 +172,8 @@ public class Bookings extends AppCompatActivity {
|
|||
TextView start;
|
||||
TextView end;
|
||||
TextView status;
|
||||
String ho;
|
||||
String sp;
|
||||
int starth;
|
||||
int startmin;
|
||||
int endh;
|
||||
|
@ -165,6 +192,7 @@ public class Bookings extends AppCompatActivity {
|
|||
end = row.findViewById(R.id.EndTime);
|
||||
status = row.findViewById(R.id.StatusName);
|
||||
|
||||
|
||||
row.setOnClickListener(this);
|
||||
}
|
||||
@Override
|
||||
|
@ -176,10 +204,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 +231,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 +262,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 +278,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 +301,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 +351,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,20 @@
|
|||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:background="@drawable/background"
|
||||
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:id="@+id/Bookings"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="500dp"/>
|
||||
android:layout_height="450dp"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -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"
|
||||
/>
|
||||
|
|
|
@ -13,10 +13,11 @@
|
|||
<item name="android:textColor">@color/colorBlack</item>
|
||||
</style>
|
||||
|
||||
<style name="RatingBar" parent="Theme.AppCompat">
|
||||
<style name="Switch" parent="Theme.AppCompat">
|
||||
<item name="colorControlNormal">@color/colorWhite</item>
|
||||
<item name="colorControlActivated">@color/colorWhite</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue