// Path: app/src/main/java/cat/ppicas/cleanarch/app/ServiceContainer.java
// public interface ServiceContainer {
// 
//     CityRepository getCityRepository();
// 
//     CurrentWeatherRepository getCurrentWeatherRepository();
// 
//     DailyForecastRepository getDailyForecastRepository();
// 
//     TaskExecutor getTaskExecutor();
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/app/ServiceContainers.java
// public final class ServiceContainers {
// 
//     private ServiceContainers() {
//         throw new RuntimeException("Instances are not allowed for this class");
//     }
// 
//     public static ServiceContainer getFromApp(Context context) {
//         Context app = context.getApplicationContext();
//         ServiceContainerProvider provider = (ServiceContainerProvider) app;
//         return provider.getServiceContainer();
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/presenter/CityCurrentWeatherPresenter.java
// public class CityCurrentWeatherPresenter extends Presenter<CityCurrentWeatherVista> {
// 
//     private final TaskExecutor mTaskExecutor;
//     private final CurrentWeatherRepository mRepository;
//     private final String mCityId;
// 
//     private GetCurrentWeatherTask mGetCurrentWeatherTask;
//     private CurrentWeather mLastCurrentWeather;
// 
//     public CityCurrentWeatherPresenter(TaskExecutor taskExecutor,
//             CurrentWeatherRepository repository, String cityId) {
//         mTaskExecutor = taskExecutor;
//         mRepository = repository;
//         mCityId = cityId;
//     }
// 
//     @Override
//     public void onStart(CityCurrentWeatherVista vista) {
//         if (mLastCurrentWeather != null) {
//             updateVista(vista, mLastCurrentWeather);
//         } else {
//             vista.displayLoading(true);
//             if (!mTaskExecutor.isRunning(mGetCurrentWeatherTask)) {
//                 mGetCurrentWeatherTask = new GetCurrentWeatherTask(mRepository, mCityId);
//                 mTaskExecutor.execute(mGetCurrentWeatherTask, new GetCurrentWeatherTaskCallback());
//             }
//         }
//     }
// 
//     private void updateVista(CityCurrentWeatherVista vista, CurrentWeather cw) {
//         vista.setCurrentTemp(NumberFormat.formatTemperature(cw.getCurrentTemp()));
//         vista.setHumidity(NumberFormat.formatHumidity(cw.getHumidity()));
//         vista.setWindSpeed(NumberFormat.formatWindSpeed(cw.getWindSpeed()));
//     }
// 
//     private class GetCurrentWeatherTaskCallback extends DisplayErrorTaskCallback<CurrentWeather> {
//         public GetCurrentWeatherTaskCallback() {
//             super(CityCurrentWeatherPresenter.this);
//         }
// 
//         @Override
//         public void onSuccess(CurrentWeather cw) {
//             mLastCurrentWeather = cw;
//             CityCurrentWeatherVista vista = getVista();
//             if (vista != null) {
//                 vista.displayLoading(false);
//                 updateVista(vista, cw);
//             }
//         }
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/framework/ui/PresenterFactory.java
// public interface PresenterFactory<T extends Presenter<?>> {
// 
//     T createPresenter();
// 
//     String getPresenterTag();
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/framework/ui/PresenterHolder.java
// public interface PresenterHolder {
// 
//     <T extends Presenter<?>> T getOrCreatePresenter(PresenterFactory<T> presenterFactory);
// 
//     void destroyPresenter(PresenterFactory<?> presenterFactory);
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/vista/CityCurrentWeatherVista.java
// public interface CityCurrentWeatherVista extends TaskResultVista {
// 
//     void setCurrentTemp(String temp);
// 
//     void setHumidity(String humidity);
// 
//     void setWindSpeed(String windSpeed);
// 
// }


