Tons of refactoring and deleting unused stuff

This commit is contained in:
woheller69 2023-04-03 10:18:25 +02:00
parent 54cd149896
commit b734fef432
73 changed files with 157 additions and 998 deletions

View file

@ -5,6 +5,10 @@
solarCast forecasts the output of your solar power plant
This app takes direct and diffuse radiation data from Open-Meteo.com, calculates the position
of the sun and projects the radiation on your solar panel.
It shows the estimated energy production for the next hours and up to 16 days.
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/01.png" width="150"/><img src="fastlane/metadata/android/en-US/images/phoneScreenshots/02.png" width="150"/> <img src="fastlane/metadata/android/en-US/images/phoneScreenshots/03.png" width="150"/>

View file

@ -1,17 +1,10 @@
package org.woheller69.weather.activities;
import static java.lang.Boolean.TRUE;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import androidx.core.app.ActivityCompat;
import androidx.preference.PreferenceManager;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
@ -19,31 +12,25 @@ import com.google.android.material.tabs.TabLayoutMediator;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.TextView;
import android.widget.Toast;
import org.woheller69.weather.R;
import org.woheller69.weather.database.CityToWatch;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.database.WeekForecast;
import org.woheller69.weather.ui.updater.IUpdateableCityUI;
import org.woheller69.weather.ui.updater.ViewUpdater;
import org.woheller69.weather.ui.viewPager.WeatherPagerAdapter;
import static org.woheller69.weather.database.SQLiteHelper.getWidgetCityID;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Locale;
public class ForecastCityActivity extends NavigationActivity implements IUpdateableCityUI {
private WeatherPagerAdapter pagerAdapter;
@ -88,9 +75,9 @@ public class ForecastCityActivity extends NavigationActivity implements IUpdatea
if (pagerAdapter.getItemCount()>0) { //only if at least one city is watched
//if pagerAdapter has item with current cityId go there, otherwise use cityId from current item
if (pagerAdapter.getPosForCityID(cityId)==-1) cityId=pagerAdapter.getCityIDForPos(viewPager2.getCurrentItem());
CurrentWeatherData currentWeather = db.getCurrentWeatherByCityId(cityId);
GeneralData generalData = db.getGeneralDataByCityId(cityId);
long timestamp = currentWeather.getTimestamp();
long timestamp = generalData.getTimestamp();
long systemTime = System.currentTimeMillis() / 1000;
SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
long updateInterval = (long) (Float.parseFloat(prefManager.getString("pref_updateInterval", "2")) * 60 * 60);
@ -120,9 +107,9 @@ public class ForecastCityActivity extends NavigationActivity implements IUpdatea
//Update current tab if outside update interval, show animation
SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SQLiteHelper database = SQLiteHelper.getInstance(getApplicationContext().getApplicationContext());
CurrentWeatherData currentWeather = database.getCurrentWeatherByCityId(pagerAdapter.getCityIDForPos(position));
GeneralData generalData = database.getGeneralDataByCityId(pagerAdapter.getCityIDForPos(position));
long timestamp = currentWeather.getTimestamp();
long timestamp = generalData.getTimestamp();
long systemTime = System.currentTimeMillis() / 1000;
long updateInterval = (long) (Float.parseFloat(prefManager.getString("pref_updateInterval", "2")) * 60 * 60);
@ -204,7 +191,7 @@ public class ForecastCityActivity extends NavigationActivity implements IUpdatea
}
@Override
public void processNewCurrentWeatherData(CurrentWeatherData data) {
public void processNewGeneralData(GeneralData data) {
if (refreshActionButton != null && refreshActionButton.getActionView() != null) {
refreshActionButton.getActionView().clearAnimation();
}

View file

@ -150,7 +150,8 @@ public class ManageLocationsActivity extends NavigationActivity {
@Override
public void afterTextChanged(Editable editable) {
float elevation = Float.parseFloat("0"+editElevation.getText().toString());
editDiffuseEfficiency.setText(Float.toString(100-50 * elevation/90));
int diffuseEfficiency = (int) (100-50 * elevation/90);
editDiffuseEfficiency.setText(Float.toString((float) diffuseEfficiency));
}
});

View file

@ -9,40 +9,23 @@ import java.util.TimeZone;
* This class represents the database model for current weather data of cities.
*/
public class CurrentWeatherData {
public class GeneralData {
private int id;
private int city_id;
private long timestamp;
private int weatherID;
private float temperatureCurrent;
private float humidity;
private float pressure;
private float windSpeed;
private float windDirection;
private float cloudiness;
private long timeSunrise;
private long timeSunset;
private int timeZoneSeconds;
private String Rain60min;
private String city_name;
public CurrentWeatherData() {
public GeneralData() {
this.city_id = Integer.MIN_VALUE;
}
public CurrentWeatherData(int id, int city_id, long timestamp, int weatherID, float temperatureCurrent, float temperatureMin, float temperatureMax, float humidity, float pressure, float windSpeed, float windDirection, float cloudiness, long timeSunrise, long timeSunset, int timeZoneSeconds) {
public GeneralData(int id, int city_id, long timestamp, int weatherID, float temperatureCurrent, float temperatureMin, float temperatureMax, float humidity, float pressure, float windSpeed, float windDirection, float cloudiness, long timeSunrise, long timeSunset, int timeZoneSeconds) {
this.id = id;
this.city_id = city_id;
this.timestamp = timestamp;
this.weatherID = weatherID;
this.temperatureCurrent = temperatureCurrent;
this.humidity = humidity;
this.pressure = pressure;
this.windSpeed = windSpeed;
this.windDirection = windDirection;
this.cloudiness = cloudiness;
this.timeSunrise = timeSunrise;
this.timeSunset = timeSunset;
this.timeZoneSeconds = timeZoneSeconds;
@ -72,61 +55,6 @@ public class CurrentWeatherData {
this.timestamp = timestamp;
}
public int getWeatherID() {
return weatherID;
}
public void setWeatherID(int weatherID) {
this.weatherID = weatherID;
}
public float getTemperatureCurrent() {
return temperatureCurrent;
}
public void setTemperatureCurrent(float temperatureCurrent) {
this.temperatureCurrent = temperatureCurrent;
}
public float getHumidity() {
return humidity;
}
public void setHumidity(float humidity) {
this.humidity = humidity;
}
public float getPressure() {
return pressure;
}
public void setPressure(float pressure) {
this.pressure = pressure;
}
public float getWindSpeed() {
return windSpeed;
}
public void setWindSpeed(float windSpeed) {
this.windSpeed = windSpeed;
}
public float getWindDirection() {
return windDirection;
}
public void setWindDirection(float windDirection) {
this.windDirection = windDirection;
}
public float getCloudiness() {
return cloudiness;
}
public void setCloudiness(float cloudiness) {
this.cloudiness = cloudiness;
}
public boolean isDay(Context context){
Calendar timeStamp = Calendar.getInstance();
@ -158,14 +86,6 @@ public class CurrentWeatherData {
this.timeSunset = timeSunset;
}
public String getCity_name() {
return city_name;
}
public void setCity_name(String city_name) {
this.city_name = city_name;
}
public int getTimeZoneSeconds() {
return timeZoneSeconds;
}
@ -174,11 +94,4 @@ public class CurrentWeatherData {
this.timeZoneSeconds = timeZoneSeconds;
}
public String getRain60min() {
return Rain60min;
}
public void setRain60min(String Rain60min) {
this.Rain60min = Rain60min;
}
}

View file

@ -45,7 +45,7 @@ public class HourlyForecast {
*/
public long getLocalForecastTime(Context context) {
SQLiteHelper dbhelper = SQLiteHelper.getInstance(context);
int timezoneseconds = dbhelper.getCurrentWeatherByCityId(city_id).getTimeZoneSeconds();
int timezoneseconds = dbhelper.getGeneralDataByCityId(city_id).getTimeZoneSeconds();
return forecastFor + timezoneseconds * 1000L;
}

View file

@ -33,7 +33,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
private static final String TABLE_CITIES_TO_WATCH = "CITIES_TO_WATCH";
private static final String TABLE_HOURLY_FORECAST = "FORECASTS";
private static final String TABLE_WEEKFORECAST = "WEEKFORECASTS";
private static final String TABLE_CURRENT_WEATHER = "CURRENT_WEATHER";
private static final String TABLE_GENERAL_DATA = "GENERAL_DATA";
//Names of columns in TABLE_CITIES_TO_WATCH
@ -69,55 +69,30 @@ public class SQLiteHelper extends SQLiteOpenHelper {
private static final String WEEKFORECAST_COLUMN_TIME_MEASUREMENT = "time_of_measurement";
private static final String WEEKFORECAST_COLUMN_FORECAST_FOR = "forecast_for";
private static final String WEEKFORECAST_COLUMN_WEATHER_ID = "weather_id";
private static final String WEEKFORECAST_COLUMN_TEMPERATURE_CURRENT = "temperature_current";
private static final String WEEKFORECAST_COLUMN_TEMPERATURE_MIN = "temperature_min";
private static final String WEEKFORECAST_COLUMN_TEMPERATURE_MAX = "temperature_max";
private static final String WEEKFORECAST_COLUMN_HUMIDITY = "humidity";
private static final String WEEKFORECAST_COLUMN_PRESSURE = "pressure";
private static final String WEEKFORECAST_COLUMN_PRECIPITATION = "precipitation";
private static final String WEEKFORECAST_COLUMN_WIND_SPEED = "wind_speed";
private static final String WEEKFORECAST_COLUMN_WIND_DIRECTION = "wind_direction";
private static final String WEEKFORECAST_COLUMN_UV_INDEX = "uv_index";
private static final String WEEKFORECAST_COLUMN_ENERGY_DAY = "energy_day";
private static final String WEEKFORECAST_COLUMN_TIME_SUNRISE = "time_sunrise";
private static final String WEEKFORECAST_COLUMN_TIME_SUNSET = "time_sunset";
//Names of columns in TABLE_CURRENT_WEATHER
private static final String CURRENT_WEATHER_ID = "current_weather_id";
private static final String CURRENT_WEATHER_CITY_ID = "city_id";
//Names of columns in TABLE_GENERAL_DATA
private static final String COLUMN_ID = "current_id";
private static final String COLUMN_CITY_ID = "city_id";
private static final String COLUMN_TIME_MEASUREMENT = "time_of_measurement";
private static final String COLUMN_WEATHER_ID = "weather_id";
private static final String COLUMN_TEMPERATURE_CURRENT = "temperature_current";
private static final String COLUMN_HUMIDITY = "humidity";
private static final String COLUMN_PRESSURE = "pressure";
private static final String COLUMN_WIND_SPEED = "wind_speed";
private static final String COLUMN_WIND_DIRECTION = "wind_direction";
private static final String COLUMN_CLOUDINESS = "cloudiness";
private static final String COLUMN_TIME_SUNRISE = "time_sunrise";
private static final String COLUMN_TIME_SUNSET = "time_sunset";
private static final String COLUMN_TIMEZONE_SECONDS = "timezone_seconds";
private static final String COLUMN_RAIN60MIN = "Rain60min";
/**
* Create Table statements for all tables
*/
private static final String CREATE_CURRENT_WEATHER = "CREATE TABLE " + TABLE_CURRENT_WEATHER +
private static final String CREATE_GENERAL_DATA = "CREATE TABLE " + TABLE_GENERAL_DATA +
"(" +
CURRENT_WEATHER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
CURRENT_WEATHER_CITY_ID + " INTEGER," +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
COLUMN_CITY_ID + " INTEGER," +
COLUMN_TIME_MEASUREMENT + " LONG NOT NULL," +
COLUMN_WEATHER_ID + " INTEGER," +
COLUMN_TEMPERATURE_CURRENT + " REAL," +
COLUMN_HUMIDITY + " REAL," +
COLUMN_PRESSURE + " REAL," +
COLUMN_WIND_SPEED + " REAL," +
COLUMN_WIND_DIRECTION + " REAL," +
COLUMN_CLOUDINESS + " REAL," +
COLUMN_TIME_SUNRISE + " LONG NOT NULL," +
COLUMN_TIME_SUNSET + " LONG NOT NULL," +
COLUMN_TIMEZONE_SECONDS + " INTEGER," +
COLUMN_RAIN60MIN + " VARCHAR(25) NOT NULL) ;";
COLUMN_TIMEZONE_SECONDS + " INTEGER)";
private static final String CREATE_TABLE_FORECASTS = "CREATE TABLE " + TABLE_HOURLY_FORECAST +
"(" +
@ -137,15 +112,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
WEEKFORECAST_COLUMN_TIME_MEASUREMENT + " LONG NOT NULL," +
WEEKFORECAST_COLUMN_FORECAST_FOR + " VARCHAR(200) NOT NULL," +
WEEKFORECAST_COLUMN_WEATHER_ID + " INTEGER," +
WEEKFORECAST_COLUMN_TEMPERATURE_CURRENT + " REAL," +
WEEKFORECAST_COLUMN_TEMPERATURE_MIN + " REAL," +
WEEKFORECAST_COLUMN_TEMPERATURE_MAX + " REAL," +
WEEKFORECAST_COLUMN_HUMIDITY + " REAL," +
WEEKFORECAST_COLUMN_PRESSURE + " REAL," +
WEEKFORECAST_COLUMN_PRECIPITATION + " REAL," +
WEEKFORECAST_COLUMN_WIND_SPEED + " REAL," +
WEEKFORECAST_COLUMN_WIND_DIRECTION + " REAL," +
WEEKFORECAST_COLUMN_UV_INDEX + " REAL," +
WEEKFORECAST_COLUMN_ENERGY_DAY + " REAL," +
WEEKFORECAST_COLUMN_TIME_SUNRISE + " LONG NOT NULL," +
WEEKFORECAST_COLUMN_TIME_SUNSET + " LONG NOT NULL)";
@ -182,7 +149,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_CITIES_TO_WATCH);
db.execSQL(CREATE_CURRENT_WEATHER);
db.execSQL(CREATE_GENERAL_DATA);
db.execSQL(CREATE_TABLE_FORECASTS);
db.execSQL(CREATE_TABLE_WEEKFORECASTS);
}
@ -192,7 +159,6 @@ public class SQLiteHelper extends SQLiteOpenHelper {
}
/**
* Methods for TABLE_CITIES_TO_WATCH
*/
@ -352,7 +318,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
public synchronized void deleteCityToWatch(CityToWatch cityToWatch) {
//First delete all weather data for city which is deleted
deleteCurrentWeatherByCityId(cityToWatch.getCityId());
deleteGeneralDataByCityId(cityToWatch.getCityId());
deleteForecastsByCityId(cityToWatch.getCityId());
deleteWeekForecastsByCityId(cityToWatch.getCityId());
@ -457,15 +423,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
values.put(WEEKFORECAST_COLUMN_TIME_MEASUREMENT, weekForecast.getTimestamp());
values.put(WEEKFORECAST_COLUMN_FORECAST_FOR, weekForecast.getForecastTime());
values.put(WEEKFORECAST_COLUMN_WEATHER_ID, weekForecast.getWeatherID());
values.put(WEEKFORECAST_COLUMN_TEMPERATURE_CURRENT, weekForecast.getTemperature());
values.put(WEEKFORECAST_COLUMN_TEMPERATURE_MIN, weekForecast.getMinTemperature());
values.put(WEEKFORECAST_COLUMN_TEMPERATURE_MAX, weekForecast.getMaxTemperature());
values.put(WEEKFORECAST_COLUMN_HUMIDITY, weekForecast.getHumidity());
values.put(WEEKFORECAST_COLUMN_PRESSURE, weekForecast.getPressure());
values.put(WEEKFORECAST_COLUMN_PRECIPITATION, weekForecast.getPrecipitation());
values.put(WEEKFORECAST_COLUMN_WIND_SPEED, weekForecast.getWind_speed());
values.put(WEEKFORECAST_COLUMN_WIND_DIRECTION, weekForecast.getWind_direction());
values.put(WEEKFORECAST_COLUMN_UV_INDEX, weekForecast.getUv_index());
values.put(WEEKFORECAST_COLUMN_ENERGY_DAY, weekForecast.getEnergyDay());
values.put(WEEKFORECAST_COLUMN_TIME_SUNRISE, weekForecast.getTimeSunrise());
values.put(WEEKFORECAST_COLUMN_TIME_SUNSET, weekForecast.getTimeSunset());
database.insert(TABLE_WEEKFORECAST, null, values);
@ -492,15 +450,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
WEEKFORECAST_COLUMN_TIME_MEASUREMENT,
WEEKFORECAST_COLUMN_FORECAST_FOR,
WEEKFORECAST_COLUMN_WEATHER_ID,
WEEKFORECAST_COLUMN_TEMPERATURE_CURRENT,
WEEKFORECAST_COLUMN_TEMPERATURE_MIN,
WEEKFORECAST_COLUMN_TEMPERATURE_MAX,
WEEKFORECAST_COLUMN_HUMIDITY,
WEEKFORECAST_COLUMN_PRESSURE,
WEEKFORECAST_COLUMN_PRECIPITATION,
WEEKFORECAST_COLUMN_WIND_SPEED,
WEEKFORECAST_COLUMN_WIND_DIRECTION,
WEEKFORECAST_COLUMN_UV_INDEX,
WEEKFORECAST_COLUMN_ENERGY_DAY,
WEEKFORECAST_COLUMN_TIME_SUNRISE,
WEEKFORECAST_COLUMN_TIME_SUNSET}
, WEEKFORECAST_CITY_ID + "=?",
@ -517,17 +467,9 @@ public class SQLiteHelper extends SQLiteOpenHelper {
weekForecast.setTimestamp(Long.parseLong(cursor.getString(2)));
weekForecast.setForecastTime(Long.parseLong(cursor.getString(3)));
weekForecast.setWeatherID(Integer.parseInt(cursor.getString(4)));
weekForecast.setTemperature(Float.parseFloat(cursor.getString(5)));
weekForecast.setMinTemperature(Float.parseFloat(cursor.getString(6)));
weekForecast.setMaxTemperature(Float.parseFloat(cursor.getString(7)));
weekForecast.setHumidity(Float.parseFloat(cursor.getString(8)));
weekForecast.setPressure(Float.parseFloat(cursor.getString(9)));
weekForecast.setPrecipitation(Float.parseFloat(cursor.getString(10)));
weekForecast.setWind_speed(Float.parseFloat(cursor.getString(11)));
weekForecast.setWind_direction(Float.parseFloat(cursor.getString(12)));
weekForecast.setUv_index(Float.parseFloat(cursor.getString(13)));
weekForecast.setTimeSunrise(Long.parseLong(cursor.getString(14)));
weekForecast.setTimeSunset(Long.parseLong(cursor.getString(15)));
weekForecast.setEnergyDay(Float.parseFloat(cursor.getString(5)));
weekForecast.setTimeSunrise(Long.parseLong(cursor.getString(6)));
weekForecast.setTimeSunset(Long.parseLong(cursor.getString(7)));
list.add(weekForecast);
} while (cursor.moveToNext());
@ -538,128 +480,71 @@ public class SQLiteHelper extends SQLiteOpenHelper {
}
/**
* Methods for TABLE_CURRENT_WEATHER
* Methods for TABLE_GENERAL_DATA
*/
public synchronized void addCurrentWeather(CurrentWeatherData currentWeather) {
public synchronized void addGeneralData(GeneralData generalData) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(CURRENT_WEATHER_CITY_ID, currentWeather.getCity_id());
values.put(COLUMN_TIME_MEASUREMENT, currentWeather.getTimestamp());
values.put(COLUMN_WEATHER_ID, currentWeather.getWeatherID());
values.put(COLUMN_TEMPERATURE_CURRENT, currentWeather.getTemperatureCurrent());
values.put(COLUMN_HUMIDITY, currentWeather.getHumidity());
values.put(COLUMN_PRESSURE, currentWeather.getPressure());
values.put(COLUMN_WIND_SPEED, currentWeather.getWindSpeed());
values.put(COLUMN_WIND_DIRECTION, currentWeather.getWindDirection());
values.put(COLUMN_CLOUDINESS, currentWeather.getCloudiness());
values.put(COLUMN_TIME_SUNRISE, currentWeather.getTimeSunrise());
values.put(COLUMN_TIME_SUNSET, currentWeather.getTimeSunset());
values.put(COLUMN_TIMEZONE_SECONDS, currentWeather.getTimeZoneSeconds());
values.put(COLUMN_RAIN60MIN, currentWeather.getRain60min());
values.put(COLUMN_CITY_ID, generalData.getCity_id());
values.put(COLUMN_TIME_MEASUREMENT, generalData.getTimestamp());
values.put(COLUMN_TIME_SUNRISE, generalData.getTimeSunrise());
values.put(COLUMN_TIME_SUNSET, generalData.getTimeSunset());
values.put(COLUMN_TIMEZONE_SECONDS, generalData.getTimeZoneSeconds());
database.insert(TABLE_CURRENT_WEATHER, null, values);
database.insert(TABLE_GENERAL_DATA, null, values);
database.close();
}
public synchronized CurrentWeatherData getCurrentWeatherByCityId(int cityId) {
public synchronized GeneralData getGeneralDataByCityId(int cityId) {
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.query(TABLE_CURRENT_WEATHER,
new String[]{CURRENT_WEATHER_ID,
CURRENT_WEATHER_CITY_ID,
Cursor cursor = database.query(TABLE_GENERAL_DATA,
new String[]{COLUMN_ID,
COLUMN_CITY_ID,
COLUMN_TIME_MEASUREMENT,
COLUMN_WEATHER_ID,
COLUMN_TEMPERATURE_CURRENT,
COLUMN_HUMIDITY,
COLUMN_PRESSURE,
COLUMN_WIND_SPEED,
COLUMN_WIND_DIRECTION,
COLUMN_CLOUDINESS,
COLUMN_TIME_SUNRISE,
COLUMN_TIME_SUNSET,
COLUMN_TIMEZONE_SECONDS,
COLUMN_RAIN60MIN},
CURRENT_WEATHER_CITY_ID + " = ?",
COLUMN_TIMEZONE_SECONDS},
COLUMN_CITY_ID + " = ?",
new String[]{String.valueOf(cityId)}, null, null, null, null);
CurrentWeatherData currentWeather = new CurrentWeatherData();
GeneralData generalData = new GeneralData();
if (cursor != null && cursor.moveToFirst()) {
currentWeather.setId(Integer.parseInt(cursor.getString(0)));
currentWeather.setCity_id(Integer.parseInt(cursor.getString(1)));
currentWeather.setTimestamp(Long.parseLong(cursor.getString(2)));
currentWeather.setWeatherID(Integer.parseInt(cursor.getString(3)));
currentWeather.setTemperatureCurrent(Float.parseFloat(cursor.getString(4)));
currentWeather.setHumidity(Float.parseFloat(cursor.getString(5)));
currentWeather.setPressure(Float.parseFloat(cursor.getString(6)));
currentWeather.setWindSpeed(Float.parseFloat(cursor.getString(7)));
currentWeather.setWindDirection(Float.parseFloat(cursor.getString(8)));
currentWeather.setCloudiness(Float.parseFloat(cursor.getString(9)));
currentWeather.setTimeSunrise(Long.parseLong(cursor.getString(10)));
currentWeather.setTimeSunset(Long.parseLong(cursor.getString(11)));
currentWeather.setTimeZoneSeconds(Integer.parseInt(cursor.getString(12)));
currentWeather.setRain60min(cursor.getString(13));
generalData.setId(Integer.parseInt(cursor.getString(0)));
generalData.setCity_id(Integer.parseInt(cursor.getString(1)));
generalData.setTimestamp(Long.parseLong(cursor.getString(2)));
generalData.setTimeSunrise(Long.parseLong(cursor.getString(3)));
generalData.setTimeSunset(Long.parseLong(cursor.getString(4)));
generalData.setTimeZoneSeconds(Integer.parseInt(cursor.getString(5)));
cursor.close();
}
return currentWeather;
return generalData;
}
public synchronized void updateCurrentWeather(CurrentWeatherData currentWeather) {
public synchronized void updateGeneralData(GeneralData generalData) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(CURRENT_WEATHER_CITY_ID, currentWeather.getCity_id());
values.put(COLUMN_TIME_MEASUREMENT, currentWeather.getTimestamp());
values.put(COLUMN_WEATHER_ID, currentWeather.getWeatherID());
values.put(COLUMN_TEMPERATURE_CURRENT, currentWeather.getTemperatureCurrent());
values.put(COLUMN_HUMIDITY, currentWeather.getHumidity());
values.put(COLUMN_PRESSURE, currentWeather.getPressure());
values.put(COLUMN_WIND_SPEED, currentWeather.getWindSpeed());
values.put(COLUMN_WIND_DIRECTION, currentWeather.getWindDirection());
values.put(COLUMN_CLOUDINESS, currentWeather.getCloudiness());
values.put(COLUMN_TIME_SUNRISE, currentWeather.getTimeSunrise());
values.put(COLUMN_TIME_SUNSET, currentWeather.getTimeSunset());
values.put(COLUMN_TIMEZONE_SECONDS, currentWeather.getTimeZoneSeconds());
values.put(COLUMN_RAIN60MIN, currentWeather.getRain60min());
values.put(COLUMN_CITY_ID, generalData.getCity_id());
values.put(COLUMN_TIME_MEASUREMENT, generalData.getTimestamp());
values.put(COLUMN_TIME_SUNRISE, generalData.getTimeSunrise());
values.put(COLUMN_TIME_SUNSET, generalData.getTimeSunset());
values.put(COLUMN_TIMEZONE_SECONDS, generalData.getTimeZoneSeconds());
database.update(TABLE_CURRENT_WEATHER, values, CURRENT_WEATHER_CITY_ID + " = ?",
new String[]{String.valueOf(currentWeather.getCity_id())});
database.update(TABLE_GENERAL_DATA, values, COLUMN_CITY_ID + " = ?",
new String[]{String.valueOf(generalData.getCity_id())});
}
public synchronized void deleteCurrentWeather(CurrentWeatherData currentWeather) {
public synchronized void deleteGeneralDataByCityId(int cityId) {
SQLiteDatabase database = this.getWritableDatabase();
database.delete(TABLE_CURRENT_WEATHER, CURRENT_WEATHER_ID + " = ?",
new String[]{Integer.toString(currentWeather.getId())});
database.close();
}
public synchronized void deleteCurrentWeatherByCityId(int cityId) {
SQLiteDatabase database = this.getWritableDatabase();
database.delete(TABLE_CURRENT_WEATHER, CURRENT_WEATHER_CITY_ID + " = ?",
database.delete(TABLE_GENERAL_DATA, COLUMN_CITY_ID + " = ?",
new String[]{Integer.toString(cityId)});
database.close();
}
public static int getWidgetCityID(Context context) {
SQLiteHelper db = SQLiteHelper.getInstance(context);
int cityID=0;
List<CityToWatch> cities = db.getAllCitiesToWatch();
int rank=cities.get(0).getRank();
for (int i = 0; i < cities.size(); i++) { //find cityID for first city to watch = lowest Rank
CityToWatch city = cities.get(i);
//Log.d("debugtag",Integer.toString(city.getRank()));
if (city.getRank() <= rank ){
rank=city.getRank();
cityID = city.getCityId();
}
}
return cityID;
}
}

View file

@ -13,36 +13,20 @@ public class WeekForecast {
private long timestamp;
private long forecastFor;
private int weatherID;
private float temperature;
private float temperature_min;
private float temperature_max;
private float humidity;
private float pressure;
private float precipitation;
private float wind_speed;
private float wind_direction;
private float uv_index;
private float energyDay;
private long timeSunrise;
private long timeSunset;
public WeekForecast() {
}
public WeekForecast(int id, int city_id, long timestamp, long forecastFor, int weatherID, float temperature, float temperature_min, float temperature_max, float humidity, float pressure, float precipitation, float wind_speed, float wind_direction, float uv_index) {
public WeekForecast(int id, int city_id, long timestamp, long forecastFor, int weatherID, float temperature, float temperature_min, float temperature_max, float humidity, float pressure, float energyDay, float wind_speed, float wind_direction, float uv_index) {
this.id = id;
this.city_id = city_id;
this.timestamp = timestamp;
this.forecastFor = forecastFor;
this.weatherID = weatherID;
this.temperature = temperature;
this.temperature_min = temperature_min;
this.temperature_max = temperature_max;
this.humidity = humidity;
this.pressure = pressure;
this.precipitation=precipitation;
this.wind_speed=wind_speed;
this.wind_direction=wind_direction;
this.uv_index=uv_index;
this.energyDay = energyDay;
}
@ -69,7 +53,7 @@ public class WeekForecast {
*/
public long getLocalForecastTime(Context context) {
SQLiteHelper dbhelper = SQLiteHelper.getInstance(context);
int timezoneseconds = dbhelper.getCurrentWeatherByCityId(city_id).getTimeZoneSeconds();
int timezoneseconds = dbhelper.getGeneralDataByCityId(city_id).getTimeZoneSeconds();
return forecastFor + timezoneseconds * 1000L;
}
@ -117,77 +101,9 @@ public class WeekForecast {
this.weatherID = weatherID;
}
/**
* @return Returns the current temperature in Celsius.
*/
public float getTemperature() {
return temperature;
}
public float getEnergyDay() {return energyDay;}
/**
* @param temperature The current temperature to set in Celsius.
*/
public void setTemperature(float temperature) {
this.temperature = temperature;
}
/**
* @return Returns the min temperature in Celsius.
*/
public float getMinTemperature() {
return temperature_min;
}
/**
* @param temperature_min The min temperature to set in Celsius.
*/
public void setMinTemperature(float temperature_min) {
this.temperature_min = temperature_min;
}
/**
* @return Returns the max temperature in Celsius.
*/
public float getMaxTemperature() {
return temperature_max;
}
/**
* @param temperature_max The max temperature to set in Celsius.
*/
public void setMaxTemperature(float temperature_max) {
this.temperature_max = temperature_max;
}
/**
* @return Returns the humidity value in percent.
*/
public float getHumidity() {
return humidity;
}
/**
* @param humidity The humidity value in percent to set.
*/
public void setHumidity(float humidity) {
this.humidity = humidity;
}
public float getPressure() { return pressure;}
public void setPressure(float pressure) {this.pressure=pressure;}
public float getPrecipitation() {return precipitation; }
public void setPrecipitation(float precipitation) {this.precipitation=precipitation;}
public float getWind_speed() { return wind_speed;}
public void setWind_speed(float wind_speed) {this.wind_speed=wind_speed;}
public float getWind_direction() { return wind_direction;}
public void setWind_direction(float wind_direction) {this.wind_direction=wind_direction;}
public float getUv_index() { return uv_index; }
public void setUv_index(float uv_index) {this.uv_index=uv_index;}
public void setEnergyDay(float energyDay) {this.energyDay =energyDay;}
public long getTimeSunrise() { return timeSunrise; }

View file

@ -54,161 +54,6 @@ public final class StringFormatUtils {
return df.format(time);
}
public static String formatWindSpeed(Context context, float wind_speed) {
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(context);
if (sharedPreferences.getBoolean("pref_WindFormat",true)==TRUE) {
if (wind_speed < 0.3) {
return formatInt(0, context.getString(R.string.units_Bft)); // Calm
} else if (wind_speed < 1.5) {
return formatInt(1, context.getString(R.string.units_Bft)); // Light air
} else if (wind_speed < 3.3) {
return formatInt(2, context.getString(R.string.units_Bft)); // Light breeze
} else if (wind_speed < 5.5) {
return formatInt(3, context.getString(R.string.units_Bft)); // Gentle breeze
} else if (wind_speed < 7.9) {
return formatInt(4, context.getString(R.string.units_Bft)); // Moderate breeze
} else if (wind_speed < 10.7) {
return formatInt(5, context.getString(R.string.units_Bft)); // Fresh breeze
} else if (wind_speed < 13.8) {
return formatInt(6, context.getString(R.string.units_Bft)); // Strong breeze
} else if (wind_speed < 17.1) {
return formatInt(7, context.getString(R.string.units_Bft)); // High wind
} else if (wind_speed < 20.7) {
return formatInt(8, context.getString(R.string.units_Bft)); // Gale
} else if (wind_speed < 24.4) {
return formatInt(9, context.getString(R.string.units_Bft)); // Strong gale
} else if (wind_speed < 28.4) {
return formatInt(10, context.getString(R.string.units_Bft)); // Storm
} else if (wind_speed < 32.6) {
return formatInt(11, context.getString(R.string.units_Bft)); // Violent storm
} else {
return formatInt(12, context.getString(R.string.units_Bft)); // Hurricane
}
}else{
if (sharedPreferences.getString("distanceUnit", "0").equals("1")) { //distanceUnit km
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));
}
}
public static Drawable colorWindSpeed(Context context, float wind_speed) {
if (wind_speed < 0.3) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (wind_speed < 1.5) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (wind_speed < 3.3) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (wind_speed < 5.5) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (wind_speed < 7.9) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (wind_speed < 10.7) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_yellow,null);
} else if (wind_speed < 13.8) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_yellow,null);
} else if (wind_speed < 17.1) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_yellow,null);
} else if (wind_speed < 20.7) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_orange,null);
} else if (wind_speed < 24.4) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_orange,null);
} else if (wind_speed < 28.4) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_lightred,null);
} else if (wind_speed < 32.6) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_lightred,null);
} else {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_red,null);
}
}
public static int colorWindSpeedWidget(float wind_speed) {
if (wind_speed < 0.3) {
return R.drawable.ic_wind_empty;
} else if (wind_speed < 1.5) {
return R.drawable.ic_wind_empty;
} else if (wind_speed < 3.3) {
return R.drawable.ic_wind_empty;
} else if (wind_speed < 5.5) {
return R.drawable.ic_wind_empty;
} else if (wind_speed < 7.9) {
return R.drawable.ic_wind_empty;
} else if (wind_speed < 10.7) {
return R.drawable.ic_wind_yellow;
} else if (wind_speed < 13.8) {
return R.drawable.ic_wind_yellow;
} else if (wind_speed < 17.1) {
return R.drawable.ic_wind_yellow;
} else if (wind_speed < 20.7) {
return R.drawable.ic_wind_orange;
} else if (wind_speed < 24.4) {
return R.drawable.ic_wind_orange;
} else if (wind_speed < 28.4) {
return R.drawable.ic_wind_lightred;
} else if (wind_speed < 32.6) {
return R.drawable.ic_wind_lightred;
} else {
return R.drawable.ic_wind_lightred;
}
}
public static Drawable colorUVindex(Context context, int uvindex) {
if (uvindex <=2) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_transparent,null);
} else if (uvindex <= 5) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_yellow,null);
} else if (uvindex <= 7) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_orange,null);
} else if (uvindex <= 10) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_lightred,null);
} else {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_violet,null);
}
}
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) {
return R.drawable.rounded_green;
} else if (uvindex <= 5) {
return R.drawable.rounded_yellow;
} else if (uvindex <= 7) {
return R.drawable.rounded_orange;
} else if (uvindex <= 10) {
return R.drawable.rounded_lightred;
} else {
return R.drawable.rounded_violet;
}
}
public static Integer getDayShort(int day){
switch(day) {

View file

@ -3,7 +3,6 @@ package org.woheller69.weather.ui.RecycleList;
import android.content.Context;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
@ -15,27 +14,23 @@ import android.widget.TextView;
import com.db.chart.Tools;
import com.db.chart.model.BarSet;
import com.db.chart.model.ChartSet;
import com.db.chart.model.LineSet;
import com.db.chart.view.AxisController;
import com.db.chart.view.BarChartView;
import org.woheller69.weather.R;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.database.WeekForecast;
import org.woheller69.weather.preferences.AppPreferencesManager;
import org.woheller69.weather.ui.Help.StringFormatUtils;
import org.woheller69.weather.ui.UiResourceProvider;
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> {
private static final String TAG = "Forecast_Adapter";
private int[] dataSetTypes;
private List<HourlyForecast> courseDayList;
@ -46,7 +41,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
private RecyclerView mCourseOfDay;
private RecyclerView mWeekWeather;
private CurrentWeatherData currentWeatherDataList;
private GeneralData generalDataList;
public static final int OVERVIEW = 0;
public static final int DETAILS = 1;
@ -55,15 +50,15 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
public static final int CHART = 4;
public static final int EMPTY = 5;
public CityWeatherAdapter(CurrentWeatherData currentWeatherDataList, int[] dataSetTypes, Context context) {
this.currentWeatherDataList = currentWeatherDataList;
public CityWeatherAdapter(GeneralData generalDataList, int[] dataSetTypes, Context context) {
this.generalDataList = generalDataList;
this.dataSetTypes = dataSetTypes;
this.context = context;
SQLiteHelper database = SQLiteHelper.getInstance(context.getApplicationContext());
List<HourlyForecast> hourlyForecasts = database.getForecastsByCityId(currentWeatherDataList.getCity_id());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(currentWeatherDataList.getCity_id());
List<HourlyForecast> hourlyForecasts = database.getForecastsByCityId(generalDataList.getCity_id());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(generalDataList.getCity_id());
updateForecastData(hourlyForecasts);
updateWeekForecastData(weekforecasts);
@ -90,21 +85,21 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
int cityId = forecasts.get(0).getCity_id();
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context.getApplicationContext());
int zonemilliseconds = dbHelper.getCurrentWeatherByCityId(cityId).getTimeZoneSeconds() * 1000;
int zonemilliseconds = dbHelper.getGeneralDataByCityId(cityId).getTimeZoneSeconds() * 1000;
//temp max 0, temp min 1, humidity 2, pressure 3, precipitation 4, wind 5, wind direction 6, uv_index 7, forecast time 8, weather ID 9, number of FCs for day 10
forecastData = new float[forecasts.size()][11];
for (int i=0;i<forecasts.size();i++){
forecastData[i][0]=forecasts.get(i).getMaxTemperature();
forecastData[i][1]=forecasts.get(i).getMinTemperature();
forecastData[i][2]=forecasts.get(i).getHumidity();
forecastData[i][3]=forecasts.get(i).getPressure();
forecastData[i][4]=forecasts.get(i).getPrecipitation();
forecastData[i][5]=forecasts.get(i).getWind_speed();
forecastData[i][6]=forecasts.get(i).getWind_direction();
forecastData[i][7]=forecasts.get(i).getUv_index();
forecastData[i][0]=0;
forecastData[i][1]=0;
forecastData[i][2]=0;
forecastData[i][3]=0;
forecastData[i][4]=forecasts.get(i).getEnergyDay();
forecastData[i][5]=0;
forecastData[i][6]=0;
forecastData[i][7]=0;
forecastData[i][8]=forecasts.get(i).getForecastTime()+zonemilliseconds;
forecastData[i][9]=forecasts.get(i).getWeatherID();
forecastData[i][10]=1;
@ -123,17 +118,13 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
public class OverViewHolder extends ViewHolder {
TextView temperature;
ImageView weather;
ImageView windicon;
TextView updatetime;
TextView sun;
OverViewHolder(View v) {
super(v);
this.temperature = v.findViewById(R.id.card_overview_temperature);
this.weather = v.findViewById(R.id.card_overview_weather_image);
this.sun=v.findViewById(R.id.card_overview_sunrise_sunset);
this.windicon=v.findViewById(R.id.card_overview_windicon);
this.updatetime=v.findViewById(R.id.card_overview_update_time);
}
}
@ -236,27 +227,22 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
boolean isDay = currentWeatherDataList.isDay(context);
if (viewHolder.getItemViewType() == OVERVIEW) {
OverViewHolder holder = (OverViewHolder) viewHolder;
//correct for timezone differences
int zoneseconds = currentWeatherDataList.getTimeZoneSeconds();
long riseTime = (currentWeatherDataList.getTimeSunrise() + zoneseconds) * 1000;
long setTime = (currentWeatherDataList.getTimeSunset() + zoneseconds) * 1000;
int zoneseconds = generalDataList.getTimeZoneSeconds();
long riseTime = (generalDataList.getTimeSunrise() + zoneseconds) * 1000;
long setTime = (generalDataList.getTimeSunset() + zoneseconds) * 1000;
if (riseTime==zoneseconds*1000 || setTime==zoneseconds*1000) holder.sun.setText("\u2600\u25b2 --:--" + " \u25bc --:--" );
else {
holder.sun.setText("\u2600\u25b2 " + StringFormatUtils.formatTimeWithoutZone(context, riseTime) + " \u25bc " + StringFormatUtils.formatTimeWithoutZone(context, setTime));
}
holder.windicon.setImageResource(StringFormatUtils.colorWindSpeedWidget(currentWeatherDataList.getWindSpeed()));
long time = currentWeatherDataList.getTimestamp();
long time = generalDataList.getTimestamp();
long updateTime = ((time + zoneseconds) * 1000);
holder.updatetime.setText("("+StringFormatUtils.formatTimeWithoutZone(context, updateTime)+")");
setImage(currentWeatherDataList.getWeatherID(), holder.weather, isDay);
} else if (viewHolder.getItemViewType() == WEEK) {
@ -265,7 +251,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
holder.recyclerView.setLayoutManager(layoutManager);
final WeekWeatherAdapter adapter = new WeekWeatherAdapter(context, forecastData,currentWeatherDataList.getCity_id());
final WeekWeatherAdapter adapter = new WeekWeatherAdapter(context, forecastData, generalDataList.getCity_id());
holder.recyclerView.setAdapter(adapter);
holder.recyclerView.setFocusable(false);
@ -280,7 +266,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
@Override
public void onItemClick(View view, int position) {
SQLiteHelper database = SQLiteHelper.getInstance(context.getApplicationContext());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(currentWeatherDataList.getCity_id());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(generalDataList.getCity_id());
long time = weekforecasts.get(position).getForecastTime(); //time of clicked week item
time=time-6*3600000; //week item normally midday -> subtract 6h to get morning time
@ -343,7 +329,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
ChartViewHolder holder = (ChartViewHolder) viewHolder;
SQLiteHelper database = SQLiteHelper.getInstance(context.getApplicationContext());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(currentWeatherDataList.getCity_id());
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(generalDataList.getCity_id());
if (weekforecasts.isEmpty()) {
return;
@ -355,12 +341,12 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT"));
int zonemilliseconds = currentWeatherDataList.getTimeZoneSeconds()*1000;
int zonemilliseconds = generalDataList.getTimeZoneSeconds()*1000;
for (int i=0 ; i< weekforecasts.size();i++) {
c.setTimeInMillis(weekforecasts.get(i).getForecastTime()+zonemilliseconds);
int day = c.get(Calendar.DAY_OF_WEEK);
float precip=weekforecasts.get(i).getPrecipitation();
float precip=weekforecasts.get(i).getEnergyDay();
String dayString = context.getResources().getString(StringFormatUtils.getDayShort(day));
if (weekforecasts.size()>8) dayString=dayString.substring(0,1); //use first character only if more than 8 days to avoid overlapping text
@ -369,18 +355,12 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
if (precip>pmax) pmax=precip;
}
int step;
ArrayList<ChartSet> temperature = new ArrayList<>();
ArrayList<ChartSet> precipitation = new ArrayList<>();
precipitation.add(precipitationDataset);
precipitationDataset.setColor(ContextCompat.getColor(context,R.color.yellow));
precipitationDataset.setAlpha(0.8f); // make precipitation bars transparent
step = (int) Math.ceil((Math.max(1,pmax))/4);
holder.barChartView.addData(precipitation);
holder.barChartView.setBarSpacing(10);
holder.barChartView.setXAxis(false);
@ -398,10 +378,6 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
//No update for error needed
}
public void setImage(int value, ImageView imageView, boolean isDay) {
imageView.setImageResource(UiResourceProvider.getImageResourceForWeatherCategory(value, isDay));
}
@Override
public int getItemCount() {

View file

@ -12,7 +12,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.woheller69.weather.R;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.ui.Help.StringFormatUtils;
@ -63,14 +63,14 @@ public class CourseOfDayAdapter extends RecyclerView.Adapter<CourseOfDayAdapter.
@Override
public void onBindViewHolder(CourseOfDayViewHolder holder, int position) {
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context);
CurrentWeatherData currentWeather = dbHelper.getCurrentWeatherByCityId(courseOfDayList.get(position).getCity_id());
GeneralData generalData = dbHelper.getGeneralDataByCityId(courseOfDayList.get(position).getCity_id());
Calendar forecastTime = Calendar.getInstance();
forecastTime.setTimeZone(TimeZone.getTimeZone("GMT"));
forecastTime.setTimeInMillis(courseOfDayList.get(position).getLocalForecastTime(context));
boolean isDay;
if (currentWeather.getTimeSunrise()==0 || currentWeather.getTimeSunset()==0){
if (generalData.getTimeSunrise()==0 || generalData.getTimeSunset()==0){
if ((dbHelper.getCityToWatch(courseOfDayList.get(position).getCity_id()).getLatitude())>0){ //northern hemisphere
isDay= forecastTime.get(Calendar.DAY_OF_YEAR) >= 80 && forecastTime.get(Calendar.DAY_OF_YEAR) <= 265; //from March 21 to September 22 (incl)
}else{ //southern hemisphere
@ -79,14 +79,14 @@ public class CourseOfDayAdapter extends RecyclerView.Adapter<CourseOfDayAdapter.
}else {
Calendar sunSetTime = Calendar.getInstance();
sunSetTime.setTimeZone(TimeZone.getTimeZone("GMT"));
sunSetTime.setTimeInMillis(currentWeather.getTimeSunset() * 1000 + currentWeather.getTimeZoneSeconds() * 1000L);
sunSetTime.setTimeInMillis(generalData.getTimeSunset() * 1000 + generalData.getTimeZoneSeconds() * 1000L);
sunSetTime.set(Calendar.DAY_OF_YEAR, forecastTime.get(Calendar.DAY_OF_YEAR));
sunSetTime.set(Calendar.YEAR, forecastTime.get(Calendar.YEAR));
Calendar sunRiseTime = Calendar.getInstance();
sunRiseTime.setTimeZone(TimeZone.getTimeZone("GMT"));
sunRiseTime.setTimeInMillis(currentWeather.getTimeSunrise() * 1000 + currentWeather.getTimeZoneSeconds() * 1000L);
sunRiseTime.setTimeInMillis(generalData.getTimeSunrise() * 1000 + generalData.getTimeZoneSeconds() * 1000L);
sunRiseTime.set(Calendar.DAY_OF_YEAR, forecastTime.get(Calendar.DAY_OF_YEAR));
sunRiseTime.set(Calendar.YEAR, forecastTime.get(Calendar.YEAR));

View file

@ -12,7 +12,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.woheller69.weather.R;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.ui.Help.StringFormatUtils;
import org.woheller69.weather.ui.UiResourceProvider;
@ -69,7 +69,7 @@ public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.
if (dayValues.length!=11) return; //Fixes app crash if forecastData not yet ready.
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context);
CurrentWeatherData currentWeather = dbHelper.getCurrentWeatherByCityId(cityID);
GeneralData generalData = dbHelper.getGeneralDataByCityId(cityID);
Calendar forecastTime = Calendar.getInstance();
forecastTime.setTimeZone(TimeZone.getTimeZone("GMT"));
@ -77,7 +77,7 @@ public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.
boolean isDay;
if (currentWeather.getTimeSunrise()==0 || currentWeather.getTimeSunset()==0) {
if (generalData.getTimeSunrise()==0 || generalData.getTimeSunset()==0) {
if ((dbHelper.getCityToWatch(cityID).getLatitude()) > 0) { //northern hemisphere
isDay = forecastTime.get(Calendar.DAY_OF_YEAR) >= 80 && forecastTime.get(Calendar.DAY_OF_YEAR) <= 265; //from March 21 to September 22 (incl)
} else { //southern hemisphere

View file

@ -158,147 +158,4 @@ public class UiResourceProvider {
}
}
/**
* @param categoryNumber The category number. See IApiToDatabaseConversion#WeatherCategories
* for details.
* @param isDay True if TimeStamp between sunrise and sunset
* @return Returns the image resource that belongs to the given category number.
*/
public static int getImageResourceForWeatherCategory(int categoryNumber, boolean isDay) {
if (categoryNumber == WeatherCategories.CLEAR_SKY.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_00d;
} else {
return R.drawable.wmo_image_00n;
}
} else if (categoryNumber == WeatherCategories.FEW_CLOUDS.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_01d;
} else {
return R.drawable.wmo_image_01n;
}
} else if (categoryNumber == WeatherCategories.SCATTERED_CLOUDS.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_02d;
} else {
return R.drawable.wmo_image_02n;
}
} else if (categoryNumber == WeatherCategories.OVERCAST_CLOUDS.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_03d;
} else {
return R.drawable.wmo_image_03n;
}
} else if (categoryNumber == WeatherCategories.MIST.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_45d;
} else {
return R.drawable.wmo_image_45n;
}
} else if (categoryNumber == WeatherCategories.DRIZZLE_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_53d;
} else {
return R.drawable.wmo_image_53n;
}
} else if (categoryNumber == WeatherCategories.FREEZING_DRIZZLE_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_57d;
} else {
return R.drawable.wmo_image_57n;
}
} else if (categoryNumber == WeatherCategories.LIGHT_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_61d;
} else {
return R.drawable.wmo_image_61n;
}
} else if (categoryNumber == WeatherCategories.MODERATE_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_63d;
} else {
return R.drawable.wmo_image_63n;
}
} else if (categoryNumber == WeatherCategories.HEAVY_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_65d;
} else {
return R.drawable.wmo_image_65n;
}
} else if (categoryNumber == WeatherCategories.LIGHT_SHOWER_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_80d;
} else {
return R.drawable.wmo_image_80n;
}
} else if (categoryNumber == WeatherCategories.SHOWER_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_81d;
} else {
return R.drawable.wmo_image_81n;
}
} else if (categoryNumber == WeatherCategories.LIGHT_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_71d;
} else {
return R.drawable.wmo_image_71n;
}
} else if (categoryNumber == WeatherCategories.MODERATE_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_73d;
} else {
return R.drawable.wmo_image_73n;
}
} else if (categoryNumber == WeatherCategories.HEAVY_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_75d;
} else {
return R.drawable.wmo_image_75n;
}
} else if (categoryNumber == WeatherCategories.LIGHT_FREEZING_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_66d;
} else {
return R.drawable.wmo_image_66n;
}
} else if (categoryNumber == WeatherCategories.FREEZING_RAIN.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_67d;
} else {
return R.drawable.wmo_image_67n;
}
} else if (categoryNumber == WeatherCategories.LIGHT_SHOWER_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_85d;
} else {
return R.drawable.wmo_image_85n;
}
} else if (categoryNumber == WeatherCategories.SHOWER_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_86d;
} else {
return R.drawable.wmo_image_86n;
}
} else if (categoryNumber == WeatherCategories.SHOWER_RAIN_SNOW.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_84d;
} else {
return R.drawable.wmo_image_84n;
}
} else if (categoryNumber == WeatherCategories.THUNDERSTORM.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_95d;
} else {
return R.drawable.wmo_image_95n;
}
} else if (categoryNumber == WeatherCategories.THUNDERSTORM_HAIL.getNumVal()) {
if (isDay) {
return R.drawable.wmo_image_96d;
} else {
return R.drawable.wmo_image_96n;
}
} else { //this should not occur
return R.drawable.wmo_image_error;
}
}
}

