diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/ShowTemparature.java b/app/src/main/java/fr/romanet/vj/apps/myweather/ShowTemparature.java index b422529..a21ce95 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/ShowTemparature.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/ShowTemparature.java @@ -6,6 +6,7 @@ import androidx.appcompat.widget.Toolbar; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; @@ -44,29 +45,40 @@ public class ShowTemparature extends AppCompatActivity { textView2 = (TextView) findViewById(R.id.textView2); + // - Build Retrofit API tool Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.openweathermap.org/data/2.5/") .addConverterFactory(GsonConverterFactory.create()) .build(); + // - Build Interface with Retrofit JsonApiInterfce jsonApiInterfce = retrofit.create(JsonApiInterfce.class); - Call call = jsonApiInterfce.getPost(); + Call call = jsonApiInterfce.getPost(currentCityName, "metric", "0ac5802392867db8e1ae4f91529f7890"); + // - 'Execute' the GET query with 'enqueue' method, Retrofit will create an AsyncTask that avoids UI Thread freeze Exception. call.enqueue(new Callback() { + + // - If GET has an answer... @Override public void onResponse(Call call, Response response) { + + // - Check if that answer is not an error (like 500, 404, etc) if(! response.isSuccessful()){ textView2.setText("Code: " + response.code()); return; } + // - If it's all right, update Activity Objects with JSON parsed answer Weather weather = response.body(); - textView2.append(weather.get_weatherDescription().get_description()); + textView2.append(weather.get_temps().get_temp_feels_like()); } + // - If GET has no answer... @Override public void onFailure(Call call, Throwable t) { + + // - Display error message textView2.setText("Error: " + t.getMessage()); } }); diff --git a/app/src/main/java/fr/romanet/vj/apps/myweather/network/JsonApiInterfce.java b/app/src/main/java/fr/romanet/vj/apps/myweather/network/JsonApiInterfce.java index a4414a4..246ce12 100644 --- a/app/src/main/java/fr/romanet/vj/apps/myweather/network/JsonApiInterfce.java +++ b/app/src/main/java/fr/romanet/vj/apps/myweather/network/JsonApiInterfce.java @@ -3,11 +3,11 @@ package fr.romanet.vj.apps.myweather.network; import fr.romanet.vj.apps.myweather.weather.Weather; import retrofit2.Call; import retrofit2.http.GET; +import retrofit2.http.Path; +import retrofit2.http.Query; public interface JsonApiInterfce { -// @GET("?q=madrid&units=metric&appid=0ac5802392867db8e1ae4f91529f7890"); - - @GET("weather?q=paris&units=metric&appid=0ac5802392867db8e1ae4f91529f7890") - Call getPost(); + @GET("weather") + Call getPost(@Query("q") String city, @Query("units") String units, @Query("appid") String appid); } diff --git a/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml b/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml new file mode 100644 index 0000000..8f9be44 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_arrow_downward_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/img50d.png b/app/src/main/res/drawable/img50d.png new file mode 100644 index 0000000..f04122b Binary files /dev/null and b/app/src/main/res/drawable/img50d.png differ diff --git a/app/src/main/res/drawable/img50n.png b/app/src/main/res/drawable/img50n.png new file mode 100644 index 0000000..f04122b Binary files /dev/null and b/app/src/main/res/drawable/img50n.png differ diff --git a/app/src/main/res/drawable/img_01d.png b/app/src/main/res/drawable/img_01d.png new file mode 100644 index 0000000..ed42ad9 Binary files /dev/null and b/app/src/main/res/drawable/img_01d.png differ diff --git a/app/src/main/res/drawable/img_01n.png b/app/src/main/res/drawable/img_01n.png new file mode 100644 index 0000000..85efa16 Binary files /dev/null and b/app/src/main/res/drawable/img_01n.png differ diff --git a/app/src/main/res/drawable/img_02d.png b/app/src/main/res/drawable/img_02d.png new file mode 100644 index 0000000..fabd9c3 Binary files /dev/null and b/app/src/main/res/drawable/img_02d.png differ diff --git a/app/src/main/res/drawable/img_02n.png b/app/src/main/res/drawable/img_02n.png new file mode 100644 index 0000000..288a40e Binary files /dev/null and b/app/src/main/res/drawable/img_02n.png differ diff --git a/app/src/main/res/drawable/img_03d.png b/app/src/main/res/drawable/img_03d.png new file mode 100644 index 0000000..ef2e9f7 Binary files /dev/null and b/app/src/main/res/drawable/img_03d.png differ diff --git a/app/src/main/res/drawable/img_03n.png b/app/src/main/res/drawable/img_03n.png new file mode 100644 index 0000000..ef2e9f7 Binary files /dev/null and b/app/src/main/res/drawable/img_03n.png differ diff --git a/app/src/main/res/drawable/img_04d.png b/app/src/main/res/drawable/img_04d.png new file mode 100644 index 0000000..9c64ea8 Binary files /dev/null and b/app/src/main/res/drawable/img_04d.png differ diff --git a/app/src/main/res/drawable/img_04n.png b/app/src/main/res/drawable/img_04n.png new file mode 100644 index 0000000..9c64ea8 Binary files /dev/null and b/app/src/main/res/drawable/img_04n.png differ diff --git a/app/src/main/res/drawable/img_09d.png b/app/src/main/res/drawable/img_09d.png new file mode 100644 index 0000000..0f14cb6 Binary files /dev/null and b/app/src/main/res/drawable/img_09d.png differ diff --git a/app/src/main/res/drawable/img_09n.png b/app/src/main/res/drawable/img_09n.png new file mode 100644 index 0000000..0f14cb6 Binary files /dev/null and b/app/src/main/res/drawable/img_09n.png differ diff --git a/app/src/main/res/drawable/img_10d.png b/app/src/main/res/drawable/img_10d.png new file mode 100644 index 0000000..62304fd Binary files /dev/null and b/app/src/main/res/drawable/img_10d.png differ diff --git a/app/src/main/res/drawable/img_10n.png b/app/src/main/res/drawable/img_10n.png new file mode 100644 index 0000000..b5e5d10 Binary files /dev/null and b/app/src/main/res/drawable/img_10n.png differ diff --git a/app/src/main/res/drawable/img_11d.png b/app/src/main/res/drawable/img_11d.png new file mode 100644 index 0000000..4a885cf Binary files /dev/null and b/app/src/main/res/drawable/img_11d.png differ diff --git a/app/src/main/res/drawable/img_11n.png b/app/src/main/res/drawable/img_11n.png new file mode 100644 index 0000000..4a885cf Binary files /dev/null and b/app/src/main/res/drawable/img_11n.png differ diff --git a/app/src/main/res/drawable/img_13d.png b/app/src/main/res/drawable/img_13d.png new file mode 100644 index 0000000..7867322 Binary files /dev/null and b/app/src/main/res/drawable/img_13d.png differ diff --git a/app/src/main/res/drawable/img_13n.png b/app/src/main/res/drawable/img_13n.png new file mode 100644 index 0000000..7867322 Binary files /dev/null and b/app/src/main/res/drawable/img_13n.png differ diff --git a/app/src/main/res/layout/activity_temparature.xml b/app/src/main/res/layout/activity_temparature.xml index cc139bf..7543830 100644 --- a/app/src/main/res/layout/activity_temparature.xml +++ b/app/src/main/res/layout/activity_temparature.xml @@ -29,9 +29,81 @@ android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="TextView" + android:layout_marginTop="56dp" + android:text="My City" + android:textSize="50sp" + android:textStyle="bold" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.497" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/appBarLayout2" /> + + + + + + + + + + + + + + \ No newline at end of file