version:4.1
fix:优化天气横竖屏报错 update:更新天气背景
This commit is contained in:
@@ -82,7 +82,9 @@ public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
Log.e("getWeather", "onError: " + throwable.getMessage());
|
||||
mView.setWeather(null);
|
||||
if (mView != null) {
|
||||
mView.setWeather(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +92,9 @@ public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
String jsonString = new Gson().toJson(weatherDailyBean);
|
||||
Log.d("getWeather", "onSuccess: " + jsonString);
|
||||
mMMKV.encode(WEATHER_DAILY_KEY, jsonString);
|
||||
mView.setWeather(weatherDailyBean);
|
||||
if (mView != null) {
|
||||
mView.setWeather(weatherDailyBean);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiui.aios.R;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class WeatherDayApdapter extends RecyclerView.Adapter<WeatherDayApdapter.WeatherHolder> {
|
||||
@@ -40,17 +43,25 @@ public class WeatherDayApdapter extends RecyclerView.Adapter<WeatherDayApdapter.
|
||||
WeatherDailyBean.DailyBean dailyBean = mDailyBeans.get(position);
|
||||
String dateString;
|
||||
switch (position) {
|
||||
case 0:
|
||||
dateString = "今天";
|
||||
break;
|
||||
case 1:
|
||||
dateString = "明天";
|
||||
break;
|
||||
case 2:
|
||||
dateString = "后天";
|
||||
break;
|
||||
// case 0:
|
||||
// dateString = "今天";
|
||||
// break;
|
||||
// case 1:
|
||||
// dateString = "明天";
|
||||
// break;
|
||||
// case 2:
|
||||
// dateString = "后天";
|
||||
// break;
|
||||
default:
|
||||
dateString = dailyBean.getFxDate();
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = sdf.parse(dailyBean.getFxDate());
|
||||
SimpleDateFormat now = new SimpleDateFormat("MM月dd日");
|
||||
dateString = now.format(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
holder.tv_date.setText(dateString);
|
||||
holder.tv_temp.setText(dailyBean.getTempMin() + "℃ - " + dailyBean.getTempMax() + "℃");
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.7 KiB |
20
app/src/main/res/drawable/background_weather_rain.xml
Normal file
20
app/src/main/res/drawable/background_weather_rain.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 内部颜色 -->
|
||||
<solid
|
||||
android:color="#00b7ee" />
|
||||
<!-- 圆角的幅度 -->
|
||||
<corners
|
||||
android:topLeftRadius="16dp"
|
||||
android:topRightRadius="16dp"
|
||||
android:bottomLeftRadius="16dp"
|
||||
android:bottomRightRadius="16dp" />
|
||||
|
||||
<padding
|
||||
android:top="4dp"
|
||||
android:bottom="4dp"
|
||||
android:left="4dp"
|
||||
android:right="4dp"
|
||||
/>
|
||||
</shape>
|
||||
20
app/src/main/res/drawable/background_weather_sun.xml
Normal file
20
app/src/main/res/drawable/background_weather_sun.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 内部颜色 -->
|
||||
<solid
|
||||
android:color="#fbc23b" />
|
||||
<!-- 圆角的幅度 -->
|
||||
<corners
|
||||
android:topLeftRadius="16dp"
|
||||
android:topRightRadius="16dp"
|
||||
android:bottomLeftRadius="16dp"
|
||||
android:bottomRightRadius="16dp" />
|
||||
|
||||
<padding
|
||||
android:top="4dp"
|
||||
android:bottom="4dp"
|
||||
android:left="4dp"
|
||||
android:right="4dp"
|
||||
/>
|
||||
</shape>
|
||||
20
app/src/main/res/drawable/background_weather_sunny.xml
Normal file
20
app/src/main/res/drawable/background_weather_sunny.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 内部颜色 -->
|
||||
<solid
|
||||
android:color="#acd598" />
|
||||
<!-- 圆角的幅度 -->
|
||||
<corners
|
||||
android:topLeftRadius="16dp"
|
||||
android:topRightRadius="16dp"
|
||||
android:bottomLeftRadius="16dp"
|
||||
android:bottomRightRadius="16dp" />
|
||||
|
||||
<padding
|
||||
android:top="4dp"
|
||||
android:bottom="4dp"
|
||||
android:left="4dp"
|
||||
android:right="4dp"
|
||||
/>
|
||||
</shape>
|
||||
@@ -69,7 +69,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="位置"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp"
|
||||
android:textSize="@dimen/sp_18"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/imageView"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView" />
|
||||
|
||||
@@ -25,10 +25,12 @@
|
||||
android:id="@+id/tv_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="36dp"
|
||||
android:text="2022-01-21 17:48:48"
|
||||
android:layout_marginBottom="@dimen/dp_8"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="17:48"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textSize="@dimen/sp_20"
|
||||
app:layout_constraintBottom_toTopOf="@+id/iv_weather"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
@@ -49,9 +51,9 @@
|
||||
android:id="@+id/tv_weather"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginTop="@dimen/dp_8"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textSize="@dimen/sp_20"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/iv_weather" />
|
||||
@@ -60,7 +62,7 @@
|
||||
android:id="@+id/tv_temp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginTop="@dimen/dp_8"
|
||||
android:text="15-22"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="26sp"
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
android:id="@+id/constraintLayout3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginStart="8dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/back_white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@@ -69,7 +70,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="位置"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp"
|
||||
android:textSize="@dimen/sp_18"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/imageView"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView" />
|
||||
|
||||
@@ -29,24 +29,24 @@
|
||||
android:id="@+id/tv_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="36dp"
|
||||
android:text="2022-01-21 17:48:48"
|
||||
android:layout_marginStart="@dimen/dp_32"
|
||||
android:layout_marginTop="@dimen/dp_32"
|
||||
android:text="17:48"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/iv_weather"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
android:textSize="@dimen/sp_20"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_weather"
|
||||
android:layout_width="140dp"
|
||||
android:layout_height="140dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginEnd="@dimen/dp_32"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/he100"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
@@ -54,21 +54,23 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textSize="@dimen/sp_20"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/iv_weather" />
|
||||
app:layout_constraintTop_toTopOf="@+id/iv_bg" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_temp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="15-22"
|
||||
android:layout_marginTop="@dimen/dp_8"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="26sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_weather" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/iv_weather"
|
||||
app:layout_constraintStart_toStartOf="@+id/iv_weather"
|
||||
app:layout_constraintTop_toBottomOf="@+id/iv_weather" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user