Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Confirmation Dialog On Pressing Delete in Playback Menu #443

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 63 additions & 20 deletions src/ui/page_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include "util/filesystem.h"
#include "util/math.h"
#include "util/system.h"

#define MEDIA_FILES_DIR REC_diskPATH REC_packPATH // "/mnt/extsd/movies" --> "/mnt/extsd" "/movies/"

// #define MEDIA_FILES_DIR "/mnt/extsd/movies/"--Useful for testing playback page
bool status_displayed = false;
lv_obj_t *status;
LV_IMG_DECLARE(img_star);
LV_IMG_DECLARE(img_arrow1);

Expand All @@ -33,6 +34,31 @@ static lv_coord_t row_dsc[] = {150, 30, 150, 30, 150, 30, 30, LV_GRID_TEMPLATE_L
static media_db_t media_db;
static pb_ui_item_t pb_ui[ITEMS_LAYOUT_CNT];

/**
* Displays the status message box.
*/
static void page_playback_open_status_box(const char *title, const char *text) {
status_displayed = true;
lv_label_set_text(lv_msgbox_get_title(status), title);
lv_label_set_text(lv_msgbox_get_text(status), text);
lv_obj_clear_flag(status, LV_OBJ_FLAG_HIDDEN);
}
/**
* Cancel operation.
*/
static void page_playback_cancel() {
}

static bool page_playback_close_status_box() {
lv_obj_add_flag(status, LV_OBJ_FLAG_HIDDEN);
status_displayed = false;
return status_displayed;
}

static void page_playback_on_click(uint8_t key, int sel) {
pb_key(key);
}

static lv_obj_t *page_playback_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *page = lv_menu_page_create(parent, NULL);
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
Expand Down Expand Up @@ -96,7 +122,8 @@ static lv_obj_t *page_playback_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_style_text_color(label, lv_color_make(255, 255, 255), 0);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
lv_obj_set_pos(label, 10, 700);

status = create_msgbox_item("Status", "None");
lv_obj_add_flag(status, LV_OBJ_FLAG_HIDDEN);
return page;
}

Expand Down Expand Up @@ -178,8 +205,7 @@ int hot_alphasort(const struct dirent **a, const struct dirent **b) {
return strcoll((*a)->d_name, (*b)->d_name);
}

static bool dvr_has_stars(const char* filename)
{
static bool dvr_has_stars(const char *filename) {
char star_file[256] = "";
int count = snprintf(star_file, sizeof(star_file), "%s" REC_starSUFFIX, filename);

Expand Down Expand Up @@ -381,6 +407,7 @@ static void delete_video_file(int seq) {
}

static void page_playback_exit() {
page_playback_close_status_box();
clear_videofile_cnt();
update_page();
}
Expand All @@ -398,16 +425,11 @@ static void page_playback_enter() {
void pb_key(uint8_t const key) {
static bool done = true;
static uint8_t state = 0; // 0= select video files, 1=playback
static bool status_deleting = false;
char fname[128];
uint32_t cur_page_num, lst_page_num;
uint8_t cur_pos, lst_pos;

// LOGI("onkey:Key=%d,Count=%d",key,media_db.count);

if (!key || !media_db.count || !done) {
return;
}

if (state == 1) {
if (mplayer_on_key(key)) {
state = 0;
Expand All @@ -416,9 +438,17 @@ void pb_key(uint8_t const key) {
return;
}

if (!key || !media_db.count || (!done && status_displayed && !status_deleting)) {
return;
}
char text[128];
done = false;
switch (key) {
case DIAL_KEY_UP: // up
if (status_displayed) {
page_playback_close_status_box();
break;
}
lst_page_num = (uint32_t)floor((double)media_db.cur_sel / ITEMS_LAYOUT_CNT);
lst_pos = media_db.cur_sel - lst_page_num * ITEMS_LAYOUT_CNT;

Expand All @@ -439,6 +469,10 @@ void pb_key(uint8_t const key) {
break;

case DIAL_KEY_DOWN: // down
if (status_displayed) {
page_playback_close_status_box();
break;
}
lst_page_num = (uint32_t)floor((double)media_db.cur_sel / ITEMS_LAYOUT_CNT);
lst_pos = media_db.cur_sel - lst_page_num * ITEMS_LAYOUT_CNT;

Expand All @@ -459,36 +493,45 @@ void pb_key(uint8_t const key) {
break;

case DIAL_KEY_CLICK: // Enter
if (get_seleteced(media_db.cur_sel, fname)) {
if (status_displayed) {
delete_video_file(media_db.cur_sel);
status_deleting = page_playback_close_status_box();
} else if (get_seleteced(media_db.cur_sel, fname)) {
mplayer_file(fname);
state = 1;
app_state_push(APP_STATE_PLAYBACK);
}
break;

case DIAL_KEY_PRESS: // long press
status_deleting = page_playback_close_status_box();
page_playback_exit();
break;

case RIGHT_KEY_CLICK:
mark_video_file(media_db.cur_sel);
if (status_displayed) {
status_deleting = page_playback_close_status_box();
} else {
mark_video_file(media_db.cur_sel);
}
break;

case RIGHT_KEY_PRESS:
delete_video_file(media_db.cur_sel);
if (!status_displayed) {
snprintf(text, sizeof(text), "%s", "Click center of dial to continue.\nClick function(right button) or scroll to exit.");
page_playback_open_status_box("Are you sure you want to DELETE the file", text);
status_deleting = true;
} else {
page_playback_close_status_box();
}
break;
done = true;
}
done = true;
}

static void page_playback_on_roller(uint8_t key) {
pb_key(key);
}

static void page_playback_on_click(uint8_t key, int sel) {
pb_key(key);
}

static void page_playback_on_right_button(bool is_short) {
pb_key(is_short ? RIGHT_KEY_CLICK : RIGHT_KEY_PRESS);
}
Expand Down