diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index a72ac4f..03c8afe 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/.idea/misc.xml b/OlympusServices/.idea/misc.xml index cc51e58..dc34569 100644 --- a/OlympusServices/.idea/misc.xml +++ b/OlympusServices/.idea/misc.xml @@ -25,7 +25,7 @@ - + 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 5577ecc..c7b38ca 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 @@ -12,11 +12,14 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; +import java.util.List; + public class Bookings extends AppCompatActivity { //field for RecyclerView @@ -37,14 +40,18 @@ public class Bookings extends AppCompatActivity { username = bundle.getString("username"); dbhelper = new DBHelper(this); - //Booking[] bookings = (Booking[])dbhelper.findBookings(username).toArray(); + List booking = (List)dbhelper.findBookings(username); + Booking[] bookings = new Booking[booking.size()]; + bookings = booking.toArray(bookings); - Booking[] testbooking = {new Booking(5, 5, 6, 6, 2, 3, 2019, (ServiceProvider)dbhelper.findUserByUsername("testing"), + /* mock data + Booking[] bookings = {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 MyAdapter(testbooking, this); + mAdapter = new MyAdapter(bookings, this); mRecyclerView.setAdapter(mAdapter); } @@ -98,7 +105,7 @@ public class Bookings extends AppCompatActivity { @Override public void onBindViewHolder(BookingHolder holder, int position) { Booking booking = bookings[position]; - holder.serviceprovider.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); + holder.serviceprovider.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()+", "+booking.getServiceprovider().getCompanyname()); holder.homeowner.setText(booking.getHomeowner().getFirstname()+" "+booking.getHomeowner().getLastname()); holder.service.setText(booking.getService().getName()); String day; @@ -173,6 +180,7 @@ public class Bookings extends AppCompatActivity { 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(); } @@ -213,21 +221,30 @@ public class Bookings extends AppCompatActivity { RadioGroup ratingselect = ((AlertDialog) arg0).findViewById(R.id.RatingSelect); int selectedId = ratingselect.getCheckedRadioButtonId(); RadioButton ratingpicked; - if(selectedId!=-1){ + EditText comment = ((AlertDialog) arg0).findViewById(R.id.Comment); + 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, + /*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(); + 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)); + if(!dbhelper.addRating(booking, rating, comment.getText().toString())){ + Toast.makeText(Bookings.this, "Rating could not be added", Toast.LENGTH_SHORT).show(); } else{ Bookings.this.recreate(); } } + else{ + Toast.makeText(Bookings.this, "Rating and comment must be filled in", Toast.LENGTH_SHORT).show(); + } } }); 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 3934647..a585ceb 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 @@ -1185,7 +1185,7 @@ public class DBHelper extends SQLiteOpenHelper { + COLUMN_BOOKINGYEAR + " = ? AND " + COLUMN_BOOKINGMONTH + " = ? AND " + COLUMN_BOOKINGDATE + " = ? AND " - + COLUMN_BOOKINGSTART + " = ?)", + + COLUMN_BOOKINGSTART + " = ?", new String[] {booking.getServiceprovider().getUsername(), booking.getHomeowner().getUsername(), String.valueOf(booking.getYear()), @@ -1274,9 +1274,9 @@ public class DBHelper extends SQLiteOpenHelper { public List getAllRatingsAndComments(String serviceProviderName, String serviceName){ return getAll("SELECT " + COLUMN_BOOKINGHOMEOWNER +", " + COLUMN_RATING + ", " + COLUMN_COMMENT + " FROM " + TABLE_BOOKINGS - + " WHERE " + COLUMN_BOOKINGSERVICEPROVIDER + " = " + serviceProviderName - + " AND " + COLUMN_BOOKINGSERVICE + " = " + serviceName - + " AND " + COLUMN_RATING + " > 0"); + + " WHERE " + COLUMN_BOOKINGSERVICEPROVIDER + " = '" + serviceProviderName + + "' AND " + COLUMN_BOOKINGSERVICE + " = '" + serviceName + + "' AND " + COLUMN_RATING + " > 0"); } public String[] getSpecificRatingAndComment(String serviceProviderName, String serviceName, @@ -1739,7 +1739,7 @@ public class DBHelper extends SQLiteOpenHelper { (ServiceProvider) findUserByUsername(cursor.getString(0)) : serviceProvider); HomeOwner homeowner = (homeOwner == null ? (HomeOwner) findUserByUsername(cursor.getString(1)) : homeOwner); - Service service = findService(cursor.getString(3)); + Service service = (Service)findService(cursor.getString(2)); Booking booking = new Booking(starth, startmin, endh, endmin, day, month, year, serviceprovider, homeowner, service); booking.setStatus(status); 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 1f526c7..717d6f7 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 @@ -3,9 +3,11 @@ package com.uottawa.olympus.olympusservices; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; @@ -13,8 +15,10 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; +import android.widget.ListView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RatingBar; @@ -78,6 +82,18 @@ public class FindServiceProvider extends AppCompatActivity { startActivity(intent); finish(); } + + public void Reset(View view){ + + + //clears recycler view + String[][] empty = {}; + mAdapter = new MyAdapter(empty, this); + mRecyclerView.setAdapter(mAdapter); + mAdapter.notifyDataSetChanged(); + + + } public void Search(View view){ MaterialSpinner spinner = findViewById(R.id.ServicesInput); Button button = findViewById(R.id.Start); @@ -320,6 +336,7 @@ public class FindServiceProvider extends AppCompatActivity { String[] serviceprovider = serviceProviders[position]; holder.name.setText(serviceprovider[1]+" "+serviceprovider[2]); holder.rate.setText(""+serviceprovider[3]); + holder.username.setText(serviceprovider[0]); @@ -336,18 +353,93 @@ public class FindServiceProvider extends AppCompatActivity { TextView name; TextView rate; + TextView username; public ProviderHolder(View row){ super(row); name = row.findViewById(R.id.Name); rate = row.findViewById(R.id.Rate); + username = row.findViewById(R.id.Username); row.setOnClickListener(this); } @Override public void onClick(View view) { - TextView nameview = (TextView)view.findViewById(R.id.Name); - String name = nameview.getText().toString(); - makeBooking(name); + TextView nameview = (TextView)view.findViewById(R.id.Username); + final String name = nameview.getText().toString(); + + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FindServiceProvider.this); + + + alertDialogBuilder.setView(R.layout.sp_info_item); + + + alertDialogBuilder.setPositiveButton("Make Booking", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, int arg1) { + makeBooking(name); + } + }); + + alertDialogBuilder.setNegativeButton("Nevermind", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); + ServiceProvider sp = (ServiceProvider)dbHelper.findUserByUsername(name); + TextView spname = alertDialog.findViewById(R.id.NameName); + spname.setText(sp.getFirstname()+" "+sp.getLastname()); + + TextView company = alertDialog.findViewById(R.id.CompanyName); + company.setText(sp.getCompanyname()); + + TextView address = alertDialog.findViewById(R.id.AddressName); + address.setText(sp.getAddress()); + + TextView phone = alertDialog.findViewById(R.id.PhoneNumberName); + phone.setText(sp.getPhonenumber()); + + TextView licensed = alertDialog.findViewById(R.id.LicensedName); + if(sp.isLicensed()){ + licensed.setText("Yes"); + } + else{ + licensed.setText("No"); + } + TextView description = alertDialog.findViewById(R.id.DescriptionName); + description.setText(sp.getDescription()); + + TextView rating = alertDialog.findViewById(R.id.AverageRatingName); + MaterialSpinner spinner = findViewById(R.id.ServicesInput); + rating.setText(""+dbHelper.getAverageRating(name, spinner.getText().toString())); + + TextView ratingtext = alertDialog.findViewById(R.id.AverageRating); + ratingtext.setText("Rating for " +spinner.getText().toString()); + + //actual data + List randc = dbHelper.getAllRatingsAndComments(name,spinner.getText().toString()); + String[] ratings = new String[randc.size()]; + for(int i=0; i(FindServiceProvider.this, R.layout.simple_list_item_1_customized, ratings); + + ListView listView = (ListView) alertDialog.findViewById(R.id.RatingList); + listView.setAdapter(adapter); + + + } 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 b75780f..5c51195 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 @@ -81,17 +81,21 @@ public class MakeBooking extends AppCompatActivity { else{ if (starth + +