public class WeatherFragPresenterImpl extends BasePresenter implements IWeatherMainFragPresenter {
    private IWeatherFragView mView;

    public WeatherFragPresenterImpl(IBaseView view) {
        super(view);
        mView = (IWeatherFragView) view;


    }

    @Override
    public void init() {
        super.init();
        if (hasView())
            mView.init();
    }

    @Override
    protected IDataSource setDataSource() {
        return null;
    }

    @Override
    public void start() {

    }

    @Override
    public void onClickBackgroundPic(ImageView imageViewToLoadImage) {
        int i = getRandomNum(7, 17);
        loadPicture(DateUtil.getDate("yy-MM-dd", i), imageViewToLoadImage);
    }

    @Override
    public void initBackgroundPic(ImageView imageViewToInit) {
        loadPicture(DateUtil.getDate("yy-MM-dd"), imageViewToInit);
    }

    @Override
    public void checkForecastSource(String link, Context context) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(link));
        context.startActivity(intent);
    }

    private int getRandomNum(int from, int to) {
        Random random = new Random();
        return (random.nextInt(to - from) + from);
    }

    private void loadPicture(String s, ImageView imageView) {
        Glide.with(imageView.getContext()).load("http://s.tu.ihuan.me/bgc/" + s + ".png")
                .placeholder(R.drawable.back)
                .fitCenter()
                .into(imageView);
    }


} public interface IBasePresenter {

    void init();

    void start();

    void onDestroy();
} public interface IWeatherMainFragPresenter extends IBasePresenter {
    @Override
    void init();

    @Override
    void start();

    @Override
    void onDestroy();

    void onClickBackgroundPic(ImageView imageViewToLoadImage);

    void checkForecastSource(String link, Context context);

    void initBackgroundPic(ImageView imageViewToInit);


} public interface IWeatherViewPresenter extends IBasePresenter {


    @Override
    void init();

    @Override
    void start();

    @Override
    void onDestroy();

    void startAutoUpdateService();

    void onClickFab();

    void refreshWeather();

    void refreshWeather(City city);

    void selectCitySuccess(City selectedCity);

    void goToSelectLocationActivity();




} public class BackgroundPictureView extends LinearLayout implements View.OnClickListener {
    // TODO: 16-10-12 这个View应该添加更多其他控件,并设计成可复用
    LinearLayout container;
    Context mContext;
    ImageView imageView;
    OnBackgroundPicClickListener listener;

    public BackgroundPictureView(Context context) {
        super(context);
        init(context);
    }

    public BackgroundPictureView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public BackgroundPictureView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);


    }

    private void init(Context context) {
        mContext = context;
        container = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.include_background_picture, null);
        // TODO: 16-10-12 null?
        imageView = (ImageView) container.findViewById(R.id.back_pic);
        addView(container);



        imageView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        LogUtil.v(this.toString(),"onClick()");
        switch (v.getId()) {
            case R.id.back_pic:
                if (listener != null) {
                    listener.OnClickClickPic(imageView);
                }
                break;
        }
    }



    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (listener != null) {
            listener.initBackgroundPic(imageView);
        }
    }



    public void addOnBackgroundPicClickListener(OnBackgroundPicClickListener listener) {
        this.listener = listener;
    }

    public interface OnBackgroundPicClickListener{
        void OnClickClickPic(ImageView pic);

        void initBackgroundPic(ImageView pic);
    }


} public abstract class BaseActivity extends AppCompatActivity implements IBaseView {
    private IBasePresenter mPresenter;


    public IBasePresenter getPresenter() {
        if (mPresenter != null) {
            return mPresenter;
        }

        return null;
    }


    public boolean hasPresenter() {
        return mPresenter != null;
    }


    protected abstract IBasePresenter setPresenter();

    protected abstract int setLayoutId();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = setPresenter();

        setContentView(setLayoutId());


    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(this.getClass().getSimpleName(), "Activity onDestroy");
//        RefWatcher watcher = App.getWatcher(this);
//        watcher.watch(this);
        if (hasPresenter())
            mPresenter.onDestroy();

    }
} public abstract class BaseFragment extends Fragment implements IBaseView {

    private IBasePresenter mPresenter;

    protected abstract int setLayoutId();


    public IBasePresenter getPresenter() {
        return this.mPresenter;
    }


    public boolean hasPresenter() {
        return this.mPresenter != null;
    }

    protected abstract IBasePresenter setPresenter();


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = setPresenter();
    }

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

        return inflater.inflate(setLayoutId(), container, false);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
