// 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: core/src/main/java/cat/ppicas/cleanarch/model/City.java
// public class City {
// 
//     private String mId;
//     private String mName;
//     private String mCountry;
//     private CurrentWeatherPreview mCurrentWeatherPreview;
// 
//     public City(String id, String name, String country) {
//         mId = id;
//         mName = name;
//         mCountry = country;
//     }
// 
//     public City(String id, String name, String country,
//             CurrentWeatherPreview currentWeatherPreview) {
//         mId = id;
//         mName = name;
//         mCountry = country;
//         mCurrentWeatherPreview = currentWeatherPreview;
//     }
// 
//     public String getId() {
//         return mId;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public String getCountry() {
//         return mCountry;
//     }
// 
//     public CurrentWeatherPreview getCurrentWeatherPreview() {
//         return mCurrentWeatherPreview;
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/vista/CityListItemVista.java
// public interface CityListItemVista extends Vista {
// 
//     void setCityName(String name);
// 
//     void setCountry(String country);
// 
//     void setCurrentTemp(String temp);
// 
//     void setLoadingElevation(boolean loading);
// 
//     void setElevation(int elevation);
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/presenter/CityListItemPresenter.java
// public class CityListItemPresenter extends Presenter<CityListItemVista> {
// 
//     private TaskExecutor mTaskExecutor;
//     private City mCity;
// 
//     private int mElevation = -1;
//     private GetElevationTask mGetElevationTask;
// 
//     public CityListItemPresenter(TaskExecutor taskExecutor, City city) {
//         mTaskExecutor = taskExecutor;
//         mCity = city;
//     }
// 
//     @Override
//     public void onStart(CityListItemVista vista) {
//         updateVista();
// 
//         if (mElevation > -1) {
//             vista.setLoadingElevation(false);
//             vista.setElevation(mElevation);
//         } else {
//             vista.setLoadingElevation(true);
//             if (!mTaskExecutor.isRunning(mGetElevationTask)) {
//                 mGetElevationTask = new GetElevationTask(mCity);
//                 mTaskExecutor.execute(mGetElevationTask, new GetElevationTaskCallback());
//             }
//         }
//     }
// 
//     @Override
//     public void onDestroy() {
//         if (mTaskExecutor.isRunning(mGetElevationTask)) {
//             mGetElevationTask.cancel();
//         }
//     }
// 
//     public void setCity(City city) {
//         if (mCity.getId().equals(city.getId()) && mCity.getName().equals(city.getName())) {
//             return;
//         }
// 
//         mCity = city;
//         updateVista();
// 
//         if (mTaskExecutor.isRunning(mGetElevationTask)) {
//             mGetElevationTask.cancel();
//         }
//         if (getVista() != null) {
//             getVista().setLoadingElevation(true);
//         }
//         mElevation = -1;
//         mGetElevationTask = new GetElevationTask(city);
//         mTaskExecutor.execute(mGetElevationTask, new GetElevationTaskCallback());
//     }
// 
//     private void updateVista() {
//         CityListItemVista vista = getVista();
//         if (vista == null) {
//             return;
//         }
// 
//         vista.setCityName(mCity.getName());
//         vista.setCountry(mCity.getCountry());
//         double temp = mCity.getCurrentWeatherPreview().getCurrentTemp();
//         vista.setCurrentTemp(NumberFormat.formatTemperature(temp));
//     }
// 
//     private class GetElevationTaskCallback extends SuccessTaskCallback<Integer> {
//         @Override
//         public void onSuccess(Integer elevation) {
//             mElevation = elevation;
//             if (getVista() != null) {
//                 getVista().setElevation(elevation);
//                 getVista().setLoadingElevation(false);
//             }
//         }
//     }
// }
// 
// Path: core/src/main/java/cat/ppicas/framework/task/TaskExecutor.java
// public interface TaskExecutor {
// 
//     <R, E extends Exception> void execute(Task<R, E> task, TaskCallback<R, E> callback);
// 
//     boolean isRunning(Task<?, ?> task);
// 
// }


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import cat.ppicas.cleanarch.R;
import cat.ppicas.cleanarch.app.ServiceContainers;
import cat.ppicas.cleanarch.model.City;
import cat.ppicas.cleanarch.ui.vista.CityListItemVista;
import cat.ppicas.cleanarch.ui.presenter.CityListItemPresenter;
import cat.ppicas.framework.task.TaskExecutor;
/*
 * Copyright (C) 2015 Pau Picas Sans <pau.picas@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package cat.ppicas.cleanarch.ui.adapter;



public class CityAdapter extends ArrayAdapter<City> {

    private final LayoutInflater mInflater;
    private final TaskExecutor mTaskExecutor;

    public CityAdapter(Context context) {
        super(context, android.R.layout.simple_list_item_1);
        mInflater = LayoutInflater.from(context);

// 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: core/src/main/java/cat/ppicas/cleanarch/model/City.java
// public class City {
// 
//     private String mId;
//     private String mName;
//     private String mCountry;
//     private CurrentWeatherPreview mCurrentWeatherPreview;
// 
//     public City(String id, String name, String country) {
//         mId = id;
//         mName = name;
//         mCountry = country;
//     }
// 
//     public City(String id, String name, String country,
//             CurrentWeatherPreview currentWeatherPreview) {
//         mId = id;
//         mName = name;
//         mCountry = country;
//         mCurrentWeatherPreview = currentWeatherPreview;
//     }
// 
//     public String getId() {
//         return mId;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public String getCountry() {
//         return mCountry;
//     }
// 
//     public CurrentWeatherPreview getCurrentWeatherPreview() {
//         return mCurrentWeatherPreview;
//     }
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/vista/CityListItemVista.java
// public interface CityListItemVista extends Vista {
// 
//     void setCityName(String name);
// 
//     void setCountry(String country);
// 
//     void setCurrentTemp(String temp);
// 
//     void setLoadingElevation(boolean loading);
// 
//     void setElevation(int elevation);
// 
// }
// 
// Path: app/src/main/java/cat/ppicas/cleanarch/ui/presenter/CityListItemPresenter.java
// public class CityListItemPresenter extends Presenter<CityListItemVista> {
// 
//     private TaskExecutor mTaskExecutor;
//     private City mCity;
// 
//     private int mElevation = -1;
//     private GetElevationTask mGetElevationTask;
// 
//     public CityListItemPresenter(TaskExecutor taskExecutor, City city) {
//         mTaskExecutor = taskExecutor;
//         mCity = city;
//     }
// 
//     @Override
//     public void onStart(CityListItemVista vista) {
//         updateVista();
// 
//         if (mElevation > -1) {
//             vista.setLoadingElevation(false);
//             vista.setElevation(mElevation);
//         } else {
//             vista.setLoadingElevation(true);
//             if (!mTaskExecutor.isRunning(mGetElevationTask)) {
//                 mGetElevationTask = new GetElevationTask(mCity);
//                 mTaskExecutor.execute(mGetElevationTask, new GetElevationTaskCallback());
//             }
//         }
//     }
// 
//     @Override
//     public void onDestroy() {
//         if (mTaskExecutor.isRunning(mGetElevationTask)) {
//             mGetElevationTask.cancel();
//         }
//     }
// 
//     public void setCity(City city) {
//         if (mCity.getId().equals(city.getId()) && mCity.getName().equals(city.getName())) {
//             return;
//         }
// 
//         mCity = city;
//         updateVista();
// 
//         if (mTaskExecutor.isRunning(mGetElevationTask)) {
//             mGetElevationTask.cancel();
//         }
//         if (getVista() != null) {
//             getVista().setLoadingElevation(true);
//         }
//         mElevation = -1;
//         mGetElevationTask = new GetElevationTask(city);
//         mTaskExecutor.execute(mGetElevationTask, new GetElevationTaskCallback());
//     }
// 
//     private void updateVista() {
//         CityListItemVista vista = getVista();
//         if (vista == null) {
//             return;
//         }
// 
//         vista.setCityName(mCity.getName());
//         vista.setCountry(mCity.getCountry());
//         double temp = mCity.getCurrentWeatherPreview().getCurrentTemp();
//         vista.setCurrentTemp(NumberFormat.formatTemperature(temp));
//     }
// 
//     private class GetElevationTaskCallback extends SuccessTaskCallback<Integer> {
//         @Override
//         public void onSuccess(Integer elevation) {
//             mElevation = elevation;
//             if (getVista() != null) {
//                 getVista().setElevation(elevation);
//                 getVista().setLoadingElevation(false);
//             }
//         }
//     }
// }
// 
// Path: core/src/main/java/cat/ppicas/framework/task/TaskExecutor.java
// public interface TaskExecutor {
// 
//     <R, E extends Exception> void execute(Task<R, E> task, TaskCallback<R, E> callback);
// 
//     boolean isRunning(Task<?, ?> task);
// 
// }


// Path: app/src/main/java/cat/ppicas/cleanarch/ui/adapter/CityAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import cat.ppicas.cleanarch.R;
import cat.ppicas.cleanarch.app.ServiceContainers;
import cat.ppicas.cleanarch.model.City;
import cat.ppicas.cleanarch.ui.vista.CityListItemVista;
import cat.ppicas.cleanarch.ui.presenter.CityListItemPresenter;
import cat.ppicas.framework.task.TaskExecutor;

/*
 * Copyright (C) 2015 Pau Picas Sans <pau.picas@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package cat.ppicas.cleanarch.ui.adapter;



public class CityAdapter extends ArrayAdapter<City> {

    private final LayoutInflater mInflater;
    private final TaskExecutor mTaskExecutor;

    public CityAdapter(Context context) {
        super(context, android.R.layout.simple_list_item_1);
        mInflater = LayoutInflater.from(context);

        mTaskExecutor = ServiceContainers.getFromApp(context).getTaskExecutor();