Add display name to options panel, begin multi-profile work

This commit is contained in:
Nick Bisby 2019-04-22 14:08:10 -05:00
parent a76eacb624
commit e62fbc4f63
No known key found for this signature in database
GPG Key ID: F6E0C4E6D0B5EB36
7 changed files with 105 additions and 25 deletions

View File

@ -8,24 +8,48 @@
<field id="favorite" type="boolean" />
<field id="watched" type="boolean" />
<field id="seasons" type="associativearray" />
<field id="container" type="string" />
<field id="json" type="associativearray" onChange="setFields" />
</interface>
<script type="text/brightscript">
<![CDATA[
sub setFields()
datum = m.top.json
json = m.top.json
m.top.id = datum.id
m.top.title = datum.name
m.top.overview = datum.overview
m.top.favorite = datum.UserData.isFavorite
m.top.watched = datum.UserData.played
m.top.id = json.id
m.top.title = json.name
m.top.overview = json.overview
m.top.favorite = json.UserData.isFavorite
m.top.watched = json.UserData.played
if datum.posterURL <> invalid
m.top.posterURL = datum.posterURL
setPoster()
setContainer()
end sub
sub setPoster()
json = m.top.json
if json.posterURL <> invalid
m.top.posterURL = json.posterURL
else
m.top.posterURL = ""
end if
end sub
sub setContainer()
json = m.top.json
if json.mediaSources = invalid then return
if json.mediaSources.count() = 0 then return
m.top.container = json.mediaSources[0].container
if m.top.container = invalid then m.top.container = ""
if m.top.container = "m4v" or m.top.container = "mov"
m.top.container = "mp4"
end if
end sub
]]>
</script>

View File

@ -2,7 +2,7 @@
<component name="OptionsData" extends="ContentNode">
<interface>
<field id="base_title" type="string" />
<field id="choices" type="stringarray" />
<field id="choices" type="array" />
<field id="config_key" type="string" />
<field id="value_index" type="integer" />
<field id="value" type="string" onChange="update_title" />
@ -17,12 +17,12 @@
sub update_title()
for i=0 to m.top.choices.count() - 1
if m.top.choices[i] = m.top.value
if m.top.choices[i].value = m.top.value
m.top.value_index = i
exit for
end if
end for
m.top.title = m.top.base_title + ": " + m.top.value
m.top.title = m.top.base_title + ": " + m.top.choices[m.top.value_index].display
end sub
sub press()
@ -33,7 +33,7 @@
end while
m.top.value_index = i
m.top.value = m.top.choices[m.top.value_index]
m.top.value = m.top.choices[m.top.value_index].value
set_user_setting(m.top.config_key, m.top.value)
end sub

View File

@ -4,7 +4,10 @@
<field id="id" type="string" />
<field id="username" type="string" />
<field id="token" type="string" />
<field id="server" type="string" />
<field id="port" type="string" />
<field id="json" type="associativearray" onChange="setDataFromJSON" />
<function name="setServer" />
<function name="getPreference" />
<function name="setPreference" />
<function name="loadFromRegistry" />
@ -36,6 +39,22 @@
function saveToRegistry()
set_user_setting("username", m.top.username)
set_user_setting("token", m.top.token)
users = get_setting("available_users", {})
this_user = invalid
for each user in users
if user.id = m.top.id then this_user = user
end for
if this_user = invalid
users[m.top.id] = {
id: m.top.id,
username: m.top.username,
server: get_setting("server"),
port: get_setting("port")
}
set_setting("available_users", users)
end if
end function
function getPreference(key as String, default as String)
@ -49,6 +68,11 @@
function setActive()
set_setting("active_user", m.top.id)
end function
function setServer(hostname as string, port as string)
m.top.server = hostname
m.top.port = port
end function
]]>
</script>
</component>

View File

@ -2,8 +2,20 @@ sub Main()
keepalive = CreateObject("roSGScreen")
keepalive.show()
app_start:
' First thing to do is validate the ability to use the API
LoginFlow()
' Confirm the configured server and user work
ShowLibrarySelect()
' Have a catch for exiting the library on sign-out
if get_setting("active_user") = invalid
goto app_start
end if
end sub
sub LoginFlow()
start_login:
if get_setting("server") = invalid then
print "Get server details"
@ -14,8 +26,8 @@ sub Main()
' Maybe don't unset setting, but offer as a prompt
' Server not found, is it online? New values / Retry
print "Connection to server failed, restart flow"
SignOut()
unset_setting("server")
unset_setting("active_user")
goto start_login
end if
@ -24,17 +36,10 @@ sub Main()
ShowSigninSelect()
end if
' Confirm the configured server and user work
m.user = AboutMe()
if m.user = invalid or m.user.id <> get_setting("active_user")
print "Login failed, restart flow"
unset_setting("active_user")
goto start_login
end if
ShowLibrarySelect()
if get_setting("active_user") = invalid
goto start_login
end if
end sub

View File

@ -213,12 +213,19 @@ sub ShowMovieOptions(library)
"base_title": "Sort Field",
"key": "movie_sort_field",
"default": "DateCreated",
"values": ["DateCreated", "PremiereDate", "SortName"]},
"values": [
{display: "Date Added", value: "DateCreated"},
{display: "Release Date", value: "PremiereDate"},
{display: "Name", value: "SortName"}
]},
{"title": "Sort Order",
"base_title": "Sort Order",
"key": "movie_sort_order",
"default": "Descending",
"values": ["Descending", "Ascending"]}
"values": [
{display: "Descending", value: "Descending"},
{display: "Ascending", value: "Ascending"}
]}
]
new_options = []
for each opt in movie_options
@ -490,12 +497,19 @@ sub ShowCollections(library)
"base_title": "Sort Field",
"key": "movie_sort_field",
"default": "DateCreated",
"values": ["DateCreated", "PremiereDate", "SortName"]},
"values": [
{display: "Date Added", value: "DateCreated"},
{display: "Release Date", value: "PremiereDate"},
{display: "Name", value: "SortName"}
]},
{"title": "Sort Order",
"base_title": "Sort Order",
"key": "movie_sort_order",
"default": "Descending",
"values": ["Descending", "Ascending"]}
"values": [
{display: "Descending", value: "Descending"},
{display: "Ascending", value: "Ascending"}
]}
]
new_options = []
for each opt in panel_options

View File

@ -45,8 +45,10 @@ function VideoContent(id) as object
end function
function getContainerType(meta as object) as string
print type(meta)
if meta.json.mediaSources = invalid then return ""
container = meta.json.mediaSources[0].container
if container = invalid
container = ""

View File

@ -22,10 +22,21 @@ function AboutMe()
end function
function SignOut()
unset_user_setting("token")
if get_setting("active_user") <> invalid
unset_user_setting("token")
end if
unset_setting("active_user")
end function
function AvailableUsers()
users = get_setting("available_users", {})
return users
end function
function PickUser(id as string)
end function
function ServerInfo()
url = "System/Info/Public"