Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1196 - Loading weather image. #1198

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ private void setWeatherData() {
double weatherTemp = weatherResponse.getCurrent_forecast().getTemperature();

if (weatherIcon != null && !weatherIcon.isEmpty()) {
WeatherUtils.setWeatherImage(weatherImageView, weatherIcon, this);
WeatherUtils.setWeatherImage(weatherImageView, weatherIcon);
}else{
weatherImageView.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.onebusaway.android.ui.weather;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -12,25 +11,15 @@

public class WeatherUtils {

public static void setWeatherImage(ImageView imageView, String weatherCondition, Context context) {
// TODO FIXME: This is temporarily commented out because it was causing a large number
// of crashes in 2.13.0.
// See https://github.com/OneBusAway/onebusaway-android/issues/1196

// String resName = weatherCondition.replace("-", "_");
//
// int resId = context.getResources().getIdentifier(resName, "drawable", context.getPackageName());
//
// if (resId != 0) {
// // Adjusting scale for fog and wind icons.
// if(weatherCondition.equals("fog") || weatherCondition.equals("wind")){
// imageView.setScaleType(ImageView.ScaleType.CENTER);
// }
// imageView.setImageResource(resId);
// } else {
// // Default
// imageView.setImageResource(R.drawable.clear_day);
// }
public static void setWeatherImage(ImageView imageView, String weatherCondition) {
String resName = weatherCondition.replaceAll("-", "_");
// Adjusting scale for fog and wind icons.
if (weatherCondition.equals("fog") || weatherCondition.equals("wind")) {
imageView.setScaleType(ImageView.ScaleType.CENTER);
}else{
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
imageView.setImageResource(getWeatherDrawableRes(resName));
}

public static void setWeatherTemp(TextView weatherTempTxtView, double temp) {
Expand All @@ -51,6 +40,32 @@ public static void setWeatherTemp(TextView weatherTempTxtView, double temp) {
}


private static int getWeatherDrawableRes(String condition) {
switch (condition) {
case "clear_night":
return R.drawable.clear_night;
case "rain":
return R.drawable.rain;
case "snow":
return R.drawable.snow;
case "sleet":
return R.drawable.sleet;
case "wind":
return R.drawable.wind;
case "fog":
return R.drawable.fog;
case "cloudy":
return R.drawable.cloudy;
case "partly_cloudy_day":
return R.drawable.partly_cloudy_day;
case "partly_cloudy_night":
return R.drawable.partly_cloudy_night;
default:
return R.drawable.clear_day;
}
}


public static String getDefaultUserTemp() {
Locale locale = Locale.getDefault();
String countryCode = locale.getCountry();
Expand Down
1 change: 0 additions & 1 deletion onebusaway-android/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@

<ImageView
android:id="@+id/weatherStateImageView"
android:visibility="gone"
android:layout_width="24dp"
android:layout_height="24dp"
android:scaleType="centerCrop"
Expand Down
Loading