diff --git a/components/MovieData.xml b/components/MovieData.xml index 4d878936..08e2e1a1 100644 --- a/components/MovieData.xml +++ b/components/MovieData.xml @@ -6,6 +6,7 @@ + @@ -23,6 +24,7 @@ end if m.top.description = datum.overview m.top.favorite = datum.UserData.isFavorite + m.top.watched = datum.UserData.played end sub ]]> diff --git a/components/MovieItemDetails.brs b/components/MovieItemDetails.brs index eb6f4bad..d99a54d3 100644 --- a/components/MovieItemDetails.brs +++ b/components/MovieItemDetails.brs @@ -33,7 +33,7 @@ sub itemContentChanged() setFieldText("tagline", itemData.taglines[0]) end if setFavoriteColor() - m.top.itemContent.observeField("favorite", "setFavoriteColor") + setWatchedColor() end sub sub setFieldText(field as string, value) @@ -84,7 +84,18 @@ sub setFavoriteColor() fave_button.textColor = "0xddddddff" fave_button.focusedTextColor = "#262626ff" end if +end sub +sub setWatchedColor() + watched = m.top.itemContent.watched + watched_button = m.top.findNode("buttons").getChild(2) + if watched + watched_button.textColor = "#ff0000ff" + watched_button.focusedTextColor = "#992626ff" + else + watched_button.textColor = "0xddddddff" + watched_button.focusedTextColor = "#262626ff" + end if end sub function round(f as Float) as Integer diff --git a/components/TVSeasonData.xml b/components/TVSeasonData.xml index 7bf76dfe..8a05df1d 100644 --- a/components/TVSeasonData.xml +++ b/components/TVSeasonData.xml @@ -17,7 +17,7 @@ if datum.posterURL <> invalid m.top.posterURL = datum.posterURL else - "" + m.top.posterURL = "" end if m.top.description = datum.overview end sub diff --git a/source/HelperUtils.brs b/source/HelperUtils.brs index f2d48d53..3b16d7e9 100644 --- a/source/HelperUtils.brs +++ b/source/HelperUtils.brs @@ -28,5 +28,11 @@ sub themeScene(scene) if overhang <> invalid overhang.logoUri = "pkg:/images/logo.png" end if - end sub + +function leftPad(base as string, fill as string, length as integer) as string + while len(base) < length + base = fill + base + end while + return base +end function diff --git a/source/ShowScenes.brs b/source/ShowScenes.brs index e2c303b6..9a4a794a 100644 --- a/source/ShowScenes.brs +++ b/source/ShowScenes.brs @@ -200,16 +200,22 @@ sub ShowMovieDetails(movie_id) else if nodeEventQ(msg, "buttonSelected") button = msg.getROSGNode() ' TODO - a better way to verify buttonSelected is in fact "play", etc - if button.buttonSelected = 0 + if button.buttonSelected = 0 ' Play showVideoPlayer(movie_id) - else if button.buttonSelected = 3 + else if button.buttonSelected = 2 ' Watched + if content.watched + UnmarkItemWatched(movie_id) + else + MarkItemWatched(movie_id) + end if + content.watched = not content.watched + else if button.buttonSelected = 3 ' Favorite if content.favorite UnmarkItemFavorite(movie_id) else MarkItemFavorite(movie_id) end if content.favorite = not content.favorite - 'content.callfunc("favorite_toggle") end if else print msg diff --git a/source/api_userlibrary.brs b/source/api_userlibrary.brs index 8be689b2..8cc389b8 100644 --- a/source/api_userlibrary.brs +++ b/source/api_userlibrary.brs @@ -10,3 +10,25 @@ function UnmarkItemFavorite(id as String) resp.setRequest("DELETE") return getJson(resp) end function + +function MarkItemWatched(id as String) + date = CreateObject("roDateTime") + date.toLocalTime() + dateStr = stri(date.getYear()).trim() + dateStr += leftPad(stri(date.getMonth()).trim(), "0", 2) + dateStr += leftPad(stri(date.getDayOfMonth()).trim(), "0", 2) + dateStr += leftPad(stri(date.getHours()).trim(), "0", 2) + dateStr += leftPad(stri(date.getMinutes()).trim(), "0", 2) + dateStr += leftPad(stri(date.getSeconds()).trim(), "0", 2) + + url = Substitute("Users/{0}/PlayedItems/{1}", get_setting("active_user"), id) + resp = APIRequest(url, {"DatePlayed": dateStr}) + data = postJson(resp) +end function + +function UnmarkItemWatched(id as String) + url = Substitute("Users/{0}/PlayedItems/{1}", get_setting("active_user"), id) + resp = APIRequest(url) + resp.setRequest("DELETE") + return getJson(resp) +end function