package com.example.android.waitlist;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
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;

import com.example.android.waitlist.data.TestUtil;
import com.example.android.waitlist.data.WaitlistDbHelper;


public class MainActivity extends AppCompatActivity {

    private GuestListAdapter mAdapter;

    // completed (1) Create a local field member of type SQLiteDatabase called mDb
    private SQLiteDatabase 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);

        // completed (2) Create a WaitlistDbHelper instance, pass "this" to the constructor as context
        WaitlistDbHelper dbHelper = new WaitlistDbHelper(this);

        // completed (3) Get a writable database reference using getWritableDatabase and store it in mDb
        mDb = dbHelper.getWritableDatabase();

        // completed (4) call insertFakeData from TestUtil and pass the database reference mDb
        TestUtil.insertFakeData(mDb);

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

        // 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) {

    }

    // compelted (5) Create a private method called getAllGuests that returns a cursor
    private Cursor getAllGuests(){

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

        return guest_cursor;
    };

}
@@ -365,16 +365,75 @@
 stUtil;%0A
+import com.example.android.waitlist.data.WaitlistContract;%0A
 import c
@@ -1230,121 +1230,8 @@
 );%0A%0A
-        // Create an adapter for that cursor to display the data%0A        mAdapter = new GuestListAdapter(this);%0A%0A
     
@@ -1691,20 +1691,25 @@
      // 
-TODO
+completed
  (7) Run
@@ -1804,39 +1804,8 @@
 or =
- new Cursor();%0A        cursor =
  get
@@ -1829,20 +1829,25 @@
      // 
-TODO
+completed
  (12) Pa
@@ -1890,16 +1890,147 @@
  adapter
+%0A        // Create an adapter for that cursor to display the data%0A        mAdapter = new GuestListAdapter(this, cursor.getCount());
 %0A%0A      
@@ -2463,12 +2463,17 @@
  // 
-TODO
+completed
  (6)
@@ -2580,24 +2580,26 @@
 AMP%0A        
+//
 Cursor guest
@@ -2638,28 +2638,269 @@
  return 
-guest_cursor
+mDb.query(%0A                WaitlistContract.WaitlistEntry.TABLE_NAME,%0A                null,%0A                null,%0A                null,%0A                null,%0A                null,%0A                WaitlistContract.WaitlistEntry.COLUMN_TIMESTAMP%0A        )
 ;%0A    %7D;

complete steps to return cursor