Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.androidsx.rainnotifications.backgroundservice.util.NotificationHelper;
import com.androidsx.rainnotifications.backgroundservice.util.UserLocationFetcher;
import com.androidsx.rainnotifications.forecastapislibrary.WeatherClientException;
import com.androidsx.rainnotifications.forecastapislibrary.WeatherClientResponseListener;
import com.androidsx.rainnotifications.forecastapislibrary.WeatherClientHourlyResponseListener;
import com.androidsx.rainnotifications.model.Alert;
import com.androidsx.rainnotifications.model.Day;
import com.androidsx.rainnotifications.model.DayTemplate;
Expand Down Expand Up @@ -59,7 +59,7 @@ public int onStartCommand(final Intent intent, int flags, int startId) {
UserLocationFetcher.getUserLocation(this, new UserLocationFetcher.UserLocationResultListener() {
@Override
public void onLocationSuccess(Location location) {
WeatherClientFactory.requestForecastForLocation(getApplicationContext(), location.getLatitude(), location.getLongitude(), new WeatherClientResponseListener() {
WeatherClientFactory.requestHourlyForecastForLocation(getApplicationContext(), location.getLatitude(), location.getLongitude(), new WeatherClientHourlyResponseListener() {
@Override
public void onForecastSuccess(ForecastTable forecastTable) {
if (intent != null && intent.getIntExtra(Constants.Extras.EXTRA_DAY_ALARM, 0) == Constants.Alarms.DAY_ALARM_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class CommonConstants {
/**
* Current application environment. It is essential to switch this to {@link Env#LIVE} for the Live APKs.
*/
public static final Env ENV = Env.DEV;
public static final Env ENV = Env.BETA;

/**
* Definition of the different runtime environments.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.androidsx.rainnotifications.dailyclothes.model;

public class Clothes {
private final int photo;
import android.content.Context;
import android.os.Parcelable;
import android.widget.ImageView;

public Clothes (int photo) {
this.photo = photo;
}

public int getPhoto() {
return photo;
}
public abstract class Clothes implements Parcelable{
public abstract void loadOnImageView(Context context, ImageView imageView);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader;

import android.content.Context;

import com.androidsx.rainnotifications.model.DailyWeatherWrapper;

public interface ClothesLoader {
public void loadClothes(Context context, DailyWeatherWrapper dailyWeather, ClothesLoaderListener listener);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader;

public class ClothesLoaderException extends Exception {

public ClothesLoaderException(String detailMessage) {
super(detailMessage);
}
public ClothesLoaderException(String detailMessage, Throwable throwable) {
super(detailMessage, throwable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader;

import android.content.Context;

import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.local.LocalClothesLoader;
import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.network.NetworkClothesLoader;
import com.androidsx.rainnotifications.model.DailyWeatherWrapper;

public abstract class ClothesLoaderFactory {

private static final ClothesLoaderType TYPE = ClothesLoaderType.LOCAL_LOADER;

public static void getClothes(Context context, DailyWeatherWrapper dailyWeather, ClothesLoaderListener listener) {

final ClothesLoader clothesLoader;
switch (TYPE) {
case NETWORK_LOADER: clothesLoader = new NetworkClothesLoader();
break;
case LOCAL_LOADER: clothesLoader = new LocalClothesLoader();
break;
default: throw new IllegalArgumentException("Unsupported type: " + TYPE);
}

clothesLoader.loadClothes(context, dailyWeather, listener);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader;

import com.androidsx.rainnotifications.dailyclothes.model.Clothes;

import java.util.List;

public interface ClothesLoaderListener {
public void onClothesLoaderSuccess(List<Clothes> clothesList);

public void onClothesLoaderFailure(ClothesLoaderException exception);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader;

public enum ClothesLoaderType {
LOCAL_LOADER,
NETWORK_LOADER;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader.local;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.ImageView;

import com.androidsx.rainnotifications.dailyclothes.model.Clothes;
import com.squareup.picasso.Picasso;

public class LocalClothes extends Clothes{

public static final Parcelable.Creator<LocalClothes> CREATOR = new Parcelable.Creator<LocalClothes>() {
public LocalClothes createFromParcel(Parcel in) {
return new LocalClothes(in);
}

public LocalClothes[] newArray(int size) {
return new LocalClothes[size];
}
};

private final String imagePath;

public LocalClothes(String imagePath) {
this.imagePath = imagePath;
}

private LocalClothes(Parcel in) {
imagePath = in.readString();
}

@Override
public void loadOnImageView(Context context, ImageView imageView) {
Picasso.with(context).load(imagePath).into(imageView);
}

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

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(imagePath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader.local;

import android.content.Context;
import android.os.Handler;

import com.androidsx.rainnotifications.dailyclothes.model.Clothes;
import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.ClothesLoader;
import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.ClothesLoaderException;
import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.ClothesLoaderListener;
import com.androidsx.rainnotifications.model.DailyWeatherWrapper;
import com.androidsx.rainnotifications.model.WeatherWrapper;

import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

public class LocalClothesLoader implements ClothesLoader {

private static final int SIMULATE_ASYNC_TASK_DELAY = 200;
private static final String PATH_ASSETS = "file:///android_asset/";
private static final String PATH_CLOTHES = "clothes/";


@Override
public void loadClothes(Context context, DailyWeatherWrapper dailyWeather, ClothesLoaderListener listener) {
// TODO: At this time temperature is not taken into account

Timber.d("LOADING CLOTHES FOR " + dailyWeather.getWeatherType()
+ " Min: " + dailyWeather.getMinTemperature(WeatherWrapper.TemperatureScale.CELSIUS)
+ " Max: " + dailyWeather.getMaxTemperature(WeatherWrapper.TemperatureScale.CELSIUS));

try {
String weatherClothesPath = PATH_CLOTHES + dailyWeather.getWeatherType().toString().toLowerCase();
String[] clothesPaths = context.getAssets().list(weatherClothesPath);

final List<Clothes> clothesList = new ArrayList<Clothes>();
for (String path : clothesPaths) {
clothesList.add(new LocalClothes(PATH_ASSETS + weatherClothesPath + "/" + path));
}

simulateAsyncLoad(listener, clothesList);

} catch (Exception e) {
Timber.e(e, "Failed to load clothes from assets");
simulateAsyncLoad(listener, null);
}
}

private void simulateAsyncLoad(final ClothesLoaderListener listener, final List<Clothes> clothesList) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
if(clothesList == null) {
listener.onClothesLoaderFailure(new ClothesLoaderException("Null assets list"));
}
else if(clothesList.isEmpty()) {
listener.onClothesLoaderFailure(new ClothesLoaderException("Empty assets list"));
}
else {
listener.onClothesLoaderSuccess(clothesList);
}
}
}, SIMULATE_ASYNC_TASK_DELAY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.androidsx.rainnotifications.dailyclothes.model.clothesloader.network;

import android.content.Context;

import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.ClothesLoader;
import com.androidsx.rainnotifications.dailyclothes.model.clothesloader.ClothesLoaderListener;
import com.androidsx.rainnotifications.model.DailyWeatherWrapper;

public class NetworkClothesLoader implements ClothesLoader{

@Override
public void loadClothes(Context context, DailyWeatherWrapper dailyWeather, ClothesLoaderListener listener) {
throw new IllegalArgumentException("Unimplemented NetworkClothesLoader");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,44 @@ public ClothesPagerAdapter(FragmentManager fm, List<Clothes> clothesList) {
this.clothesList = clothesList;
}

public void updateClothesList(List<Clothes> clothesList) {
this.clothesList = clothesList;
notifyDataSetChanged();
}

@Override
public Fragment getItem(int position) {
return ClothesFragment.newInstance(clothesList.get(position).getPhoto());
return ClothesFragment.newInstance(clothesList.get(position));
}

@Override
public int getCount() {
return clothesList.size();
return clothesList != null ? clothesList.size() : 0;
}

public static class ClothesFragment extends Fragment {

private static final String ARG_IMAGE_RESOURCE = "ImageFragment:imageResource";
private int imageResource;
private static final String ARG_CLOTHES = "ImageFragment:clothes";
private Clothes clothes;

public static ClothesFragment newInstance(int imageResource) {
public static ClothesFragment newInstance(Clothes clothes) {
ClothesFragment fragment = new ClothesFragment();
Bundle args = new Bundle();
args.putInt(ARG_IMAGE_RESOURCE, imageResource);
args.putParcelable(ARG_CLOTHES, clothes);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageResource = getArguments().getInt(ARG_IMAGE_RESOURCE);
clothes = getArguments().getParcelable(ARG_CLOTHES);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_clothes, container, false);

((ImageView) rootView.findViewById(R.id.image_view)).setImageResource(imageResource); //TODO: Hacer con Picasso

clothes.loadOnImageView(getActivity(), (ImageView) rootView.findViewById(R.id.image_view));
return rootView;
}
}
Expand Down
Loading