// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.5.4
// LVGL version: 9.1.0
// Project name: your_chat_bot_WeChat

#include "ui.h"
#include "app_ui_helper.h"

void volume_bar_value_changed(lv_event_t *e)
{
    // Your code here
    uint8_t value = lv_slider_get_value(lv_event_get_target_obj(e));
    LV_LOG_USER("volume_change_callback, value: %d", value);
    app_ui_set_volume_value(value);
}

void brightness_bar_value_changed(lv_event_t *e)
{
    // Your code here
}

void theme_button_changed(lv_event_t *e)
{
    // Your code here
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t       *obj  = lv_event_get_target(e);
    if (code == LV_EVENT_VALUE_CHANGED) {
        // LV_UNUSED(obj);
        bool is_checked = lv_obj_has_state(obj, LV_STATE_CHECKED);
        LV_LOG_USER("State: %s\n", is_checked ? "On" : "Off");
        if (is_checked) {
            ui_theme_set(UI_THEME_DARK_THEME);
        } else {
            ui_theme_set(UI_THEME_DEFAULT);
        }
    }
}

void reset_button_callback(lv_event_t *e)
{
    // Your code here
    lv_event_code_t event_code    = lv_event_get_code(e);
    static uint32_t pressed_start = 0;

    if (LV_EVENT_PRESSED == event_code) {
        pressed_start = lv_tick_get();
        LV_LOG_USER("reset_button_pressed, start: %d", pressed_start);
    } else if (LV_EVENT_PRESSING == event_code) {
        uint32_t elapsed = lv_tick_elaps(pressed_start);
        if (elapsed > 3000) {
            LV_LOG_USER("reset_button_pressing, elapsed: %d", elapsed);
            app_ui_reset_device();
        }
    }
}

void home_screen_loaded(lv_event_t *e)
{
    // Your code here
    // get wifi connection status
    uint8_t wifi_status = 0;
    app_ui_get_wifi_status(&wifi_status);
    ui_setting_wifi_update(wifi_status);

    // subscribe wifi connection status
    app_ui_network_status_change_subscribe();
}

void home_screen_unloaded(lv_event_t *e)
{
    // Your code here
}

void setting_screen_loaded(lv_event_t *e)
{
    // Your code here
    // get wifi connection status
    uint8_t wifi_status = 0;
    app_ui_get_wifi_status(&wifi_status);
    ui_setting_wifi_update(wifi_status);
    // get time
    uint32_t hour = 0, minute = 0;
    app_ui_get_time(&hour, &minute);
    ui_setting_time_update(hour, minute);
    // get date
    uint32_t year = 0, month = 0, day = 0;
    app_ui_get_date(&year, &month, &day);
    ui_setting_date_update(year, month, day);
    // get volume
    uint8_t volume = app_ui_get_volume_value();
    ui_setting_volume_slider_update(volume);

    // subscribe time/date update event
    app_ui_get_date_time_loop_start();
}

void setting_screen_unloaded(lv_event_t *e)
{
    // Your code here
    // unsubscribe time/date update event
    app_ui_get_date_time_loop_stop();
}
