// 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/CityDetailPresenter.java
// public class CityDetailPresenter extends Presenter<CityDetailVista> {
// 
//     private static final String DAY_OF_WEEK_DATE_FORMAT_PATTERN = "cccc";
// 
//     private final TaskExecutor mTaskExecutor;
//     private final CityRepository mCityRepository;
//     private final Resources mResources;
//     private final String mCityId;
// 
//     private GetCityTask mGetCityTask;
//     private City mCity;
// 
//     public CityDetailPresenter(TaskExecutor taskExecutor, CityRepository cityRepository,
//             Resources resources, String cityId) {
//         mTaskExecutor = taskExecutor;
//         mCityRepository = cityRepository;
//         mResources = resources;
//         mCityId = cityId;
//     }
// 
//     @Override
//     public void onStart(CityDetailVista vista) {
//         vista.setTitle(R.string.city_details__title_loading);
// 
//         if (mCity != null) {
//             vista.setTitle(R.string.city_details__title, mCity.getName());
//         } else {
//             vista.displayLoading(true);
//             if (!mTaskExecutor.isRunning(mGetCityTask)) {
//                 mGetCityTask = new GetCityTask(mCityRepository, mCityId);
//                 mTaskExecutor.execute(mGetCityTask, new GetCityTaskCallback());
//             }
//         }
//     }
// 
//     public String getForecastPageTitle(int daysFromToday) {
//         if (daysFromToday == 0) {
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     mResources.getString(R.string.global__today));
//         } else if (daysFromToday == 1) {
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     mResources.getString(R.string.global__tomorrow));
//         } else {
//             Calendar cal = Calendar.getInstance();
//             cal.add(Calendar.DAY_OF_MONTH, daysFromToday);
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     DateFormat.format(DAY_OF_WEEK_DATE_FORMAT_PATTERN, cal));
//         }
//     }
// 
//     private class GetCityTaskCallback extends DisplayErrorTaskCallback<City> {
// 
//         public GetCityTaskCallback() {
//             super(CityDetailPresenter.this);
//         }
// 
//         @Override
//         public void onSuccess(City city) {
//             mCity = city;
//             CityDetailVista vista = getVista();
//             if (vista != null) {
//                 vista.displayLoading(false);
//                 vista.setTitle(R.string.city_details__title, city.getName());
//             }
//         }
//     }
// }
// 
// 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/CityDetailVista.java
// public interface CityDetailVista extends TaskResultVista {
// 
//     void setTitle(int stringResId, Object... args);
// 
// }


import cat.ppicas.framework.ui.PresenterFactory;
import cat.ppicas.framework.ui.PresenterHolder;
import cat.ppicas.cleanarch.ui.vista.CityDetailVista;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.CityDetailPresenter;
    @Override
    public void onStart() {
        super.onStart();
        mPresenter.start(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.stop();
    }

    @Override
    public void setTitle(int stringResId, Object... args) {
        getActivity().setTitle(getString(stringResId, args));
    }

    @Override
    public void displayLoading(boolean display) {
        getActivity().setProgressBarIndeterminate(true);
        getActivity().setProgressBarIndeterminateVisibility(display);
    }

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

    @Override
    public CityDetailPresenter createPresenter() {
// 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/CityDetailPresenter.java
// public class CityDetailPresenter extends Presenter<CityDetailVista> {
// 
//     private static final String DAY_OF_WEEK_DATE_FORMAT_PATTERN = "cccc";
// 
//     private final TaskExecutor mTaskExecutor;
//     private final CityRepository mCityRepository;
//     private final Resources mResources;
//     private final String mCityId;
// 
//     private GetCityTask mGetCityTask;
//     private City mCity;
// 
//     public CityDetailPresenter(TaskExecutor taskExecutor, CityRepository cityRepository,
//             Resources resources, String cityId) {
//         mTaskExecutor = taskExecutor;
//         mCityRepository = cityRepository;
//         mResources = resources;
//         mCityId = cityId;
//     }
// 
//     @Override
//     public void onStart(CityDetailVista vista) {
//         vista.setTitle(R.string.city_details__title_loading);
// 
//         if (mCity != null) {
//             vista.setTitle(R.string.city_details__title, mCity.getName());
//         } else {
//             vista.displayLoading(true);
//             if (!mTaskExecutor.isRunning(mGetCityTask)) {
//                 mGetCityTask = new GetCityTask(mCityRepository, mCityId);
//                 mTaskExecutor.execute(mGetCityTask, new GetCityTaskCallback());
//             }
//         }
//     }
// 
//     public String getForecastPageTitle(int daysFromToday) {
//         if (daysFromToday == 0) {
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     mResources.getString(R.string.global__today));
//         } else if (daysFromToday == 1) {
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     mResources.getString(R.string.global__tomorrow));
//         } else {
//             Calendar cal = Calendar.getInstance();
//             cal.add(Calendar.DAY_OF_MONTH, daysFromToday);
//             return mResources.getString(R.string.city_details__tab_forecast,
//                     DateFormat.format(DAY_OF_WEEK_DATE_FORMAT_PATTERN, cal));
//         }
//     }
// 
//     private class GetCityTaskCallback extends DisplayErrorTaskCallback<City> {
// 
//         public GetCityTaskCallback() {
//             super(CityDetailPresenter.this);
//         }
// 
//         @Override
//         public void onSuccess(City city) {
//             mCity = city;
//             CityDetailVista vista = getVista();
//             if (vista != null) {
//                 vista.displayLoading(false);
//                 vista.setTitle(R.string.city_details__title, city.getName());
//             }
//         }
//     }
// }
// 
// 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/CityDetailVista.java
// public interface CityDetailVista extends TaskResultVista {
// 
//     void setTitle(int stringResId, Object... args);
// 
// }


// Path: app/src/main/java/cat/ppicas/cleanarch/ui/fragment/CityDetailFragment.java
import cat.ppicas.framework.ui.PresenterFactory;
import cat.ppicas.framework.ui.PresenterHolder;
import cat.ppicas.cleanarch.ui.vista.CityDetailVista;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.CityDetailPresenter;

    @Override
    public void onStart() {
        super.onStart();
        mPresenter.start(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.stop();
    }

    @Override
    public void setTitle(int stringResId, Object... args) {
        getActivity().setTitle(getString(stringResId, args));
    }

    @Override
    public void displayLoading(boolean display) {
        getActivity().setProgressBarIndeterminate(true);
        getActivity().setProgressBarIndeterminateVisibility(display);
    }

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

    @Override
    public CityDetailPresenter createPresenter() {
        ServiceContainer sc = ServiceContainers.getFromApp(getActivity());