Skip to content
Merged
Show file tree
Hide file tree
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
88 changes: 87 additions & 1 deletion source/scenes/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ int VIDEO_LIST_Y_HIGH = 240;

int cur_video_sort_type = 0; // 0: newest, 1: popular, 2: oldest
int video_sort_request = -1;
int cur_streams_sort_type = 0; // 0: newest, 1: popular, 2: oldest
int streams_sort_request = -1;
int cur_shorts_sort_type = 0; // 0: newest, 1: popular, 2: oldest
int shorts_sort_request = -1;

Expand All @@ -50,6 +52,7 @@ ImageView *banner_view;
ChannelView *channel_view;
Tab2View *tab_view;
SelectorView *video_sort_selector;
SelectorView *streams_sort_selector;
SelectorView *shorts_sort_selector;
// anonymous VerticalListView
VerticalListView *video_list_view;
Expand Down Expand Up @@ -105,6 +108,15 @@ void Channel_init(void) {
video_sort_request = cur_video_sort_type = view.selected_button;
});

streams_sort_selector = (new SelectorView(0, 0, 320, MIDDLE_FONT_INTERVAL, false))
->set_texts({(std::function<std::string()>)[]() { return LOCALIZED(LATEST); },
(std::function<std::string()>)[]() { return LOCALIZED(POPULAR); },
(std::function<std::string()>)[]() { return LOCALIZED(OLDEST); }},
cur_streams_sort_type)
->set_on_change([](const SelectorView &view) {
streams_sort_request = cur_streams_sort_type = view.selected_button;
});

