Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Optimized three-day weather display.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobozhen committed Aug 2, 2019
1 parent 2ead247 commit 87cde41
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/com/absinthe/chillweather/WeatherActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 6 additions & 21 deletions app/src/main/res/layout/forecast_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<TextView
android:id="@+id/tv_forecast_date"
android:id="@+id/tv_forecast_date_and_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="3"
android:textSize="@dimen/forecast_text_size"
android:textColor="@color/itemTextColor"/>

<TextView
android:id="@+id/tv_forecast_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_gravity="start"
android:gravity="start"
android:layout_weight="1"
android:gravity="center"
android:textSize="@dimen/forecast_text_size"
android:textColor="@color/itemTextColor"/>

<ImageView
android:id="@+id/iv_weather_icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" />

<TextView
android:id="@+id/tv_max_min_degree"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="3"
android:layout_gravity="end"
android:gravity="end"
android:textSize="@dimen/forecast_text_size"
android:textColor="@color/itemTextColor"/>
Expand Down

0 comments on commit 87cde41

Please sign in to comment.