summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-10-04 15:38:18 +1100
committerjacqueline <me@jacqueline.id.au>2023-10-04 15:38:18 +1100
commitee8e5234562c2b9ee1bb261785135abd4f718f83 (patch)
treececd2f215dcd7298e17e9538902da8c59b7fadb8 /src/ui
parent28633e857f86a21d874117fd677de5e8ad21d8d3 (diff)
downloadtangara-fw-ee8e5234562c2b9ee1bb261785135abd4f718f83.tar.gz
Add a basic database reindex screen
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/include/modal_progress.hpp7
-rw-r--r--src/ui/include/ui_events.hpp1
-rw-r--r--src/ui/include/ui_fsm.hpp19
-rw-r--r--src/ui/modal_progress.cpp29
-rw-r--r--src/ui/screen_settings.cpp6
-rw-r--r--src/ui/ui_fsm.cpp46
6 files changed, 102 insertions, 6 deletions
diff --git a/src/ui/include/modal_progress.hpp b/src/ui/include/modal_progress.hpp
index f312d509..2ccb671a 100644
--- a/src/ui/include/modal_progress.hpp
+++ b/src/ui/include/modal_progress.hpp
@@ -19,10 +19,15 @@ namespace modals {
class Progress : public Modal {
public:
- Progress(Screen*, std::pmr::string title);
+ Progress(Screen*, std::pmr::string title, std::pmr::string subtitle = "");
+
+ void title(const std::pmr::string&);
+ void subtitle(const std::pmr::string&);
private:
lv_obj_t* container_;
+ lv_obj_t* title_;
+ lv_obj_t* subtitle_;
};
} // namespace modals
diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp
index e08f8888..4549a51d 100644
--- a/src/ui/include/ui_events.hpp
+++ b/src/ui/include/ui_events.hpp
@@ -37,6 +37,7 @@ struct IndexSelected : tinyfsm::Event {
};
struct ControlSchemeChanged : tinyfsm::Event {};
+struct ReindexDatabase : tinyfsm::Event {};
struct BackPressed : tinyfsm::Event {};
struct ShowNowPlaying : tinyfsm::Event {};
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index eef96b50..da63b77f 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -14,6 +14,7 @@
#include "audio_events.hpp"
#include "battery.hpp"
#include "bindey/property.h"
+#include "db_events.hpp"
#include "gpios.hpp"
#include "lvgl_task.hpp"
#include "model_playback.hpp"
@@ -75,6 +76,11 @@ class UiState : public tinyfsm::Fsm<UiState> {
}
virtual void react(const internal::OnboardingNavigate&) {}
void react(const internal::ControlSchemeChanged&);
+ virtual void react(const internal::ReindexDatabase&){};
+
+ virtual void react(const database::event::UpdateStarted&){};
+ virtual void react(const database::event::UpdateProgress&){};
+ virtual void react(const database::event::UpdateFinished&){};
virtual void react(const system_fsm::DisplayReady&) {}
virtual void react(const system_fsm::BootComplete&) {}
@@ -130,6 +136,7 @@ class Browse : public UiState {
void react(const internal::ShowNowPlaying&) override;
void react(const internal::ShowSettingsPage&) override;
+ void react(const internal::ReindexDatabase&) override;
void react(const system_fsm::StorageMounted&) override;
void react(const system_fsm::BluetoothDevicesChanged&) override;
@@ -150,6 +157,18 @@ class Playing : public UiState {
using UiState::react;
};
+class Indexing : public UiState {
+ public:
+ void entry() override;
+ void exit() override;
+
+ void react(const database::event::UpdateStarted&) override;
+ void react(const database::event::UpdateProgress&) override;
+ void react(const database::event::UpdateFinished&) override;
+
+ using UiState::react;
+};
+
class FatalError : public UiState {};
} // namespace states
diff --git a/src/ui/modal_progress.cpp b/src/ui/modal_progress.cpp
index 1213de7e..d3d3e9b9 100644
--- a/src/ui/modal_progress.cpp
+++ b/src/ui/modal_progress.cpp
@@ -28,18 +28,39 @@
namespace ui {
namespace modals {
-Progress::Progress(Screen* host, std::pmr::string title_text) : Modal(host) {
+Progress::Progress(Screen* host,
+ std::pmr::string title_text,
+ std::pmr::string subtitle_text)
+ : Modal(host) {
lv_obj_set_layout(root_, LV_LAYOUT_FLEX);
lv_obj_set_flex_flow(root_, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(root_, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_CENTER);
- lv_obj_t* title = lv_label_create(root_);
- lv_label_set_text(title, title_text.c_str());
- lv_obj_set_size(title, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
+ title_ = lv_label_create(root_);
+ lv_obj_set_size(title_, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
+
+ subtitle_ = lv_label_create(root_);
+ lv_obj_set_size(subtitle_, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_t* spinner = lv_spinner_create(root_, 3000, 45);
lv_obj_set_size(spinner, 16, 16);
+
+ title(title_text);
+ subtitle(subtitle_text);
+}
+
+void Progress::title(const std::pmr::string& s) {
+ lv_label_set_text(title_, s.c_str());
+}
+
+void Progress::subtitle(const std::pmr::string& s) {
+ if (s.empty()) {
+ lv_obj_add_flag(subtitle_, LV_OBJ_FLAG_HIDDEN);
+ } else {
+ lv_obj_clear_flag(subtitle_, LV_OBJ_FLAG_HIDDEN);
+ lv_label_set_text(subtitle_, s.c_str());
+ }
}
} // namespace modals
diff --git a/src/ui/screen_settings.cpp b/src/ui/screen_settings.cpp
index 6ee8405e..a661392f 100644
--- a/src/ui/screen_settings.cpp
+++ b/src/ui/screen_settings.cpp
@@ -469,8 +469,12 @@ Storage::Storage(models::TopBar& bar) : MenuScreen(bar, "Storage") {
lv_obj_t* reset_btn = lv_btn_create(content_);
lv_obj_t* reset_label = lv_label_create(reset_btn);
- lv_label_set_text(reset_label, "Reset Database");
+ lv_label_set_text(reset_label, "Update Database");
lv_group_add_obj(group_, reset_btn);
+
+ lv_bind(reset_btn, LV_EVENT_CLICKED, [&](lv_obj_t*) {
+ events::Ui().Dispatch(internal::ReindexDatabase{});
+ });
}
FirmwareUpdate::FirmwareUpdate(models::TopBar& bar)
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index f8c9d3f3..b5a0fa34 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -21,6 +21,7 @@
#include "lvgl_task.hpp"
#include "modal_add_to_queue.hpp"
#include "modal_confirm.hpp"
+#include "modal_progress.hpp"
#include "model_playback.hpp"
#include "nvs.hpp"
#include "relative_wheel.hpp"
@@ -328,6 +329,10 @@ void Browse::react(const system_fsm::BluetoothDevicesChanged&) {
}
}
+void Browse::react(const internal::ReindexDatabase& ev) {
+ transit<Indexing>();
+}
+
static std::shared_ptr<screens::Playing> sPlayingScreen;
void Playing::entry() {
@@ -347,6 +352,47 @@ void Playing::react(const internal::BackPressed& ev) {
transit<Browse>();
}
+static std::shared_ptr<modals::Progress> sIndexProgress;
+
+void Indexing::entry() {
+ sIndexProgress.reset(new modals::Progress(sCurrentScreen.get(), "Indexing",
+ "Preparing database"));
+ sCurrentModal = sIndexProgress;
+ auto db = sServices->database().lock();
+ if (!db) {
+ // TODO: Hmm.
+ return;
+ }
+ db->Update();
+}
+
+void Indexing::exit() {
+ sCurrentModal.reset();
+ sIndexProgress.reset();
+}
+
+void Indexing::react(const database::event::UpdateStarted&) {}
+
+void Indexing::react(const database::event::UpdateProgress& ev) {
+ std::ostringstream str;
+ switch (ev.stage) {
+ case database::event::UpdateProgress::Stage::kVerifyingExistingTracks:
+ sIndexProgress->title("Verifying");
+ str << "Tracks checked: " << ev.val;
+ sIndexProgress->subtitle(str.str().c_str());
+ break;
+ case database::event::UpdateProgress::Stage::kScanningForNewTracks:
+ sIndexProgress->title("Scanning");
+ str << "Files checked: " << ev.val;
+ sIndexProgress->subtitle(str.str().c_str());
+ break;
+ }
+}
+
+void Indexing::react(const database::event::UpdateFinished&) {
+ transit<Browse>();
+}
+
} // namespace states
} // namespace ui