diff --git a/app/build.gradle b/app/build.gradle index b5d4167..2c6fb99 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { applicationId "com.absinthe.chillweather" minSdkVersion 21 - targetSdkVersion 28 - versionCode 662 + targetSdkVersion 29 + versionCode 677 versionName "1.1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/absinthe/chillweather/WeatherActivity.java b/app/src/main/java/com/absinthe/chillweather/WeatherActivity.java index aaa4ad0..2b5c1b1 100644 --- a/app/src/main/java/com/absinthe/chillweather/WeatherActivity.java +++ b/app/src/main/java/com/absinthe/chillweather/WeatherActivity.java @@ -9,6 +9,7 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.preference.PreferenceManager; @@ -287,7 +288,9 @@ public void initView() { mChannel.setShowBadge(false); mChannel.setVibrationPattern(new long[]{0}); mChannel.setSound(null, null); - manager.createNotificationChannel(mChannel); + if (manager != null) { + manager.createNotificationChannel(mChannel); + } } swipeRefresh.setOnRefreshListener(() -> requestWeather(mWeatherId)); @@ -358,20 +361,28 @@ private void showWeatherInfo(Weather weather) { feelDegreeText.setTypeface(typeface); forecastLayout.removeAllViews(); + + int iter = 0; + String[] date = {"今天", "明天", "后天"}; + for (Forecast forecast : weather.forecastList) { View view = LayoutInflater.from(this) .inflate(R.layout.forecast_item, forecastLayout, false); - TextView dateText = view.findViewById(R.id.tv_forecast_date); - TextView infoText = view.findViewById(R.id.tv_forecast_info); + TextView dateAndConditionText = view.findViewById(R.id.tv_forecast_date_and_info); TextView maxMinText = view.findViewById(R.id.tv_max_min_degree); - ImageView weatherIcon = view.findViewById(R.id.iv_weather_icon); - dateText.setText(Integer.valueOf(forecast.date.substring(5, 7)) + "月" + Integer.valueOf(forecast.date.substring(8, 10)) + "日"); - infoText.setText(forecast.dayCondition); + dateAndConditionText.setText(date[iter++] + "-" + forecast.dayCondition); maxMinText.setText(forecast.temperatureMax + "℃" + " / " + forecast.temperatureMin + "℃"); - weatherIcon.setImageResource(Utility.WeatherIconSelector(forecast.dayCondition, Calendar.getInstance().get(Calendar.HOUR_OF_DAY))); - dateText.setTypeface(typeface); + Drawable image = getResources().getDrawable( Utility.WeatherIconSelector(forecast.dayCondition, Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) ); + int h = maxMinText.getLineHeight(); + int w = maxMinText.getLineHeight(); + + image.setBounds( 0, 0, h, w ); + maxMinText.setCompoundDrawables(null , null, image, null ); + maxMinText.setCompoundDrawablePadding(10); + + dateAndConditionText.setTypeface(typeface); maxMinText.setTypeface(typeface); forecastLayout.addView(view); diff --git a/app/src/main/res/layout/forecast_item.xml b/app/src/main/res/layout/forecast_item.xml index 17866b1..5a1d6aa 100644 --- a/app/src/main/res/layout/forecast_item.xml +++ b/app/src/main/res/layout/forecast_item.xml @@ -3,41 +3,26 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" + android:orientation="horizontal" android:layout_margin="15dp"> - - -