View file

@ -2,9 +2,7 @@ package org.woheller69.weather.ui;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.CHART;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.DAY;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.DETAILS;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.EMPTY;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.OVERVIEW;
import static org.woheller69.weather.ui.RecycleList.CityWeatherAdapter.WEEK;
import android.annotation.SuppressLint;
@ -16,7 +14,6 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
@ -25,7 +22,7 @@ import android.view.ViewGroup;
import org.woheller69.weather.R;
import org.woheller69.weather.activities.ForecastCityActivity;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.database.WeekForecast;
@ -38,7 +35,7 @@ import org.woheller69.weather.ui.viewPager.WeatherPagerAdapter;
import java.util.List;
public class WeatherCityFragment extends Fragment implements IUpdateableCityUI {
private static final int MINGRIDWIDTH = 500;
private int mCityId = -1;
private int[] mDataSetTypes = new int[]{};
private static int[] mFull = {DAY, WEEK, CHART}; //TODO Make dynamic from Settings
@ -65,10 +62,10 @@ public class WeatherCityFragment extends Fragment implements IUpdateableCityUI {
}
public void loadData() {
CurrentWeatherData currentWeatherData = SQLiteHelper.getInstance(getContext()).getCurrentWeatherByCityId(mCityId);
if (currentWeatherData.getTimestamp()==0) mDataSetTypes=mEmpty; //show empty view if no data available yet
GeneralData generalData = SQLiteHelper.getInstance(getContext()).getGeneralDataByCityId(mCityId);
if (generalData.getTimestamp()==0) mDataSetTypes=mEmpty; //show empty view if no data available yet
else mDataSetTypes=mFull;
mAdapter = new CityWeatherAdapter(currentWeatherData, mDataSetTypes, getContext());
mAdapter = new CityWeatherAdapter(generalData, mDataSetTypes, getContext());
setAdapter(mAdapter);
}
@ -123,7 +120,7 @@ public class WeatherCityFragment extends Fragment implements IUpdateableCityUI {
}
@Override
public void processNewCurrentWeatherData(CurrentWeatherData data) {
public void processNewGeneralData(GeneralData data) {
if (data != null && data.getCity_id() == mCityId) {
mDataSetTypes= mFull;
setAdapter(new CityWeatherAdapter(data, mDataSetTypes, getContext()));

View file

@ -1,6 +1,6 @@
package org.woheller69.weather.ui.updater;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.WeekForecast;
@ -10,7 +10,7 @@ import java.util.List;
* Created by chris on 24.01.2017.
*/
public interface IUpdateableCityUI {
void processNewCurrentWeatherData(CurrentWeatherData data);
void processNewGeneralData(GeneralData data);
void processNewForecasts(List<HourlyForecast> hourlyForecasts);

View file

@ -1,6 +1,6 @@
package org.woheller69.weather.ui.updater;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.WeekForecast;
@ -24,10 +24,10 @@ public class ViewUpdater {
subscribers.remove(sub);
}
public static void updateCurrentWeatherData(CurrentWeatherData data) {
public static void updateGeneralDataData(GeneralData data) {
ArrayList<IUpdateableCityUI> subcopy = new ArrayList<>(subscribers); //copy list needed as bugfix for concurrent modification exception
for (IUpdateableCityUI sub : subcopy) {
sub.processNewCurrentWeatherData(data);
sub.processNewGeneralData(data);
}
}

View file

@ -9,7 +9,7 @@ import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import org.woheller69.weather.database.CityToWatch;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.database.WeekForecast;
@ -77,7 +77,7 @@ public class WeatherPagerAdapter extends FragmentStateAdapter implements IUpdate
@Override
public void processNewCurrentWeatherData(CurrentWeatherData data) {
public void processNewGeneralData(GeneralData data) {
}

View file

@ -1,23 +1,16 @@
package org.woheller69.weather.weather_api;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.WeekForecast;
import java.util.List;
/**
* This interface defines the frame of the functionality to extractCurrentWeatherData weather information from which
* This interface defines the frame of the functionality to extractGeneralData weather information from which
* is returned by some API.
*/
public interface IDataExtractor {
/**
* @param data The data that contains the information to instantiate a CurrentWeatherData
* object. In the easiest case this is the (HTTP) response of the One Call API.
* @return Returns the extracted information as a CurrentWeatherData instance.
*/
CurrentWeatherData extractCurrentWeather(String data);
/**
* @param data The data that contains the information to instantiate a Forecast object.
* @return Returns the extracted weather forecast information. In case some error occurs, null
@ -33,10 +26,4 @@ public interface IDataExtractor {
List<HourlyForecast> extractHourlyForecast(String data, int cityID);
/**
* @param data0, data1, data2, data3, data4 contain the information to retrieve the rain for a minute within the next 60min.
* @return Returns a string with a rain drop in case of rain or a - in case of no rain
*/
String extractRain60min(String data0,String data1, String data2, String data3, String data4);
}

View file

@ -10,7 +10,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.woheller69.weather.SolarPowerPlant;
import org.woheller69.weather.database.CityToWatch;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.SQLiteHelper;
import org.woheller69.weather.database.WeekForecast;
@ -30,50 +30,17 @@ public class OMDataExtractor implements IDataExtractor {
this.context = context;
}
@Override
public CurrentWeatherData extractCurrentWeather(String data) {
try {
JSONObject jsonData = new JSONObject(data);
CurrentWeatherData weatherData = new CurrentWeatherData();
weatherData.setTimestamp(System.currentTimeMillis() / 1000);
IApiToDatabaseConversion conversion = new OMToDatabaseConversion();
if (jsonData.has("weathercode")) weatherData.setWeatherID(conversion.convertWeatherCategory(jsonData.getString("weathercode")));
if (jsonData.has("temperature")) weatherData.setTemperatureCurrent((float) jsonData.getDouble("temperature"));
if (jsonData.has("windspeed")) weatherData.setWindSpeed((float) jsonData.getDouble("windspeed"));
if (jsonData.has("winddirection")) weatherData.setWindDirection((float) jsonData.getDouble("winddirection"));
weatherData.setTimeSunrise(0L);
weatherData.setTimeSunset(0L);
weatherData.setHumidity(0);
weatherData.setPressure(0);
weatherData.setCloudiness(0);
return weatherData;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
public List<WeekForecast> extractWeekForecast(String data) {
try {
SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(context);
List<WeekForecast> weekforecasts = new ArrayList<>();
JSONObject jsonData = new JSONObject(data);
JSONArray timeArray = jsonData.getJSONArray("time");
JSONArray weathercodeArray = jsonData.has("weathercode") ? jsonData.getJSONArray("weathercode") : null;
JSONArray tempMaxArray = jsonData.has("temperature_2m_max") ? jsonData.getJSONArray("temperature_2m_max") : null;
JSONArray tempMinArray = jsonData.has("temperature_2m_min") ? jsonData.getJSONArray("temperature_2m_min") : null;
JSONArray sunriseArray = jsonData.has("sunrise") ? jsonData.getJSONArray("sunrise") : null;
JSONArray sunsetArray = jsonData.has("sunset") ? jsonData.getJSONArray("sunset") : null;
JSONArray uvIndexArray = jsonData.has("uv_index_max") ? jsonData.getJSONArray("uv_index_max") : null;
JSONArray precipitationArray = jsonData.has("precipitation_sum") ? jsonData.getJSONArray("precipitation_sum") : null;
JSONArray windSpeedArray = jsonData.has("windspeed_10m_max") ? jsonData.getJSONArray("windspeed_10m_max") : null;
JSONArray snowfallArray = jsonData.has("snowfall_sum") ? jsonData.getJSONArray("snowfall_sum") : null;
JSONArray showersArray = jsonData.has("showers_sum") ? jsonData.getJSONArray("showers_sum") : null;
JSONArray rainArray = jsonData.has("rain_sum") ? jsonData.getJSONArray("rain_sum") : null;
IApiToDatabaseConversion conversion = new OMToDatabaseConversion();
for (int i = 0; i < timeArray.length(); i++) {
@ -81,14 +48,8 @@ public class OMDataExtractor implements IDataExtractor {
weekForecast.setTimestamp(System.currentTimeMillis() / 1000);
if (!timeArray.isNull(i)) weekForecast.setForecastTime((timeArray.getLong(i)+12*3600)*1000L); //shift to midday
if (!weathercodeArray.isNull(i)) weekForecast.setWeatherID(conversion.convertWeatherCategory(weathercodeArray.getString(i)));
if (!tempMaxArray.isNull(i)) weekForecast.setMaxTemperature((float) tempMaxArray.getDouble(i));
if (!tempMinArray.isNull(i)) weekForecast.setMinTemperature((float) tempMinArray.getDouble(i));
if (!sunriseArray.isNull(i)) weekForecast.setTimeSunrise(sunriseArray.getLong(i));
if (!sunsetArray.isNull(i)) weekForecast.setTimeSunset(sunsetArray.getLong(i));
if (!uvIndexArray.isNull(i)) {
weekForecast.setUv_index((float) uvIndexArray.getDouble(i));
} else weekForecast.setUv_index(-1);
if (!windSpeedArray.isNull(i)) weekForecast.setWind_speed((float) windSpeedArray.getDouble(i));
weekforecasts.add(weekForecast);
}
return weekforecasts;
@ -139,47 +100,4 @@ public class OMDataExtractor implements IDataExtractor {
}
/**
* @see IDataExtractor#extractRain60min(String, String, String, String, String)
*/
@Override
public String extractRain60min(String data0,String data1, String data2, String data3, String data4) {
try {
String rain = "";
JSONObject jsonData0 = new JSONObject(data0);
JSONObject jsonData1 = new JSONObject(data1);
JSONObject jsonData2 = new JSONObject(data2);
JSONObject jsonData3 = new JSONObject(data3);
JSONObject jsonData4 = new JSONObject(data4);
double rain5min=jsonData0.getDouble("precipitation")+jsonData1.getDouble("precipitation")+jsonData2.getDouble("precipitation")+jsonData3.getDouble("precipitation")+jsonData4.getDouble("precipitation");
if (rain5min==0){
rain ="\u25a1";
} else if (rain5min<2.5){ // very light rain equals <0.5mm/h (2.5 = 5 x 0.5)
rain ="\u25a4";
}else if (rain5min<12.5){ //light rain equals <2.5mm/h (12.5 = 5 x 2.5)
rain ="\u25a6";
} else{
rain ="\u25a0";
}
return rain;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* @param data The data that contains the information to retrieve the ID of the city.
* If data for a single city were requested, the response string can be
* passed as an argument.
* If data for multiple cities were requested, make sure to pass only one item
* of the response list at a time!
* @return Returns the ID of the city or Integer#MIN_VALUE in case the data is not well-formed
* and the information could not be extracted.
*/
}

View file

@ -24,7 +24,7 @@ public class OMHttpRequest {
SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
return String.format(
"%sforecast?latitude=%s&longitude=%s&forecast_days=%s&hourly=diffuse_radiation,direct_normal_irradiance,weathercode&daily=weathercode,temperature_2m_max,temperature_2m_min,sunrise,sunset,uv_index_max,precipitation_sum,windspeed_10m_max&current_weather=true&windspeed_unit=ms&timeformat=unixtime&timezone=auto",
"%sforecast?latitude=%s&longitude=%s&forecast_days=%s&hourly=diffuse_radiation,direct_normal_irradiance,weathercode&daily=weathercode,sunrise,sunset,&timeformat=unixtime&timezone=auto",
BuildConfig.BASE_URL,
lat,
lon,

View file

@ -1,11 +1,7 @@
package org.woheller69.weather.weather_api.open_meteo;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.widget.RemoteViews;
import android.widget.Toast;
import com.android.volley.VolleyError;
@ -14,8 +10,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.woheller69.weather.R;
import org.woheller69.weather.activities.NavigationActivity;
import org.woheller69.weather.database.CityToWatch;
import org.woheller69.weather.database.CurrentWeatherData;
import org.woheller69.weather.database.GeneralData;
import org.woheller69.weather.database.HourlyForecast;
import org.woheller69.weather.database.WeekForecast;
import org.woheller69.weather.database.SQLiteHelper;
@ -23,7 +18,6 @@ import org.woheller69.weather.ui.updater.ViewUpdater;
import org.woheller69.weather.weather_api.IDataExtractor;
import org.woheller69.weather.weather_api.IProcessHttpRequest;
import androidx.preference.PreferenceManager;
import org.woheller69.weather.weather_api.IApiToDatabaseConversion.WeatherCategories;
import java.util.ArrayList;
@ -88,27 +82,18 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
}
//Extract current weather
String rain60min=context.getResources().getString(R.string.error_no_rain60min_data);
CurrentWeatherData weatherData = extractor.extractCurrentWeather(json.getString("current_weather"));
if (weatherData == null) {
final String ERROR_MSG = context.getResources().getString(R.string.error_convert_to_json);
if (NavigationActivity.isVisible)
Toast.makeText(context, ERROR_MSG, Toast.LENGTH_LONG).show();
} else {
weatherData.setCity_id(cityId);
weatherData.setRain60min(rain60min);
weatherData.setTimeSunrise(weekforecasts.get(0).getTimeSunrise());
weatherData.setTimeSunset(weekforecasts.get(0).getTimeSunset());
weatherData.setTimeZoneSeconds(json.getInt("utc_offset_seconds"));
CurrentWeatherData current = dbHelper.getCurrentWeatherByCityId(cityId);
GeneralData generalData = new GeneralData();
generalData.setTimestamp(System.currentTimeMillis() / 1000);
generalData.setCity_id(cityId);
generalData.setTimeSunrise(weekforecasts.get(0).getTimeSunrise());
generalData.setTimeSunset(weekforecasts.get(0).getTimeSunset());
generalData.setTimeZoneSeconds(json.getInt("utc_offset_seconds"));
GeneralData current = dbHelper.getGeneralDataByCityId(cityId);
if (current != null && current.getCity_id() == cityId) {
dbHelper.updateCurrentWeather(weatherData);
dbHelper.updateGeneralData(generalData);
} else {
dbHelper.addCurrentWeather(weatherData);
dbHelper.addGeneralData(generalData);
}
}
//Extract hourly weather
dbHelper.deleteForecastsByCityId(cityId);
@ -131,7 +116,7 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
dbHelper.addWeekForecasts(weekforecasts);
ViewUpdater.updateCurrentWeatherData(weatherData);
ViewUpdater.updateGeneralDataData(generalData);
ViewUpdater.updateWeekForecasts(weekforecasts);
ViewUpdater.updateForecasts(hourlyforecasts);
@ -192,7 +177,7 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
totalEnergy+=hourlyForecast.getPower();
}
}
weekForecast.setPrecipitation(totalEnergy/1000);
weekForecast.setEnergyDay(totalEnergy/1000);
}
return weekforecasts;

View file

@ -1,20 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#00000000"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#00000000"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>

View file

@ -1,20 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/colorPrimaryDark"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/lightred"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>

View file

@ -1,20 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/colorPrimaryDark"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/orange"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>

View file

@ -1,20 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/colorPrimaryDark"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/red"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>

View file

@ -1,20 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/colorPrimaryDark"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="@color/yellow"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -5,13 +5,6 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
<ImageView
android:id="@+id/card_overview_weather_image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/wmo_image_00d" />
<TextView
android:layout_width="wrap_content"
@ -27,15 +20,6 @@
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<ImageView
android:id="@+id/card_overview_windicon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:src="@drawable/ic_wind_orange"
android:translationY="-20dp" />
<TextView
android:id="@+id/card_overview_temperature"

View file

@ -1,9 +1,11 @@
solarCast prognostiziert den Ertrag Ihrer PV Anlage
Die Wetterdaten werden über die freie API von Open-Meteo.com.
Diese App nimmt direkte und diffuse Strahlungsdaten von Open-Meteo.com, berechnet die Position
der Sonne und projiziert die Strahlung auf Ihr Solarpanel.
Es zeigt die geschätzte Energieproduktion für die nächsten Stunden und bis zu 16 Tage an.
Features:
- Stündliches Prognose es Ertrags für bis zu 16 Tage
- Stündliches Prognose des Ertrags für bis zu 16 Tage
- Keine Werbung
Minimale Berechtigungen:

View file

@ -1,6 +1,8 @@
solarCast forecasts the output of your solar power plant
Weather data is provided via the free API from Open-Meteo.com.
This app takes direct and diffuse radiation data from Open-Meteo.com, calculates the position
of the sun and projects the radiation on your solar panel.
It shows the estimated energy production for the next hours and up to 16 days.
Features:
- Hourly forecasts for the output for up to 16 days