From bb23d12201319b0015665f07aa34c5d17f80f900 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Fri, 23 Nov 2018 14:51:40 -0500 Subject: [PATCH] combined booking classes --- .../app/src/main/AndroidManifest.xml | 3 +- .../olympus/olympusservices/Bookings.java | 184 ++++++++++++++++++ .../olympusservices/HomeOwnerBookings.java | 120 ------------ .../ServiceProviderBookings.java | 120 ------------ .../ServiceProviderWelcome.java | 2 +- .../olympus/olympusservices/Welcome.java | 2 +- ...ner_bookings.xml => activity_bookings.xml} | 2 +- .../activity_service_provider_bookings.xml | 22 --- .../src/main/res/layout/booking_list_item.xml | 34 +++- 9 files changed, 221 insertions(+), 268 deletions(-) create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java delete mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerBookings.java delete mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderBookings.java rename OlympusServices/app/src/main/res/layout/{activity_home_owner_bookings.xml => activity_bookings.xml} (95%) delete mode 100644 OlympusServices/app/src/main/res/layout/activity_service_provider_bookings.xml diff --git a/OlympusServices/app/src/main/AndroidManifest.xml b/OlympusServices/app/src/main/AndroidManifest.xml index 37d14c4..425603f 100644 --- a/OlympusServices/app/src/main/AndroidManifest.xml +++ b/OlympusServices/app/src/main/AndroidManifest.xml @@ -70,8 +70,7 @@ android:label="Availabilities" android:screenOrientation="portrait" /> - - + 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 new file mode 100644 index 0000000..f0a94d0 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Bookings.java @@ -0,0 +1,184 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +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.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.widget.Toast; + +public class Bookings extends AppCompatActivity { + + //field for RecyclerView + private RecyclerView mRecyclerView; + //field for adapter of Recycler view + private RecyclerView.Adapter mAdapter; + //field for layout manager of Recyler view. + private RecyclerView.LayoutManager mLayoutManager; + + String username; + DBHelper dbhelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_bookings); + Bundle bundle = getIntent().getExtras(); + username = bundle.getString("username"); + dbhelper = new DBHelper(this); + + /* + Booking[] bookings; + //get bookings here + mRecyclerView = (RecyclerView) findViewById(R.id.Bookings); + mLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLayoutManager); + mAdapter = new AdminServicesList.MyAdapter(booking, this); + mRecyclerView.setAdapter(mAdapter); + */ + } + + /** + * Override so that previous screen refreshes when pressing the + * back button on this activity of the app. + * + */ + @Override + public void onBackPressed(){ + Intent intent = new Intent(getApplicationContext(),Welcome.class); + intent.putExtra("username", username); + startActivity(intent); + finish(); + } + + + public class MyAdapter extends RecyclerView.Adapter { + + private Booking[] bookings; + private Context context; + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // 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(Booking[] bookings, Context context) { + this.bookings = bookings; + } + + // Create new views (invoked by the layout manager) + @NonNull + @Override + public BookingHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.booking_list_item, parent, false); + BookingHolder vh = new BookingHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(BookingHolder holder, int position) { + Booking booking = bookings[position]; + //holder.name.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); + + + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return bookings.length; + } + + class BookingHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + + TextView homeowner; + TextView serviceprovider; + TextView date; + TextView start; + TextView end; + TextView status; + + public BookingHolder(View row){ + super(row); + homeowner = row.findViewById(R.id.HomeOwnerName); + serviceprovider = row.findViewById(R.id.ServiceProviderName); + date = row.findViewById(R.id.DateName); + start = row.findViewById(R.id.StartTime); + end = row.findViewById(R.id.EndTime); + status = row.findViewById(R.id.StatusName); + + row.setOnClickListener(this); + } + @Override + public void onClick(View view) { + if(dbhelper.findUserByUsername(username).getRole()=="ServiceProvider"){ + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Bookings.this); + alertDialogBuilder.setMessage("Cancel or Confirm your booking"); + alertDialogBuilder.setPositiveButton("Confirm", + 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(); + } + }); + + alertDialogBuilder.setNegativeButton("No", + 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(); + } + }); + + AlertDialog alertDialog = alertDialogBuilder.create(); + 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", + 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(); + } + }); + + alertDialogBuilder.setNegativeButton("Nevermind", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); + + } + + + } + + + } + + + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerBookings.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerBookings.java deleted file mode 100644 index 85359a9..0000000 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/HomeOwnerBookings.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.uottawa.olympus.olympusservices; - -import android.content.Context; -import android.content.Intent; -import android.support.annotation.NonNull; -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.TextView; - -public class HomeOwnerBookings extends AppCompatActivity { - - //field for RecyclerView - private RecyclerView mRecyclerView; - //field for adapter of Recycler view - private RecyclerView.Adapter mAdapter; - //field for layout manager of Recyler view. - private RecyclerView.LayoutManager mLayoutManager; - - String username; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_home_owner_bookings); - Bundle bundle = getIntent().getExtras(); - username = bundle.getString("username"); - - /* - Booking[] bookings; - //get bookings here - mRecyclerView = (RecyclerView) findViewById(R.id.Bookings); - mLayoutManager = new LinearLayoutManager(this); - mRecyclerView.setLayoutManager(mLayoutManager); - mAdapter = new AdminServicesList.MyAdapter(booking, this); - mRecyclerView.setAdapter(mAdapter); - */ - } - - /** - * Override so that previous screen refreshes when pressing the - * back button on this activity of the app. - * - */ - @Override - public void onBackPressed(){ - Intent intent = new Intent(getApplicationContext(),Welcome.class); - intent.putExtra("username", username); - startActivity(intent); - finish(); - } - - public class MyAdapter extends RecyclerView.Adapter { - - private Booking[] bookings; - private Context context; - - // Provide a reference to the views for each data item - // Complex data items may need more than one view per item, and - // 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(Booking[] bookings, Context context) { - this.bookings = bookings; - } - - // Create new views (invoked by the layout manager) - @NonNull - @Override - public BookingHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.booking_list_item, parent, false); - BookingHolder vh = new BookingHolder(v); - return vh; - } - - // Replace the contents of a view (invoked by the layout manager) - @Override - public void onBindViewHolder(BookingHolder holder, int position) { - Booking booking = bookings[position]; - holder.name.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); - - - - } - - // Return the size of your dataset (invoked by the layout manager) - @Override - public int getItemCount() { - return bookings.length; - } - - class BookingHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ - - TextView name; - TextView rate; - - public BookingHolder(View row){ - super(row); - name = row.findViewById(R.id.Name); - rate = row.findViewById(R.id.Rate); - row.setOnClickListener(this); - } - @Override - public void onClick(View view) { - TextView nameview = (TextView)view.findViewById(R.id.Name); - String name = nameview.getText().toString(); - - } - - - } - - - } -} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderBookings.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderBookings.java deleted file mode 100644 index 952bec4..0000000 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderBookings.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.uottawa.olympus.olympusservices; - -import android.content.Context; -import android.content.Intent; -import android.support.annotation.NonNull; -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.TextView; - -public class ServiceProviderBookings extends AppCompatActivity { - - //field for RecyclerView - private RecyclerView mRecyclerView; - //field for adapter of Recycler view - private RecyclerView.Adapter mAdapter; - //field for layout manager of Recyler view. - private RecyclerView.LayoutManager mLayoutManager; - - String username; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_home_owner_bookings); - Bundle bundle = getIntent().getExtras(); - username = bundle.getString("username"); - - /* - Booking[] bookings; - //get bookings here - mRecyclerView = (RecyclerView) findViewById(R.id.Bookings); - mLayoutManager = new LinearLayoutManager(this); - mRecyclerView.setLayoutManager(mLayoutManager); - mAdapter = new AdminServicesList.MyAdapter(booking, this); - mRecyclerView.setAdapter(mAdapter); - */ - } - - /** - * Override so that previous screen refreshes when pressing the - * back button on this activity of the app. - * - */ - @Override - public void onBackPressed(){ - Intent intent = new Intent(getApplicationContext(),Welcome.class); - intent.putExtra("username", username); - startActivity(intent); - finish(); - } - - public class MyAdapter extends RecyclerView.Adapter { - - private Booking[] bookings; - private Context context; - - // Provide a reference to the views for each data item - // Complex data items may need more than one view per item, and - // 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(Booking[] bookings, Context context) { - this.bookings = bookings; - } - - // Create new views (invoked by the layout manager) - @NonNull - @Override - public BookingHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.booking_list_item, parent, false); - BookingHolder vh = new BookingHolder(v); - return vh; - } - - // Replace the contents of a view (invoked by the layout manager) - @Override - public void onBindViewHolder(BookingHolder holder, int position) { - Booking booking = bookings[position]; - holder.name.setText(booking.getServiceprovider().getFirstname()+" "+booking.getServiceprovider().getLastname()); - - - - } - - // Return the size of your dataset (invoked by the layout manager) - @Override - public int getItemCount() { - return bookings.length; - } - - class BookingHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ - - TextView name; - TextView rate; - - public BookingHolder(View row){ - super(row); - name = row.findViewById(R.id.Name); - rate = row.findViewById(R.id.Rate); - row.setOnClickListener(this); - } - @Override - public void onClick(View view) { - TextView nameview = (TextView)view.findViewById(R.id.Name); - String name = nameview.getText().toString(); - - } - - - } - - - } -} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java index 73a3e8a..7a8c7cb 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServiceProviderWelcome.java @@ -79,7 +79,7 @@ public class ServiceProviderWelcome extends AppCompatActivity { finish(); } public void SeeBookings(View view){ - Intent intent = new Intent(getApplicationContext(),ServiceProviderBookings.class); + Intent intent = new Intent(getApplicationContext(),Bookings.class); intent.putExtra("username", username); startActivity(intent); finish(); diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java index ffe91bb..8ee61e6 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/Welcome.java @@ -61,7 +61,7 @@ public class Welcome extends AppCompatActivity { } public void SeeBookings(View view){ - Intent intent = new Intent(getApplicationContext(),HomeOwnerBookings.class); + Intent intent = new Intent(getApplicationContext(),Bookings.class); intent.putExtra("username", username); startActivity(intent); finish(); diff --git a/OlympusServices/app/src/main/res/layout/activity_home_owner_bookings.xml b/OlympusServices/app/src/main/res/layout/activity_bookings.xml similarity index 95% rename from OlympusServices/app/src/main/res/layout/activity_home_owner_bookings.xml rename to OlympusServices/app/src/main/res/layout/activity_bookings.xml index a1c5d1d..eb704f7 100644 --- a/OlympusServices/app/src/main/res/layout/activity_home_owner_bookings.xml +++ b/OlympusServices/app/src/main/res/layout/activity_bookings.xml @@ -11,7 +11,7 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/background" - tools:context=".HomeOwnerBookings"> + tools:context=".Bookings"> - - - - - \ No newline at end of file diff --git a/OlympusServices/app/src/main/res/layout/booking_list_item.xml b/OlympusServices/app/src/main/res/layout/booking_list_item.xml index 2f8d2cb..451922b 100644 --- a/OlympusServices/app/src/main/res/layout/booking_list_item.xml +++ b/OlympusServices/app/src/main/res/layout/booking_list_item.xml @@ -122,7 +122,39 @@ android:layout_width="wrap_content" android:layout_height="45dp" android:layout_weight="1" - android:text="Date Start-End" + android:text="Date" + android:textColor="@color/colorBlack" + android:textSize="15sp" + /> + + +