Update of all weather Classes (Some deleted, some modified)
Setup of Retrofit API and API Interface Added test TextView2 on activity_temparature.xml in order to test API answer Display Paris weather description on any city we click for the moment.
This commit is contained in:
parent
49871926bd
commit
cb7db29f87
@ -29,5 +29,5 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
@ -8,16 +8,25 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myweather.bo.City;
|
||||
import fr.romanet.vj.apps.myweather.network.JsonApiInterfce;
|
||||
import fr.romanet.vj.apps.myweather.repository.CityRepository;
|
||||
import fr.romanet.vj.apps.myweather.weather.Weather;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class ShowTemparature extends AppCompatActivity {
|
||||
|
||||
private String currentCityName;
|
||||
private TextView textView2;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -32,6 +41,36 @@ public class ShowTemparature extends AppCompatActivity {
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
|
||||
textView2 = (TextView) findViewById(R.id.textView2);
|
||||
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://api.openweathermap.org/data/2.5/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
JsonApiInterfce jsonApiInterfce = retrofit.create(JsonApiInterfce.class);
|
||||
Call<Weather> call = jsonApiInterfce.getPost();
|
||||
|
||||
call.enqueue(new Callback<Weather>() {
|
||||
@Override
|
||||
public void onResponse(Call<Weather> call, Response<Weather> response) {
|
||||
if(! response.isSuccessful()){
|
||||
textView2.setText("Code: " + response.code());
|
||||
return;
|
||||
}
|
||||
|
||||
Weather weather = response.body();
|
||||
textView2.append(weather.get_weatherDescription().get_description());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Weather> call, Throwable t) {
|
||||
textView2.setText("Error: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
package fr.romanet.vj.apps.myweather.network;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class ApiClient {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://api.github.com/")
|
||||
.build();
|
||||
|
||||
GitHubService service = retrofit.create(GitHubService.class);
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
package fr.romanet.vj.apps.myweather.network;
|
||||
|
||||
public class Get {
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package fr.romanet.vj.apps.myweather.network;
|
||||
|
||||
import fr.romanet.vj.apps.myweather.weather.Weather;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
public interface JsonApiInterfce {
|
||||
|
||||
// @GET("?q=madrid&units=metric&appid=0ac5802392867db8e1ae4f91529f7890");
|
||||
|
||||
@GET("weather?q=paris&units=metric&appid=0ac5802392867db8e1ae4f91529f7890")
|
||||
Call<Weather> getPost();
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package fr.romanet.vj.apps.myweather.weather;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Coord {
|
||||
|
||||
@SerializedName("lon")
|
||||
private String _lon;
|
||||
@SerializedName("lat")
|
||||
private String _lat;
|
||||
|
||||
public Coord(String lon, String lat){
|
||||
_lon = lon;
|
||||
_lat = lat;
|
||||
}
|
||||
}
|
||||
@ -19,4 +19,21 @@ public class Temps {
|
||||
_temp_min = temp_min;
|
||||
_temp_max = temp_max;
|
||||
}
|
||||
|
||||
|
||||
public String get_temp() {
|
||||
return _temp;
|
||||
}
|
||||
|
||||
public String get_temp_feels_like() {
|
||||
return _temp_feels_like;
|
||||
}
|
||||
|
||||
public String get_temp_min() {
|
||||
return _temp_min;
|
||||
}
|
||||
|
||||
public String get_temp_max() {
|
||||
return _temp_max;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,39 @@ package fr.romanet.vj.apps.myweather.weather;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Weather {
|
||||
|
||||
@SerializedName("coord")
|
||||
private Coord _coord;
|
||||
@SerializedName("main")
|
||||
private Temps _temps;
|
||||
@SerializedName("weather")
|
||||
private WeatherDescription _weatherDescription;
|
||||
private List<WeatherDescription> _weatherDescription;
|
||||
@SerializedName("name")
|
||||
private String _city_name;
|
||||
@SerializedName("id")
|
||||
private String _city_id;
|
||||
|
||||
public Weather(Temps temps, List<WeatherDescription> weatherDescription, String city_name, String city_id){
|
||||
_temps = temps;
|
||||
_weatherDescription = weatherDescription;
|
||||
_city_name = city_name;
|
||||
_city_id = city_id;
|
||||
}
|
||||
|
||||
public Temps get_temps() {
|
||||
return _temps;
|
||||
}
|
||||
|
||||
public WeatherDescription get_weatherDescription() {
|
||||
return _weatherDescription.get(0);
|
||||
}
|
||||
|
||||
public String get_city_name() {
|
||||
return _city_name;
|
||||
}
|
||||
|
||||
public String get_city_id() {
|
||||
return _city_id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,4 +14,11 @@ public class WeatherDescription {
|
||||
_icon = icon;
|
||||
}
|
||||
|
||||
public String get_description() {
|
||||
return _description;
|
||||
}
|
||||
|
||||
public String get_icon() {
|
||||
return _icon;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
tools:context=".ShowTemparature">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Theme.MyWeather.AppBarOverlay"
|
||||
@ -24,4 +25,13 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/appBarLayout2" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user