package com.example.android.waitlist;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;


public class MainActivity extends AppCompatActivity {

    private GuestListAdapter mAdapter;

    // TODO (1) Create a local field member of type SQLiteDatabase called mDb

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RecyclerView waitlistRecyclerView;

        // Set local attributes to corresponding views
        waitlistRecyclerView = (RecyclerView) this.findViewById(R.id.all_guests_list_view);

        // Set layout for the RecyclerView, because it's a list we are using the linear layout
        waitlistRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        // Create an adapter for that cursor to display the data
        mAdapter = new GuestListAdapter(this);

        // TODO (2) Create a WaitlistDbHelper instance, pass "this" to the constructor as context

        // TODO (3) Get a writable database reference using getWritableDatabase and store it in mDb

        // TODO (4) call insertFakeData from TestUtil and pass the database reference mDb

        // TODO (7) Run the getAllGuests function and store the result in a Cursor variable

        // TODO (12) Pass the resulting cursor count to the adapter

        // Link the adapter to the RecyclerView
        waitlistRecyclerView.setAdapter(mAdapter);

    }

    /**
     * This method is called when user clicks on the Add to waitlist button
     *
     * @param view The calling view (button)
     */
    public void addToWaitlist(View view) {

    }

    // TODO (5) Create a private method called getAllGuests that returns a cursor

    // TODO (6) Inside, call query on mDb passing in the table name and projection String [] order by COLUMN_TIMESTAMP

}
@@ -32,16 +32,95 @@
 tlist;%0A%0A
+import android.database.Cursor;%0Aimport android.database.sqlite.SQLiteDatabase;%0A
 import a
@@ -314,16 +314,127 @@
 .View;%0A%0A
+import com.example.android.waitlist.data.TestUtil;%0Aimport com.example.android.waitlist.data.WaitlistDbHelper;%0A%0A
 %0Apublic 
@@ -528,20 +528,25 @@
 %0A    // 
-TODO
+completed
  (1) Cre
@@ -599,24 +599,56 @@
 e called mDb
+%0A    private SQLiteDatabase mDb;
 %0A%0A    @Overr
@@ -1291,20 +1291,25 @@
      // 
-TODO
+completed
  (2) Cre
@@ -1382,16 +1382,80 @@
  context
+%0A        WaitlistDbHelper dbHelper = new WaitlistDbHelper(this);
 %0A%0A      
@@ -1459,20 +1459,25 @@
      // 
-TODO
+completed
  (3) Get
@@ -1548,24 +1548,70 @@
 re it in mDb
+%0A        mDb = dbHelper.getWritableDatabase();
 %0A%0A        //
@@ -1611,20 +1611,25 @@
      // 
-TODO
+completed
  (4) cal
@@ -1694,16 +1694,54 @@
 ence mDb
+%0A        TestUtil.insertFakeData(mDb);
 %0A%0A      
@@ -1825,16 +1825,87 @@
 variable
+%0A        Cursor cursor = new Cursor();%0A        cursor = getAllGuests();
 %0A%0A      
@@ -2276,20 +2276,25 @@
 %0A    // 
-TODO
+compelted
  (5) Cre
@@ -2356,17 +2356,56 @@
  cursor%0A
-%0A
+    private Cursor getAllGuests()%7B%0A%0A    
     // T
@@ -2514,11 +2514,92 @@
 IMESTAMP
+%0A        Cursor guest_cursor = new Cursor();%0A%0A        return guest_cursor;%0A    %7D;
 %0A%0A%7D

complete TODO 1-5