blob: fdeb3afe4be3d5ffbd38094a4513b7c546803251 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* 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::pmr::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,
std::shared_ptr<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>;
std::weak_ptr<database::Database> db_;
lv_obj_t* back_button_;
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::shared_ptr<database::Result<database::IndexRecord>> initial_page_;
std::deque<std::shared_ptr<database::Result<database::IndexRecord>>>
current_pages_;
};
} // namespace screens
} // namespace ui
|