]> iEval git - unical.git/commitdiff
Clean up EventListActivity
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 06:26:37 +0000 (09:26 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 06:26:37 +0000 (09:26 +0300)
src/ro/ieval/unical/EventAdapter.java [deleted file]
src/ro/ieval/unical/EventListActivity.java

diff --git a/src/ro/ieval/unical/EventAdapter.java b/src/ro/ieval/unical/EventAdapter.java
deleted file mode 100644 (file)
index a9e0181..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-package ro.ieval.unical;
-import java.util.Date;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-
-
-public class EventAdapter extends ArrayAdapter<Event> {
-       private final Event[] values;
-       private final Context context;
-
-       public EventAdapter(final Context context, final Event[] values) {//NOPMD
-               super(context,R.layout.event_row_layout,values);
-               this.context=context;
-               this.values=values;
-       }
-
-       @Override
-       public View getView(final int position, final View convertView, final ViewGroup parent) {
-               final LayoutInflater inflater = (LayoutInflater) context
-                       .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-               final View rowView = inflater.inflate(R.layout.event_row_layout, parent, false);
-               final TextView title = (TextView) rowView.findViewById(R.id.smalleventtitle);
-               final TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart);
-               final TextView dend = (TextView) rowView.findViewById(R.id.smalldateend);
-               final View header = rowView.findViewById(R.id.rowHeader);
-               header.setBackgroundColor(values[position].eventColour);
-               title.setText(values[position].title);
-               dstart.setText(new Date(values[position].dtstart).toString());
-               dend.setText(new Date(values[position].dtend).toString());
-
-               return rowView;
-        }
-}
index 27eaef5dc26317c53474d25580a55f4a13bd0f8e..642b77f2115d05cc0b25b45b0964d79bb3ba7f9e 100644 (file)
@@ -1,49 +1,25 @@
 package ro.ieval.unical;
 
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import android.app.Activity;
+import android.app.ListActivity;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
-import android.widget.AdapterView;
+import android.view.ViewGroup;
 import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.ListView;
+import android.widget.TextView;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Date;
 
-
-public class EventListActivity extends Activity {
-
-       //Used to refresh events if the user wants to display only certain events
-       //Sry for bad english
-       //Muie la comisie
-       private void displayEvents() {
-               final Event events[]=Event.getAllEvents(getBaseContext());
-               final ListView lv = (ListView) findViewById(R.id.eventlist);
-
-               Arrays.sort(events,new EventComparator());
-               int idx=-1;//index of the first event to be displayed
-               for(int i=0; i<events.length; ++i)
-                       if(idx==-1 && events[i].dtend>new Date().getTime()) idx=i;
-               if(idx==-1) idx=0;
-
-               final EventAdapter adapter = new EventAdapter(this, events);
-               lv.setAdapter(adapter);
-               lv.setSelectionFromTop(idx, 0);
-               lv.setOnItemClickListener(new OnItemClickListener() {
-
-                       @Override
-                       public void onItemClick(final AdapterView<?> arg0, final View arg1, final int arg2,
-                                       final long arg3) {
-                               DisplayEventActivity.displayEvent(EventListActivity.this,events[arg2]);
-                       }
-
-               });
-       }
-
+public final class EventListActivity extends ListActivity {
        private static class EventComparator implements Comparator<Event> {
                @Override
                public int compare(final Event lhs, final Event rhs) {
@@ -56,11 +32,51 @@ public class EventListActivity extends Activity {
 
        }
 
+       private class EventAdapter extends ArrayAdapter<Event> {
+               public EventAdapter() {//NOPMD
+                       super(EventListActivity.this, R.layout.event_row_layout);
+               }
+
+               @Override
+                       public View getView(final int position, final View convertView, final ViewGroup parent) {
+                       final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+                       final View rowView = inflater.inflate(R.layout.event_row_layout, parent, false);
+                       final TextView title = (TextView) rowView.findViewById(R.id.smalleventtitle);
+                       final TextView dstart = (TextView) rowView.findViewById(R.id.smalldatestart);
+                       final TextView dend = (TextView) rowView.findViewById(R.id.smalldateend);
+                       final View header = rowView.findViewById(R.id.rowHeader);
+                       header.setBackgroundColor(events[position].eventColour);
+                       title.setText(events[position].title);
+                       dstart.setText(new Date(events[position].dtstart).toString());
+                       dend.setText(new Date(events[position].dtend).toString());
+
+                       return rowView;
+               }
+       }
+
+       private Event[] events;
+
+       @Override
+       public void onListItemClick(final ListView view, final View v, final int pos, final long id) {
+               DisplayEventActivity.displayEvent(this, events[pos]);
+       }
+
+       private void displayEvents() {
+               events = Event.getAllEvents(this);
+
+               Arrays.sort(events, new EventComparator());
+               int idx=-1;//index of the first event to be displayed
+               for(int i=0; i<events.length; ++i)
+                       if(idx==-1 && events[i].dtend>new Date().getTime()) idx=i;
+               if(idx==-1) idx=0;
+
+               setListAdapter(new EventAdapter());
+               getListView().setSelectionFromTop(idx, 0);
+       }
+
        @Override
        protected void onCreate(final Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
-               setContentView(R.layout.event_list);
-
                displayEvents();
        }
 
@@ -75,8 +91,7 @@ public class EventListActivity extends Activity {
        public boolean onOptionsItemSelected(final MenuItem item) {
                switch (item.getItemId()) {
                        case R.id.add_event:
-                               final Intent i=new Intent(this,AddEventActivity.class);
-                               startActivity(i);
+                               startActivity(new Intent(this,AddEventActivity.class));
                                return true;
                        case R.id.refresh:
                                displayEvents();
This page took 0.03178 seconds and 4 git commands to generate.