|
9 | 9 | import android.content.SharedPreferences; |
10 | 10 | import android.graphics.Color; |
11 | 11 | import android.graphics.Typeface; |
| 12 | +import android.graphics.drawable.Drawable; |
12 | 13 | import android.net.Uri; |
13 | 14 | import android.os.Build; |
14 | 15 | import android.preference.PreferenceManager; |
@@ -287,7 +288,9 @@ public void initView() { |
287 | 288 | mChannel.setShowBadge(false); |
288 | 289 | mChannel.setVibrationPattern(new long[]{0}); |
289 | 290 | mChannel.setSound(null, null); |
290 | | - manager.createNotificationChannel(mChannel); |
| 291 | + if (manager != null) { |
| 292 | + manager.createNotificationChannel(mChannel); |
| 293 | + } |
291 | 294 | } |
292 | 295 |
|
293 | 296 | swipeRefresh.setOnRefreshListener(() -> requestWeather(mWeatherId)); |
@@ -358,20 +361,28 @@ private void showWeatherInfo(Weather weather) { |
358 | 361 | feelDegreeText.setTypeface(typeface); |
359 | 362 |
|
360 | 363 | forecastLayout.removeAllViews(); |
| 364 | + |
| 365 | + int iter = 0; |
| 366 | + String[] date = {"今天", "明天", "后天"}; |
| 367 | + |
361 | 368 | for (Forecast forecast : weather.forecastList) { |
362 | 369 | View view = LayoutInflater.from(this) |
363 | 370 | .inflate(R.layout.forecast_item, forecastLayout, false); |
364 | | - TextView dateText = view.findViewById(R.id.tv_forecast_date); |
365 | | - TextView infoText = view.findViewById(R.id.tv_forecast_info); |
| 371 | + TextView dateAndConditionText = view.findViewById(R.id.tv_forecast_date_and_info); |
366 | 372 | TextView maxMinText = view.findViewById(R.id.tv_max_min_degree); |
367 | | - ImageView weatherIcon = view.findViewById(R.id.iv_weather_icon); |
368 | 373 |
|
369 | | - dateText.setText(Integer.valueOf(forecast.date.substring(5, 7)) + "月" + Integer.valueOf(forecast.date.substring(8, 10)) + "日"); |
370 | | - infoText.setText(forecast.dayCondition); |
| 374 | + dateAndConditionText.setText(date[iter++] + "-" + forecast.dayCondition); |
371 | 375 | maxMinText.setText(forecast.temperatureMax + "℃" + " / " + forecast.temperatureMin + "℃"); |
372 | | - weatherIcon.setImageResource(Utility.WeatherIconSelector(forecast.dayCondition, Calendar.getInstance().get(Calendar.HOUR_OF_DAY))); |
373 | 376 |
|
374 | | - dateText.setTypeface(typeface); |
| 377 | + Drawable image = getResources().getDrawable( Utility.WeatherIconSelector(forecast.dayCondition, Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) ); |
| 378 | + int h = maxMinText.getLineHeight(); |
| 379 | + int w = maxMinText.getLineHeight(); |
| 380 | + |
| 381 | + image.setBounds( 0, 0, h, w ); |
| 382 | + maxMinText.setCompoundDrawables(null , null, image, null ); |
| 383 | + maxMinText.setCompoundDrawablePadding(10); |
| 384 | + |
| 385 | + dateAndConditionText.setTypeface(typeface); |
375 | 386 | maxMinText.setTypeface(typeface); |
376 | 387 |
|
377 | 388 | forecastLayout.addView(view); |
|
0 commit comments