Skip to content

Commit 0a9e727

Browse files
committedSep 22, 2022
Make the weather recyclerview expandable to check more weather details
Use the viewbinding instead of findViewById method
1 parent 3d6d6c8 commit 0a9e727

15 files changed

+415
-183
lines changed
 

‎app/build.gradle

+3-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77

88
defaultConfig {
99
applicationId "ml.ruby.weatherrecyclerview"
10-
minSdk 24 //26
10+
minSdk 24
1111
targetSdk 31
1212
versionCode 1
1313
versionName "1.0"
@@ -84,16 +84,11 @@ dependencies {
8484
implementation 'com.github.bumptech.glide:glide:4.13.0'
8585
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
8686

87-
// Gif drawable
88-
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
89-
9087
// Room
9188
def room_version = "2.4.2"
9289
implementation "androidx.room:room-runtime:$room_version"
9390
annotationProcessor "androidx.room:room-compiler:$room_version"
9491

95-
// Flipper
96-
debugImplementation 'com.facebook.flipper:flipper:0.145.0'
97-
debugImplementation 'com.facebook.soloader:soloader:0.10.1'
98-
releaseImplementation 'com.facebook.flipper:flipper-noop:0.145.0'
92+
// ExpandableLayout
93+
implementation 'com.github.cachapa:ExpandableLayout:2.9.2'
9994
}

‎app/src/main/java/ml/ruby/weatherrecyclerview/MainActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ protected void onCreate(Bundle savedInstanceState) {
4646
super.onCreate(savedInstanceState);
4747
binding = ActivityMainBinding.inflate(getLayoutInflater());
4848
setContentView(binding.getRoot());
49-
5049
bindFragment();
5150

5251
PreferenceManage preferenceManage = new PreferenceManage(MyApplication.getPreference());
@@ -191,4 +190,5 @@ private void setWeatherWidget(OneCallBean bean) {
191190
binding.visibility.setText(getString(R.string.visibility, current.getVisibility() / 1000));
192191
binding.dewPoint.setText(getString(R.string.dew_point, (int) (current.getDewPoint() - Constants.KELVINS)));
193192
}
193+
194194
}

‎app/src/main/java/ml/ruby/weatherrecyclerview/adapter/HourlyWeatherAdapter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ml.ruby.weatherrecyclerview.adapter;
22

33
import android.content.Context;
4+
import android.os.Handler;
5+
import android.os.Looper;
46
import android.view.LayoutInflater;
57
import android.view.View;
68
import android.view.ViewGroup;
@@ -40,7 +42,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
4042
@Override
4143
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
4244
Hourly hourly = hourlies.get(position);
43-
holder.hour.setText(Utility.getTimeFromTimeStamp(hourly.getDt()) + ":00");
45+
holder.hour.setText(Utility.getTimeFromTimeStamp(hourly.getDt(), "HH") + ":00");
4446
holder.temperature.setText((int) (hourly.getTemp() - Constants.KELVINS) + "℃");
4547
holder.weather_icon.setImageResource(Utility.getWeatherArtImage(hourly.getWeather().get(0).getId()));
4648
}
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
package ml.ruby.weatherrecyclerview.adapter;
22

3+
import android.annotation.SuppressLint;
34
import android.view.LayoutInflater;
4-
import android.view.View;
55
import android.view.ViewGroup;
6-
import android.widget.TextView;
76

87
import java.util.Calendar;
98
import java.util.Date;
109
import java.util.List;
1110

1211
import androidx.annotation.NonNull;
1312
import androidx.recyclerview.widget.RecyclerView;
13+
import ml.ruby.weatherrecyclerview.MyApplication;
1414
import ml.ruby.weatherrecyclerview.R;
15+
import ml.ruby.weatherrecyclerview.databinding.WeatherRecyclerviewItemsBinding;
1516
import ml.ruby.weatherrecyclerview.model.onecall.Daily;
1617
import ml.ruby.weatherrecyclerview.utils.Constants;
18+
import ml.ruby.weatherrecyclerview.utils.NumberOperation;
19+
import ml.ruby.weatherrecyclerview.utils.Utility;
1720

