text/plain
•
2.70 KB
•
106 lines
#include "queue_dialog_screen.h"
#include <stdlib.h>
#include <string.h>
#include "../audio_player.h"
#include "../playlist.h"
#include "../topbar.h"
#include "audiobooks_screen.h"
#include "files_screen.h"
#include "music_screen.h"
#include "podcast_feed_screen.h"
// Navigate back to the return screen with correct directory/focus
static void go_back(void) {
lv_obj_t* scr = navigate_prepare(ANIM_BACK);
switch (app_state.return_screen) {
case SCREEN_MUSIC:
ui_state = setup_music_screen(scr, app_state.return_cwd,
app_state.return_focus);
break;
case SCREEN_AUDIOBOOKS:
ui_state = setup_audiobooks_screen(scr, app_state.return_cwd,
app_state.return_focus);
break;
case SCREEN_FILES:
ui_state = setup_files_screen(scr, app_state.return_cwd,
app_state.return_focus);
break;
case SCREEN_PODCAST_FEED:
ui_state = setup_podcast_feed_screen(scr, app_state.return_cwd,
app_state.return_focus);
break;
default:
ui_state = setup_screen(SCREEN_HOME, scr);
break;
}
navigate_commit();
}
static void play_now_cb(lv_event_t* e) {
if (lv_event_get_code(e) != LV_EVENT_CLICKED) {
return;
}
audio_player_stop();
playlist_clear();
playlist_add(app_state.pending_path, app_state.pending_type);
playlist_set_index(0);
playlist_save();
navigate_to(SCREEN_NOW_PLAYING);
}
static void add_to_queue_cb(lv_event_t* e) {
if (lv_event_get_code(e) != LV_EVENT_CLICKED) {
return;
}
playlist_add(app_state.pending_path, app_state.pending_type);
playlist_save();
go_back();
}
static void back_cb(lv_event_t* e) {
if (lv_event_get_code(e) != LV_EVENT_CLICKED) {
return;
}
go_back();
}
static void cancel_event_cb(lv_event_t* e) {
(void)e;
go_back();
}
ui_state_t setup_queue_dialog_screen(lv_obj_t* parent) {
queue_dialog_screen_state_t* state =
calloc(1, sizeof(queue_dialog_screen_state_t));
topbar_set_title("Queue");
state->list = bvs_list_create(parent);
lv_obj_t* queue_btn =
bvs_list_add_nav_button(state->list, NULL, "Add to queue",
add_to_queue_cb, NULL, cancel_event_cb);
bvs_list_add_nav_button(state->list, NULL, "Play now", play_now_cb, NULL,
cancel_event_cb);
bvs_list_add_nav_button(state->list, NULL, "Back", back_cb, NULL,
cancel_event_cb);
lv_group_focus_obj(queue_btn);
return (ui_state_t){.type = SCREEN_QUEUE_DIALOG, .queue_dialog = state};
}
void free_queue_dialog_screen(queue_dialog_screen_state_t* state) {
if (!state) {
return;
}
free(state);
}
void update_queue_dialog_screen(queue_dialog_screen_state_t* state) {
(void)state;
}