From 28b294dd3b9a83060b4fcdca1005fa0ad2c5d71f Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 5 Nov 2022 14:46:01 -0400 Subject: [PATCH] Populate home screen a bit --- src/components/GridScreen/GridScreen.xml | 1 + src/components/tasks/MainLoaderTask.brs | 25 ++++++++++++++++++------ src/source/services/Invidious.bs | 10 ++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/components/GridScreen/GridScreen.xml b/src/components/GridScreen/GridScreen.xml index 6d30d345..b8700748 100644 --- a/src/components/GridScreen/GridScreen.xml +++ b/src/components/GridScreen/GridScreen.xml @@ -16,6 +16,7 @@ rowitemSize="[[320,180]]" rowItemSpacing="[[20,0]]" itemSize="[1160,270]" + itemSpacing="[0,20]" rowLabelOffset="[[50,20]]" focusXOffset="[50]" showRowLabel="[true]" diff --git a/src/components/tasks/MainLoaderTask.brs b/src/components/tasks/MainLoaderTask.brs index 3451783b..e675684c 100644 --- a/src/components/tasks/MainLoaderTask.brs +++ b/src/components/tasks/MainLoaderTask.brs @@ -9,11 +9,15 @@ end sub sub GetContent() rootChildren = [] - trendingJson = RokuYoutube.Services.Invidious.GetTrending() - trending = GetCategoryContent("Trending", trendingJson) - if trending <> invalid - rootChildren.Push(trending) - end if + trendingTypes = [invalid, "Music", "Gaming", "Movies"] + for each trendingType in trendingTypes + trendingJson = RokuYoutube.Services.Invidious.GetTrending(trendingType) + title = trendingType <> invalid ? `Trending - ${trendingType}` : "Trending" + trending = GetCategoryContent(title, trendingJson) + if trending <> invalid + rootChildren.Push(trending) + end if + end for popularJson = RokuYoutube.Services.Invidious.GetPopular() popular = GetCategoryContent("Popular", popularJson) @@ -27,6 +31,15 @@ sub GetContent() rootChildren.Push(feed) end if + keywords = ["Funny Animals", "News"] + for each keyword in keywords + json = RokuYoutube.Services.Invidious.Search(keyword, 0, RokuYoutube.Models.Invidious.SearchFilter.SortBy.UploadDate) + data = GetCategoryContent(keyword, json) + if data <> invalid + rootChildren.Push(data) + end if + end for + ' set up a root ContentNode to represent rowList on the GridScreen contentNode = CreateObject("roSGNode", "ContentNode") contentNode.Update({ @@ -38,7 +51,7 @@ sub GetContent() end sub function GetCategoryContent(category as string, json as object) as object - if json <> invalid + if json <> invalid and json.Count() > 0 row = {} row.title = category row.children = [] diff --git a/src/source/services/Invidious.bs b/src/source/services/Invidious.bs index 7150fdf4..32afda28 100644 --- a/src/source/services/Invidious.bs +++ b/src/source/services/Invidious.bs @@ -24,9 +24,15 @@ namespace RokuYoutube.Services.Invidious end if end function - function GetTrending() + function GetTrending(trendingType = invalid as string) url = `${API_URL}${TRENDING_ENDPOINT}` - response = Requests().get(url) + + args = { params: {} } + if trendingType <> invalid + args.params.type = trendingType + end if + + response = Requests().get(url, args) if response.statuscode = 200 return response.json