diff --git a/app/src/main/java/com/olrep/theweatherapp/ui/detail/WeatherDetailActivity.java b/app/src/main/java/com/olrep/theweatherapp/ui/detail/WeatherDetailActivity.java index b43bc01..157d2c4 100644 --- a/app/src/main/java/com/olrep/theweatherapp/ui/detail/WeatherDetailActivity.java +++ b/app/src/main/java/com/olrep/theweatherapp/ui/detail/WeatherDetailActivity.java @@ -86,12 +86,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { // various ui elements to be shown final TextView cityTv = findViewById(R.id.tv_city_name); final TextView lastUpdatedTv = findViewById(R.id.tv_last_updated); - final TextView tempMinTv = findViewById(R.id.tv_min_temp); - final TextView tempMaxTv = findViewById(R.id.tv_max_temp); - final TextView tempTv = findViewById(R.id.tv_temp_large); + final TextView largeTempTv = findViewById(R.id.tv_temp_large); + final TextView tempRangeTv = findViewById(R.id.tv_temp_range); final TextView tempFeelsTv = findViewById(R.id.tv_temp_desc); final TextView weatherDescTv = findViewById(R.id.tv_weather_desc); - final ImageView weatherConditionTv = findViewById(R.id.iv_weather_condition_2x); + final ImageView weatherConditionIv = findViewById(R.id.iv_weather_condition_2x); // observing current weather live data via view model // both cached (from db) and network call gets updated and propagated here @@ -103,21 +102,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { if (resultPair != null && resultPair.first && resultPair.second != null) { Log.d(TAG, "setting views"); - StringBuilder stringBuilder = new StringBuilder(); - Picasso.get().load(Utils.getIconUrl(resultPair.second.weather_icon)).into(weatherConditionTv); + Picasso.get().load(Utils.getIconUrl2x(resultPair.second.weather_icon)).into(weatherConditionIv); - cityTv.setText(stringBuilder.append(resultPair.second.city).append(", ").append(resultPair.second.country).toString()); + cityTv.setText(cityTv.getContext().getString(R.string.city_country, resultPair.second.city, resultPair.second.country)); lastUpdatedTv.setText(Utils.lastUpdated(resultPair.second.last_updated)); - tempMinTv.setText(String.valueOf(resultPair.second.temp_min)); - tempMaxTv.setText(String.valueOf(resultPair.second.temp_max)); - - stringBuilder.setLength(0); - tempTv.setText(stringBuilder.append((resultPair.second.temp)).append("°").toString()); - - stringBuilder.setLength(0); - tempFeelsTv.setText(stringBuilder.append("Temperate at this time feels like ").append(resultPair.second.temp_feels_like).append("°").toString()); - weatherDescTv.setText(resultPair.second.weather_description); + largeTempTv.setText(largeTempTv.getContext().getString(R.string.large_temp, String.valueOf(resultPair.second.temp))); + tempRangeTv.setText(tempRangeTv.getContext().getString(R.string.temp_range, String.valueOf(resultPair.second.temp_min), String.valueOf(resultPair.second.temp_max))); + tempFeelsTv.setText(tempFeelsTv.getContext().getString(R.string.temp_feels_like, String.valueOf(resultPair.second.temp_feels_like))); + weatherDescTv.setText(weatherDescTv.getContext().getString(R.string.weather_condition, resultPair.second.weather_description)); favButton.setVisibility(View.VISIBLE); @@ -137,7 +130,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { // to toggle add/remove icon of floating button private int getFavRes(boolean favourite) { return favourite ? R.drawable.ic_close : R.drawable.ic_add; - } // checking whether it's a fav already diff --git a/app/src/main/java/com/olrep/theweatherapp/utils/Utils.java b/app/src/main/java/com/olrep/theweatherapp/utils/Utils.java index ee8d7ec..741193b 100644 --- a/app/src/main/java/com/olrep/theweatherapp/utils/Utils.java +++ b/app/src/main/java/com/olrep/theweatherapp/utils/Utils.java @@ -8,6 +8,10 @@ public static String getIconUrl(String iconId) { return "http://openweathermap.org/img/wn/" + iconId + ".png"; // can add @Nx before . to get bigger size todo } + public static String getIconUrl2x(String iconId) { + return "http://openweathermap.org/img/wn/" + iconId + "@2x.png"; // can add @Nx before . to get bigger size todo + } + // returns the last updated time diff as "4 hours ago" public static String lastUpdated(long lastUpdated) { return (DateUtils.getRelativeTimeSpanString(lastUpdated)).toString(); diff --git a/app/src/main/res/layout/weather_detail_activity.xml b/app/src/main/res/layout/weather_detail_activity.xml index 1cec20b..7e04ded 100644 --- a/app/src/main/res/layout/weather_detail_activity.xml +++ b/app/src/main/res/layout/weather_detail_activity.xml @@ -9,7 +9,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" - android:textSize="35sp" + android:fontFamily="sans-serif-smallcaps" + android:textColor="@color/purple_500" + android:textSize="25sp" tools:text="Bangalore, IN" /> @@ -30,6 +34,7 @@ android:id="@+id/tv_last_updated" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:textSize="20sp" tools:text="3d4h" /> @@ -53,74 +58,45 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginStart="20dp" - android:textSize="50sp" + android:textSize="40sp" tools:text="34°" /> - - - - - - - - - - - - - + android:layout_marginStart="10dp" + android:fontFamily="sans-serif" + android:text="Temperature today will be between 35° and 45°." + android:textColor="@android:color/black" + android:textSize="@dimen/font_small" /> + android:layout_below="@id/tv_temp_range" + android:layout_marginStart="10dp" + android:layout_marginTop="10dp" + android:fontFamily="sans-serif" + android:textColor="@android:color/black" + android:textSize="@dimen/font_small" + tools:text="But temperature right now feels like 45°." /> + android:fontFamily="sans-serif" + android:textColor="@android:color/black" + android:textSize="@dimen/font_small" + tools:text="Today's weather condition is: mist." /> \ No newline at end of file diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml new file mode 100644 index 0000000..cb218a8 --- /dev/null +++ b/app/src/main/res/values/dimen.xml @@ -0,0 +1,4 @@ + + + 17sp + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b6a37b0..ee90932 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,9 @@ TheWeatherApp Enter city name + %1$s, %2$s + %1$s° + Temperature today will be between %1$s° and %2$2s°. + But temperature right now feels like %1$s°. + Today\'s weather condition is: %1$s. \ No newline at end of file