diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index 53e0a9f..66d481e 100644 Binary files a/OlympusServices/.idea/caches/build_file_checksums.ser and b/OlympusServices/.idea/caches/build_file_checksums.ser differ 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 f0a94d0..5577ecc 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 @@ -7,10 +7,13 @@ import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; @@ -34,15 +37,16 @@ public class Bookings extends AppCompatActivity { username = bundle.getString("username"); dbhelper = new DBHelper(this); - /* - Booking[] bookings; - //get bookings here + //Booking[] bookings = (Booking[])dbhelper.findBookings(username).toArray(); + + Booking[] testbooking = {new Booking(5, 5, 6, 6, 2, 3, 2019, (ServiceProvider)dbhelper.findUserByUsername("testing"), + (HomeOwner)dbhelper.findUserByUsername("tester"), dbhelper.findService("service1"))}; mRecyclerView = (RecyclerView) findViewById(R.id.Bookings); mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); - mAdapter = new AdminServicesList.MyAdapter(booking, this); + mAdapter = new MyAdapter(testbooking, this); mRecyclerView.setAdapter(mAdapter); - */ + } /** @@ -52,7 +56,14 @@ public class Bookings extends AppCompatActivity { */ @Override public void onBackPressed(){ - Intent intent = new Intent(getApplicationContext(),Welcome.class); + Intent intent; + if(dbhelper.findUserByUsername(username).getRole().equals("ServiceProvider")){ + intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + } + else{ + intent = new Intent(getApplicationContext(),Welcome.class); + } + intent.putExtra("username", username); startActivity(intent); finish(); @@ -87,8 +98,29 @@ public class Bookings extends AppCompatActivity { @Override public void onBindViewHolder(BookingHolder holder, int position) { Booking booking = bookings[position]; - //holder.name.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); + holder.serviceprovider.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); + holder.homeowner.setText(booking.getHomeowner().getFirstname()+" "+booking.getHomeowner().getLastname()); + holder.service.setText(booking.getService().getName()); + String day; + String month; + String year = booking.getYear()+""; + if(booking.getDay()<10){ + day = "0"+booking.getDay(); + } + else{ + day = booking.getDay()+""; + } + if(booking.getMonth()<10){ + month = "0"+booking.getMonth(); + } + else{ + month = booking.getMonth()+""; + } + holder.date.setText(month+"/"+day+"/"+year); + holder.start.setText(formatTime(booking.getStarth(), booking.getStartmin())); + holder.end.setText(formatTime(booking.getEndh(), booking.getEndmin())); + holder.status.setText(booking.getStatus().toString()); } @@ -103,15 +135,24 @@ public class Bookings extends AppCompatActivity { TextView homeowner; TextView serviceprovider; + TextView service; TextView date; TextView start; TextView end; TextView status; + int starth; + int startmin; + int endh; + int endmin; + int month; + int day; + int year; public BookingHolder(View row){ super(row); homeowner = row.findViewById(R.id.HomeOwnerName); serviceprovider = row.findViewById(R.id.ServiceProviderName); + service = row.findViewById(R.id.ServiceName); date = row.findViewById(R.id.DateName); start = row.findViewById(R.id.StartTime); end = row.findViewById(R.id.EndTime); @@ -124,23 +165,38 @@ public class Bookings extends AppCompatActivity { if(dbhelper.findUserByUsername(username).getRole()=="ServiceProvider"){ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this); alertDialogBuilder.setMessage("Cancel or Confirm your booking"); - alertDialogBuilder.setPositiveButton("Confirm", + alertDialogBuilder.setPositiveButton("Confirm Booking", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { - //confirm booking - Toast.makeText(Bookings.this,"Booking is confirmed",Toast.LENGTH_LONG).show(); - Bookings.this.recreate(); + 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())))){ + Toast.makeText(Bookings.this,"Booking is confirmed",Toast.LENGTH_LONG).show(); + Bookings.this.recreate(); + } + else{ + Toast.makeText(Bookings.this,"Booking could not be confirmed",Toast.LENGTH_LONG).show(); + } + } }); - alertDialogBuilder.setNegativeButton("No", + alertDialogBuilder.setNegativeButton("Cancel Booking", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - //delete booking - Toast.makeText(Bookings.this,"Booking is deleted",Toast.LENGTH_LONG).show(); - Bookings.this.recreate(); + 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())))){ + Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show(); + Bookings.this.recreate(); + } + else{ + Toast.makeText(Bookings.this,"Booking could not be cancelled",Toast.LENGTH_LONG).show(); + } } }); @@ -148,23 +204,48 @@ public class Bookings extends AppCompatActivity { alertDialog.show(); } else{ - AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this); - alertDialogBuilder.setMessage("Are you sure you want to cancel your booking"); - alertDialogBuilder.setPositiveButton("Cancel", + final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this); + alertDialogBuilder.setView(R.layout.rating_item); + alertDialogBuilder.setPositiveButton("Rate Booking", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { - //cancel booking - Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show(); - Bookings.this.recreate(); + RadioGroup ratingselect = ((AlertDialog) arg0).findViewById(R.id.RatingSelect); + int selectedId = ratingselect.getCheckedRadioButtonId(); + RadioButton ratingpicked; + if(selectedId!=-1){ + 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()));; + if(!dbhelper.addRating(booking, rating)){ + Toast.makeText(context, "Rating could not be added", Toast.LENGTH_SHORT).show(); + } + else{ + Bookings.this.recreate(); + } + + } + } }); - alertDialogBuilder.setNegativeButton("Nevermind", + alertDialogBuilder.setNegativeButton("Cancel Booking", 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())))){ + Toast.makeText(Bookings.this,"Booking is cancelled",Toast.LENGTH_LONG).show(); + Bookings.this.recreate(); + } + else{ + Toast.makeText(Bookings.this,"Booking could not be cancelled",Toast.LENGTH_LONG).show(); + } } }); @@ -181,4 +262,19 @@ public class Bookings extends AppCompatActivity { } + private String formatTime(int hours, int minutes){ + String time = ""; + if(hours<10){ + time = time+"0"+hours+":"; + }else{ + time = time+hours+":"; + } + if (minutes<10){ + time = time+"0"+minutes; + } + else { + time = time+minutes; + } + return time; + } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java index 8448b52..b72bfe7 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java @@ -1308,7 +1308,7 @@ public class DBHelper extends SQLiteOpenHelper { List providers = getAll("SELECT " + TABLE_SERVICEPROVIDERS + "." + COLUMN_SERVICEPROVIDERNAME + ", " + TABLE_LOGIN + "." + COLUMN_FIRSTNAME + ", " + TABLE_LOGIN + "." + COLUMN_LASTNAME + ", " - + TABLE_SERVICEPROVIDERS + "." + COLUMN_AVERAGERATING + ", " + + TABLE_SERVICEPROVIDERS + "." + COLUMN_AVERAGERATING + " " + " FROM " + TABLE_SERVICEPROVIDERS + " JOIN " + TABLE_LOGIN + " ON " + TABLE_SERVICEPROVIDERS + "." + COLUMN_SERVICEPROVIDERNAME + " = " + TABLE_LOGIN + "." + COLUMN_USERNAME diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java index d29783f..1f526c7 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/FindServiceProvider.java @@ -15,6 +15,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.DatePicker; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.RatingBar; import android.widget.TextView; import android.widget.TimePicker; @@ -44,8 +46,6 @@ public class FindServiceProvider extends AppCompatActivity { Bundle bundle = getIntent().getExtras(); username = bundle.getString("username"); - MaterialSpinner spinner = findViewById(R.id.RatingInput); - spinner.setItems("",1, 2, 3, 4, 5); dbHelper = new DBHelper(this); MaterialSpinner spinner2 = findViewById(R.id.ServicesInput); @@ -60,19 +60,13 @@ public class FindServiceProvider extends AppCompatActivity { spinner2.setItems(services); - //iffy code, update once we can pull the actual service providers - ServiceProvider provider = (ServiceProvider)dbHelper.findUserByUsername("testing"); - ServiceProvider[] providerslist = {provider}; - //iffy code ends here - mRecyclerView = (RecyclerView) findViewById(R.id.ServiceProviders); mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); - mAdapter = new MyAdapter(providerslist, this); - mRecyclerView.setAdapter(mAdapter); + // } @@ -89,31 +83,81 @@ public class FindServiceProvider extends AppCompatActivity { Button button = findViewById(R.id.Start); Button button2 = findViewById(R.id.End); Button button3 = findViewById(R.id.Date); - MaterialSpinner spinner2 = findViewById(R.id.RatingInput); + RadioGroup ratingselect = findViewById(R.id.RatingSelect); + int selectedId = ratingselect.getCheckedRadioButtonId(); + RadioButton ratingpicked; String service = spinner.getText().toString(); - int start; - int end; + String start; + String end; String date; - if(button.getText().toString()!="Start" && button.getText().toString()!="End" - && button3.getText().toString()!="Date"){ - start = Integer.parseInt(button.getText().toString()); - end = Integer.parseInt(button2.getText().toString()); + double rating; + List providers; + if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End") + && !button3.getText().toString().equals("Date")){ + System.out.println(button.getText().toString()+":"+button2.getText().toString()+":"+button3.getText().toString()); + start = button.getText().toString(); + end = button2.getText().toString(); date = button3.getText().toString(); + + String[] dates = date.split("/"); + int month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + int day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + int year = Integer.parseInt(dates[2].replaceAll("\\s+","")); + + String[] starttimes = start.split(":"); + int starth = Integer.parseInt(starttimes[0].replaceAll("\\s+","")); + int startmin = Integer.parseInt(starttimes[1].replaceAll("\\s+","")); + + String[] endtimes = end.split(":"); + int endh = Integer.parseInt(endtimes[0].replaceAll("\\s+","")); + int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+","")); + + int[] times = {starth, startmin, endh, endmin}; + if(selectedId!=-1 && validateTime(times)){ + ratingpicked = (RadioButton) findViewById(selectedId); + rating = Double.parseDouble(ratingpicked.getText().toString()); + providers = dbHelper.getProvidersByTimeAndRating(service, rating, year, month, day, + starth, startmin, endh, endmin); + } + else if(validateTime(times)){ + providers = dbHelper.getProvidersByTime(service, year, month, day, + starth, startmin, endh, endmin); + } + else if(selectedId!=-1){ + Toast.makeText(this, "Times are invalid, only searching by service and rating"+starth+";"+startmin+","+endh+";"+endmin, Toast.LENGTH_SHORT).show(); + ratingpicked = (RadioButton) findViewById(selectedId); + rating = Double.parseDouble(ratingpicked.getText().toString()); + providers = dbHelper.getProvidersAboveRating(service, rating); + + } + else{ + Toast.makeText(this, "Times are invalid, only searching by service", Toast.LENGTH_SHORT).show(); + providers = dbHelper.getAllProvidersByService(service); + + } } else{ - //figure out with dbhelper + if(selectedId!=-1){ + ratingpicked = (RadioButton) findViewById(selectedId); + rating = Double.parseDouble(ratingpicked.getText().toString()); + providers = dbHelper.getProvidersAboveRating(service, rating); + } + else{ + providers = dbHelper.getAllProvidersByService(service); + } } - int rating; - if(spinner2.getText().toString()!=""){ - rating = Integer.parseInt(spinner2.getText().toString()); + //update recycler view + String[][] providerslist = new String[providers.size()][]; + for(int i=0; i { - private ServiceProvider[] serviceProviders; + private String[][] serviceProviders; private Context context; // Provide a reference to the views for each data item @@ -258,7 +300,7 @@ public class FindServiceProvider extends AppCompatActivity { // you provide access to all the views for a data item in a view holder // Provide a suitable constructor (depends on the kind of dataset) - public MyAdapter(ServiceProvider[] serviceProviders, Context context) { + public MyAdapter(String[][] serviceProviders, Context context) { this.serviceProviders = serviceProviders; } @@ -275,10 +317,10 @@ public class FindServiceProvider extends AppCompatActivity { // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ProviderHolder holder, int position) { - ServiceProvider serviceprovider = serviceProviders[position]; - holder.name.setText(serviceprovider.getFirstname()+" "+serviceprovider.getLastname()); - holder.rate.setText("5"); - //serviceprovider.getRating() + String[] serviceprovider = serviceProviders[position]; + holder.name.setText(serviceprovider[1]+" "+serviceprovider[2]); + holder.rate.setText(""+serviceprovider[3]); + diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerEditProfile.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerEditProfile.java index 2819c18..ae8cc8a 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerEditProfile.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerEditProfile.java @@ -39,7 +39,7 @@ public class HomeOwnerEditProfile extends AppCompatActivity { */ @Override public void onBackPressed(){ - Intent intent = new Intent(getApplicationContext(),ServiceProviderWelcome.class); + Intent intent = new Intent(getApplicationContext(),Welcome.class); intent.putExtra("username", username); startActivity(intent); finish(); diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MakeBooking.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MakeBooking.java index 2873abe..b75780f 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MakeBooking.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MakeBooking.java @@ -10,8 +10,11 @@ import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; +import android.widget.Toast; +import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Date; public class MakeBooking extends AppCompatActivity { String homeowner; @@ -49,7 +52,63 @@ public class MakeBooking extends AppCompatActivity { } public void Book(View view){ - // + Button button = findViewById(R.id.Start); + Button button2 = findViewById(R.id.End); + Button button3 = findViewById(R.id.Date); + + if(!button.getText().toString().equals("Start") && !button2.getText().toString().equals("End") + && !button3.getText().toString().equals("Date")){ + String[] dates = button3.getText().toString().split("/"); + int month = Integer.parseInt(dates[0].replaceAll("\\s+","")); + int day = Integer.parseInt(dates[1].replaceAll("\\s+","")); + int year = Integer.parseInt(dates[2].replaceAll("\\s+","")); + + String[] starttimes = button.getText().toString().split(":"); + int starth = Integer.parseInt(starttimes[0].replaceAll("\\s+","")); + int startmin = Integer.parseInt(starttimes[1].replaceAll("\\s+","")); + + String[] endtimes = button2.getText().toString().split(":"); + int endh = Integer.parseInt(endtimes[0].replaceAll("\\s+","")); + int endmin = Integer.parseInt(endtimes[1].replaceAll("\\s+","")); + + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date selecteddate = sdf.parse(dates[2].replaceAll("\\s+","") + "-" + dates[0].replaceAll("\\s+","") + "-" + dates[1].replaceAll("\\s+","")); + if(selecteddate.compareTo(date)<0){ + Toast.makeText(this, "Date must be a future date", Toast.LENGTH_SHORT).show(); + } + else{ + if (starth - + \ No newline at end of file diff --git a/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml b/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml index 9bd9a8d..a8097c3 100644 --- a/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml +++ b/OlympusServices/app/src/main/res/layout/activity_find_service_provider.xml @@ -38,67 +38,123 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" + android:gravity="start" + android:layout_gravity="start" >