package com.example.checkmiles;

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

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView mileageText = (TextView) findViewById(R.id.mileageText);
    String distance = "";
    String date = "";
    Uri uri = Uri.parse("content://com.example.fueltrack.provider/mileage");
    String[] projection = {
        "date", "distance"
    };
    String orderBy = "date DESC";
    Cursor cursor = getContentResolver().query(uri, projection, null, null,
        orderBy);
    if (cursor != null && cursor.moveToFirst()) {
      distance = cursor.getString(cursor.getColumnIndex("distance"));
      date = cursor.getString(cursor.getColumnIndex("date"));
      cursor.close();
      mileageText.setText(date + ": " + distance);
    }

  }

}
