package org.dosomething.android.activities;

import java.text.SimpleDateFormat;

import org.dosomething.android.R;
import org.dosomething.android.widgets.ActionBar;

import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.inject.Inject;
import com.nostra13.universalimageloader.core.ImageLoader;

public class Campaign extends RoboActivity {
	
	private static final String CAMPAIGN = "campaign";
	
	@Inject private ImageLoader imageLoader;
	
	@InjectView(R.id.actionbar) private ActionBar actionBar;
	@InjectView(R.id.image) private ImageView imgLogo;
	@InjectView(R.id.image_container) private LinearLayout llImageContainer;
	@InjectView(R.id.dates) private TextView txtDates;
	@InjectView(R.id.teaser) private TextView txtTeaser;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.campaign);
        
        org.dosomething.android.transfer.Campaign campaign = (org.dosomething.android.transfer.Campaign) getIntent().getSerializableExtra(CAMPAIGN);
        
        actionBar.setTitle(campaign.getName());
        
        SimpleDateFormat df = new SimpleDateFormat("MMMMM dd");
        
        txtDates.setText(df.format(campaign.getStartDate()) + "-" + df.format(campaign.getEndDate()));
        txtTeaser.setText(campaign.getTeaser());
        
        llImageContainer.setBackgroundColor(Color.parseColor(campaign.getBackgroundColor()));
        imageLoader.displayImage(campaign.getLogoUrl(), imgLogo);
    }
	
	public void signUp(View v){
		startActivity(CampaignSignedUp.getIntent(this));
	}

	public static Intent getIntent(Context context, org.dosomething.android.transfer.Campaign campaign) {
		Intent answer = new Intent(context, Campaign.class);
		answer.putExtra(CAMPAIGN, campaign);
		return answer;
	}
	
}

@@ -72,16 +72,43 @@
 eFormat;
+%0Aimport java.util.Calendar;
 %0A%0Aimport
@@ -1420,81 +1420,8 @@
    %0A
-        SimpleDateFormat df = new SimpleDateFormat(%22MMMMM dd%22);%0A        %0A
     
@@ -1441,25 +1441,31 @@
 setText(
-df.
 format
+DateRange
 (campaig
@@ -1469,64 +1469,8 @@
 aign
-.getStartDate()) + %22-%22 + df.format(campaign.getEndDate()
 ));%0A
@@ -1691,14 +1691,770 @@
 o);%0A
-
     %7D%0A
+%09%0A%09private String formatDateRange(org.dosomething.android.transfer.Campaign campaign)%7B%0A%09%09SimpleDateFormat mf = new SimpleDateFormat(%22MMMMM%22);%0A%09%09%0A%09%09Calendar scal = Calendar.getInstance();%0A%09%09scal.setTime(campaign.getStartDate());%0A%09%09%0A%09%09Calendar ecal = Calendar.getInstance();%0A%09%09ecal.setTime(campaign.getEndDate());%0A%09%09%0A%09%09int sday = scal.get(Calendar.DAY_OF_MONTH);%0A%09%09int eday = ecal.get(Calendar.DAY_OF_MONTH);%0A%09%09%0A%09%09return mf.format(campaign.getStartDate()) + %22 %22 + sday + getOrdinalFor(sday)%0A%09%09%09%09+ %22-%22 + mf.format(campaign.getEndDate()) + %22 %22 + eday + getOrdinalFor(eday);%0A%09%7D%0A%0A%09private static String getOrdinalFor(int value) %7B%0A%09%09switch (value) %7B%0A%09%09case 1:%0A%09%09%09return %22st%22;%0A%09%09case 2:%0A%09%09%09return %22nd%22;%0A%09%09case 3:%0A%09%09%09return %22rd%22;%0A%09%09default:%0A%09%09%09return %22th%22;%0A%09%09%7D%0A%09%7D%0A%0A
 %09%0A%09p

format dates better