Skip to content

Commit 4d4dbdb

Browse files
committed
Time-slots settings made work across 12 AM boundary
1 parent 7b4d88e commit 4d4dbdb

55 files changed

Lines changed: 2352 additions & 1637 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if (APPLE)
4646
models/apple/SGCalendarManager.h
4747
models/apple/SGCalendarExporter.h
4848
models/apple/SGCalendarExporter.mm
49-
)
49+
models/color.mm)
5050
endif ()
5151

5252
set(MODELS ${MODELS_PLATFORM_FILES}
@@ -96,7 +96,9 @@ set(MODELS ${MODELS_PLATFORM_FILES}
9696
models/event.cpp
9797
models/event.h
9898
models/color.cpp
99-
models/color.h)
99+
models/color.h
100+
models/theme.cpp
101+
models/theme.h)
100102

101103
set(MODELS_TESTS
102104
models/tests/activity_tests.cpp

deployment/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,5 @@
5353
<string>Strategr would be able to export activity sessions as events to the Calendar</string>
5454
<key>SUFeedURL</key>
5555
<string>${APPCAST_URL}</string>
56-
<key>SUPublicEDKey</key>
57-
<string>G0A4GIM5nGFE2ANNKzogtjCjWHwItD6oy56yL1qJngQ=</string>
5856
</dict>
5957
</plist>

models/activity.cpp

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,90 +4,92 @@
44
#include "activity.h"
55
#include "activityinvalidpropertyexception.h"
66

7-
const std::vector<stg::activity::color_info_t> &stg::activity::default_colors() {
8-
const static std::vector<stg::activity::color_info_t> colors = {
9-
{"#FF6562", "Red"},
10-
{"#FFB700", "Orange"},
11-
{"#FFD600", "Yellow"},
12-
{"#A463F2", "Purple"},
13-
{"#D5008F", "Indigo"},
14-
{"#19A974", "Green"},
15-
{"#357EDD", "Blue"},
16-
{"#000000", "Black"},
17-
{"#777777", "Gray"}
7+
namespace stg {
8+
auto activity::default_colors() -> const std::vector<stg::activity::color_info_t> & {
9+
const static std::vector<activity::color_info_t> colors = {
10+
{"#FF6562", "Red"},
11+
{"#FFB700", "Orange"},
12+
{"#FFD600", "Yellow"},
13+
{"#A463F2", "Purple"},
14+
{"#D5008F", "Indigo"},
15+
{"#19A974", "Green"},
16+
{"#357EDD", "Blue"},
17+
{"#000000", "Black"},
18+
{"#777777", "Gray"}
19+
};
20+
21+
return colors;
1822
};
1923

20-
return colors;
21-
};
24+
activity::activity(name_t name, color_t color) : _color(std::move(color)) {
25+
if (!is_valid(name)) {
26+
throw empty_name_exception();
27+
}
2228

23-
stg::activity::activity(name_t name, color_t color) : _color(std::move(color)) {
24-
if (!is_valid(name)) {
25-
throw empty_name_exception();
29+
_name = std::move(name);
2630
}
2731

28-
_name = std::move(name);
29-
}
30-
31-
bool stg::activity::is_valid(const activity::name_t &name) {
32-
bool white_spaces_only = name.find_first_not_of(" \t\n\v\f\r") == std::string::npos;
33-
return !white_spaces_only;
34-
}
35-
36-
stg::activity::invalid_property_exception stg::activity::empty_name_exception() {
37-
const auto message = "activity name can't be empty";
38-
return invalid_property_exception(message);
39-
}
40-
41-
const stg::activity::name_t &stg::activity::name() const {
42-
return _name;
43-
}
44-
45-
const stg::activity::color_t &stg::activity::color() const {
46-
return _color;
47-
}
48-
49-
bool stg::operator==(const stg::activity &lhs, const stg::activity &rhs) {
50-
return lhs.name() == rhs.name() &&
51-
lhs.color() == rhs.color();
52-
}
53-
54-
bool stg::operator!=(const stg::activity &lhs, const stg::activity &rhs) {
55-
return !(lhs == rhs);
56-
}
57-
58-
std::ostream &stg::operator<<(std::ostream &os,
59-
const stg::activity &activity) {
60-
os << "activity("
61-
<< activity.name()
62-
<< ", "
63-
<< activity.color()
64-
<< ")";
65-
66-
return os;
67-
}
68-
69-
stg::activity stg::activity::copy_changing_name(const name_t &name) const {
70-
return activity(name, _color);
71-
}
72-
73-
stg::activity stg::activity::copy_changing_color(const color_t &color) const {
74-
return activity(_name, color);
75-
}
76-
77-
nlohmann::json stg::activity::to_json() {
78-
nlohmann::json j;
79-
j[keys::name] = this->name();
80-
j[keys::color] = this->color();
81-
return j;
82-
}
83-
84-
stg::activity stg::activity::from_json(const nlohmann::json &j) {
85-
auto name = j[keys::name];
86-
87-
stg::color color = activity::default_color;
88-
if (j.count(keys::color) && !j[keys::color].is_null()) {
89-
color = j[keys::color];
32+
auto activity::is_valid(const activity::name_t &name) -> bool {
33+
bool white_spaces_only = name.find_first_not_of(" \t\n\v\f\r") == std::string::npos;
34+
return !white_spaces_only;
9035
}
9136

92-
return activity{name, color};
37+
auto activity::empty_name_exception() -> activity::invalid_property_exception {
38+
const auto *message = "activity name can't be empty";
39+
return invalid_property_exception(message);
40+
}
41+
42+
auto activity::name() const -> const activity::name_t & {
43+
return _name;
44+
}
45+
46+
auto activity::color() const -> const activity::color_t & {
47+
return _color;
48+
}
49+
50+
auto operator==(const stg::activity &lhs, const stg::activity &rhs) -> bool {
51+
return lhs.name() == rhs.name() &&
52+
lhs.color() == rhs.color();
53+
}
54+
55+
auto operator!=(const stg::activity &lhs, const stg::activity &rhs) -> bool {
56+
return !(lhs == rhs);
57+
}
58+
59+
auto operator<<(std::ostream &os,
60+
const stg::activity &activity) -> std::ostream & {
61+
os << "activity("
62+
<< activity.name()
63+
<< ", "
64+
<< activity.color()
65+
<< ")";
66+
67+
return os;
68+
}
69+
70+
auto activity::with_name(const name_t &name) const -> activity {
71+
return activity(name, _color);
72+
}
73+
74+
auto activity::with_color(const color_t &color) const -> activity {
75+
return activity(_name, color);
76+
}
77+
78+
auto activity::to_json() const -> nlohmann::json {
79+
nlohmann::json j;
80+
j[keys::name] = this->name();
81+
j[keys::color] = this->color();
82+
return j;
83+
}
84+
85+
auto activity::from_json(const nlohmann::json &j) -> activity {
86+
auto name = j[keys::name];
87+
88+
stg::color color = activity::default_color;
89+
if (j.count(keys::color) && !j[keys::color].is_null()) {
90+
color = j[keys::color];
91+
}
92+
93+
return activity{name, color};
94+
}
9395
}

models/activity.h

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,49 @@ namespace stg {
1717
class invalid_property_exception;
1818

1919
static constexpr auto default_color = "#000000";
20-
static const std::vector<color_info_t> &default_colors();
20+
static auto default_colors() -> const std::vector<color_info_t> &;
2121

2222
explicit activity(name_t name, color_t color = default_color) noexcept(false);
2323

24-
const name_t &name() const;
25-
const color_t &color() const;
24+
auto name() const -> const name_t &;
25+
auto color() const -> const color_t &;
2626

27-
activity copy_changing_name(const name_t &name) const;
28-
activity copy_changing_color(const color_t &color) const;
27+
auto light_color() const -> color_t {
28+
auto clr = color();
29+
clr.set_alpha_component(0.15);
2930

30-
friend bool operator==(const activity &lhs, const activity &rhs);
31-
friend bool operator!=(const activity &lhs, const activity &rhs);
31+
return clr;
32+
}
3233

33-
friend std::ostream &operator<<(std::ostream &os,
34-
const activity &activity);
34+
auto desaturated_light_color() const -> color_t {
35+
auto clr = color();
36+
clr.set_hsl(clr.hue(), 0.3, 0.75);
37+
clr.set_alpha_component(0.2);
3538

36-
nlohmann::json to_json();
37-
static activity from_json(const nlohmann::json &j);
39+
return clr;
40+
}
41+
42+
auto desaturated_dark_color() const -> color_t {
43+
auto clr = color_t();
44+
45+
if (color().lightness() < 0.2)
46+
clr = color_t(0xffffffff);
47+
48+
clr.set_alpha_component(0.1);
49+
return clr;
50+
}
51+
52+
auto with_name(const name_t &name) const -> activity;
53+
auto with_color(const color_t &color) const -> activity;
54+
55+
friend auto operator==(const activity &lhs, const activity &rhs) -> bool;
56+
friend auto operator!=(const activity &lhs, const activity &rhs) -> bool;
57+
58+
friend auto operator<<(std::ostream &os,
59+
const activity &activity) -> std::ostream &;
60+
61+
auto to_json() const -> nlohmann::json;
62+
static auto from_json(const nlohmann::json &j) -> activity;
3863

3964
private:
4065
name_t _name;
@@ -45,9 +70,9 @@ namespace stg {
4570
static constexpr auto color = "color";
4671
};
4772

48-
static invalid_property_exception empty_name_exception();
73+
static auto empty_name_exception() -> invalid_property_exception;
4974

50-
static bool is_valid(const name_t &name);
75+
static auto is_valid(const name_t &name) -> bool;
5176
};
5277
}
5378

models/activityinvalidpropertyexception.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include "activityinvalidpropertyexception.h"
66
#include <utility>
77

8-
const char *stg::activity::invalid_property_exception::what() const noexcept {
9-
return message.c_str();
10-
}
8+
namespace stg {
9+
activity::invalid_property_exception::invalid_property_exception(std::string message) :
10+
std::exception(),
11+
message(std::move(message)) {}
1112

12-
stg::activity::invalid_property_exception::invalid_property_exception(std::string message) :
13-
std::exception(),
14-
message(std::move(message)) {}
13+
auto activity::invalid_property_exception::what() const noexcept -> const char * {
14+
return message.c_str();
15+
}
16+
}

models/activityinvalidpropertyexception.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace stg {
1111
class activity::invalid_property_exception : public std::exception {
1212
public:
1313
explicit invalid_property_exception(std::string message);
14-
const char *what() const noexcept override;
14+
auto what() const noexcept -> const char * override;
1515

1616
private:
1717
std::string message;

0 commit comments

Comments
 (0)