shorts_sort_selector = (new SelectorView(0, 0, 320, MIDDLE_FONT_INTERVAL, false))
->set_texts({(std::function<std::string()>)[]() { return LOCALIZED(LATEST); },
(std::function<std::string()>)[]() { return LOCALIZED(POPULAR); },
Expand Down Expand Up @@ -201,7 +213,10 @@ void Channel_init(void) {
->set_views(
{(new HorizontalListView(0, 0, MIDDLE_FONT_INTERVAL))->set_views({video_sort_selector}),
(new RuleView(0, 0, 320, 2)), video_list_view, video_load_more_view}),
(new VerticalListView(0, 0, 320))->set_views({stream_list_view, stream_load_more_view}),
(new VerticalListView(0, 0, 320))
->set_views(
{(new HorizontalListView(0, 0, MIDDLE_FONT_INTERVAL))->set_views({streams_sort_selector}),
(new RuleView(0, 0, 320, 2)), stream_list_view, stream_load_more_view}),
(new VerticalListView(0, 0, 320))
->set_views(
{(new HorizontalListView(0, 0, MIDDLE_FONT_INTERVAL))->set_views({shorts_sort_selector}),
Expand Down Expand Up @@ -249,6 +264,9 @@ void Channel_resume(std::string arg) {
if (video_sort_selector) {
video_sort_selector->selected_button = cur_video_sort_type;
}
if (streams_sort_selector) {
streams_sort_selector->selected_button = cur_streams_sort_type;
}
if (shorts_sort_selector) {
shorts_sort_selector->selected_button = cur_shorts_sort_type;
}
Expand Down Expand Up @@ -359,6 +377,7 @@ View *community_post_2_view(const YouTubeChannelDetail::CommunityPost &post) {
->set_time_str(post.time)
->set_upvote_str(post.upvotes_str)
->set_additional_image_url(post.image_url)
->set_disable_timestamps(true)
->set_content_lines(content_lines)
->set_has_more_replies([]() { return false; });

Expand Down Expand Up @@ -463,6 +482,10 @@ static void load_channel(void *) {
if (video_sort_selector) {
video_sort_selector->selected_button = cur_video_sort_type;
}
cur_streams_sort_type = channel_info.current_streams_sort_type;
if (streams_sort_selector) {
streams_sort_selector->selected_button = cur_streams_sort_type;
}
cur_shorts_sort_type = channel_info.current_shorts_sort_type;
if (shorts_sort_selector) {
shorts_sort_selector->selected_button = cur_shorts_sort_type;
Expand Down Expand Up @@ -554,6 +577,20 @@ static void load_channel(void *) {
});
}

auto streams_tab_view = dynamic_cast<VerticalListView *>(tab_view->views[1]);
if (!channel_info.streams_sort_token_newest.empty() || !channel_info.streams_sort_token_popular.empty() ||
!channel_info.streams_sort_token_oldest.empty()) {
dynamic_cast<HorizontalListView *>(streams_tab_view->views[0])->update_y_range(0, MIDDLE_FONT_INTERVAL);
streams_tab_view->views[0]->set_is_visible(true);
dynamic_cast<RuleView *>(streams_tab_view->views[1])->update_y_range(0, 2);
streams_tab_view->views[1]->set_is_visible(true);
} else {
dynamic_cast<HorizontalListView *>(streams_tab_view->views[0])->update_y_range(0, 0);
streams_tab_view->views[0]->set_is_visible(false);
dynamic_cast<RuleView *>(streams_tab_view->views[1])->update_y_range(0, 0);
streams_tab_view->views[1]->set_is_visible(false);
}

// shorts list
shorts_list_view->recursive_delete_subviews();
if (result.shorts.size() > 0) {
Expand Down Expand Up @@ -699,6 +736,15 @@ static void load_channel_stream(void *) {
channel_info.streams = streams_result.streams;
channel_info.streams_continue_token = streams_result.streams_continue_token;
channel_info.streams_loaded = true;
// Update sort tokens
channel_info.streams_sort_token_newest = streams_result.streams_sort_token_newest;
channel_info.streams_sort_token_popular = streams_result.streams_sort_token_popular;
channel_info.streams_sort_token_oldest = streams_result.streams_sort_token_oldest;
channel_info.current_streams_sort_type = streams_result.current_streams_sort_type;
cur_streams_sort_type = streams_result.current_streams_sort_type;
if (streams_sort_selector) {
streams_sort_selector->selected_button = cur_streams_sort_type;
}
if (streams_result.error == "") {
channel_info_cache[channel_info.url_original] = channel_info;
}
Expand All @@ -715,6 +761,20 @@ static void load_channel_stream(void *) {
stream_load_more_view->set_is_visible(false);
}

auto streams_tab_view = dynamic_cast<VerticalListView *>(tab_view->views[1]);
if (!channel_info.streams_sort_token_newest.empty() || !channel_info.streams_sort_token_popular.empty() ||
!channel_info.streams_sort_token_oldest.empty()) {
dynamic_cast<HorizontalListView *>(streams_tab_view->views[0])->update_y_range(0, MIDDLE_FONT_INTERVAL);
streams_tab_view->views[0]->set_is_visible(true);
dynamic_cast<RuleView *>(streams_tab_view->views[1])->update_y_range(0, 2);
streams_tab_view->views[1]->set_is_visible(true);
} else {
dynamic_cast<HorizontalListView *>(streams_tab_view->views[0])->update_y_range(0, 0);
streams_tab_view->views[0]->set_is_visible(false);
dynamic_cast<RuleView *>(streams_tab_view->views[1])->update_y_range(0, 0);
streams_tab_view->views[1]->set_is_visible(false);
}

var_need_refresh = true;
resource_lock.unlock();
}
Expand Down Expand Up @@ -1113,6 +1173,32 @@ void Channel_draw(void) {
video_sort_request = -1;
}

if (streams_sort_request != -1 && tab_view && tab_view->selected_tab == 1) {
std::string sort_token;
if (streams_sort_request == 0) {
sort_token = channel_info.streams_sort_token_newest;
} else if (streams_sort_request == 1) {
sort_token = channel_info.streams_sort_token_popular;
} else if (streams_sort_request == 2) {
sort_token = channel_info.streams_sort_token_oldest;
}

if (!sort_token.empty()) {
stream_list_view->recursive_delete_subviews();
stream_list_view->views.clear();
channel_info.streams.clear();
channel_info.streams_continue_token = sort_token;
channel_info.current_streams_sort_type = streams_sort_request;
channel_info_cache[cur_channel_url] = channel_info;

if (!is_async_task_running(load_channel_stream_more)) {
queue_async_task(load_channel_stream_more, NULL);
}
}

streams_sort_request = -1;
}

if (shorts_sort_request != -1 && tab_view && tab_view->selected_tab == 2) {
std::string sort_token;
if (shorts_sort_request == 0) {
Expand Down
31 changes: 23 additions & 8 deletions source/ui/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,24 @@ void Draw(std::string text, float x, float y, float text_size_x, float text_size
C2D_Font cur_font = Extfont_is_extfont_loaded(0) ? system_fonts[prev_font_list_num] : NULL;

C2D_TextBufClear(c2d_buf);
float actual_text_size_x = text_size_x;
float actual_text_size_y = text_size_y;
float width_scale = 1.0f;

if (prev_font_list_num == 1) {
y_offset = 3 * text_size_y;
} else if (prev_font_list_num == 2) {
// Korean font scaling (80% visual size, 115% width)
y_offset = 4 * text_size_y;
actual_text_size_x *= 0.80;
actual_text_size_y *= 0.80;
width_scale = 1.15f;
} else if (prev_font_list_num == 3) {
// Traditional Chinese font scaling (80% visual size, 125% width)
y_offset = 5 * text_size_y;
actual_text_size_x *= 0.80;
actual_text_size_y *= 0.80;
width_scale = 1.25f;
} else {
y_offset = 0;
}
Expand All @@ -315,9 +329,10 @@ void Draw(std::string text, float x, float y, float text_size_x, float text_size

C2D_TextFontParse(&c2d_text, cur_font, c2d_buf, draw_str.c_str());
C2D_TextOptimize(&c2d_text);
C2D_TextGetDimensions(&c2d_text, text_size_x, text_size_y, &width, &height);
C2D_DrawText(&c2d_text, C2D_WithColor, x, y + y_offset, 0.0, text_size_x, text_size_y, abgr8888);
x += width;
C2D_TextGetDimensions(&c2d_text, actual_text_size_x, actual_text_size_y, &width, &height);
C2D_DrawText(&c2d_text, C2D_WithColor, x, y + y_offset, 0.0, actual_text_size_x, actual_text_size_y,
abgr8888);
x += width * width_scale;
} else if (prev_font_list_num == 4) {
Extfont_draw_extfonts(draw_part_text + consecutive_start, i - consecutive_start, x, y,
text_size_x * 1.56, text_size_y * 1.56, abgr8888, &width);
Expand Down Expand Up @@ -484,11 +499,11 @@ Result_with_string Draw_load_texture(std::string file_name, int sheet_map_num, C

void Draw_touch_pos(void) {
if (var_hide_pointer == false) {
Hid_info key;
Util_hid_query_key_state(&key);
if (key.p_touch || key.h_touch) {
Draw_texture(var_square_image[0], DEF_DRAW_RED, key.touch_x - 1, key.touch_y - 1, 3, 3);
}
Hid_info key;
Util_hid_query_key_state(&key);
if (key.p_touch || key.h_touch) {
Draw_texture(var_square_image[0], DEF_DRAW_RED, key.touch_x - 1, key.touch_y - 1, 3, 3);
}
}
}

Expand Down
Loading