/*        RefWatcher watcher = App.getWatcher(getActivity());
        watcher.watch(this);*/

        if (hasPresenter())
            mPresenter.onDestroy();
    }
} public interface IWeatherFragView extends IBaseView {

    void showWeather(List<Forecast> forecastList);

    void showForecastInfo(ForecastInfo info);

    void scrollToTop();

} public class Forecast implements Parcelable{
    public static final Parcelable.Creator<Forecast> CREATOR = new Creator<Forecast>() {
        @Override
        public Forecast createFromParcel(Parcel source) {
            Forecast forecast = new Forecast(source.readString(), source.readString(), source.readString(),
                    source.readString(), source.readString());

            return null;
        }

        @Override
        public Forecast[] newArray(int size) {
            return new Forecast[size];
        }
    };
    private String date;
    private String high;
    private String low;
    private String text;
    private String woeid;

    public Forecast(String date, String high, String low, String text, String woeid) {
        this.date = date;
        this.high = high;
        this.low = low;
        this.text = text;
        this.woeid = woeid;
    }



    public String getDate() {
        return date;
    }

    public String getHigh() {
        return high;
    }

    public String getLow() {
        return low;
    }

    public String getText() {
        return text;
    }

    public String getWoeid() {
        return woeid;
    }

    public void setWoeid(String woeid) {
        this.woeid = woeid;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(date);
        dest.writeString(high);
        dest.writeString(low);
        dest.writeString(text);
        dest.writeString(woeid);
    }
} public class ForecastInfo implements Serializable {
    private String link;
    private String lastBuildDate;
    private String windDirection;
    private String windSpeed;
    private String date;
    private String temp;
    private String text;
    private String sunrise;
    private String sunset;
    private String woeid;

    public ForecastInfo(String link, String lastBuildDate, String windDirection, String windSpeed,
                        String date, String temp, String text, String woeid, String sunrise, String sunset) {

        this.link = link;
        this.lastBuildDate = lastBuildDate;
        this.windDirection = windDirection;
        this.windSpeed = windSpeed;
        this.date = date;
        this.temp = temp;
        this.text = text;
        this.woeid = woeid;
        this.sunrise = sunrise;
        this.sunset = sunset;
    }


    public String getLink() {
        return link;
    }

    public String getLastBuildDate() {
        return lastBuildDate;
    }

    public String getWindDirection() {
        return windDirection;
    }

    public String getWindSpeed() {
        return windSpeed;
    }

    public String getDate() {
        return date;
    }

    public String getTemp() {
        return temp;
    }

    public String getText() {

        return text;
    }

    public String getWoeid() {
        return woeid;
    }

    public String getSunset() {
        return sunset;
    }

    public String getSunrise() {
        return sunrise;
    }
}
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.kuahusg.weather.Presenter.WeatherFragPresenterImpl;
import com.kuahusg.weather.Presenter.base.IBasePresenter;
import com.kuahusg.weather.Presenter.interfaceOfPresenter.IWeatherMainFragPresenter;
import com.kuahusg.weather.Presenter.interfaceOfPresenter.IWeatherViewPresenter;
import com.kuahusg.weather.R;
import com.kuahusg.weather.UI.Widget.BackgroundPictureView;
import com.kuahusg.weather.UI.base.BaseActivity;
import com.kuahusg.weather.UI.base.BaseFragment;
import com.kuahusg.weather.UI.interfaceOfView.IWeatherFragView;
import com.kuahusg.weather.model.bean.Forecast;
import com.kuahusg.weather.model.bean.ForecastInfo;
import java.util.List;
package com.kuahusg.weather.UI.Fragment;




/**
 * Created by kuahusg on 16-9-29.
 */

public class WeatherFragment extends BaseFragment implements IWeatherFragView, View.OnClickListener {
    private IWeatherMainFragPresenter mPresenter;

    private View view;
    private TextView date;
    private TextView temp_now;
    private TextView temp1;
    private TextView temp2;
    private TextView weather_text;
    private TextView cal_date;
    private ImageView weatherPic;
    private TextView wind_speed;
    private TextView wind_direction;
    private TextView sunrise;
    private TextView sunset;
    private Button check;
    private String link;
    private TextView refresh_time;
    private TextView mTvMessage;
    private BackgroundPictureView backgroundPictureView;