package com.alexandrite.first;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Databases extends AppCompatActivity {

    FeedReaderDbHelper mDbHelper;

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

        mDbHelper = new FeedReaderDbHelper(this);

        Button saveFeedButton = (Button) findViewById(R.id.saveFeedButton);

        saveFeedButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        EditText title = (EditText) findViewById(R.id.title);
                        EditText subTitle = (EditText) findViewById(R.id.subTitle);

                        saveFeed(title.getText().toString(), subTitle.getText().toString());
                    }
                }
        );

    }

    public void saveFeed(String title, String subTitle) {
        // Gets the data repository in write mode
        SQLiteDatabase db = mDbHelper.getWritableDatabase();

        // Create a new map of values, where column names are the keys
        ContentValues values = new ContentValues();
        values.put(ContractFeed.FeedEntry.COLUMN_NAME_TITLE, title);
        values.put(ContractFeed.FeedEntry.COLUMN_NAME_SUBTITLE, subTitle);

        // Insert the new row, returning the primary key value of the new row
        long newRowId = db.insert(ContractFeed.FeedEntry.TABLE_NAME, null, values);
    }

    // Test commit

}

@@ -63,16 +63,48 @@
 Values;%0A
+import android.database.Cursor;%0A
 import a
@@ -304,16 +304,45 @@
 ditText;
+%0Aimport android.widget.Toast;
 %0A%0Apublic
@@ -1810,29 +1810,1326 @@
     
-%7D%0A%0A    // Test commit
+    Toast.makeText(getBaseContext(), Long.toString(newRowId) + %22 row created %22, Toast.LENGTH_SHORT).show();%0A    %7D%0A%0A    public void displayFeed() %7B%0A        SQLiteDatabase db = mDbHelper.getReadableDatabase();%0A%0A        // Define a projection that specify which column from the database%0A        // you will actually use after this query%0A        String%5B%5D projection = %7B%0A                ContractFeed.FeedEntry._ID,%0A                ContractFeed.FeedEntry.COLUMN_NAME_TITLE,%0A                ContractFeed.FeedEntry.COLUMN_NAME_SUBTITLE%0A        %7D;%0A%0A        // Filter results WHERE %22title%22 = 'my_title'%0A        String selection = ContractFeed.FeedEntry.COLUMN_NAME_TITLE + %22 = ? %22;%0A        String%5B%5D selectionArgs = %7B%22My Title%22%7D;%0A%0A        // How you want the results sorted in the result cursor%0A        String sortOrder = ContractFeed.FeedEntry.COLUMN_NAME_SUBTITLE + %22 DESC%22;%0A%0A        Cursor cursor = db.query(%0A                ContractFeed.FeedEntry.TABLE_NAME, // The table to query%0A                projection, // The columns to return%0A                selection, // The columns for the WHERE clause%0A                selectionArgs, // The values for the WHERE clause%0A                null, // don't group the rows%0A                null, // don't filter the row groups%0A                sortOrder  // the sort order%0A        );%0A    %7D%0A%0A
 %0A%0A%7D%0A

Store feed final