package com.example.checkregisterstatus;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textCount = (TextView)findViewById(R.id.count);
    TextView textDate = (TextView)findViewById(R.id.checkDate);
    TextView textNum = (TextView)findViewById(R.id.checkNum);
    TextView textBal = (TextView)findViewById(R.id.balance);
    Uri uri = Uri.parse("content://com.example.checkregister.provider/check");
    Cursor c = getContentResolver().query(uri,
        new String[]{"date","check_number","balance"}, null, null, "date");
    if ( c != null && c.moveToLast() ) {
      String date = c.getString(c.getColumnIndex("date"));
      int num = c.getInt(c.getColumnIndex("check_number"));
      double balance = c.getDouble(c.getColumnIndex("balance"));
      int count = c.getCount();
      textCount.setText("Total entries: " + count);
      textDate.setText("Most Recent: " + date);
      textNum.setText("Check Number: " + num);
      textBal.setText("Balance: " + balance);
    }
    c.close();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

}