1821
/**
1922
* @author: jwhan
2023
* @createTime: 2022/04/27 10:40 AM
2124
* @description:
2225
*/
2326
public class WeatherRecyclerViewAdapter extends RecyclerView.Adapter<WeatherRecyclerViewAdapter.ViewHolder> {
24-
private static final String TAG = "WeatherRecyclerViewAdap";
2527
List<Daily> weatherBeanList;
26-
private String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
28+
private final String[] days = MyApplication.getContext().getResources().getStringArray(R.array.week_array);
2729

2830
public WeatherRecyclerViewAdapter(List<Daily> weatherBeanList) {
2931
this.weatherBeanList = weatherBeanList;
@@ -32,46 +34,61 @@ public WeatherRecyclerViewAdapter(List<Daily> weatherBeanList) {
3234
@NonNull
3335
@Override
3436
public WeatherRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
35-
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.weather_recyclerview_items,
36-
parent, false);
37-
return new ViewHolder(view);
37+
WeatherRecyclerviewItemsBinding binding = WeatherRecyclerviewItemsBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
38+
return new ViewHolder(binding);
3839
}
3940

41+
@SuppressLint("SetTextI18n")
4042
@Override
4143
public void onBindViewHolder(@NonNull WeatherRecyclerViewAdapter.ViewHolder holder, int position) {
4244
Daily daily = weatherBeanList.get(position);
4345
Date date = new Date(daily.getSunrise() * 1000L);
4446
Calendar calendar = Calendar.getInstance();
4547
calendar.setTime(date);
46-
holder.dayOfWeek.setText(days[calendar.get(Calendar.DAY_OF_WEEK) - 1]);
48+
holder.binding.date.setText(Utility.getTimeFromTimeStamp(daily.getDt(), "MM.dd")
49+
+ " " + days[calendar.get(Calendar.DAY_OF_WEEK) - 1]);
4750
// Handle the temperature
4851
String temp = "";
49-
// double min = NumberOperation.round(daily.getTemp().getMin() - Constants.KELVINS, 0);
50-
// double max = NumberOperation.round(daily.getTemp().getMax() - Constants.KELVINS, 0);
5152
// Integer maybe better for reading
5253
long min = Math.round(daily.getTemp().getMin() - Constants.KELVINS);
5354
long max = Math.round(daily.getTemp().getMax() - Constants.KELVINS);
54-
temp += min + "℃ - " + max + "℃";
55-
holder.temperature.setText(temp);
55+
temp += min + " / " + max + "℃";
56+
holder.binding.temperatureRange.setText(temp);
5657
// The weather forecast description
57-
holder.forecast.setText(daily.getWeather().get(0).getDescription());
58+
holder.binding.forecast.setImageResource(Utility.getWeatherArtImage(daily.getWeather().get(0).getId()));
59+
setListeners(holder, daily, position);
5860
}
5961

6062
@Override
6163
public int getItemCount() {
6264
return weatherBeanList.size();
6365
}
6466

67+
private void setListeners(@NonNull WeatherRecyclerViewAdapter.ViewHolder holder, Daily daily, int position) {
68+
holder.binding.weatherItem.setOnClickListener(v -> {
69+
holder.binding.expandableLayout.toggle();
70+
if (holder.binding.expandableLayout.isExpanded()) {
71+
holder.binding.precipitationKey.setText(MyApplication.getContext().getString(R.string.precipitation_key, daily.getRain()));
72+
holder.binding.popKey.setText(MyApplication.getContext().getString(R.string.pop_key, (int) (daily.getPop() * 100)));
73+
holder.binding.windKey.setText(MyApplication.getContext().
74+
getString(R.string.wind_key, daily.getWindSpeed(), Utility.convertDegreeToCardinalDirection(daily.getWindDeg())));
75+
holder.binding.humidityKey.setText(MyApplication.getContext().getString(R.string.humidity_key, daily.getHumidity()));
76+
holder.binding.uvIndexKey.setText(String.valueOf(NumberOperation.round(daily.getUvi(), 1)));
77+
holder.binding.sunriseKey.setText(Utility.getTimeFromTimeStamp(daily.getSunrise(), "HH:mm"));
78+
holder.binding.sunsetKey.setText(Utility.getTimeFromTimeStamp(daily.getSunset(), "HH:mm"));
79+
holder.binding.expandableIcon.setImageResource(R.drawable.ic_collapse);
80+
} else {
81+
holder.binding.expandableIcon.setImageResource(R.drawable.ic_expand);
82+
}
83+
});
84+
}
85+
6586
static class ViewHolder extends RecyclerView.ViewHolder {
66-
TextView dayOfWeek;
67-
TextView temperature;
68-
TextView forecast;
87+
WeatherRecyclerviewItemsBinding binding;
6988

70-
public ViewHolder(@NonNull View itemView) {
71-
super(itemView);
72-
dayOfWeek = itemView.findViewById(R.id.dayOfWeek);
73-
temperature = itemView.findViewById(R.id.temperature_range);
74-
forecast = itemView.findViewById(R.id.forecast);
89+
public ViewHolder(@NonNull WeatherRecyclerviewItemsBinding binding) {
90+
super(binding.getRoot());
91+
this.binding = binding;
7592
}
7693
}
7794
}

‎app/src/main/java/ml/ruby/weatherrecyclerview/repository/PlacesRepository.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import android.content.pm.PackageManager;
66
import android.location.Location;
77
import android.location.LocationManager;
8+
import android.nfc.Tag;
89
import android.os.Build;
910

1011
import java.util.List;
1112

1213
import androidx.annotation.NonNull;
1314
import androidx.annotation.Nullable;
15+
import androidx.constraintlayout.utils.widget.ImageFilterView;
1416
import androidx.core.content.ContextCompat;
1517
import androidx.lifecycle.LiveData;
1618
import androidx.lifecycle.MutableLiveData;
@@ -147,13 +149,15 @@ public void updateLocation() {
147149
location -> {
148150
if (location != null) {
149151
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
150-
double lat = NumberOperation.round(lastKnownLocation.getLatitude(), 2);
151-
double lon = NumberOperation.round(lastKnownLocation.getLongitude(), 2);
152-
queryPlacesReverseGeo(lat, lon, BuildConfig.WEATHER_API_KEY);
153-
saveTheData2Sp((float) lat, (float) lon);
152+
if (lastKnownLocation != null) {
153+
double lat = NumberOperation.round(lastKnownLocation.getLatitude(), 2);
154+
double lon = NumberOperation.round(lastKnownLocation.getLongitude(), 2);
155+
queryPlacesReverseGeo(lat, lon, BuildConfig.WEATHER_API_KEY);
156+
saveTheData2Sp((float) lat, (float) lon);
157+
}
154158
}
155159
});
156-
} catch (IllegalArgumentException e) {
160+
} catch (IllegalArgumentException e ) {
157161
Logs.logDebug(TAG, "updateLocation: " + "The device doesn't support GPS");
158162
}
159163
}

