Skip to content

Commit

Permalink
Display dialog with condition details
Browse files Browse the repository at this point in the history
Refs: #16
  • Loading branch information
orontee committed Aug 31, 2023
1 parent 7a386c9 commit 6cf0589
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Display dialog with condition details
[#16](https://github.com/orontee/argos/issues/16)

- Specify language when calling OpenWeather API
[#15](https://github.com/orontee/argos/issues/15)

Expand Down
20 changes: 15 additions & 5 deletions src/l10n.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ inline void initialize_translations() {
"connexion réseau.");
AddTranslation("Service unavailable", "Service indisponible");

// currentconditionbox.h
AddTranslation("Felt", "Ressenti");

// errors.h
AddTranslation("Location unknown to the service providing weather data. "
"Check configuration.",
Expand Down Expand Up @@ -56,18 +59,25 @@ inline void initialize_translations() {
AddTranslation("Updated at", "Mis à jour à ");
AddTranslation("Weather data from", "Données météorologiques de");

// currentconditionbox.h
AddTranslation("Felt", "Ressenti");
// ui.h
AddTranslation("Sunrise", "Lever");
AddTranslation("Sunset", "Coucher");
AddTranslation("Pressure", "Pression");
AddTranslation("Humidity", "Humidité");
AddTranslation("UV index", "Index UV");
AddTranslation("Visibility", "Visibilité");
AddTranslation("Wind", "Vent");
AddTranslation("Gust", "Rafale");
} else if (std::strcmp(currentLang(), "de") == 0) {
// German translations

// currentconditionbox.h
AddTranslation("Felt", "Gefühlt");

// statusbar.h
AddTranslation("Ongoing update…", "Laufendes Update…");
AddTranslation("Updated at", "Aktualisiert am");
AddTranslation("Weather data from", "Wetterdaten von");

// currentconditionbox.h
AddTranslation("Felt", "Gefühlt");
}
}
} // namespace taranis
3 changes: 3 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ struct Condition {
int pressure;
int humidity;
long double uv_index;
int visibility;
long double wind_speed;
int wind_degree;
long double wind_gust;
Weather weather{CLEAR_SKY};
std::string weather_description;
std::string weather_icon_name;
Expand Down
8 changes: 6 additions & 2 deletions src/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ class Service {
const auto felt_temperature = value.get("feels_like", NAN).asDouble();
const auto pressure = value.get("pressure", NAN).asInt();
const auto humidity = value.get("humidity", NAN).asInt();
const auto uv_index = value.get("uv_index", NAN).asDouble();
const auto uv_index = value.get("uvi", NAN).asDouble();
const auto visibility = value.get("visibility", NAN).asInt();
const auto wind_speed = value.get("wind_speed", NAN).asDouble();
const auto wind_degree = value.get("wind_deg", NAN).asInt();
const auto wind_gust = value.get("wind_gust", NAN).asDouble();

Condition condition{date, sunrise, sunset,
temperature, felt_temperature, pressure,
humidity, uv_index, wind_speed};
humidity, uv_index, visibility,
wind_speed, wind_degree, wind_gust};

if (value.isMember("weather") and value["weather"].isArray() and
value["weather"].isValidIndex(0)) {
Expand Down
4 changes: 4 additions & 0 deletions src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ void taranis::handle_menu_item_selected(int item_index) {
break;
}
}

void taranis::handle_current_condition_dialog_button_clicked(int button_index) {
CloseDialog();
}
70 changes: 63 additions & 7 deletions src/ui.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include <inkview.h>
#include <iomanip>
#include <memory>
#include <sstream>

#include "currentconditionbox.h"
#include "fonts.h"
Expand All @@ -16,6 +18,8 @@ namespace taranis {

void handle_menu_item_selected(int item_index);

void handle_current_condition_dialog_button_clicked(int button_index);

class Ui {
public:
// ⚠️ Must be instantiated after application received the EVT_INIT
Expand Down Expand Up @@ -74,7 +78,14 @@ class Ui {
}

if (event_type == EVT_POINTERUP) {
if (this->open_menu_maybe(pointer_pos_x, pointer_pos_y)) {
if (this->is_pointer_on_menu_button(pointer_pos_x, pointer_pos_y)) {
this->open_menu();
return 1;
}

if (this->is_pointer_on_current_condition_box(pointer_pos_x,
pointer_pos_y)) {
this->open_current_condition_dialog();
return 1;
}
}
Expand Down Expand Up @@ -129,18 +140,63 @@ class Ui {

void desactivate_menu_button() { this->menu_button->desactivate(); }

bool open_menu_maybe(int pointer_pos_x, int pointer_pos_y) {
bool is_pointer_on_menu_button(int pointer_pos_x, int pointer_pos_y) {
const auto menu_button_bounding_box = this->menu_button->get_bounding_box();

if (IsInRect(pointer_pos_x, pointer_pos_y, &menu_button_bounding_box)) {
return IsInRect(pointer_pos_x, pointer_pos_y, &menu_button_bounding_box);
}

void open_menu() {
if (this->menu_button->is_activated()) {
this->menu_button->desactivate();
this->open_menu();
return true;
}
return false;
this->menu_button->open_menu(handle_menu_item_selected);
}

void open_menu() { this->menu_button->open_menu(handle_menu_item_selected); }
bool is_pointer_on_current_condition_box(int pointer_pos_x,
int pointer_pos_y) {
const auto bounding_box = this->current_condition_box->get_bounding_box();
return IsInRect(pointer_pos_x, pointer_pos_y, &bounding_box);
}

void open_current_condition_dialog() {
if (not this->model->current_condition) {
return;
}
const auto condition = *(this->model->current_condition);

const char *const time_format = "%H:%M";
std::string sunrise_text{"?????"};
std::strftime(const_cast<char *>(sunrise_text.c_str()), 6, time_format,
std::localtime(&condition.sunrise));
std::string sunset_text{"?????"};
std::strftime(const_cast<char *>(sunset_text.c_str()), 6, time_format,
std::localtime(&condition.sunset));

std::stringstream content;
content << T("Sunrise") << std::right << std::setw(10) << sunrise_text
<< std::endl
<< T("Sunset") << std::right << std::setw(10) << sunset_text
<< std::endl
<< T("Pressure") << std::right << std::setw(10)
<< std::to_string(condition.pressure) + "hPa" << std::endl
<< T("Humidity") << std::right << std::setw(10)
<< std::to_string(condition.humidity) + "%" << std::endl
<< T("UV index") << std::right << std::setw(10) << std::fixed
<< std::setprecision(1) << condition.uv_index << std::endl
<< T("Visibility") << std::right << std::setw(10)
<< std::to_string(condition.visibility) + "m" << std::endl
<< T("Wind") << std::right << std::setw(10)
<< std::to_string(static_cast<int>(condition.wind_speed)) + "m/s"
<< std::endl
<< T("Gust") << std::right << std::setw(10)
<< std::to_string(static_cast<int>(condition.wind_gust)) + "m/s"
<< std::endl;

Dialog(ICON_INFORMATION, T("Current Weather Conditions"),
content.str().c_str(), T("Ok"), nullptr,
&handle_current_condition_dialog_button_clicked);
}
};

} // namespace taranis

0 comments on commit 6cf0589

Please sign in to comment.