package com.example.android.sunshine.app;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * {@link ForecastAdapter} exposes a list of weather forecasts
 * from a {@link android.database.Cursor} to a {@link android.widget.ListView}.
 */
public class ForecastAdapter extends CursorAdapter {
    public ForecastAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
    }

    /**
     * Prepare the weather high/lows for presentation.
     */
    private String formatHighLows(double high, double low) {
        boolean isMetric = Utility.isMetric(mContext);
        String highLowStr = Utility.formatTemperature(high, isMetric) + "/" + Utility.formatTemperature(low, isMetric);
        return highLowStr;
    }

    /*
        This is ported from FetchWeatherTask --- but now we go straight from the cursor to the
        string.
     */
    private String convertCursorRowToUXFormat(Cursor cursor) {
        String highAndLow = formatHighLows(
              cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP),
              cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP));

        return Utility.formatDate(cursor.getLong(ForecastFragment.COL_WEATHER_DATE)) +
              " - " + cursor.getString(ForecastFragment.COL_WEATHER_DESC) +
              " - " + highAndLow;
    }

    /*
        Remember that these views are reused as needed.
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_forecast, parent, false);

        return view;
    }

    /*
        This is where we fill-in the views with the contents of the cursor.
     */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // our view is pretty simple here --- just a text view
        // we'll keep the UI functional with a simple (and slow!) binding.

        //TextView tv = (TextView)view;
        //tv.setText(convertCursorRowToUXFormat(cursor));
    }
}
@@ -240,16 +240,81 @@
 ewGroup;
+%0Aimport android.widget.ImageView;%0Aimport android.widget.TextView;
 %0A%0A/**%0A *
@@ -2161,19 +2161,487 @@
   //
-TextView tv
+ Read weather icon ID from cursor%0A        int weatherId = cursor.getInt(ForecastFragment.COL_WEATHER_ID);%0A        // Use placeholder image for now%0A        ImageView iconView = (ImageView) view.findViewById(R.id.list_item_icon);%0A        iconView.setImageResource(R.drawable.ic_launcher);%0A%0A        // Read date from cursor%0A        long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE);%0A        // Find TextView and set formatted date on it%0A        TextView dateView
  = (
@@ -2653,68 +2653,1148 @@
 iew)
+ 
 view
-;%0A        //tv.setText(convertCursorRowToUXFormat(cursor
+.findViewById(R.id.list_item_date_textview);%0A        dateView.setText(Utility.getFriendlyDayString(context, dateInMillis));%0A%0A        // Read weather forecast from cursor%0A        String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC);%0A        // Find TextView and set weather forecast on it%0A        TextView descriptionView = (TextView) view.findViewById(R.id.list_item_forecast_textview);%0A        descriptionView.setText(description);%0A%0A        // Read user preference for metric or imperial temperature units%0A        boolean isMetric = Utility.isMetric(context);%0A%0A        // Read high temperature from cursor%0A        double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP);%0A        TextView highView = (TextView) view.findViewById(R.id.list_item_high_textview);%0A        highView.setText(Utility.formatTemperature(high, isMetric));%0A%0A        // Read low temperature from cursor%0A        double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP);%0A        TextView lowView = (TextView) view.findViewById(R.id.list_item_low_textview);%0A        lowView.setText(Utility.formatTemperature(low, isMetric
 ));%0A

Update bindView