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
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

70 changes: 70 additions & 0 deletions .idea/markdown-navigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 57 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -34,7 +38,7 @@ allprojects {

```gradle
dependencies {
compile 'com.github.code-crusher:EasyWeather:v1.2'
compile 'com.github.sokarcreative:EasyWeather:1.3.0'
}
```

Expand All @@ -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<CurrentWeatherResponseModel>() {
@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<CurrentWeatherResponseModel>() {
@Override
public void success(WeatherResponseModel response) {

public void success(CurrentWeatherResponseModel response) {
Log.i(response.toString());
}

@Override
Expand All @@ -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<ForecastResponseModel>() {
@Override
public void success(ForecastResponseModel response) {
Weather weather[] = response.getList()[index].getWeather();
Log.i(response.toString());
}

@Override
Expand All @@ -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<ForecastResponseModel>() {
@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<DailyForecastResponseModel>() {
@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<DailyForecastResponseModel>() {
@Override
public void success(DailyForecastResponseModel response) {
Log.i(response.toString());
}

@Override
Expand Down
14 changes: 9 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'

}
79 changes: 50 additions & 29 deletions app/src/main/java/github/vatsal/easyweatherdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CurrentWeatherResponseModel>() {
@Override
public void success(WeatherResponseModel response) {
public void success(CurrentWeatherResponseModel response) {
populateWeather(response);
Log.i(response.toString());
}

@Override
Expand All @@ -93,10 +96,22 @@ public void failure(String message) {
}
});

weatherMap.getCityForecast(city, new ForecastCallback() {
weatherMap.getCityForecast(city, new WeatherCallback<ForecastResponseModel>() {
@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<DailyForecastResponseModel>() {
@Override
public void success(DailyForecastResponseModel response) {
Log.i(response.toString());
}

@Override
Expand All @@ -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());
Expand All @@ -127,4 +142,10 @@ public void go() {
city = etCity.getText().toString().trim();
loadWeather(city);
}

@Override
protected void onDestroy() {
super.onDestroy();

}
}
Loading