‎app/src/main/java/ml/ruby/weatherrecyclerview/utils/Utility.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public static int getWeatherArtImage(int weatherId) {
3939
}
4040
}
4141

42-
// 从时间戳里获取对应的小时
43-
public static String getTimeFromTimeStamp(long timeStamp) {
42+
// 从时间戳中获取对应格式的时间
43+
public static String getTimeFromTimeStamp(long timeStamp, String pattern) {
4444
Date date = new Date(timeStamp * 1000);
45-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
45+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
4646
return simpleDateFormat.format(date);
4747
}
4848

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#6C6C6C"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M8.12,14.71L12,10.83l3.88,3.88c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L12.7,8.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L6.7,13.3c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.38 1.03,0.39 1.42,0z"/>
5+
</vector>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#6C6C6C"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M8.12,9.29L12,13.17l3.88,-3.88c0.39,-0.39 1.02,-0.39 1.41,0 0.39,0.39 0.39,1.02 0,1.41l-4.59,4.59c-0.39,0.39 -1.02,0.39 -1.41,0L6.7,10.7c-0.39,-0.39 -0.39,-1.02 0,-1.41 0.39,-0.38 1.03,-0.39 1.42,0z"/>
5+
</vector>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#6C6C6C"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27c1.2,-1.4 1.82,-3.31 1.48,-5.34 -0.47,-2.78 -2.79,-5 -5.59,-5.34 -4.23,-0.52 -7.79,3.04 -7.27,7.27 0.34,2.8 2.56,5.12 5.34,5.59 2.03,0.34 3.94,-0.28 5.34,-1.48l0.27,0.28v0.79l4.25,4.25c0.41,0.41 1.08,0.41 1.49,0 0.41,-0.41 0.41,-1.08 0,-1.49L15.5,14zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
5+
</vector>

‎app/src/main/res/layout/activity_main.xml

+131-121
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
android:layout_gravity="center"
76
android:orientation="vertical">
87

98
<androidx.appcompat.widget.Toolbar
@@ -26,6 +25,7 @@
2625
android:layout_height="35dp"
2726
android:layout_marginEnd="8dp"
2827
android:layout_weight="1"
28+
app:cardBackgroundColor="@color/white"
2929
app:cardCornerRadius="20dp">
3030

3131
<LinearLayout
@@ -36,7 +36,7 @@
3636
android:layout_width="30dp"
3737
android:layout_height="30dp"
3838
android:layout_gravity="center_vertical"
39-
android:src="@drawable/ic_location" />
39+
android:src="@drawable/search_icon" />
4040

4141
<TextView
4242
android:id="@+id/location_place_name"
@@ -45,7 +45,8 @@
4545
android:layout_gravity="center_vertical"
4646
android:layout_marginStart="5dp"
4747
android:layout_marginEnd="5dp"
48-
android:layout_weight="1" />
48+
android:layout_weight="1"
49+
android:textColor="@color/text_color" />
4950

5051
</LinearLayout>
5152
</com.google.android.material.card.MaterialCardView>
@@ -66,154 +67,163 @@
6667
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
6768
android:id="@+id/refresh_data"
6869
android:layout_width="match_parent"
69-
android:layout_height="wrap_content"
70+
android:layout_height="0dp"
7071
app:layout_behavior="@string/appbar_scrolling_view_behavior"
7172
app:layout_constraintBottom_toBottomOf="parent"
7273
app:layout_constraintEnd_toEndOf="parent"
7374
app:layout_constraintStart_toStartOf="parent"
7475
app:layout_constraintTop_toBottomOf="@+id/progressbar">
7576

76-
<androidx.constraintlayout.widget.ConstraintLayout
77+
<ScrollView
7778
android:layout_width="match_parent"
78-
android:layout_height="wrap_content">
79-
80-
<ImageView
81-
android:id="@+id/weather_icon"
82-
android:layout_width="40dp"
83-
android:layout_height="40dp"
84-
android:layout_marginTop="24dp"
85-
android:scaleType="centerCrop"
86-
app:layout_constraintBottom_toTopOf="@+id/temperature"
87-
app:layout_constraintEnd_toStartOf="@id/weather_info"
88-
app:layout_constraintHorizontal_chainStyle="packed"
89-
app:layout_constraintStart_toStartOf="parent"
90-
app:layout_constraintTop_toTopOf="parent" />
91-
92-
<TextView
93-
android:id="@+id/weather_info"
94-
android:layout_width="wrap_content"
95-
android:layout_height="wrap_content"
96-
android:textColor="@color/text_color"
97-
android:textSize="20sp"
98-
app:layout_constraintBottom_toBottomOf="@id/weather_icon"
99-
app:layout_constraintEnd_toEndOf="parent"
100-
app:layout_constraintStart_toEndOf="@+id/weather_icon"
101-
app:layout_constraintTop_toTopOf="@+id/weather_icon" />
102-
103-
<TextView
104-
android:id="@+id/temperature"
105-
android:layout_width="wrap_content"
106-
android:layout_height="wrap_content"
107-
android:layout_marginTop="24dp"
108-
android:textColor="@color/text_color"
109-
android:textSize="60sp"
110-
app:layout_constraintBottom_toTopOf="@+id/feels_like"
111-
app:layout_constraintEnd_toEndOf="parent"
112-
app:layout_constraintStart_toStartOf="parent"
113-
app:layout_constraintTop_toBottomOf="@+id/weather_icon" />
114-
115-
<TextView
116-
android:id="@+id/feels_like"
117-
android:layout_width="wrap_content"
118-
android:layout_height="wrap_content"
119-
android:layout_marginTop="8dp"
120-
app:layout_constraintBottom_toTopOf="@+id/weather_widget"
121-
app:layout_constraintEnd_toEndOf="parent"
122-
app:layout_constraintStart_toStartOf="parent"
123-
app:layout_constraintTop_toBottomOf="@+id/temperature" />
124-
125-
<RelativeLayout
126-
android:id="@+id/weather_widget"
79+
android:layout_height="0dp"
80+
android:overScrollMode="never"
81+
app:layout_constraintBottom_toBottomOf="parent">
82+
83+
<androidx.constraintlayout.widget.ConstraintLayout
12784
android:layout_width="match_parent"
128-
android:layout_height="wrap_content"
129-
android:layout_marginStart="5dp"
130-
android:layout_marginTop="16dp"
131-
android:layout_marginEnd="8dp"
132-
android:paddingTop="8dp"
133-
android:paddingBottom="8dp"
134-
app:layout_constraintBottom_toTopOf="@id/fragment_hourly_weather"
135-
app:layout_constraintEnd_toEndOf="parent"
136-
app:layout_constraintStart_toStartOf="parent"
137-
app:layout_constraintTop_toBottomOf="@+id/feels_like">
85+
android:layout_height="wrap_content">
86+
87+
<ImageView
88+
android:id="@+id/weather_icon"
89+
android:layout_width="24dp"
90+
android:layout_height="38dp"
91+
android:layout_marginTop="24dp"
92+
android:scaleType="centerCrop"
93+
app:layout_constraintBottom_toTopOf="@+id/temperature"
94+
app:layout_constraintEnd_toStartOf="@id/weather_info"
95+
app:layout_constraintHorizontal_chainStyle="packed"
96+
app:layout_constraintStart_toStartOf="parent"
97+
app:layout_constraintTop_toTopOf="parent" />
13898

13999
<TextView
140-
android:id="@+id/wind_speed"
100+
android:id="@+id/weather_info"
141101
android:layout_width="wrap_content"
142102
android:layout_height="wrap_content"
143-
android:layout_alignParentStart="true"
144-
android:layout_marginStart="10dp"
145103
android:textColor="@color/text_color"
146-
android:textStyle="bold" />
104+
android:textSize="20sp"
105+
app:layout_constraintBottom_toBottomOf="@id/weather_icon"
106+
app:layout_constraintEnd_toEndOf="parent"
107+
app:layout_constraintStart_toEndOf="@+id/weather_icon"
108+
app:layout_constraintTop_toTopOf="@+id/weather_icon" />
147109

148110
<TextView
149-
android:id="@+id/humidity"
111+
android:id="@+id/temperature"
150112
android:layout_width="wrap_content"
151113
android:layout_height="wrap_content"
152-
android:layout_centerHorizontal="true"
114+
android:layout_marginTop="24dp"
153115
android:textColor="@color/text_color"
154-
android:textStyle="bold" />
116+
android:textSize="60sp"
117+
app:layout_constraintBottom_toTopOf="@+id/feels_like"
118+
app:layout_constraintEnd_toEndOf="parent"
119+
app:layout_constraintStart_toStartOf="parent"
120+
app:layout_constraintTop_toBottomOf="@+id/weather_icon" />
155121

156122
<TextView
157-
android:id="@+id/uv_index"
123+
android:id="@+id/feels_like"
158124
android:layout_width="wrap_content"
159125
android:layout_height="wrap_content"
160-
android:layout_alignParentEnd="true"
161-
android:layout_marginEnd="10dp"
162-
android:textColor="@color/text_color"
163-
android:textStyle="bold" />
126+
android:layout_marginTop="8dp"
127+
app:layout_constraintBottom_toTopOf="@+id/weather_widget"
128+
app:layout_constraintEnd_toEndOf="parent"
129+
app:layout_constraintStart_toStartOf="parent"
130+
app:layout_constraintTop_toBottomOf="@+id/temperature" />
164131

165-
<TextView
166-
android:id="@+id/pressure"
167-
android:layout_width="wrap_content"
132+
<RelativeLayout
133+
android:id="@+id/weather_widget"
134+
android:layout_width="match_parent"
168135
android:layout_height="wrap_content"
169-
android:layout_below="@+id/wind_speed"
170-
android:layout_alignParentStart="true"
171-
android:layout_marginStart="10dp"
172-
android:layout_marginTop="8dp"
173-
android:textColor="@color/text_color"
174-
android:textStyle="bold" />
136+
android:layout_marginStart="5dp"
137+
android:layout_marginTop="16dp"
138+
android:layout_marginEnd="5dp"
139+
android:paddingTop="8dp"
140+
android:paddingBottom="8dp"
141+
app:layout_constraintBottom_toTopOf="@id/fragment_hourly_weather"
142+
app:layout_constraintEnd_toEndOf="parent"
143+
app:layout_constraintStart_toStartOf="parent"
144+
app:layout_constraintTop_toBottomOf="@+id/feels_like">
175145

176-
<TextView
177-
android:id="@+id/visibility"
178-
android:layout_width="wrap_content"
146+
<TextView
147+
android:id="@+id/wind_speed"
148+
android:layout_width="wrap_content"
149+
android:layout_height="wrap_content"
150+
android:layout_alignParentStart="true"
151+
android:layout_marginStart="10dp"
152+
android:textColor="@color/text_color"
153+
android:textStyle="bold" />
154+
155+
<TextView
156+
android:id="@+id/humidity"
157+
android:layout_width="wrap_content"
158+
android:layout_height="wrap_content"
159+
android:layout_centerHorizontal="true"
160+
android:textColor="@color/text_color"
161+
android:textStyle="bold" />
162+
163+
<TextView
164+
android:id="@+id/uv_index"
165+
android:layout_width="wrap_content"
166+
android:layout_height="wrap_content"
167+
android:layout_alignParentEnd="true"
168+
android:layout_marginEnd="10dp"
169+
android:textColor="@color/text_color"
170+
android:textStyle="bold" />
171+
172+
<TextView
173+
android:id="@+id/pressure"
174+
android:layout_width="wrap_content"
175+
android:layout_height="wrap_content"
176+
android:layout_below="@+id/wind_speed"
177+
android:layout_alignParentStart="true"
178+
android:layout_marginStart="10dp"
179+
android:layout_marginTop="8dp"
180+
android:textColor="@color/text_color"
181+
android:textStyle="bold" />
182+
183+
<TextView
184+
android:id="@+id/visibility"
185+
android:layout_width="wrap_content"
186+
android:layout_height="wrap_content"
187+
android:layout_below="@+id/humidity"
188+
android:layout_centerHorizontal="true"
189+
android:layout_marginTop="8dp"
190+
android:textColor="@color/text_color"
191+
android:textStyle="bold" />
192+
193+
<TextView
194+
android:id="@+id/dew_point"
195+
android:layout_width="wrap_content"
196+
android:layout_height="wrap_content"
197+
android:layout_below="@+id/uv_index"
198+
android:layout_alignParentEnd="true"
199+
android:layout_marginTop="8dp"
200+
android:layout_marginEnd="10dp"
201+
android:textColor="@color/text_color"
202+
android:textStyle="bold" />
203+
204+
</RelativeLayout>
205+
206+
<androidx.fragment.app.FragmentContainerView
207+
android:id="@+id/fragment_hourly_weather"
208+
android:layout_width="match_parent"
179209
android:layout_height="wrap_content"
180-
android:layout_below="@+id/humidity"
181-
android:layout_centerHorizontal="true"
182210
android:layout_marginTop="8dp"
183-
android:textColor="@color/text_color"
184-
android:textStyle="bold" />
211+
app:layout_constraintEnd_toEndOf="parent"
212+
app:layout_constraintStart_toStartOf="parent"
213+
app:layout_constraintTop_toBottomOf="@+id/weather_widget" />
185214

186-
<TextView
187-
android:id="@+id/dew_point"
188-
android:layout_width="wrap_content"
215+
<androidx.fragment.app.FragmentContainerView
216+
android:id="@+id/fragment_weather"
217+
android:layout_width="match_parent"
189218
android:layout_height="wrap_content"
190-
android:layout_below="@+id/uv_index"
191-
android:layout_alignParentEnd="true"
192219
android:layout_marginTop="8dp"
193-
android:layout_marginEnd="10dp"
194-
android:textColor="@color/text_color"
195-
android:textStyle="bold" />
196-
197-
</RelativeLayout>
198-
199-
<androidx.fragment.app.FragmentContainerView
200-
android:id="@+id/fragment_hourly_weather"
201-
android:layout_width="match_parent"
202-
android:layout_height="wrap_content"
203-
android:layout_marginTop="8dp"
204-
app:layout_constraintEnd_toEndOf="parent"
205-
app:layout_constraintStart_toStartOf="parent"
206-
app:layout_constraintTop_toBottomOf="@+id/weather_widget" />
207-
208-
<androidx.fragment.app.FragmentContainerView
209-
android:id="@+id/fragment_weather"
210-
android:layout_width="match_parent"
211-
android:layout_height="wrap_content"
212-
android:layout_marginTop="8dp"
213-
app:layout_constraintEnd_toEndOf="parent"
214-
app:layout_constraintStart_toStartOf="parent"
215-
app:layout_constraintTop_toBottomOf="@+id/fragment_hourly_weather" />
216-
</androidx.constraintlayout.widget.ConstraintLayout>
220+
app:layout_constraintBottom_toBottomOf="parent"
221+
app:layout_constraintEnd_toEndOf="parent"
222+
app:layout_constraintStart_toStartOf="parent"
223+
app:layout_constraintTop_toBottomOf="@+id/fragment_hourly_weather" />
224+
</androidx.constraintlayout.widget.ConstraintLayout>
225+
</ScrollView>
217226
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
218227

228+
219229
</androidx.constraintlayout.widget.ConstraintLayout>

‎app/src/main/res/layout/query_places_results_item.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:layout_marginEnd="8dp"
88
android:orientation="horizontal">
99

10-
<pl.droidsonroids.gif.GifImageView
10+
<ImageView
1111
android:id="@+id/country_flag"
1212
android:layout_width="30dp"
1313
android:layout_height="30dp"
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,183 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
4-
android:layout_height="20dp"
5-
android:layout_marginStart="16dp"
6-
android:layout_marginBottom="5dp"
5+
android:layout_height="wrap_content"
6+
android:layout_marginStart="15dp"
7+
android:layout_marginEnd="15dp"
78
android:orientation="vertical">
89

9-
<LinearLayout
10+
<androidx.constraintlayout.widget.ConstraintLayout
11+
android:id="@+id/weather_item"
1012
android:layout_width="match_parent"
11-
android:layout_height="match_parent">
13+
android:layout_height="wrap_content">
1214

1315
<TextView
14-
android:id="@+id/dayOfWeek"
15-
android:layout_width="0dp"
16+
android:id="@+id/date"
17+
android:layout_width="wrap_content"
1618
android:layout_height="match_parent"
17-
android:layout_weight="3"
18-
android:text="Sunday" />
19+
app:layout_constraintStart_toStartOf="parent"
20+
app:layout_constraintTop_toTopOf="parent" />
1921

2022
<TextView
2123
android:id="@+id/temperature_range"
22-
android:layout_width="0dp"
24+
android:layout_width="wrap_content"
2325
android:layout_height="match_parent"
24-
android:layout_weight="3"
25-
android:text="0℃" />
26+
app:layout_constraintEnd_toStartOf="@+id/forecast"
27+
app:layout_constraintTop_toTopOf="parent" />
2628

27-
<TextView
29+
<ImageView
2830
android:id="@+id/forecast"
29-
android:layout_width="0dp"
30-
android:layout_height="match_parent"
31-
android:layout_weight="4"
32-
android:gravity="center"
33-
android:text="cloud" />
34-
</LinearLayout>
31+
android:layout_width="40dp"
32+
android:layout_height="40dp"
33+
android:scaleType="centerCrop"
34+
app:layout_constraintEnd_toStartOf="@id/expandable_icon"
35+
app:layout_constraintTop_toTopOf="parent" />
36+
37+
<ImageView
38+
android:id="@+id/expandable_icon"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:src="@drawable/ic_expand"
42+
app:layout_constraintEnd_toEndOf="parent"
43+
app:layout_constraintTop_toTopOf="parent" />
44+
</androidx.constraintlayout.widget.ConstraintLayout>
3545

36-
<View
46+
<net.cachapa.expandablelayout.ExpandableLayout
47+
android:id="@+id/expandable_layout"
3748
android:layout_width="match_parent"
38-
android:layout_height="1dp"
39-
android:background="@android:color/darker_gray" />
49+
android:layout_height="wrap_content"
50+
app:el_duration="1000"
51+
app:el_expanded="false"
52+
app:el_parallax="0">
53+
54+
<androidx.constraintlayout.widget.ConstraintLayout
55+
android:layout_width="match_parent"
56+
android:layout_height="wrap_content"
57+
android:orientation="horizontal"
58+
app:layout_constraintTop_toBottomOf="@+id/weather_item">
59+
60+
<TextView
61+
android:id="@+id/precipitation"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:text="@string/precipitation_word"
65+
android:textColor="@color/secondary_text_color"
66+
app:layout_constraintStart_toStartOf="parent"
67+
app:layout_constraintTop_toTopOf="parent" />
68+
69+
<TextView
70+
android:id="@+id/precipitation_key"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:textColor="@color/secondary_text_color"
74+
app:layout_constraintEnd_toEndOf="parent"
75+
app:layout_constraintTop_toTopOf="parent" />
76+
77+
<TextView
78+
android:id="@+id/pop"
79+
android:layout_width="wrap_content"
80+
android:layout_height="wrap_content"
81+
android:text="@string/pop_word"
82+
android:textColor="@color/secondary_text_color"
83+
app:layout_constraintStart_toStartOf="parent"
84+
app:layout_constraintTop_toBottomOf="@+id/precipitation" />
85+
86+
<TextView
87+
android:id="@+id/pop_key"
88+
android:layout_width="wrap_content"
89+
android:layout_height="wrap_content"
90+
android:textColor="@color/secondary_text_color"
91+
app:layout_constraintEnd_toEndOf="parent"
92+
app:layout_constraintTop_toBottomOf="@+id/precipitation_key" />
93+
94+
<TextView
95+
android:id="@+id/wind"
96+
android:layout_width="wrap_content"
97+
android:layout_height="wrap_content"
98+
android:text="@string/wind_word"
99+
android:textColor="@color/secondary_text_color"
100+
app:layout_constraintStart_toStartOf="parent"
101+
app:layout_constraintTop_toBottomOf="@id/pop" />
102+
103+
<TextView
104+
android:id="@+id/wind_key"
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
107+
android:textColor="@color/secondary_text_color"
108+
app:layout_constraintEnd_toEndOf="parent"
109+
app:layout_constraintTop_toBottomOf="@+id/pop_key" />
110+
111+
<TextView
112+
android:id="@+id/humidity"
113+
android:layout_width="wrap_content"
114+
android:layout_height="wrap_content"
115+
android:text="@string/humidity_word"
116+
android:textColor="@color/secondary_text_color"
117+
app:layout_constraintStart_toStartOf="parent"
118+
app:layout_constraintTop_toBottomOf="@+id/wind" />
119+
120+
<TextView
121+
android:id="@+id/humidity_key"
122+
android:layout_width="wrap_content"
123+
android:layout_height="wrap_content"
124+
android:textColor="@color/secondary_text_color"
125+
app:layout_constraintEnd_toEndOf="parent"
126+
app:layout_constraintTop_toBottomOf="@+id/wind_key" />
127+
128+
<TextView
129+
android:id="@+id/uv_index"
130+
android:layout_width="wrap_content"
131+
android:layout_height="wrap_content"
132+
android:text="@string/uv_index_word"
133+
android:textColor="@color/secondary_text_color"
134+
app:layout_constraintStart_toStartOf="parent"
135+
app:layout_constraintTop_toBottomOf="@id/humidity" />
136+
137+
<TextView
138+
android:id="@+id/uv_index_key"
139+
android:layout_width="wrap_content"
140+
android:layout_height="wrap_content"
141+
android:textColor="@color/secondary_text_color"
142+
app:layout_constraintEnd_toEndOf="parent"
143+
app:layout_constraintTop_toBottomOf="@+id/humidity_key" />
144+
145+
<TextView
146+
android:id="@+id/sunrise"
147+
android:layout_width="wrap_content"
148+
android:layout_height="wrap_content"
149+
android:text="@string/sunrise_word"
150+
android:textColor="@color/secondary_text_color"
151+
app:layout_constraintStart_toStartOf="parent"
152+
app:layout_constraintTop_toBottomOf="@+id/uv_index" />
153+
154+
<TextView
155+
android:id="@+id/sunrise_key"
156+
android:layout_width="wrap_content"
157+
android:layout_height="wrap_content"
158+
android:textColor="@color/secondary_text_color"
159+
app:layout_constraintEnd_toEndOf="parent"
160+
app:layout_constraintTop_toBottomOf="@+id/uv_index_key" />
161+
162+
<TextView
163+
android:id="@+id/sunset"
164+
android:layout_width="wrap_content"
165+
android:layout_height="wrap_content"
166+
android:text="@string/sunset_word"
167+
android:textColor="@color/secondary_text_color"
168+
app:layout_constraintStart_toStartOf="parent"
169+
app:layout_constraintTop_toBottomOf="@+id/sunrise" />
170+
171+
<TextView
172+
android:id="@+id/sunset_key"
173+
android:layout_width="wrap_content"
174+
android:layout_height="wrap_content"
175+
android:textColor="@color/secondary_text_color"
176+
app:layout_constraintEnd_toEndOf="parent"
177+
app:layout_constraintTop_toBottomOf="@id/sunrise_key" />
178+
179+
</androidx.constraintlayout.widget.ConstraintLayout>
180+
181+
</net.cachapa.expandablelayout.ExpandableLayout>
40182

41183
</LinearLayout>

‎app/src/main/res/values-zh-rCN/strings.xml

+23
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,27 @@
1515
<string name="denied_open_gps_notify">因为您未打开GPS, 我们将显示默认地点的天气状况</string>
1616
<string name="pull_weather_failed_notify">无法连接到Open Weather, 请检查您是否可以访问互联网</string>
1717
<string name="denied_location_permission_notify">抱歉, 您需要给我们定位权限以便显示您当地的天气</string>
18+
19+
<!--For the expandableLayout-->
20+
<string name="precipitation_word">降水量</string>
21+
<string name="pop_word">降水概率</string>
22+
<string name="wind_word">风况</string>
23+
<string name="humidity_word">湿度</string>
24+
<string name="uv_index_word">紫外线指数</string>
25+
<string name="sunrise_word">日出</string>
26+
<string name="sunset_word">日落</string>
27+
<string name="precipitation_key">%1$.1fmm</string>
28+
<string name="pop_key">%1$d%%</string>
29+
<string name="wind_key">%1$.1fm/s %2$s</string>
30+
<string name="humidity_key">%1$d%%</string>
31+
32+
<string-array name="week_array">
33+
<item>星期日</item>
34+
<item>星期一</item>
35+
<item>星期二</item>
36+
<item>星期三</item>
37+
<item>星期四</item>
38+
<item>星期五</item>
39+
<item>星期六</item>
40+
</string-array>
1841
</resources>

‎app/src/main/res/values/strings.xml

+23
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,27 @@
1515
<string name="denied_open_gps_notify">Okay, we will show London\'s weather as we cant get your location</string>
1616
<string name="pull_weather_failed_notify">Can\'t connect to open weather. Maybe you don\'t have internet now.</string>
1717
<string name="denied_location_permission_notify">Sorry, you have to grant this permission to let us show the weather at your location</string>
18+
19+
<!--For the expandableLayout-->
20+
<string name="precipitation_word">Precipitation</string>
21+
<string name="pop_word">Probability of precipitation</string>
22+
<string name="wind_word">Wind</string>
23+
<string name="humidity_word">Humidity</string>
24+
<string name="uv_index_word">UV index</string>
25+
<string name="sunrise_word">Sunrise</string>
26+
<string name="sunset_word">Sunset</string>
27+
<string name="precipitation_key">%1$.1fmm</string>
28+
<string name="pop_key">%1$d%%</string>
29+
<string name="wind_key">%1$.1fm/s %2$s</string>
30+
<string name="humidity_key">%1$d%%</string>
31+
32+
<string-array name="week_array">
33+
<item>Sun</item>
34+
<item>Mon</item>
35+
<item>Tue</item>
36+
<item>Wed</item>
37+
<item>Thu</item>
38+
<item>Fri</item>
39+
<item>Sat</item>
40+
</string-array>
1841
</resources>

‎settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencyResolutionManagement {
1010
repositories {
1111
google()
1212
mavenCentral()
13+
maven { url 'https://jitpack.io' }
1314
}
1415
}
1516
rootProject.name = "WeatherRecyclerView"

0 commit comments

Comments
 (0)
Please sign in to comment.