Add basic behavior to play, show catalog and more basic feature
This commit is contained in:
1 parent
df847becc8
commit
8e6392a84c
17 files changed
+1455
-34
No files matched your search
+105
-15
@@ -3,27 +3,75 @@ import "../Components"
|
||||
import "../Shared"
|
||||
import "../Shared/Remote.js" as Remote
|
||||
|
||||
// Écran d'accueil provisoire : confirme la connexion en attendant la vraie bibliothèque.
|
||||
// Accueil : rangées « Reprendre », « Mes médias » et derniers ajouts de chaque bibliothèque.
|
||||
// Toutes les rangées sont chargées avant affichage, pour ne pas déplacer le focus en cours de route.
|
||||
Page {
|
||||
id: page
|
||||
|
||||
title: page.session && page.session.currentUser
|
||||
? "Bonjour " + page.session.currentUser.name
|
||||
: "Accueil"
|
||||
subtitle: page.session && page.session.currentServer
|
||||
? "Connecté à " + page.session.currentServer.name + "."
|
||||
: ""
|
||||
initialFocus: backButton
|
||||
property var rows: []
|
||||
property bool loading: true
|
||||
property string error: ""
|
||||
|
||||
// La pile a été réinitialisée à la connexion : on reconstruit Serveurs > Utilisateurs
|
||||
// pour revenir au choix de l'utilisateur.
|
||||
fullscreen: true
|
||||
title: page.session && page.session.currentUser ? "Bonjour " + page.session.currentUser.name : "Accueil"
|
||||
subtitle: page.session && page.session.currentServer ? page.session.currentServer.name : ""
|
||||
initialFocus: switchUserButton
|
||||
|
||||
// La pile a été réinitialisée à la connexion : on reconstruit Serveurs > Utilisateurs.
|
||||
function goBack() {
|
||||
page.navigator.reset("ServerSelect");
|
||||
page.navigator.push("UserSelect");
|
||||
}
|
||||
|
||||
// La touche Retour de la télécommande fait la même chose que le bouton
|
||||
// (sinon, à la racine de la pile, elle fermerait l'application).
|
||||
function load() {
|
||||
page.session.loadLibraries(function (err, libraries) {
|
||||
if (err) {
|
||||
page.error = err;
|
||||
page.loading = false;
|
||||
return;
|
||||
}
|
||||
var resume = [];
|
||||
var latest = [];
|
||||
var pending = 1 + libraries.length;
|
||||
function done() {
|
||||
if (--pending === 0)
|
||||
page.build(libraries, resume, latest);
|
||||
}
|
||||
page.session.loadResume(function (e, items) {
|
||||
resume = items;
|
||||
done();
|
||||
});
|
||||
for (var i = 0; i < libraries.length; i++) {
|
||||
(function (index) {
|
||||
page.session.loadLatest(libraries[index].id, function (e, items) {
|
||||
latest[index] = items;
|
||||
done();
|
||||
});
|
||||
})(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function build(libraries, resume, latest) {
|
||||
var list = [];
|
||||
if (resume.length > 0)
|
||||
list.push({ title: "Reprendre", items: resume, landscape: true });
|
||||
if (libraries.length > 0)
|
||||
list.push({ title: "Mes médias", items: libraries, landscape: true });
|
||||
for (var i = 0; i < libraries.length; i++) {
|
||||
if (latest[i] && latest[i].length > 0)
|
||||
list.push({ title: "Ajouts récents · " + libraries[i].name, items: latest[i], landscape: false });
|
||||
}
|
||||
rows = list;
|
||||
loading = false;
|
||||
if (list.length > 0)
|
||||
rowsList.forceActiveFocus();
|
||||
}
|
||||
|
||||
Component.onCompleted: load()
|
||||
Component.onDestruction: if (page.session) page.session.cancel()
|
||||
|
||||
// Retour : choix de l'utilisateur (sinon, à la racine de la pile, l'app se fermerait).
|
||||
Keys.onPressed: {
|
||||
if (Remote.isBack(event.key)) {
|
||||
event.accepted = true;
|
||||
@@ -32,23 +80,65 @@ Page {
|
||||
}
|
||||
|
||||
Row {
|
||||
id: actions
|
||||
spacing: Theme.spacingM
|
||||
|
||||
FocusButton {
|
||||
id: backButton
|
||||
text: "Retour"
|
||||
id: switchUserButton
|
||||
text: "Changer d'utilisateur"
|
||||
KeyNavigation.right: logoutButton
|
||||
KeyNavigation.down: rowsList
|
||||
onClicked: page.goBack()
|
||||
}
|
||||
|
||||
FocusButton {
|
||||
id: logoutButton
|
||||
text: "Se déconnecter"
|
||||
KeyNavigation.left: backButton
|
||||
KeyNavigation.left: switchUserButton
|
||||
KeyNavigation.down: rowsList
|
||||
onClicked: {
|
||||
page.session.logout();
|
||||
page.goBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: rowsList
|
||||
anchors {
|
||||
top: actions.bottom
|
||||
topMargin: Theme.spacingL
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
clip: true
|
||||
spacing: Theme.spacingS
|
||||
model: page.rows
|
||||
|
||||
delegate: MediaRow {
|
||||
width: rowsList.width
|
||||
title: modelData.title
|
||||
items: modelData.items
|
||||
landscape: modelData.landscape
|
||||
session: page.session
|
||||
onActivated: page.navigator.openItem(item)
|
||||
}
|
||||
|
||||
// La rangée courante reste en haut de la zone visible.
|
||||
onCurrentIndexChanged: positionViewAtIndex(currentIndex, ListView.Beginning)
|
||||
|
||||
KeyNavigation.priority: KeyNavigation.AfterItem
|
||||
KeyNavigation.up: switchUserButton
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.centerIn: rowsList
|
||||
visible: text !== ""
|
||||
text: page.loading ? "Chargement…"
|
||||
: page.error !== "" ? page.error
|
||||
: page.rows.length === 0 ? "Aucun média disponible pour ce compte." : ""
|
||||
color: page.error !== "" ? Theme.error : Theme.textMuted
|
||||
font.pixelSize: Theme.fontBody
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user