Skip to content

Commit

Permalink
minor ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amar committed Mar 31, 2021
1 parent 6762376 commit 6015d84
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/olrep/theweatherapp/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
82 changes: 29 additions & 53 deletions app/src/main/res/layout/weather_detail_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<LinearLayout
Expand All @@ -18,18 +20,21 @@
android:layout_height="wrap_content"
android:layout_below="@id/tv_city_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="TODO"
android:src="@drawable/baseline_update_black_24" />


<TextView
android:id="@+id/tv_last_updated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
tools:text="3d4h" />
</LinearLayout>

Expand All @@ -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°" />
</LinearLayout>


<LinearLayout
android:id="@+id/ll_min"
<TextView
android:id="@+id/tv_temp_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ll_temp_and_weather_cond"
android:layout_centerHorizontal="true"
android:orientation="horizontal">

<TextView
android:id="@+id/tv_min_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="Temperature range for the day: "
android:textSize="14sp" />

<TextView
android:id="@+id/tv_min_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
tools:text="18" />

<TextView
android:id="@+id/tv_min_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="° to "
android:textSize="18sp" />

<TextView
android:id="@+id/tv_max_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
tools:text="25" />

<TextView
android:id="@+id/tv_max_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="°"
android:textSize="18sp" />

</LinearLayout>
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" />

<TextView
android:id="@+id/tv_temp_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ll_min"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
tools:text="Temperature feels like 45°" />
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°." />

<TextView
android:id="@+id/tv_weather_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_temp_desc"
android:layout_centerHorizontal="true"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
tools:text="This is how weather is today" />
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="@dimen/font_small"
tools:text="Today's weather condition is: mist." />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btn_fav"
Expand All @@ -129,8 +105,8 @@
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="32dp"
android:tag="is_not_fav"
android:src="@drawable/ic_add"
android:tag="is_not_fav"
android:visibility="invisible" />

</RelativeLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="font_small">17sp</dimen>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<resources>
<string name="app_name">TheWeatherApp</string>
<string name="action_search">Enter city name</string>
<string name="city_country">%1$s, %2$s</string>
<string name="large_temp">%1$s°</string>
<string name="temp_range">Temperature today will be between %1$s° and %2$2s°.</string>
<string name="temp_feels_like">But temperature right now feels like %1$s°.</string>
<string name="weather_condition">Today\'s weather condition is: %1$s.</string>
</resources>

0 comments on commit 6015d84

Please sign in to comment.