Skip to content

Commit

Permalink
Add option to show precipitation in inches
Browse files Browse the repository at this point in the history
Modify settings for wind speed
  • Loading branch information
woheller69 committed Dec 26, 2023
1 parent 5d35ac3 commit 015d8cd
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public float convertTemperatureFromCelsius(float temperature) {
}
}

public float convertPrecipitationFromMM(float precipitation) {
// 1 = mm, 2 = inch
int prefValue = Integer.parseInt(preferences.getString("precipitationUnit", "1"));
if (prefValue == 1) {
return precipitation;
} else {
return (float) (precipitation / 25.4);
}
}

/**
* @return Returns "°C" in case Celsius is set and "°F" if Fahrenheit was selected.
*/
Expand All @@ -70,6 +80,15 @@ public String getTemperatureUnit() {
}
}

public String getPrecipitationUnit(Context context) {
int prefValue = Integer.parseInt(preferences.getString("precipitationUnit", "1"));
if (prefValue == 1) {
return context.getString(R.string.units_mm) ;
} else {
return context.getString(R.string.units_in);
}
}

public boolean showStarDialog(Context context) {
int versionCode = preferences.getInt("versionCode",BuildConfig.VERSION_CODE);
boolean askForStar=preferences.getBoolean("askForStar",true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ public static String formatTemperature(Context context, float temperature) {
}

public static String formatPrecipitation(Context context, float precipitation) {
if (precipitation < 10.0f) return formatDecimal(precipitation, context.getString(R.string.units_mm)); //show decimal only below 10mm
else return formatInt(precipitation,context.getString(R.string.units_mm));
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(context);
if (sharedPreferences.getString("precipitationUnit", "1").equals("1")) { // mm
if (precipitation < 10.0f) return formatDecimal(precipitation, context.getString(R.string.units_mm)); //show decimal only below 10mm
else return formatInt(precipitation,context.getString(R.string.units_mm));
} else {
DecimalFormat inchFormatter = new DecimalFormat("0.00");
inchFormatter.setRoundingMode(RoundingMode.HALF_UP);
return String.format("%s\u200a%s", removeMinusIfZerosOnly(inchFormatter.format(precipitation / 25.4)), context.getString(R.string.units_in));
}
}

public static String formatTimeWithoutZone(Context context, long time) {
Expand All @@ -82,7 +89,7 @@ public static String formatDate(long time) {

public static String formatWindSpeed(Context context, float wind_speed) {
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(context);
if (sharedPreferences.getBoolean("pref_WindFormat",true)==TRUE) {
if (sharedPreferences.getString("speedUnit", "3").equals("3")) {
if (wind_speed < 0.3) {
return formatInt(0, context.getString(R.string.units_Bft)); // Calm
} else if (wind_speed < 1.5) {
Expand Down Expand Up @@ -110,11 +117,10 @@ public static String formatWindSpeed(Context context, float wind_speed) {
} else {
return formatInt(12, context.getString(R.string.units_Bft)); // Hurricane
}
}else{
if (sharedPreferences.getString("distanceUnit", "0").equals("1")) { //distanceUnit km
} else if (sharedPreferences.getString("speedUnit", "3").equals("1")) {
return formatInt((float) (wind_speed*3.6),context.getString(R.string.units_km_h));
}else return formatInt((float) (wind_speed*2.236),context.getString(R.string.units_mph));
}
} else return formatInt((float) (wind_speed*2.236),context.getString(R.string.units_mph));

}

public static Drawable colorWindSpeed(Context context, float wind_speed) {
Expand Down Expand Up @@ -191,35 +197,6 @@ public static Drawable colorUVindex(Context context, int uvindex) {
}
}

public static Integer widgetColorWindSpeed(Context context, float wind_speed) {
if (wind_speed < 0.3) {
return R.drawable.rounded_grey;
} else if (wind_speed < 1.5) {
return R.drawable.rounded_grey;
} else if (wind_speed < 3.3) {
return R.drawable.rounded_grey;
} else if (wind_speed < 5.5) {
return R.drawable.rounded_grey;
} else if (wind_speed < 7.9) {
return R.drawable.rounded_grey;
} else if (wind_speed < 10.7) {
return R.drawable.rounded_yellow;
} else if (wind_speed < 13.8) {
return R.drawable.rounded_yellow;
} else if (wind_speed < 17.1) {
return R.drawable.rounded_yellow;
} else if (wind_speed < 20.7) {
return R.drawable.rounded_orange;
} else if (wind_speed < 24.4) {
return R.drawable.rounded_orange;
} else if (wind_speed < 28.4) {
return R.drawable.rounded_lightred;
} else if (wind_speed < 32.6) {
return R.drawable.rounded_lightred;
} else {
return R.drawable.rounded_red;
}
}

public static Integer widgetColorUVindex(Context context, int uvindex) {
if (uvindex <=2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -32,7 +33,6 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.ViewHolder> {
Expand Down Expand Up @@ -79,12 +79,12 @@ public void updateForecastData(List<HourlyForecast> hourlyForecasts) {

long onehourago = System.currentTimeMillis() - (1 * 60 * 60 * 1000);

for (HourlyForecast f : hourlyForecasts) {
if (f.getForecastTime() >= onehourago) {
courseDayList.add(f);
}
for (HourlyForecast f : hourlyForecasts) {
if (f.getForecastTime() >= onehourago) {
courseDayList.add(f);
}
notifyDataSetChanged();
}
notifyDataSetChanged();
}

// function for week forecast list
Expand Down Expand Up @@ -383,7 +383,7 @@ public void onItemClick(View view, int position) {
}
}

public void onLongItemClick(View view, int position) {
public void onLongItemClick(View view, int position) {

}
})
Expand All @@ -403,6 +403,7 @@ public void onLongItemClick(View view, int position) {
if (weekForecastList==null || weekForecastList.isEmpty()) return;

AppPreferencesManager prefManager = new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(this.context));
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.context);

float tmin=1000;
float tmax=-1000;
Expand Down Expand Up @@ -430,24 +431,24 @@ public void onLongItemClick(View view, int position) {
if (weekForecastList.size()>8) dayString=dayString.substring(0,1); //use first character only if more than 8 days to avoid overlapping text

if ((i == 0) || (i == (weekForecastList.size()-1 ))) { // 1 bar at begin and end for alignment with temperature line chart (first day starts at noon, last ends at noon)
precipitationDataset.addBar(dayString, precip);
precipitationDataset.addBar(dayString, prefManager.convertPrecipitationFromMM(precip));
//x-labels for precipitation dataset must be there and cannot be empty even though they are made invisible below. Otherwise alignment gets destroyed!
datasetmax.addPoint(dayString, prefManager.convertTemperatureFromCelsius(temp_max));
datasetmin.addPoint(dayString, prefManager.convertTemperatureFromCelsius(temp_min));


} else { // 2 bars in the middle for alignment with temperature line chart

precipitationDataset.addBar(dayString, precip);
precipitationDataset.addBar(dayString, precip);
precipitationDataset.addBar(dayString, prefManager.convertPrecipitationFromMM(precip));
precipitationDataset.addBar(dayString, prefManager.convertPrecipitationFromMM(precip));

datasetmax.addPoint(dayString, prefManager.convertTemperatureFromCelsius(temp_max));
datasetmin.addPoint(dayString, prefManager.convertTemperatureFromCelsius(temp_min));
}

if (prefManager.convertTemperatureFromCelsius(temp_max)>tmax) tmax=prefManager.convertTemperatureFromCelsius(temp_max);
if (prefManager.convertTemperatureFromCelsius(temp_min)<tmin) tmin=prefManager.convertTemperatureFromCelsius(temp_min);
if (precip>pmax) pmax=precip;
if (prefManager.convertPrecipitationFromMM(precip)>pmax) pmax=prefManager.convertPrecipitationFromMM(precip);
}

tmax++; //add some space above and below
Expand Down Expand Up @@ -496,10 +497,11 @@ public void onLongItemClick(View view, int position) {

holder.lineChartView.show();

step = (int) Math.ceil((Math.max(10,pmax*2))/4);
int stepnum = sp.getString("precipitationUnit","1").equals("1") ? 4 : 2; //only 2 steps instead of 4 if inches is selected
step = (int) Math.ceil((Math.max(prefManager.convertPrecipitationFromMM(10),pmax*2))/stepnum);
holder.barChartView.addData(precipitation);
holder.barChartView.setBarSpacing(0);
holder.barChartView.setAxisBorderValues(0, step*4); //scale down in case of high precipitation, limit to lower half of chart
holder.barChartView.setAxisBorderValues(0, step*stepnum); //scale down in case of high precipitation, limit to lower half of chart
holder.barChartView.setXAxis(false);
holder.barChartView.setYAxis(false);
holder.barChartView.setYLabels(AxisController.LabelPosition.NONE); //no labels for precipitation
Expand All @@ -520,7 +522,7 @@ public void onLongItemClick(View view, int position) {

holder.barChartViewAxis.addData(precipitationAxis);
holder.barChartViewAxis.setBarSpacing(0);
holder.barChartViewAxis.setAxisBorderValues(0, step*4); //scale down in case of high precipitation, limit to lower half of chart
holder.barChartViewAxis.setAxisBorderValues(0, step*stepnum); //scale down in case of high precipitation, limit to lower half of chart
holder.barChartViewAxis.setStep(step);
holder.barChartViewAxis.setXAxis(false);
holder.barChartViewAxis.setYAxis(false);
Expand All @@ -532,7 +534,7 @@ public void onLongItemClick(View view, int position) {
holder.barChartViewAxis.show();

holder.temperatureunit.setText(" "+ prefManager.getTemperatureUnit() + " ");
holder.precipitationunit.setText(" " + context.getResources().getString(R.string.units_mm)+" ");
holder.precipitationunit.setText(" " + prefManager.getPrecipitationUnit(context) + " ");
}
//No update for error needed
}
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
<string name="about_more_info">Mere information kan findes på:</string>
<string name="activity_settings_title">Indstillinger</string>
<string name="settings_title_units">Enheder</string>
<string name="settings_summary_temperature">Indstil enheden til at bruge til at vise temperaturer</string>
<string name="settings_title_temperature">Temperaturer</string>
<string name="settings_title_temperature">Temperatur</string>
<string name="settings_celsius">Celsius</string>
<string name="settings_fahrenheit">Fahrenheit</string>
<string name="settings_summary_distance">Indstil enheden til at bruge til at vise afstande</string>
<string name="settings_title_distance">Afstande</string>
<string name="settings_kilometers">Kilometer</string>
<string name="settings_miles">Miles</string>
<string name="settings_title_speed">Vindhastighed</string>
<string name="abbreviation_monday">Ma.</string>
<string name="abbreviation_tuesday">Ti.</string>
<string name="abbreviation_wednesday">On.</string>
Expand Down Expand Up @@ -100,7 +96,6 @@
<string name="error_no_position">Ingen ledig stilling</string>
<string name="settings_time24h">24-timers format</string>
<string name="summary_time24h">Tilsidesæt systemindstilling</string>
<string name="settings_wind">Brug Beaufort skala</string>
<string name="dialog_OK_button">Okay</string>
<string name="dialog_NO_button">Ingen</string>
<string name="dialog_Later_button">Måske senere</string>
Expand All @@ -119,6 +114,7 @@
<string name="settings_forecast_days">Antal prognosedage</string>
<string name="settings_apparent_temperature">Vis følt temperatur</string>
<string name="units_hours">h</string>
<string name="settings_title_precipitation">Nedbør</string>
<!-- Generated by Automatic String Resource Translation -->
<!-- https://asrt.gluege.boerde.de -->
</resources>
10 changes: 3 additions & 7 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
<string name="dialog_add_no_city_found">Es wurde kein Ort gefunden, der der Eingabe entspricht. Es wird empfohlen, einen Eintrag aus dem Dropdown-Menu zu wählen.</string>
<string name="navigation_drawer_close">Navigationsleiste schließen</string>
<string name="settings_title_units">Maßeinheiten</string>
<string name="settings_title_temperature">Temperaturen</string>
<string name="settings_title_distance">Entfernungen</string>
<string name="settings_title_temperature">Temperatur</string>
<string name="settings_title_speed">Windgeschwindigkeit</string>
<string name="settings_celsius">Celsius</string>
<string name="settings_fahrenheit">Fahrenheit</string>
<string name="settings_kilometers">Kilometer</string>
<string name="settings_miles">Meilen</string>
<string name="settings_summary_distance">Die Einheit, die zur Anzeige von Entfernungen verwendet wird.</string>
<string name="settings_summary_temperature">Die Einheit, die zur Anzeige von Temperaturen verwendet wird.</string>
<string name="settings_interval_summary">Setzen Sie das Interval der automatischen Updates</string>
<string name="settings_intervals">Intervalle</string>
<string name="settings_update_interval">Update Intervall</string>
Expand Down Expand Up @@ -94,7 +90,6 @@
<string name="error_no_position">Keine Position verfügbar</string>
<string name="settings_time24h">24-Stunden-Format</string>
<string name="summary_time24h">Systemeinstellung überschreiben</string>
<string name="settings_wind">Beaufort-Skala benutzen</string>
<string name="dialog_OK_button">OK</string>
<string name="dialog_NO_button">Nein</string>
<string name="dialog_Later_button">Vielleicht später</string>
Expand All @@ -120,5 +115,6 @@
<string name="settings_forecast_days">Anzahl der prognostizierten Tage</string>
<string name="settings_apparent_temperature">Gefühlte Temperatur anzeigen</string>
<string name="units_hours">h</string>
<string name="settings_title_precipitation">Niederschlag</string>

</resources>
10 changes: 3 additions & 7 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
<string name="about_more_info">Puede encontrar más información en:</string>
<string name="activity_settings_title">Configuraciones</string>
<string name="settings_title_units">Unidades</string>
<string name="settings_summary_temperature">Configure la unidad que se utilizará para mostrar temperaturas</string>
<string name="settings_title_temperature">Temperaturas</string>
<string name="settings_title_temperature">Temperatura</string>
<string name="settings_celsius">Celsius</string>
<string name="settings_fahrenheit">Fahrenheit</string>
<string name="settings_summary_distance">Configure la unidad que se utilizará para mostrar distancias</string>
<string name="settings_title_distance">Distancias</string>
<string name="settings_kilometers">Kilómetros</string>
<string name="settings_miles">Miles</string>
<string name="settings_title_speed">Velocidad del viento</string>
<string name="abbreviation_monday">Lu</string>
<string name="abbreviation_tuesday">Ma</string>
<string name="abbreviation_wednesday">Mi</string>
Expand Down Expand Up @@ -93,7 +89,6 @@
<string name="error_no_position">Posición no disponible </string>
<string name="settings_time24h">Formato de 24 horas</string>
<string name="summary_time24h">Anular la configuración del sistema</string>
<string name="settings_wind">Usar escala de Beaufort</string>
<string name="dialog_OK_button">OK</string>
<string name="dialog_NO_button">No</string>
<string name="dialog_Later_button">Quizás mas tarde</string>
Expand All @@ -119,5 +114,6 @@
<string name="settings_forecast_days">Número de días de pronóstico</string>
<string name="settings_apparent_temperature">Visualización de la temperatura del fieltro</string>
<string name="units_hours">h</string>
<string name="settings_title_precipitation">Precipitación</string>

</resources>
10 changes: 3 additions & 7 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
<string name="dialog_add_no_city_found">Aucun emplacement correspondant à ce que vous avez entré n\'a été trouvé. Il est recommandé de choisir une entrée dans le menu déroulant.</string>
<string name="navigation_drawer_close">Fermer la barre de navigation</string>
<string name="settings_title_units">Unités</string>
<string name="settings_title_temperature">Températures</string>
<string name="settings_title_distance">Distances</string>
<string name="settings_title_temperature">Température</string>
<string name="settings_title_speed">Vitesse du vent</string>
<string name="settings_celsius">Celsius</string>
<string name="settings_fahrenheit">Fahrenheit</string>
<string name="settings_kilometers">Kilomètre</string>
<string name="settings_miles">Miles</string>
<string name="settings_summary_distance">L\'unité utilisée pour afficher les distances.</string>
<string name="settings_summary_temperature">L\'unité utilisée pour afficher les températures.</string>
<string name="settings_interval_summary">Définir l\'intervalle des mises à jour automatiques</string>
<string name="settings_intervals">Intervalle</string>
<string name="settings_update_interval">Intervalle de mise à jour</string>
Expand Down Expand Up @@ -94,7 +90,6 @@
<string name="error_no_position">Position non disponible</string>
<string name="settings_time24h">Format 24 heures</string>
<string name="summary_time24h">Remplacer le réglage du système</string>
<string name="settings_wind">Utiliser l\'échelle de Beaufort</string>
<string name="dialog_OK_button">D\'accord</string>
<string name="dialog_NO_button">Non</string>
<string name="dialog_Later_button">Peut-être plus tard</string>
Expand All @@ -120,5 +115,6 @@
<string name="settings_forecast_days">Nombre de jours de prévision</string>
<string name="settings_apparent_temperature">Affiche la température ressentie</string>
<string name="units_hours">h</string>
<string name="settings_title_precipitation">Précipitation</string>

</resources>
Loading

0 comments on commit 015d8cd

Please sign in to comment.