content: package io.github.akueisara.inventoryapp;
  
  import android.app.LoaderManager;
  import android.content.ContentUris;
  import android.content.CursorLoader;
  import android.content.Intent;
  import android.content.Loader;
  import android.database.Cursor;
  import android.net.Uri;
  import android.support.design.widget.FloatingActionButton;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  
  import io.github.akueisara.inventoryapp.data.ProductContract.ProductEntry;
  
  public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor>  {
  
      private static final int PRODUCT_LOADER = 0;
      ProductCursorAdapter mCursorAdapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  showAddProductDialog();
              }
          });
  
          ListView productListView = (ListView) findViewById(R.id.list_view_product);
  
          View emptyView = findViewById(R.id.empty_view);
          productListView.setEmptyView(emptyView);
  
          mCursorAdapter = new ProductCursorAdapter(this, null);
          productListView.setAdapter(mCursorAdapter);
  
          productListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                  Intent intent = new Intent(MainActivity.this, EditActivity.class);
                  Uri currentPetUri = ContentUris.withAppendedId(ProductEntry.CONTENT_URI, id);
                  intent.setData(currentPetUri);
                  startActivity(intent);
              }
          });
  
          getLoaderManager().initLoader(PRODUCT_LOADER, null, this);
      }
  
      private void showAddProductDialog() {
          AddDialogFragment newFragment = new AddDialogFragment();
          newFragment.show(getSupportFragmentManager(), getString(R.string.add_product));
      }
  
      @Override
      public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
          String[] projection = {
                  ProductEntry._ID,
                  ProductEntry.COLUMN_PRODUCT_NAME,
                  ProductEntry.COLUMN_PRODUCT_QUANTITY,
                  ProductEntry.COLUMN_PRODUCT_PRICE,
                  ProductEntry.COLUMN_PRODUCT_IMAGE};
  
          return new CursorLoader(this,
                  ProductEntry.CONTENT_URI,
                  projection,
                  null,
                  null,
                  null
          );
      }
  
      @Override
      public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
          mCursorAdapter.swapCursor(data);
      }
  
      @Override
      public void onLoaderReset(Loader<Cursor> loader) {
          mCursorAdapter.swapCursor(null);
      }
  
  }
  