package org.clintonhealthaccess.lmis.app;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.jjoe64.graphview.BarGraphView;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;

import java.util.ArrayList;

import roboguice.activity.RoboActionBarActivity;
import roboguice.inject.InjectView;


public class HomeActivity extends RoboActionBarActivity {

    public static final String DATE_FORMAT = "dd/MM/yyyy";

    private TextView textFacilityName;

    @InjectView(R.id.layoutGraph)
    private LinearLayout layout;

    @InjectView(R.id.listViewAlerts)
    private ListView listViewAlerts;

    @InjectView(R.id.listViewNotifications)
    private ListView listViewNotifications;

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

        setContentView(R.layout.activity_home);

        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

        getSupportActionBar().setCustomView(R.layout.action_bar);

        setFacilityName("Kabira Health Center");

        setupGraph();

        setupAlerts();

    }

    private void setFacilityName(String text) {
        textFacilityName = (TextView) getSupportActionBar().getCustomView().findViewById(R.id.textFacilityName);
        textFacilityName.setText(text);
    }

    private void setupAlerts() {
        String[] values = new String[]{"Low Stock for Coartem", "Low Stock for Panadol", "Low Stock for Hedex"};

        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < values.length; ++i) {
            list.add(values[i]);
        }
        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, list);
        listViewAlerts.setAdapter(adapter);


        String[] notificationValues = new String[]{"You Have a new Allocation"};

        ArrayList<String> notificationList = new ArrayList<String>();
        for (int j = 0; j < notificationValues.length; ++j) {
            notificationList.add(notificationValues[j]);
        }
        ArrayAdapter notificationAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, notificationList);
        listViewNotifications.setAdapter(notificationAdapter);
    }

    private void setupGraph() {
        GraphView graphView = new BarGraphView(
                this
                , "Commodity Consumption"
        );
        GraphViewSeries exampleSeries = new GraphViewSeries(new GraphView.GraphViewData[]{
                new GraphView.GraphViewData(1, 3.0d)
                , new GraphView.GraphViewData(2, 12d)
                , new GraphView.GraphViewData(3, 4d)
                , new GraphView.GraphViewData(4, 10d)
                , new GraphView.GraphViewData(5, 6d)

        });
        graphView.addSeries(exampleSeries);

        layout.addView(graphView);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.home, menu);
        menu.add(getDate()).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        return true;
    }

    private String getDate() {
        return android.text.format.DateFormat.format(DATE_FORMAT, new java.util.Date()).toString();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

}

@@ -450,16 +450,46 @@
 rayList;
+%0Aimport java.util.Collections;
 %0A%0Aimport
@@ -687,17 +687,16 @@
 /yyyy%22;%0A
-%0A
     priv
@@ -727,16 +727,17 @@
 yName;%0A%0A
+%0A
     @Inj
@@ -1205,17 +1205,16 @@
 USTOM);%0A
-%0A
         
@@ -1271,17 +1271,16 @@
 n_bar);%0A
-%0A
         
@@ -1320,17 +1320,16 @@
 nter%22);%0A
-%0A
         
@@ -1338,25 +1338,24 @@
 tupGraph();%0A
-%0A
         setu
@@ -1365,17 +1365,16 @@
 erts();%0A
-%0A
     %7D%0A%0A 
@@ -1797,92 +1797,41 @@
     
-for (int i = 0; i %3C values.length; ++i) %7B%0A            list.add(values%5Bi%5D);%0A        %7D
+Collections.addAll(list, values);
 %0A   
@@ -1994,17 +1994,16 @@
 pter);%0A%0A
-%0A
         
@@ -2158,74 +2158,27 @@
     
-for (int j = 0; j %3C notificationValues.length; ++j) %7B%0A            
+Collections.addAll(
 noti
@@ -2189,21 +2189,18 @@
 tionList
-.add(
+, 
 notifica
@@ -2213,23 +2213,10 @@
 lues
-%5Bj%5D);%0A        %7D
+);
 %0A   
@@ -2511,46 +2511,12 @@
 iew(
-%0A                this%0A                
+this
 , %22C
@@ -2536,25 +2536,16 @@
 umption%22
-%0A        
 );%0A     
@@ -2682,16 +2682,17 @@
 1, 3.0d)
+,
 %0A       
@@ -2691,34 +2691,32 @@
 %0A               
- ,
  new GraphView.G
@@ -2735,16 +2735,17 @@
 (2, 12d)
+,
 %0A       
@@ -2744,34 +2744,32 @@
 %0A               
- ,
  new GraphView.G
@@ -2787,16 +2787,17 @@
 a(3, 4d)
+,
 %0A       
@@ -2796,34 +2796,32 @@
 %0A               
- ,
  new GraphView.G
@@ -2840,16 +2840,17 @@
 (4, 10d)
+,
 %0A       
@@ -2861,10 +2861,8 @@
     
- ,
  new
@@ -2893,17 +2893,16 @@
 (5, 6d)%0A
-%0A
         
@@ -2989,18 +2989,188 @@
 w);%0A    
+    textFacilityName = (TextView) getSupportActionBar().getCustomView().findViewById(R.id.textFacilityName);%0A        textFacilityName.setText(%22Kabira Health Center%22);%0A    
 %7D
-%0A
 %0A%0A    @O

Inlining variable