added show cancelled optional

This commit is contained in:
IvanaE 2018-12-01 18:09:28 -05:00
parent 11e8fa677f
commit b2c33cea8e
3 changed files with 35 additions and 2 deletions

View file

@ -9,9 +9,11 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@ -54,6 +56,27 @@ public class Bookings extends AppCompatActivity {
mAdapter = new MyAdapter(bookings, this);
mRecyclerView.setAdapter(mAdapter);
SwitchCompat toggle = findViewById(R.id.Switch);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
List<Booking> booking = (List<Booking>)dbhelper.findBookings(username);
Booking[] bookings = new Booking[booking.size()];
bookings = booking.toArray(bookings);
mAdapter = new MyAdapter(bookings, Bookings.this);
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
} else {
List<Booking> booking = (List<Booking>)dbhelper.findNonCancelledBookings(username);
Booking[] bookings = new Booking[booking.size()];
bookings = booking.toArray(bookings);
mAdapter = new MyAdapter(bookings, Bookings.this);
mRecyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}
}
});
}
/**

View file

@ -12,11 +12,20 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background"
tools:context=".Bookings">
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show cancelled bookings"
android:id="@+id/Switch"
android:checked="true"
android:theme="@style/Switch"
android:layout_marginBottom="10dp"
android:textColor="@color/colorWhite"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/Bookings"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="500dp"/>
android:layout_height="450dp"/>
</LinearLayout>

View file

@ -13,10 +13,11 @@
<item name="android:textColor">@color/colorBlack</item>
</style>
<style name="RatingBar" parent="Theme.AppCompat">
<style name="Switch" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/colorWhite</item>
<item name="colorControlActivated">@color/colorWhite</item>
</style>
</resources>