latest code

This commit is contained in:
IvanaE 2018-11-28 22:12:08 -05:00
parent e50c681d54
commit 8999a149cb
13 changed files with 461 additions and 41 deletions

View file

@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -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> booking = (List<Booking>)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();
}
}
});

View file

@ -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<String[]> 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);

View file

@ -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();
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<String[]> randc = dbHelper.getAllRatingsAndComments(name,spinner.getText().toString());
String[] ratings = new String[randc.size()];
for(int i=0; i<randc.size(); i++){
ratings[i] = "Rating: "+randc.get(i)[1]+"\nComment: "+randc.get(i)[3];
}
/*mock data
String[] ratings ={"Rating: 5\nComment: Did great","Rating: 1\nComment: Worst plumber ever",
"Rating: 1\nComment: Couldn't find my house", "Rating: 2\nComment: Too expensive, ok plumber"};
*/
ArrayAdapter adapter = new ArrayAdapter<String>(FindServiceProvider.this, R.layout.simple_list_item_1_customized, ratings);
ListView listView = (ListView) alertDialog.findViewById(R.id.RatingList);
listView.setAdapter(adapter);
}

View file

@ -81,6 +81,10 @@ public class MakeBooking extends AppCompatActivity {
else{
if (starth<endh || (starth==endh && startmin<endmin)){
DBHelper dbHelper = new DBHelper(this);
//check if sp is availible not just true
if(true) {
if (dbHelper.addBooking(serviceprovider, homeowner, service, year, month, day,
starth, startmin, endh, endmin)) {
Toast.makeText(this, "Booking Made", Toast.LENGTH_SHORT).show();
@ -89,10 +93,10 @@ public class MakeBooking extends AppCompatActivity {
startActivity(intent);
finish();
}
else{
} else {
Toast.makeText(this, "Booking could not be made", Toast.LENGTH_SHORT).show();
}
}
}

View file

@ -154,10 +154,25 @@
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/Reset"
android:layout_width="150dp"
android:layout_height="45dp"
android:text="Reset"
android:theme="@style/AppTheme.Button"
android:onClick="Reset"
android:layout_marginRight="10dp"
/>
<Button
android:id="@+id/Search"
android:layout_width="400dp"
android:layout_width="150dp"
android:layout_height="45dp"
android:text="Search"
android:theme="@style/AppTheme.Button"
@ -165,6 +180,11 @@
android:layout_marginRight="10dp"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/ServiceProviders"
android:scrollbars="vertical"

View file

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:orientation="vertical"
android:layout_marginBottom="10dp"
>
<LinearLayout
@ -138,7 +139,6 @@
<TextView
android:id="@+id/StartTime"
android:paddingLeft="10dp"
android:paddingTop="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -149,7 +149,6 @@
<TextView
android:id="@+id/Timespace"
android:paddingLeft="10dp"
android:paddingTop="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -161,7 +160,6 @@
<TextView
android:id="@+id/EndTime"
android:paddingLeft="10dp"
android:paddingTop="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:layout_marginBottom="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rating:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/RatingName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment: "
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/CommentName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>

View file

@ -79,6 +79,8 @@
android:background="@color/colorWhite"
android:textSize="15sp"
android:hint="Comment"
android:text=""
android:layout_marginLeft="10dp"
android:textCursorDrawable="@color/colorWhite"/>

View file

@ -33,4 +33,16 @@
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:gravity="end"/>
<TextView
android:id="@+id/Username"
android:text=""
android:layout_height="0dp"
android:layout_width="0dp"
android:textColor="@color/colorWhite"
android:textSize="0sp"
android:gravity="end"
/>
</LinearLayout>

View file

@ -8,11 +8,13 @@
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:paddingStart="30dp"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:paddingBottom="5dp"
android:textColor="@android:color/black"
android:background="@color/colorWhite"
android:layout_marginBottom="10dp"
android:textSize="15sp"
>

View file

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="400dp"
android:layout_height="400dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Service Provider:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/NameName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FirstName"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Company"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/CompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Company"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/AddressName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/PhoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Number:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/PhoneNumberName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PhoneNumber"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Licensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Licensed:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/LicensedName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Licensed"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/DescriptionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/AverageRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Average Rating:"
android:textColor="@color/colorBlack"
android:textSize="15sp"
android:paddingRight="10dp"/>
<TextView
android:id="@+id/AverageRatingName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rating"
android:textColor="@color/colorBlack"
android:textSize="15sp" />
</LinearLayout>
<ListView
android:id="@+id/RatingList"
android:paddingTop="5dp"
android:layout_width="350dp"
android:layout_height="200dp"
android:background="@drawable/customborder2"/>
</LinearLayout>
</ScrollView>
</LinearLayout>