diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 60d6222..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Easy Weather \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..4fdc309 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 519509f..9340274 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/README.md b/README.md index eae7053..1461194 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ Easy and quick weather fetching from [OpenWeatherMap](openweathermap.org) API for Android. +Fork version of : https://github.com/code-crusher/EasyWeather + +Changes : More Generic / Support lang / Add "16 day / daily forecast" feature + -------- ###Specs @@ -34,7 +38,7 @@ allprojects { ```gradle dependencies { - compile 'com.github.code-crusher:EasyWeather:v1.2' + compile 'com.github.sokarcreative:EasyWeather:1.3.0' } ``` @@ -47,38 +51,35 @@ buildTypes.each { ``` First create `WeatherMap` object: ```Java - WeatherMap weatherMap = new WeatherMap(this, OWM_API_KEY); + WeatherMap weatherMap = new WeatherMap(this, OWM_API_KEY, LANG); // LANG like "en", #see Multilingual support : https://openweathermap.org/current at the bottom page ``` To get **Current Weather** use this in `Activity`: **By City Name**: ```Java -weatherMap.getCityWeather(city, new WeatherCallback() { +weatherMap.getCityWeather(city, new WeatherCallback() { + @Override + public void success(CurrentWeatherResponseModel response) { + Log.i(response.toString()); + } + @Override - public void success(WeatherResponseModel response) { - Weather weather[] = response.getWeather(); - String weatherMain = weather[0].getMain(); + public void failure(String message) { + } + }); ``` To get temperature in specific units you can use: ```Java Double temperature = TempUnitConverter.convertToCelsius(response.getMain().getTemp()); ``` -To get other details you can use: -```Java -String location = response.getName(); -String humidity= response.getMain().getHumidity(); -String pressure = response.getMain().getPressure(); -String windSpeed = response.getWind().getSpeed(); -String iconLink = weather[0].getIconLink(); - ``` **By Location Coordinates**: ```Java -weatherMap.getLocationWeather(latitude, longitude, new WeatherCallback() { +weatherMap.getLocationWeather(latitude, longitude, new WeatherCallback() { @Override - public void success(WeatherResponseModel response) { - + public void success(CurrentWeatherResponseModel response) { + Log.i(response.toString()); } @Override @@ -92,10 +93,10 @@ To get **Forecast** use this in `Activity` also you need specify `index` to get **By City Name:** ```Java -weatherMap.getCityForecast(city, new ForecastCallback() { +weatherMap.getCityForecast(city, new WeatherCallback() { @Override public void success(ForecastResponseModel response) { - Weather weather[] = response.getList()[index].getWeather(); + Log.i(response.toString()); } @Override @@ -109,10 +110,45 @@ weatherMap.getCityForecast(city, new ForecastCallback() { **By Location Coordinates:** ```Java -weatherMap.getLocationForecast(latitude, longitude, new ForecastCallback() { +weatherMap.getLocationForecast(latitude, longitude, new WeatherCallback() { @Override public void success(ForecastResponseModel response) { - + Log.i(response.toString()); + } + + @Override + public void failure(String message) { + + } + }); +``` + +To get **DailyForecast** use this in `Activity` also you need specify `index` to get the specific day of [16 day / daily forecast](http://openweathermap.org/forecast16): + +**By City Name:** + +```Java +weatherMap.getCityDailyForecast(city, [OPTIONAL] dayCount, new WeatherCallback() { + @Override + public void success(DailyForecastResponseModel response) { + Log.i(response.toString()); + } + + @Override + public void failure(String message) { + + } + }); +``` + + +**By Location Coordinates:** + +```Java +weatherMap.getLocationDailyForecast(latitude, longitude, [OPTIONAL] dayCount, new WeatherCallback() { + @Override + public void success(DailyForecastResponseModel response) { + Log.i(response.toString()); } @Override diff --git a/app/build.gradle b/app/build.gradle index 2db3208..ce26c40 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 25 - buildToolsVersion "25.0.1" + buildToolsVersion "25.0.2" defaultConfig { applicationId "github.vatsal.easyweatherdemo" @@ -23,11 +23,15 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:25.1.0' - compile 'com.android.support:cardview-v7:25.1.0' - compile 'com.jakewharton:butterknife:7.0.1' + compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support:cardview-v7:25.3.1' + compile 'com.jakewharton:butterknife:8.5.1' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' compile 'com.squareup.picasso:picasso:2.5.2' + compile 'co.trikita:log:1.1.5' compile project(path: ':library') -// compile 'github.vatsal.easyweather:library:1.0.0' + + //compile 'com.github.sokarcreative:EasyWeather:development-SNAPSHOT' + //compile 'github.vatsal.easyweather:library:1.0.0' } diff --git a/app/src/main/java/github/vatsal/easyweatherdemo/MainActivity.java b/app/src/main/java/github/vatsal/easyweatherdemo/MainActivity.java index 7a13322..a06f556 100644 --- a/app/src/main/java/github/vatsal/easyweatherdemo/MainActivity.java +++ b/app/src/main/java/github/vatsal/easyweatherdemo/MainActivity.java @@ -11,59 +11,61 @@ import com.squareup.picasso.Picasso; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -import github.vatsal.easyweather.Helper.ForecastCallback; import github.vatsal.easyweather.Helper.TempUnitConverter; import github.vatsal.easyweather.Helper.WeatherCallback; -import github.vatsal.easyweather.WeatherMap; +import github.vatsal.easyweather.retrofit.api.WeatherMap; +import github.vatsal.easyweather.retrofit.models.CurrentWeatherResponseModel; +import github.vatsal.easyweather.retrofit.models.DailyForecastResponseModel; import github.vatsal.easyweather.retrofit.models.ForecastResponseModel; import github.vatsal.easyweather.retrofit.models.Weather; -import github.vatsal.easyweather.retrofit.models.WeatherResponseModel; +import trikita.log.Log; public class MainActivity extends AppCompatActivity { public final String APP_ID = BuildConfig.OWM_API_KEY; + public final String lang = "fr"; String city = "San Francisco"; - @Bind(R.id.weather_title) + @BindView(R.id.weather_title) TextView weatherTitle; - @Bind(R.id.refresh) + @BindView(R.id.refresh) ImageButton refresh; - @Bind(R.id.weather_icon) + @BindView(R.id.weather_icon) ImageView weatherIcon; - @Bind(R.id.location) + @BindView(R.id.location) TextView location; - @Bind(R.id.condition) + @BindView(R.id.condition) TextView condition; - @Bind(R.id.temp) + @BindView(R.id.temp) TextView temp; - @Bind(R.id.tvHumidity) + @BindView(R.id.tvHumidity) TextView tvHumidity; - @Bind(R.id.tvPressure) + @BindView(R.id.tvPressure) TextView tvPressure; - @Bind(R.id.tvWind) + @BindView(R.id.tvWind) TextView tvWind; - @Bind(R.id.tvWindDeg) + @BindView(R.id.tvWindDeg) TextView tvWindDeg; - @Bind(R.id.et_city) + @BindView(R.id.et_city) EditText etCity; - @Bind(R.id.tv_go) + @BindView(R.id.tv_go) TextView tvGo; - @Bind(R.id.textLayout) + @BindView(R.id.textLayout) LinearLayout textLayout; - @Bind(R.id.humidity_desc) + @BindView(R.id.humidity_desc) TextView humidityDesc; - @Bind(R.id.pres_desc) + @BindView(R.id.pres_desc) TextView presDesc; - @Bind(R.id.ws_desc) + @BindView(R.id.ws_desc) TextView wsDesc; - @Bind(R.id.wd_desc) + @BindView(R.id.wd_desc) TextView wdDesc; - @Bind(R.id.ll_extraWeather) + @BindView(R.id.ll_extraWeather) LinearLayout llExtraWeather; - @Bind(R.id.weatherCard) + @BindView(R.id.weatherCard) CardView weatherCard; @Override @@ -80,11 +82,12 @@ public void refresh() { } private void loadWeather(String city) { - WeatherMap weatherMap = new WeatherMap(this, APP_ID); - weatherMap.getCityWeather(city, new WeatherCallback() { + WeatherMap weatherMap = new WeatherMap(this, APP_ID, lang); + weatherMap.getCityWeather(city, new WeatherCallback() { @Override - public void success(WeatherResponseModel response) { + public void success(CurrentWeatherResponseModel response) { populateWeather(response); + Log.i(response.toString()); } @Override @@ -93,10 +96,22 @@ public void failure(String message) { } }); - weatherMap.getCityForecast(city, new ForecastCallback() { + weatherMap.getCityForecast(city, new WeatherCallback() { @Override public void success(ForecastResponseModel response) { - ForecastResponseModel responseModel = response; + Log.i(response.toString()); + } + + @Override + public void failure(String message) { + + } + }); + + weatherMap.getCityDailyForecast(city, "3", new WeatherCallback() { + @Override + public void success(DailyForecastResponseModel response) { + Log.i(response.toString()); } @Override @@ -106,7 +121,7 @@ public void failure(String message) { }); } - private void populateWeather(WeatherResponseModel response) { + private void populateWeather(CurrentWeatherResponseModel response) { Weather weather[] = response.getWeather(); condition.setText(weather[0].getMain()); @@ -127,4 +142,10 @@ public void go() { city = etCity.getText().toString().trim(); loadWeather(city); } + + @Override + protected void onDestroy() { + super.onDestroy(); + + } } diff --git a/build.gradle b/build.gradle index 5c79079..e08ce37 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" @@ -13,6 +13,7 @@ buildscript { allprojects { repositories { jcenter() + maven { url 'https://jitpack.io' } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b71ba33..0becb10 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 05 13:13:23 IST 2017 +#Sat Apr 08 19:05:14 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index ad3f1a2..9c005d9 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -6,13 +6,13 @@ group = 'com.github.vatsal' android { compileSdkVersion 25 - buildToolsVersion "25.0.1" + buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 14 targetSdkVersion 25 - versionCode 11 - versionName "1.1" + versionCode 12 + versionName "1.2" } buildTypes { release { @@ -23,10 +23,10 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.google.code.gson:gson:2.6.2' - compile 'com.squareup.retrofit2:retrofit:2.1.0' - compile 'com.squareup.retrofit2:converter-gson:2.1.0' - compile 'com.squareup.okhttp3:logging-interceptor:3.4.2' + compile 'com.google.code.gson:gson:2.7' + compile 'com.squareup.retrofit2:retrofit:2.2.0' + compile 'com.squareup.retrofit2:converter-gson:2.2.0' + compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' } \ No newline at end of file diff --git a/library/src/main/java/github/vatsal/easyweather/Helper/ForecastCallback.java b/library/src/main/java/github/vatsal/easyweather/Helper/ForecastCallback.java deleted file mode 100644 index 5892abc..0000000 --- a/library/src/main/java/github/vatsal/easyweather/Helper/ForecastCallback.java +++ /dev/null @@ -1,16 +0,0 @@ -package github.vatsal.easyweather.Helper; - -import github.vatsal.easyweather.retrofit.models.ForecastResponseModel; - -/** - * Created by - --Vatsal Bajpai on - --6/23/2016 at - --4:29 PM - */ -public abstract class ForecastCallback { - - public abstract void success(ForecastResponseModel response); - - public abstract void failure(String message); -} diff --git a/library/src/main/java/github/vatsal/easyweather/Helper/WeatherCallback.java b/library/src/main/java/github/vatsal/easyweather/Helper/WeatherCallback.java index 0ea889c..5d0018e 100644 --- a/library/src/main/java/github/vatsal/easyweather/Helper/WeatherCallback.java +++ b/library/src/main/java/github/vatsal/easyweather/Helper/WeatherCallback.java @@ -1,14 +1,12 @@ package github.vatsal.easyweather.Helper; -import github.vatsal.easyweather.retrofit.models.WeatherResponseModel; - /** * Created by --Vatsal Bajpai on --6/23/2016 at --4:29 PM */ -public abstract class WeatherCallback { +public abstract class WeatherCallback { public abstract void success(WeatherResponseModel response); diff --git a/library/src/main/java/github/vatsal/easyweather/WeatherMap.java b/library/src/main/java/github/vatsal/easyweather/WeatherMap.java deleted file mode 100644 index 969bc30..0000000 --- a/library/src/main/java/github/vatsal/easyweather/WeatherMap.java +++ /dev/null @@ -1,195 +0,0 @@ -package github.vatsal.easyweather; - -import android.content.Context; - -import github.vatsal.easyweather.Helper.ForecastCallback; -import github.vatsal.easyweather.Helper.WeatherCallback; -import github.vatsal.easyweather.retrofit.api.ApiClient; -import github.vatsal.easyweather.retrofit.api.WeatherRetrofitCallback; -import github.vatsal.easyweather.retrofit.models.ForecastResponseModel; -import github.vatsal.easyweather.retrofit.models.WeatherResponseModel; -import retrofit2.Call; - -/** - * Created by - * --Vatsal Bajpai under - * --AppyWare on - * --22/06/16 at - * --2:44 AM in - * --OpenWeatherMapDemo - */ -public class WeatherMap { - - Context context; - String APP_ID; - - public WeatherMap(Context context, String APP_ID) { - this.context = context; - this.APP_ID = APP_ID; - } - - public void getCityWeather(String city, final WeatherCallback weatherCallback) { - final ApiClient objApi = ApiClient.getInstance(); - try { - Call objCall = null; - - objCall = objApi.getApi(context).getCityWeather(APP_ID, city); - - if (objCall != null) { - objCall.enqueue(new WeatherRetrofitCallback(context) { - - @Override - public void onFailure(Call call, Throwable t) { - - weatherCallback.failure("Failed"); - super.onFailure(call, t); - } - - @Override - protected void onResponseWeatherResponse(Call call, retrofit2.Response response) { - - if (!response.isSuccessful()) - weatherCallback.failure("Failed"); - } - - @Override - protected void onResponseWeatherObject(Call call, WeatherResponseModel response) { - - weatherCallback.success(response); - } - - @Override - protected void common() { - - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void getLocationWeather(String latitude, String longitude, final WeatherCallback weatherCallback) { - final ApiClient objApi = ApiClient.getInstance(); - try { - Call objCall = null; - - objCall = objApi.getApi(context).getLocationWeather(APP_ID, latitude, longitude); - - if (objCall != null) { - objCall.enqueue(new WeatherRetrofitCallback(context) { - - @Override - public void onFailure(Call call, Throwable t) { - - weatherCallback.failure("Failed"); - super.onFailure(call, t); - } - - @Override - protected void onResponseWeatherResponse(Call call, retrofit2.Response response) { - - if (!response.isSuccessful()) - weatherCallback.failure("Failed"); - } - - @Override - protected void onResponseWeatherObject(Call call, WeatherResponseModel response) { - - weatherCallback.success(response); - } - - @Override - protected void common() { - - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void getCityForecast(String city, final ForecastCallback forecastCallback) { - final ApiClient objApi = ApiClient.getInstance(); - try { - Call objCall = null; - - objCall = objApi.getApi(context).getCityForcast(APP_ID, city); - - if (objCall != null) { - objCall.enqueue(new WeatherRetrofitCallback(context) { - - @Override - public void onFailure(Call call, Throwable t) { - - forecastCallback.failure("Failed"); - super.onFailure(call, t); - } - - @Override - protected void onResponseWeatherResponse(Call call, retrofit2.Response response) { - - if (!response.isSuccessful()) - forecastCallback.failure("Failed"); - } - - @Override - protected void onResponseWeatherObject(Call call, ForecastResponseModel response) { - - forecastCallback.success(response); - } - - @Override - protected void common() { - - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void getLocationForecast(String latitude, String longitude, final ForecastCallback forecastCallback) { - final ApiClient objApi = ApiClient.getInstance(); - try { - Call objCall = null; - - objCall = objApi.getApi(context).getLocationForecast(APP_ID, latitude, longitude); - - if (objCall != null) { - objCall.enqueue(new WeatherRetrofitCallback(context) { - - @Override - public void onFailure(Call call, Throwable t) { - - forecastCallback.failure("Failed"); - super.onFailure(call, t); - } - - @Override - protected void onResponseWeatherResponse(Call call, retrofit2.Response response) { - - if (!response.isSuccessful()) - forecastCallback.failure("Failed"); - } - - @Override - protected void onResponseWeatherObject(Call call, ForecastResponseModel response) { - - forecastCallback.success(response); - } - - @Override - protected void common() { - - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/api/ApiClient.java b/library/src/main/java/github/vatsal/easyweather/retrofit/api/ApiClient.java index 88c153f..e95a97b 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/api/ApiClient.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/api/ApiClient.java @@ -1,9 +1,6 @@ package github.vatsal.easyweather.retrofit.api; -import android.content.Context; -import android.support.annotation.NonNull; - import java.io.IOException; import okhttp3.Interceptor; @@ -16,19 +13,20 @@ public class ApiClient { - private static ApiClient uniqInstance; - private final String URL_LIVE = "http://api.openweathermap.org/data/2.5/"; + private static ApiClient instance; + private static final String URL_LIVE = "http://api.openweathermap.org/data/2.5/"; + - private WeatherInterface weatherInterface; public static synchronized ApiClient getInstance() { - if (uniqInstance == null) { - uniqInstance = new ApiClient(); + if (instance == null) { + instance = new ApiClient(); } - return uniqInstance; + return instance; } - private void ApiClient(@NonNull final Context currContext) { + protected WeatherInterface getWeatherInterface() { + WeatherInterface weatherInterface = null; try { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); // set your desired log level @@ -51,10 +49,9 @@ public Response intercept(Interceptor.Chain chain) throws IOException { .addInterceptor(headerInterceptor) .addInterceptor(logging) .build(); - String API_URL = URL_LIVE; Retrofit retrofit = new Retrofit.Builder() - .baseUrl(API_URL) + .baseUrl(URL_LIVE) .addConverterFactory(GsonConverterFactory.create()) .client(httpClient) .build(); @@ -63,14 +60,6 @@ public Response intercept(Interceptor.Chain chain) throws IOException { } catch (Exception e) { e.printStackTrace(); } - } - - public WeatherInterface getApi(Context currContext) { - if (uniqInstance == null) { - getInstance(); - } - uniqInstance.ApiClient(currContext); - return weatherInterface; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherInterface.java b/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherInterface.java index a614c46..97cd401 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherInterface.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherInterface.java @@ -1,7 +1,8 @@ package github.vatsal.easyweather.retrofit.api; +import github.vatsal.easyweather.retrofit.models.DailyForecastResponseModel; import github.vatsal.easyweather.retrofit.models.ForecastResponseModel; -import github.vatsal.easyweather.retrofit.models.WeatherResponseModel; +import github.vatsal.easyweather.retrofit.models.CurrentWeatherResponseModel; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Query; @@ -9,21 +10,47 @@ public interface WeatherInterface { @GET("weather") - Call getCityWeather(@Query("appid") String appid, - @Query("q") String city); + Call getCityWeather(@Query("appid") String appid, + @Query("q") String city, + @Query("lang") String lang); @GET("weather") - Call getLocationWeather(@Query("appid") String appid, - @Query("lat") String latitude, - @Query("lon") String longitude); + Call getLocationWeather(@Query("appid") String appid, + @Query("lat") String latitude, + @Query("lon") String longitude, + @Query("lang") String lang); @GET("forecast") Call getCityForcast(@Query("appid") String appid, - @Query("q") String city); + @Query("q") String city, + @Query("lang") String lang); @GET("forecast") Call getLocationForecast(@Query("appid") String appid, @Query("lat") String latitude, - @Query("lon") String longitude); + @Query("lon") String longitude, + @Query("lang") String lang); + + @GET("forecast/daily") + Call getCityDailyForcast(@Query("appid") String appid, + @Query("q") String city, + @Query("lang") String lang); + @GET("forecast/daily") + Call getCityDailyForcast(@Query("appid") String appid, + @Query("q") String city, + @Query("cnt") String cnt, + @Query("lang") String lang); + + @GET("forecast/daily") + Call getLocationDailyForecast(@Query("appid") String appid, + @Query("lat") String latitude, + @Query("lon") String longitude, + @Query("lang") String lang); + @GET("forecast/daily") + Call getLocationDailyForecast(@Query("appid") String appid, + @Query("lat") String latitude, + @Query("lon") String longitude, + @Query("cnt") String cnt, + @Query("lang") String lang); } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherMap.java b/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherMap.java new file mode 100644 index 0000000..44f45c6 --- /dev/null +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/api/WeatherMap.java @@ -0,0 +1,147 @@ +package github.vatsal.easyweather.retrofit.api; + +import android.content.Context; +import android.support.annotation.Nullable; + +import github.vatsal.easyweather.Helper.WeatherCallback; +import github.vatsal.easyweather.retrofit.models.CurrentWeatherResponseModel; +import github.vatsal.easyweather.retrofit.models.DailyForecastResponseModel; +import github.vatsal.easyweather.retrofit.models.ForecastResponseModel; +import retrofit2.Call; + +/** + * Created by + * --Vatsal Bajpai under + * --AppyWare on + * --22/06/16 at + * --2:44 AM in + * --OpenWeatherMapDemo + */ +public class WeatherMap { + + private Context context; + private String APP_ID; + private String lang; + + private ApiClient apiClient; + private WeatherInterface weatherInterface; + + public WeatherMap(Context context, String APP_ID, String lang) { + this.context = context; + this.APP_ID = APP_ID; + this.lang = lang; + this.apiClient = ApiClient.getInstance(); + this.weatherInterface = apiClient.getWeatherInterface(); + } + + + public void getCityWeather(String city, WeatherCallback weatherCallback) { + try { + Call objCall = weatherInterface.getCityWeather(APP_ID, city, lang); + + if (objCall != null) { + enqueue(weatherCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getLocationWeather(String latitude, String longitude, WeatherCallback weatherCallback) { + try { + Call objCall = weatherInterface.getLocationWeather(APP_ID, latitude, longitude, lang); + + if (objCall != null) { + enqueue(weatherCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getCityForecast(String city, WeatherCallback forecastCallback) { + + try { + Call objCall = weatherInterface.getCityForcast(APP_ID, city, lang); + + if (objCall != null) { + enqueue(forecastCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getLocationForecast(String latitude, String longitude, WeatherCallback forecastCallback) { + try { + Call objCall = weatherInterface.getLocationForecast(APP_ID, latitude, longitude, lang); + + if (objCall != null) { + enqueue(forecastCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + public void getCityDailyForecast(String city, @Nullable String dayCount, WeatherCallback forecastCallback) { + try { + Call objCall = (dayCount == null)?weatherInterface.getCityDailyForcast(APP_ID, city, lang):weatherInterface.getCityDailyForcast(APP_ID, city, dayCount, lang); + + if (objCall != null) { + enqueue(forecastCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + public void getCityDailyForecast(String city, WeatherCallback forecastCallback) { + getCityDailyForecast(city, null, forecastCallback); + } + + public void getLocationDailyForecast(String latitude, String longitude, @Nullable String dayCount, WeatherCallback forecastCallback) { + try { + Call objCall = (dayCount == null)?weatherInterface.getLocationDailyForecast(APP_ID, latitude, longitude, lang):weatherInterface.getLocationDailyForecast(APP_ID, latitude, longitude, dayCount, lang); + + if (objCall != null) { + enqueue(forecastCallback, objCall); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getLocationDailyForecast(String latitude, String longitude, WeatherCallback forecastCallback) { + getLocationDailyForecast(latitude, longitude, null, forecastCallback); + } + + private void enqueue(final WeatherCallback callback, Call objCall){ + objCall.enqueue(new WeatherRetrofitCallback(context) { + + @Override + public void onFailure(Call call, Throwable t) { + + callback.failure("Failed"); + super.onFailure(call, t); + } + + @Override + protected void onResponseWeatherResponse(Call call, retrofit2.Response response) { + + if (!response.isSuccessful()) + callback.failure("Failed"); + } + + @Override + protected void onResponseWeatherObject(Call call, T response) { + + callback.success(response); + } + + @Override + protected void common() { + + } + }); + } + +} diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/City.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/City.java index 6849cf6..3c9e0fd 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/City.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/City.java @@ -71,6 +71,13 @@ public void setCountry(String country) { @Override public String toString() { - return "ClassPojo [coord = " + coord + ", id = " + id + ", sys = " + sys + ", name = " + name + ", population = " + population + ", country = " + country + "]"; + return "City{" + + "coord=" + coord + + ", id='" + id + '\'' + + ", sys=" + sys + + ", name='" + name + '\'' + + ", population='" + population + '\'' + + ", country='" + country + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Clouds.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Clouds.java index a53df55..8650545 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Clouds.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Clouds.java @@ -21,6 +21,8 @@ public void setAll(String all) { @Override public String toString() { - return "ClassPojo [all = " + all + "]"; + return "Clouds{" + + "all='" + all + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Coord.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Coord.java index 588740e..0b1f2ae 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Coord.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Coord.java @@ -31,6 +31,9 @@ public void setLat(String lat) { @Override public String toString() { - return "ClassPojo [lon = " + lon + ", lat = " + lat + "]"; + return "Coord{" + + "lon='" + lon + '\'' + + ", lat='" + lat + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/WeatherResponseModel.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/CurrentWeatherResponseModel.java similarity index 77% rename from library/src/main/java/github/vatsal/easyweather/retrofit/models/WeatherResponseModel.java rename to library/src/main/java/github/vatsal/easyweather/retrofit/models/CurrentWeatherResponseModel.java index 86bca55..5929d40 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/WeatherResponseModel.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/CurrentWeatherResponseModel.java @@ -1,6 +1,6 @@ package github.vatsal.easyweather.retrofit.models; -import java.io.Serializable; +import java.util.Arrays; /** * Created by @@ -10,7 +10,7 @@ * --3:16 PM in * --PopularMoviesApp */ -public class WeatherResponseModel implements Serializable { +public class CurrentWeatherResponseModel { private String id; @@ -134,6 +134,19 @@ public void setMain(Main main) { @Override public String toString() { - return "ClassPojo [id = " + id + ", dt = " + dt + ", clouds = " + clouds + ", coord = " + coord + ", wind = " + wind + ", cod = " + cod + ", sys = " + sys + ", name = " + name + ", base = " + base + ", weather = " + weather + ", rain = " + rain + ", main = " + main + "]"; + return "CurrentWeatherResponseModel{" + + "id='" + id + '\'' + + ", dt='" + dt + '\'' + + ", clouds=" + clouds + + ", coord=" + coord + + ", wind=" + wind + + ", cod='" + cod + '\'' + + ", sys=" + sys + + ", name='" + name + '\'' + + ", base='" + base + '\'' + + ", weather=" + Arrays.toString(weather) + + ", rain='" + rain + '\'' + + ", main=" + main + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecast.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecast.java new file mode 100644 index 0000000..d96d8f7 --- /dev/null +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecast.java @@ -0,0 +1,108 @@ +package github.vatsal.easyweather.retrofit.models; + +import java.util.Arrays; + +/** + * Created by + * --Vatsal Bajpai under + * --AppyWare on + * --23/06/16 at + * --1:50 AM in + * --OpenWeatherMapDemo + */ +public class DailyForecast { + + private String dt; + + private Temp temp; + + private String pressure; + + private String humidity; + + private Weather[] weather; + + private String speed; + + private String deg; + + private String clouds; + + public String getDt() { + return dt; + } + + public void setDt(String dt) { + this.dt = dt; + } + + public Temp getTemp() { + return temp; + } + + public void setTemp(Temp temp) { + this.temp = temp; + } + + public String getPressure() { + return pressure; + } + + public void setPressure(String pressure) { + this.pressure = pressure; + } + + public String getHumidity() { + return humidity; + } + + public void setHumidity(String humidity) { + this.humidity = humidity; + } + + public Weather[] getWeather() { + return weather; + } + + public void setWeather(Weather[] weather) { + this.weather = weather; + } + + public String getSpeed() { + return speed; + } + + public void setSpeed(String speed) { + this.speed = speed; + } + + public String getDeg() { + return deg; + } + + public void setDeg(String deg) { + this.deg = deg; + } + + public String getClouds() { + return clouds; + } + + public void setClouds(String clouds) { + this.clouds = clouds; + } + + @Override + public String toString() { + return "DailyForecast{" + + "dt='" + dt + '\'' + + ", temp=" + temp + + ", pressure='" + pressure + '\'' + + ", humidity='" + humidity + '\'' + + ", weather=" + Arrays.toString(weather) + + ", speed='" + speed + '\'' + + ", deg='" + deg + '\'' + + ", clouds='" + clouds + '\'' + + '}'; + } +} diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecastResponseModel.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecastResponseModel.java new file mode 100644 index 0000000..5dec48e --- /dev/null +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/DailyForecastResponseModel.java @@ -0,0 +1,74 @@ +package github.vatsal.easyweather.retrofit.models; + +import java.util.Arrays; + +/** + * Created by + * --Vatsal Bajpai under + * --AppyWare on + * --23/06/16 at + * --1:48 AM in + * --OpenWeatherMapDemo + */ +public class DailyForecastResponseModel { + private String message; + + private String cnt; + + private String cod; + + private DailyForecast[] list; + + private City city; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getCnt() { + return cnt; + } + + public void setCnt(String cnt) { + this.cnt = cnt; + } + + public String getCod() { + return cod; + } + + public void setCod(String cod) { + this.cod = cod; + } + + public DailyForecast[] getList() { + return list; + } + + public void setList(DailyForecast[] list) { + this.list = list; + } + + public City getCity() { + return city; + } + + public void setCity(City city) { + this.city = city; + } + + @Override + public String toString() { + return "DailyForecastResponseModel{" + + "message='" + message + '\'' + + ", cnt='" + cnt + '\'' + + ", cod='" + cod + '\'' + + ", list=" + Arrays.toString(list) + + ", city=" + city + + '}'; + } +} diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/List.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Forecast.java similarity index 77% rename from library/src/main/java/github/vatsal/easyweather/retrofit/models/List.java rename to library/src/main/java/github/vatsal/easyweather/retrofit/models/Forecast.java index d010856..b4cf81a 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/List.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Forecast.java @@ -1,5 +1,7 @@ package github.vatsal.easyweather.retrofit.models; +import java.util.Arrays; + /** * Created by * --Vatsal Bajpai under @@ -8,7 +10,7 @@ * --1:50 AM in * --OpenWeatherMapDemo */ -public class List { +public class Forecast { private Clouds clouds; private String dt; @@ -91,6 +93,15 @@ public void setMain(Main main) { @Override public String toString() { - return "ClassPojo [clouds = " + clouds + ", dt = " + dt + ", wind = " + wind + ", sys = " + sys + ", weather = " + weather + ", dt_txt = " + dt_txt + ", rain = " + rain + ", main = " + main + "]"; + return "Forecast{" + + "clouds=" + clouds + + ", dt='" + dt + '\'' + + ", wind=" + wind + + ", sys=" + sys + + ", weather=" + Arrays.toString(weather) + + ", dt_txt='" + dt_txt + '\'' + + ", rain=" + rain + + ", main=" + main + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/ForecastResponseModel.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/ForecastResponseModel.java index 5a4da10..62e0a74 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/ForecastResponseModel.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/ForecastResponseModel.java @@ -1,5 +1,7 @@ package github.vatsal.easyweather.retrofit.models; +import java.util.Arrays; + /** * Created by * --Vatsal Bajpai under @@ -15,7 +17,7 @@ public class ForecastResponseModel { private String cod; - private List[] list; + private Forecast[] list; private City city; @@ -43,11 +45,11 @@ public void setCod(String cod) { this.cod = cod; } - public List[] getList() { + public Forecast[] getList() { return list; } - public void setList(List[] list) { + public void setList(Forecast[] list) { this.list = list; } @@ -61,6 +63,14 @@ public void setCity(City city) { @Override public String toString() { - return "ClassPojo [message = " + message + ", cnt = " + cnt + ", cod = " + cod + ", list = " + list + ", city = " + city + "]"; + return "ForecastResponseModel{" + + "message='" + message + '\'' + + ", cnt='" + cnt + '\'' + + ", cod='" + cod + '\'' + + ", list=" + Arrays.toString(list) + + ", city=" + city + + '}'; } + + } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Main.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Main.java index 1fbe42d..1b0a077 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Main.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Main.java @@ -61,6 +61,12 @@ public void setTemp(String temp) { @Override public String toString() { - return "ClassPojo [humidity = " + humidity + ", pressure = " + pressure + ", temp_max = " + temp_max + ", temp_min = " + temp_min + ", temp = " + temp + "]"; + return "Main{" + + "humidity='" + humidity + '\'' + + ", pressure='" + pressure + '\'' + + ", temp_max='" + temp_max + '\'' + + ", temp_min='" + temp_min + '\'' + + ", temp='" + temp + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Rain.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Rain.java index 2aa9b62..a758a5f 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Rain.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Rain.java @@ -26,4 +26,11 @@ public void set3h(Double _3h) { this._3h = _3h; } + + @Override + public String toString() { + return "Rain{" + + "_3h=" + _3h + + '}'; + } } \ No newline at end of file diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Sys.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Sys.java index 50b5bcb..7f92243 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Sys.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Sys.java @@ -71,6 +71,13 @@ public void setCountry(String country) { @Override public String toString() { - return "ClassPojo [message = " + message + ", id = " + id + ", sunset = " + sunset + ", sunrise = " + sunrise + ", type = " + type + ", country = " + country + "]"; + return "Sys{" + + "message='" + message + '\'' + + ", id='" + id + '\'' + + ", sunset='" + sunset + '\'' + + ", sunrise='" + sunrise + '\'' + + ", type='" + type + '\'' + + ", country='" + country + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Temp.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Temp.java new file mode 100644 index 0000000..2a27f17 --- /dev/null +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Temp.java @@ -0,0 +1,80 @@ +package github.vatsal.easyweather.retrofit.models; + +/** + * Created by sokarcreative on 08/04/2017. + */ + +public class Temp { + + private String day; + + private String min; + + private String max; + + private String night; + + private String eve; + + private String morn; + + public String getDay() { + return day; + } + + public void setDay(String day) { + this.day = day; + } + + public String getMin() { + return min; + } + + public void setMin(String min) { + this.min = min; + } + + public String getMax() { + return max; + } + + public void setMax(String max) { + this.max = max; + } + + public String getNight() { + return night; + } + + public void setNight(String night) { + this.night = night; + } + + public String getEve() { + return eve; + } + + public void setEve(String eve) { + this.eve = eve; + } + + public String getMorn() { + return morn; + } + + public void setMorn(String morn) { + this.morn = morn; + } + + @Override + public String toString() { + return "Temp{" + + "day='" + day + '\'' + + ", min='" + min + '\'' + + ", max='" + max + '\'' + + ", night='" + night + '\'' + + ", eve='" + eve + '\'' + + ", morn='" + morn + '\'' + + '}'; + } +} diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Weather.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Weather.java index 821c4ad..b1aaebc 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Weather.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Weather.java @@ -55,6 +55,11 @@ public void setMain(String main) { @Override public String toString() { - return "ClassPojo [id = " + id + ", icon = " + icon + ", description = " + description + ", main = " + main + "]"; + return "Weather{" + + "id='" + id + '\'' + + ", icon='" + icon + '\'' + + ", description='" + description + '\'' + + ", main='" + main + '\'' + + '}'; } } diff --git a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Wind.java b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Wind.java index 715af6b..ea0b5ea 100644 --- a/library/src/main/java/github/vatsal/easyweather/retrofit/models/Wind.java +++ b/library/src/main/java/github/vatsal/easyweather/retrofit/models/Wind.java @@ -31,6 +31,9 @@ public void setDeg(String deg) { @Override public String toString() { - return "ClassPojo [speed = " + speed + ", deg = " + deg + "]"; + return "Wind{" + + "speed='" + speed + '\'' + + ", deg='" + deg + '\'' + + '}'; } }