package cn.ccy.test_weather.ui;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.ccy.test_weather.R;
import cn.ccy.test_weather.ShowWeatherView;
import cn.ccy.test_weather.utils.ParseIcon;
import cn.ccy.test_weather_model.WeatherDetail;

public class TomorrowFragment extends Fragment {

	public static TextView ShowWeatherT;
	public static TextView ShowWeatherWindPower;
	public static TextView ShowWeatherTomorrow;
	public static TextView ShowupdateTime;
	public static ImageView Icon1;
	public static ImageView Icon2;

	private static String updateTime = "";
	WeatherDetail info;
	private static String weatherTomorrow = "";
	private static String tomorrowT = "";
	private static String tomorrowWindPower = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		info = ShowWeatherView.wd;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View parentView = inflater.inflate(R.layout.tomorrow_fragment,
				container, false);
		LinearLayout weatherView = (LinearLayout) parentView
				.findViewById(R.id.weatherView2);
		ShowupdateTime = (TextView) parentView.findViewById(R.id.updateTime);
		ShowWeatherTomorrow = (TextView) parentView
				.findViewById(R.id.weatherTomorrow);
		ShowWeatherT = (TextView) parentView.findViewById(R.id.tomorrowT);
		ShowWeatherWindPower = (TextView) parentView
				.findViewById(R.id.tomorrowWindPower);
		Icon1 = (ImageView) parentView.findViewById(R.id.Icon1);
		Icon2 = (ImageView) parentView.findViewById(R.id.Icon2);

		Resources resources = this.getResources();
		if (info != null) {
			if (info.getWeatherTomorrow().indexOf("雨") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.rain);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherT.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherWindPower.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherTomorrow.setTextColor(this.getResources().getColor(
						R.color.white));

			} else if (info.getWeatherTomorrow().indexOf("云") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.cloud);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherT.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherWindPower.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherTomorrow.setTextColor(this.getResources().getColor(
						R.color.white));
			} else if (info.getWeatherTomorrow().indexOf("晴") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.sunny);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.sunny));
				ShowWeatherT.setTextColor(this.getResources().getColor(
						R.color.sunny));
				ShowWeatherWindPower.setTextColor(this.getResources().getColor(
						R.color.sunny));
				ShowWeatherTomorrow.setTextColor(this.getResources().getColor(
						R.color.sunny));

			} else if (info.getWeatherTomorrow().indexOf("阴") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.overcast);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherT.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherWindPower.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherTomorrow.setTextColor(this.getResources().getColor(
						R.color.white));
			}
			updateTime = "更新时间： " + info.getUpdateTime();
			tomorrowT = "温度：" + info.getTomorrowT();
			weatherTomorrow = info.getWeatherTomorrow();
			tomorrowWindPower = "风力：" + info.getTomorrowWindPower();
			System.out.println("hahahaha"+ParseIcon.parseIcon(info.getTomorrowIcon1()));
			Icon1.setImageResource(ParseIcon.parseIcon(info.getTomorrowIcon1()));
			Icon2.setImageResource(ParseIcon.parseIcon(info.getTomorrowIcon2()));
			ShowupdateTime.setText(updateTime);
			ShowWeatherTomorrow.setText(weatherTomorrow);
			ShowWeatherT.setText(tomorrowT);
			ShowWeatherWindPower.setText(tomorrowWindPower);
		}
		return parentView;
	}
}
