summaryrefslogtreecommitdiff
path: root/src/ui/include/screen_track_browser.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/include/screen_track_browser.hpp')
-rw-r--r--src/ui/include/screen_track_browser.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/ui/include/screen_track_browser.hpp b/src/ui/include/screen_track_browser.hpp
new file mode 100644
index 00000000..95fb80e2
--- /dev/null
+++ b/src/ui/include/screen_track_browser.hpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <deque>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "lvgl.h"
+
+#include "database.hpp"
+#include "screen.hpp"
+
+namespace ui {
+namespace screens {
+
+class TrackBrowser : public Screen {
+ public:
+ TrackBrowser(
+ std::weak_ptr<database::Database> db,
+ const std::string& title,
+ std::future<database::Result<database::IndexRecord>*>&& initial_page);
+ ~TrackBrowser() {}
+
+ auto Tick() -> void override;
+
+ auto OnItemSelected(lv_event_t* ev) -> void;
+ auto OnItemClicked(lv_event_t* ev) -> void;
+
+ private:
+ enum Position {
+ START = 0,
+ END = 1,
+ };
+ auto AddLoadingIndictor(Position pos) -> void;
+ auto AddResults(Position pos, database::Result<database::IndexRecord>*)
+ -> void;
+ auto DropPage(Position pos) -> void;
+ auto FetchNewPage(Position pos) -> void;
+
+ auto GetNumRecords() -> std::size_t;
+ auto GetItemIndex(lv_obj_t* obj) -> std::optional<std::size_t>;
+ auto GetRecordByIndex(std::size_t index)
+ -> std::optional<database::IndexRecord>;
+
+ std::weak_ptr<database::Database> db_;
+ lv_obj_t* list_;
+ lv_obj_t* loading_indicator_;
+
+ std::optional<Position> loading_pos_;
+ std::optional<std::future<database::Result<database::IndexRecord>*>>
+ loading_page_;
+
+ std::deque<std::unique_ptr<database::Result<database::IndexRecord>>>
+ current_pages_;
+};
+
+} // namespace screens
+} // namespace ui