added comments
This commit is contained in:
parent
b562598f3c
commit
add1965308
3 changed files with 99 additions and 15 deletions
|
@ -44,6 +44,7 @@ public class Bookings extends AppCompatActivity {
|
||||||
username = bundle.getString("username");
|
username = bundle.getString("username");
|
||||||
dbhelper = new DBHelper(this);
|
dbhelper = new DBHelper(this);
|
||||||
|
|
||||||
|
//get the list of bookings
|
||||||
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
|
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
|
||||||
Collections.reverse(booking);
|
Collections.reverse(booking);
|
||||||
Booking[] bookings = new Booking[booking.size()];
|
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"),
|
Booking[] bookings = {new Booking(5, 5, 6, 6, 2, 3, 2019, (ServiceProvider)dbhelper.findUserByUsername("testing"),
|
||||||
(HomeOwner)dbhelper.findUserByUsername("tester"), dbhelper.findService("service1"))};
|
(HomeOwner)dbhelper.findUserByUsername("tester"), dbhelper.findService("service1"))};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Make the recycler view show the bookings
|
||||||
mRecyclerView = (RecyclerView) findViewById(R.id.Bookings);
|
mRecyclerView = (RecyclerView) findViewById(R.id.Bookings);
|
||||||
mLayoutManager = new LinearLayoutManager(this);
|
mLayoutManager = new LinearLayoutManager(this);
|
||||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||||
mAdapter = new MyAdapter(bookings, this);
|
mAdapter = new MyAdapter(bookings, this);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
//remove or add cancelled booking depending on the switch position
|
||||||
SwitchCompat toggle = findViewById(R.id.Switch);
|
SwitchCompat toggle = findViewById(R.id.Switch);
|
||||||
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
|
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
|
||||||
|
Collections.reverse(booking);
|
||||||
Booking[] bookings = new Booking[booking.size()];
|
Booking[] bookings = new Booking[booking.size()];
|
||||||
bookings = booking.toArray(bookings);
|
bookings = booking.toArray(bookings);
|
||||||
mAdapter = new MyAdapter(bookings, Bookings.this);
|
mAdapter = new MyAdapter(bookings, Bookings.this);
|
||||||
|
@ -72,6 +77,7 @@ public class Bookings extends AppCompatActivity {
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
List<Booking> booking = (List<Booking>)dbhelper.findNonCancelledBookings(username);
|
List<Booking> booking = (List<Booking>)dbhelper.findNonCancelledBookings(username);
|
||||||
|
Collections.reverse(booking);
|
||||||
Booking[] bookings = new Booking[booking.size()];
|
Booking[] bookings = new Booking[booking.size()];
|
||||||
bookings = booking.toArray(bookings);
|
bookings = booking.toArray(bookings);
|
||||||
mAdapter = new MyAdapter(bookings, Bookings.this);
|
mAdapter = new MyAdapter(bookings, Bookings.this);
|
||||||
|
@ -90,6 +96,7 @@ public class Bookings extends AppCompatActivity {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed(){
|
public void onBackPressed(){
|
||||||
|
//goes back to the appropriate screen depending on the type of user
|
||||||
Intent intent;
|
Intent intent;
|
||||||
if(dbhelper.findUserByUsername(username).getRole().equals("ServiceProvider")){
|
if(dbhelper.findUserByUsername(username).getRole().equals("ServiceProvider")){
|
||||||
intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class);
|
intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class);
|
||||||
|
@ -201,6 +208,8 @@ public class Bookings extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
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"){
|
if(dbhelper.findUserByUsername(username).getRole()=="ServiceProvider"){
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
|
||||||
alertDialogBuilder.setMessage("Cancel or Confirm your booking");
|
alertDialogBuilder.setMessage("Cancel or Confirm your booking");
|
||||||
|
@ -259,7 +268,7 @@ public class Bookings extends AppCompatActivity {
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}
|
}
|
||||||
else{
|
else{ //if user is a Home Owner
|
||||||
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
|
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this);
|
||||||
alertDialogBuilder.setView(R.layout.rating_item);
|
alertDialogBuilder.setView(R.layout.rating_item);
|
||||||
alertDialogBuilder.setPositiveButton("Rate Booking",
|
alertDialogBuilder.setPositiveButton("Rate Booking",
|
||||||
|
@ -275,9 +284,12 @@ public class Bookings extends AppCompatActivity {
|
||||||
month = Integer.parseInt(dates[0].replaceAll("\\s+",""));
|
month = Integer.parseInt(dates[0].replaceAll("\\s+",""));
|
||||||
day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
|
day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
|
||||||
year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
|
year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
|
||||||
|
|
||||||
|
//rating bar
|
||||||
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;
|
||||||
|
//comment field
|
||||||
EditText comment = ((AlertDialog) arg0).findViewById(R.id.Comment);
|
EditText comment = ((AlertDialog) arg0).findViewById(R.id.Comment);
|
||||||
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);
|
||||||
|
@ -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){
|
private String formatTime(int hours, int minutes){
|
||||||
String time = "";
|
String time = "";
|
||||||
if(hours<10){
|
if(hours<10){
|
||||||
|
@ -356,7 +375,12 @@ public class Bookings extends AppCompatActivity {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a string into an array of ints representing times
|
||||||
|
* @param startTime
|
||||||
|
* @param endTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private int[] parseTime(String startTime, String endTime){
|
private int[] parseTime(String startTime, String endTime){
|
||||||
int[] times = new int[4];
|
int[] times = new int[4];
|
||||||
if(startTime.equals("START")){
|
if(startTime.equals("START")){
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
dbHelper = new DBHelper(this);
|
dbHelper = new DBHelper(this);
|
||||||
MaterialSpinner spinner2 = findViewById(R.id.ServicesInput);
|
MaterialSpinner spinner2 = findViewById(R.id.ServicesInput);
|
||||||
|
|
||||||
|
//populate the list of services
|
||||||
List<String[]> serviceslist = dbHelper.getAllServices();
|
List<String[]> serviceslist = dbHelper.getAllServices();
|
||||||
String[] services = new String[(serviceslist.size())];
|
String[] services = new String[(serviceslist.size())];
|
||||||
Iterator iter = serviceslist.iterator();
|
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
|
@Override
|
||||||
public void onBackPressed(){
|
public void onBackPressed(){
|
||||||
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
||||||
|
@ -83,8 +88,11 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the filter fields
|
||||||
|
* @param view
|
||||||
|
*/
|
||||||
public void Reset(View view){
|
public void Reset(View view){
|
||||||
|
|
||||||
Button button = findViewById(R.id.Start);
|
Button button = findViewById(R.id.Start);
|
||||||
Button button2 = findViewById(R.id.End);
|
Button button2 = findViewById(R.id.End);
|
||||||
Button button3 = findViewById(R.id.Date);
|
Button button3 = findViewById(R.id.Date);
|
||||||
|
@ -116,9 +124,9 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
String date;
|
String date;
|
||||||
double rating;
|
double rating;
|
||||||
List<String[]> providers;
|
List<String[]> providers;
|
||||||
|
//time and date picked
|
||||||
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
|
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
|
||||||
&& !button3.getText().toString().equals("Date")){
|
&& !button3.getText().toString().equals("Date")){
|
||||||
System.out.println(button.getText().toString()+":"+button2.getText().toString()+":"+button3.getText().toString());
|
|
||||||
start = button.getText().toString();
|
start = button.getText().toString();
|
||||||
end = button2.getText().toString();
|
end = button2.getText().toString();
|
||||||
date = button3.getText().toString();
|
date = button3.getText().toString();
|
||||||
|
@ -137,16 +145,19 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
|
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
|
||||||
|
|
||||||
int[] times = {starth, startmin, endh, endmin};
|
int[] times = {starth, startmin, endh, endmin};
|
||||||
|
//rating picked and time valid
|
||||||
if(selectedId!=-1 && validateTime(times)){
|
if(selectedId!=-1 && validateTime(times)){
|
||||||
ratingpicked = (RadioButton) findViewById(selectedId);
|
ratingpicked = (RadioButton) findViewById(selectedId);
|
||||||
rating = Double.parseDouble(ratingpicked.getText().toString());
|
rating = Double.parseDouble(ratingpicked.getText().toString());
|
||||||
providers = dbHelper.getProvidersByTimeAndRating(service, rating, year, month, day,
|
providers = dbHelper.getProvidersByTimeAndRating(service, rating, year, month, day,
|
||||||
starth, startmin, endh, endmin);
|
starth, startmin, endh, endmin);
|
||||||
}
|
}
|
||||||
|
//rating not picked and time valid
|
||||||
else if(validateTime(times)){
|
else if(validateTime(times)){
|
||||||
providers = dbHelper.getProvidersByTime(service, year, month, day,
|
providers = dbHelper.getProvidersByTime(service, year, month, day,
|
||||||
starth, startmin, endh, endmin);
|
starth, startmin, endh, endmin);
|
||||||
}
|
}
|
||||||
|
//rating picked
|
||||||
else if(selectedId!=-1){
|
else if(selectedId!=-1){
|
||||||
Toast.makeText(this, "Times are invalid, only searching by service and rating"+starth+";"+startmin+","+endh+";"+endmin, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Times are invalid, only searching by service and rating"+starth+";"+startmin+","+endh+";"+endmin, Toast.LENGTH_SHORT).show();
|
||||||
ratingpicked = (RadioButton) findViewById(selectedId);
|
ratingpicked = (RadioButton) findViewById(selectedId);
|
||||||
|
@ -154,12 +165,14 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
providers = dbHelper.getProvidersAboveRating(service, rating);
|
providers = dbHelper.getProvidersAboveRating(service, rating);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//no rating & time not valid
|
||||||
else{
|
else{
|
||||||
Toast.makeText(this, "Times are invalid, only searching by service", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Times are invalid, only searching by service", Toast.LENGTH_SHORT).show();
|
||||||
providers = dbHelper.getAllProvidersByService(service);
|
providers = dbHelper.getAllProvidersByService(service);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//time and date not picked
|
||||||
else{
|
else{
|
||||||
if(selectedId!=-1){
|
if(selectedId!=-1){
|
||||||
ratingpicked = (RadioButton) findViewById(selectedId);
|
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){
|
public void makeBooking(String serviceprovider){
|
||||||
MaterialSpinner spinner = findViewById(R.id.ServicesInput);
|
MaterialSpinner spinner = findViewById(R.id.ServicesInput);
|
||||||
String service = spinner.getText().toString();
|
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){
|
public void onClickDate(View view){
|
||||||
|
|
||||||
final Button button = (Button)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){
|
public void onClickTime(View view){
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
int hour = c.get(Calendar.HOUR_OF_DAY);
|
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){
|
private String formatTime(int hours, int minutes){
|
||||||
String time = "";
|
String time = "";
|
||||||
if(hours<10){
|
if(hours<10){
|
||||||
|
@ -278,6 +308,12 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse time into an array of ints
|
||||||
|
* @param startTime
|
||||||
|
* @param endTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private int[] parseTime(String startTime, String endTime){
|
private int[] parseTime(String startTime, String endTime){
|
||||||
int[] times = new int[4];
|
int[] times = new int[4];
|
||||||
if(startTime.equals("START")){
|
if(startTime.equals("START")){
|
||||||
|
@ -297,6 +333,11 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
return times;
|
return times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate times
|
||||||
|
* @param time
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private boolean validateTime(int[] time){
|
private boolean validateTime(int[] time){
|
||||||
if(time[0]==0&&time[1]==0&&time[2]==0&&time[3]==0){
|
if(time[0]==0&&time[1]==0&&time[2]==0&&time[3]==0){
|
||||||
return true;
|
return true;
|
||||||
|
@ -312,7 +353,7 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//adapter for the recycler view
|
||||||
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ProviderHolder> {
|
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ProviderHolder> {
|
||||||
|
|
||||||
private String[][] serviceProviders;
|
private String[][] serviceProviders;
|
||||||
|
@ -372,11 +413,8 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
final String name = nameview.getText().toString();
|
final String name = nameview.getText().toString();
|
||||||
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FindServiceProvider.this);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FindServiceProvider.this);
|
||||||
|
//show service provider info
|
||||||
|
|
||||||
alertDialogBuilder.setView(R.layout.sp_info_item);
|
alertDialogBuilder.setView(R.layout.sp_info_item);
|
||||||
|
|
||||||
|
|
||||||
alertDialogBuilder.setPositiveButton("Make Booking",
|
alertDialogBuilder.setPositiveButton("Make Booking",
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -394,6 +432,8 @@ public class FindServiceProvider extends AppCompatActivity {
|
||||||
|
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
|
|
||||||
|
//set the service provider info
|
||||||
ServiceProvider sp = (ServiceProvider)dbHelper.findUserByUsername(name);
|
ServiceProvider sp = (ServiceProvider)dbHelper.findUserByUsername(name);
|
||||||
TextView spname = alertDialog.findViewById(R.id.NameName);
|
TextView spname = alertDialog.findViewById(R.id.NameName);
|
||||||
spname.setText(sp.getFirstname()+" "+sp.getLastname());
|
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);
|
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 listView = (ListView) alertDialog.findViewById(R.id.RatingList);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,11 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
serv.setText("Service: \n"+service);
|
serv.setText("Service: \n"+service);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Override so that previous screen refreshes when pressing the
|
||||||
|
* back button on this activity of the app.
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed(){
|
public void onBackPressed(){
|
||||||
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
Intent intent = new Intent(getApplicationContext(),Welcome.class);
|
||||||
|
@ -56,6 +60,7 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
Button button2 = findViewById(R.id.End);
|
Button button2 = findViewById(R.id.End);
|
||||||
Button button3 = findViewById(R.id.Date);
|
Button button3 = findViewById(R.id.Date);
|
||||||
|
|
||||||
|
//check that fields are filled in
|
||||||
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
|
if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End")
|
||||||
&& !button3.getText().toString().equals("Date")){
|
&& !button3.getText().toString().equals("Date")){
|
||||||
String[] dates = button3.getText().toString().split("/");
|
String[] dates = button3.getText().toString().split("/");
|
||||||
|
@ -63,6 +68,7 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
int day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
|
int day = Integer.parseInt(dates[1].replaceAll("\\s+",""));
|
||||||
int year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
|
int year = Integer.parseInt(dates[2].replaceAll("\\s+",""));
|
||||||
|
|
||||||
|
//parse times
|
||||||
String[] starttimes = button.getText().toString().split(":");
|
String[] starttimes = button.getText().toString().split(":");
|
||||||
int starth = Integer.parseInt(starttimes[0].replaceAll("\\s+",""));
|
int starth = Integer.parseInt(starttimes[0].replaceAll("\\s+",""));
|
||||||
int startmin = Integer.parseInt(starttimes[1].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 endh = Integer.parseInt(endtimes[0].replaceAll("\\s+",""));
|
||||||
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
|
int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+",""));
|
||||||
|
|
||||||
|
//check date is valid
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
try {
|
try {
|
||||||
|
@ -79,6 +86,7 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
Toast.makeText(this, "Date must be a future date", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Date must be a future date", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
//check time is valid
|
||||||
if (starth<endh || (starth==endh && startmin<endmin)){
|
if (starth<endh || (starth==endh && startmin<endmin)){
|
||||||
DBHelper dbHelper = new DBHelper(this);
|
DBHelper dbHelper = new DBHelper(this);
|
||||||
|
|
||||||
|
@ -116,7 +124,7 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
|
|
||||||
final Button button = (Button)view;
|
final Button button = (Button)view;
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
|
//show the date picker
|
||||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||||
new DatePickerDialog.OnDateSetListener() {
|
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){
|
private String formatTime(int hours, int minutes){
|
||||||
String time = "";
|
String time = "";
|
||||||
if(hours<10){
|
if(hours<10){
|
||||||
|
@ -189,6 +203,12 @@ public class MakeBooking extends AppCompatActivity {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a string into an array of ints representing times
|
||||||
|
* @param startTime
|
||||||
|
* @param endTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private int[] parseTime(String startTime, String endTime){
|
private int[] parseTime(String startTime, String endTime){
|
||||||
int[] times = new int[4];
|
int[] times = new int[4];
|
||||||
if(startTime.equals("START")){
|
if(startTime.equals("START")){
|
||||||
|
|
Loading…
Reference in a new issue