package com.stackallocated.imageupload;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class HistoryActivity extends Activity {
    private final static String TAG = "MainActivity";

    private void displayHistory() {
        Cursor images = HistoryDatabase.getInstance(this).getImages();
        String[] columns = new String[] {
                HistoryDatabase.IMAGES_COL_URL,
                HistoryDatabase.IMAGES_COL_UPLOADED_DATE,
        };
        int[] views = {
                R.id.history_list_item_url,
                R.id.history_list_item_date,
        };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.history_list_item, images, columns, views, 0);
        ListView list = (ListView) findViewById(R.id.history_list);
        list.setAdapter(adapter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_history);

        displayHistory();
    }

    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            Intent intent = new Intent(this, SettingsActivity.class);
            startActivity(intent);
            return true;
        } else if (id == R.id.action_clear_history) {
            DialogInterface.OnClickListener clear_history_listener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    HistoryDatabase.getInstance(getApplicationContext()).deleteAllImages();
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.dialog_clear_history_title)
                   .setMessage(R.string.dialog_clear_history_prompt)
                   .setNeutralButton(R.string.dialog_cancel, null)
                   .setPositiveButton(R.string.dialog_clear_history, clear_history_listener);
            builder.show();
        }
        return super.onOptionsItemSelected(item);
    }
}

@@ -34,16 +34,40 @@
 pload;%0A%0A
+import java.util.Date;%0A%0A
 import a
@@ -119,16 +119,48 @@
 Dialog;%0A
+import android.content.Context;%0A
 import a
@@ -336,16 +336,42 @@
 nuItem;%0A
+import android.view.View;%0A
 import a
@@ -416,21 +416,23 @@
 .widget.
-Simpl
+Resourc
 eCursorA
@@ -438,16 +438,48 @@
 Adapter;
+%0Aimport android.widget.TextView;
 %0A%0Apublic
@@ -583,217 +583,654 @@
     
-private void displayHistory() %7B%0A        Cursor images = HistoryDatabase.getInstance(this).getImages();%0A        String%5B%5D columns = new String%5B%5D %7B%0A                HistoryDatabase.IMAGES_COL_URL,%0A                
+class HistoryCursorAdapter extends ResourceCursorAdapter %7B%0A        public HistoryCursorAdapter(Context context, int layout, Cursor c, int flags) %7B%0A            super(context, layout, c, flags);%0A        %7D%0A%0A        @Override%0A        public void bindView(View view, Context context, Cursor cursor) %7B%0A            TextView urlView = (TextView)view.findViewById(R.id.history_list_item_url);%0A            urlView.setText(cursor.getString(cursor.getColumnIndex(HistoryDatabase.IMAGES_COL_URL)));%0A            TextView dateView = (TextView)view.findViewById(R.id.history_list_item_date);%0A            Date date = new Date(cursor.getLong(cursor.getColumnIndex(
 Hist
@@ -1265,17 +1265,20 @@
 DED_DATE
-,
+)));
 %0A       
@@ -1282,34 +1282,46 @@
     
-%7D;%0A        int%5B%5D views = %7B
+    dateView.setText(date.toString());
 %0A   
@@ -1329,98 +1329,122 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-R.id.history_list_item_url,%0A                R.id.history_list_item_date,%0A        %7D
+private void displayHistory() %7B%0A        Cursor images = HistoryDatabase.getInstance(this).getImages()
 ;%0A  
@@ -1449,22 +1449,23 @@
         
-Simple
+History
 CursorAd
@@ -1488,14 +1488,15 @@
 new 
-Simple
+History
 Curs
@@ -1550,24 +1550,8 @@
 ges,
- columns, views,
  0);

Make adapter subclass to do custom stuff in the list view