import cat.ppicas.framework.ui.PresenterHolder;
import cat.ppicas.cleanarch.ui.vista.CityCurrentWeatherVista;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import cat.ppicas.cleanarch.R;
import cat.ppicas.cleanarch.app.ServiceContainer;
import cat.ppicas.cleanarch.app.ServiceContainers;
import cat.ppicas.cleanarch.ui.presenter.CityCurrentWeatherPresenter;
import cat.ppicas.framework.ui.PresenterFactory;
    }

    @Override
    public void setCurrentTemp(String temp) {
        mCurrent.setText(temp);
    }

    @Override
    public void setHumidity(String humidity) {
        mHumidity.setText(humidity);
    }

    @Override
    public void setWindSpeed(String windSpeed) {
        mWindSpeed.setText(windSpeed);
    }

    @Override
    public void displayLoading(boolean display) {
        mLoading.setVisibility(display ? View.VISIBLE : View.GONE);
    }

    @Override
    public void displayError(int stringResId, Object... args) {
        Toast.makeText(getActivity().getApplicationContext(), stringResId, Toast.LENGTH_LONG).show();
    }

    @Override
    public CityCurrentWeatherPresenter createPresenter() {
        ServiceContainer sc = ServiceContainers.getFromApp(getActivity());
// Path: app/src/main/java/cat/ppicas/cleanarch/app/ServiceContainer.java
// public interface ServiceContainer {
// 
//     CityRepository getCityRepository();
// 
//     CurrentWeatherRepository getCurrentWeatherRepository();
// 
//     DailyForecastRepository getDailyForecastRepository();
// 
//     TaskExecutor getTaskExecutor();
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/app/ServiceContainers.java
// public final class ServiceContainers {
// 
//     private ServiceContainers() {
//         throw new RuntimeException("Instances are not allowed for this class");
//     }
// 
//     public static ServiceContainer getFromApp(Context context) {
//         Context app = context.getApplicationContext();
//         ServiceContainerProvider provider = (ServiceContainerProvider) app;
//         return provider.getServiceContainer();
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/presenter/CityCurrentWeatherPresenter.java
// public class CityCurrentWeatherPresenter extends Presenter<CityCurrentWeatherVista> {
// 
//     private final TaskExecutor mTaskExecutor;
//     private final CurrentWeatherRepository mRepository;
//     private final String mCityId;
// 
//     private GetCurrentWeatherTask mGetCurrentWeatherTask;
//     private CurrentWeather mLastCurrentWeather;
// 
//     public CityCurrentWeatherPresenter(TaskExecutor taskExecutor,
//             CurrentWeatherRepository repository, String cityId) {
//         mTaskExecutor = taskExecutor;
//         mRepository = repository;
//         mCityId = cityId;
//     }
// 
//     @Override
//     public void onStart(CityCurrentWeatherVista vista) {
//         if (mLastCurrentWeather != null) {
//             updateVista(vista, mLastCurrentWeather);
//         } else {
//             vista.displayLoading(true);
//             if (!mTaskExecutor.isRunning(mGetCurrentWeatherTask)) {
//                 mGetCurrentWeatherTask = new GetCurrentWeatherTask(mRepository, mCityId);
//                 mTaskExecutor.execute(mGetCurrentWeatherTask, new GetCurrentWeatherTaskCallback());
//             }
//         }
//     }
// 
//     private void updateVista(CityCurrentWeatherVista vista, CurrentWeather cw) {
//         vista.setCurrentTemp(NumberFormat.formatTemperature(cw.getCurrentTemp()));
//         vista.setHumidity(NumberFormat.formatHumidity(cw.getHumidity()));
//         vista.setWindSpeed(NumberFormat.formatWindSpeed(cw.getWindSpeed()));
//     }
// 
//     private class GetCurrentWeatherTaskCallback extends DisplayErrorTaskCallback<CurrentWeather> {
//         public GetCurrentWeatherTaskCallback() {
//             super(CityCurrentWeatherPresenter.this);
//         }
// 
//         @Override
//         public void onSuccess(CurrentWeather cw) {
//             mLastCurrentWeather = cw;
//             CityCurrentWeatherVista vista = getVista();
//             if (vista != null) {
//                 vista.displayLoading(false);
//                 updateVista(vista, cw);
//             }
//         }
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/framework/ui/PresenterFactory.java
// public interface PresenterFactory<T extends Presenter<?>> {
// 
//     T createPresenter();
// 
//     String getPresenterTag();
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/framework/ui/PresenterHolder.java
// public interface PresenterHolder {
// 
//     <T extends Presenter<?>> T getOrCreatePresenter(PresenterFactory<T> presenterFactory);
// 
//     void destroyPresenter(PresenterFactory<?> presenterFactory);
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/vista/CityCurrentWeatherVista.java
// public interface CityCurrentWeatherVista extends TaskResultVista {
// 
//     void setCurrentTemp(String temp);
// 
//     void setHumidity(String humidity);
// 
//     void setWindSpeed(String windSpeed);
// 
// }


// Path: app/src/main/java/cat/ppicas/cleanarch/ui/fragment/CityCurrentWeatherFragment.java
import cat.ppicas.framework.ui.PresenterHolder;
import cat.ppicas.cleanarch.ui.vista.CityCurrentWeatherVista;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import cat.ppicas.cleanarch.R;
import cat.ppicas.cleanarch.app.ServiceContainer;
import cat.ppicas.cleanarch.app.ServiceContainers;
import cat.ppicas.cleanarch.ui.presenter.CityCurrentWeatherPresenter;
import cat.ppicas.framework.ui.PresenterFactory;

    }

    @Override
    public void setCurrentTemp(String temp) {
        mCurrent.setText(temp);
    }

    @Override
    public void setHumidity(String humidity) {
        mHumidity.setText(humidity);
    }

    @Override
    public void setWindSpeed(String windSpeed) {
        mWindSpeed.setText(windSpeed);
    }

    @Override
    public void displayLoading(boolean display) {
        mLoading.setVisibility(display ? View.VISIBLE : View.GONE);
    }

    @Override
    public void displayError(int stringResId, Object... args) {
        Toast.makeText(getActivity().getApplicationContext(), stringResId, Toast.LENGTH_LONG).show();
    }

    @Override
    public CityCurrentWeatherPresenter createPresenter() {
        ServiceContainer sc = ServiceContainers.getFromApp(getActivity());
        return new CityCurrentWeatherPresenter(sc.getTaskExecutor(),