From b7b0d209dd3b7b2cc7077c0379463b731eb99dd3 Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 8 Aug 2026 18:20:33 +0200 Subject: [PATCH] remote/keyboard nav via Lampa.Controller.collectionSet + enter/back handlers --- plugin.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/plugin.js b/plugin.js index 36c09c0..805bc22 100644 --- a/plugin.js +++ b/plugin.js @@ -73,20 +73,52 @@ function MyMovies() { var comp = this; var body; + var grid; this.create = function (b) { body = b; }; + // Wire up keyboard/remote navigation using native Lampa Controller. this.start = function () { - if (Lampa.Selector) Lampa.Selector.update(); + if (!grid) return; + var cards = grid.find('.card.selector'); + if (!cards.length) return; + + // Native collection navigation: Lampa handles up/down/left/right + // over .selector elements automatically once the collection is set. + Lampa.Controller.collectionSet(grid); + Lampa.Controller.collectionFocus(cards[0], grid); + + // Custom controller only for enter/back while this screen is active. + Lampa.Controller.add('mymovies', { + toggle: function () { + var focused = grid.find('.card.selector.focus')[0] || cards[0]; + Lampa.Controller.collectionFocus(focused, grid); + }, + enter: function () { + var el = grid.find('.card.selector.focus')[0] || cards[0]; + if (el) { + var id = $(el).attr('data-id'); + var m = comp._movies ? comp._movies.find(function (x) { return x.id === id; }) : null; + if (m) openMovie(m); + } + }, + back: function () { + Lampa.Activity.back(); + }, + gone: function () { + Lampa.Controller.clear('mymovies'); + } + }); + Lampa.Controller.toggle('mymovies'); }; this.render = function () { injectStyles(); var html = document.createElement('div'); html.className = 'mymovies'; - var grid = document.createElement('div'); + grid = document.createElement('div'); grid.className = 'movies-grid'; html.appendChild(grid); @@ -97,13 +129,15 @@ if (err) { console.error('[mymovies] catalog error', err); grid.innerHTML = '
Catalog load error
'; - if (Lampa.Selector) Lampa.Selector.update(); return; } var movies = (data && data.movies) || []; movies = sortMovies(movies); + comp._movies = movies; console.log('[mymovies] loaded', movies.length, 'films'); renderMovies($(grid), movies); + // re-apply navigation if activity already started + if (comp.activity && comp.activity.ready) comp.start(); }); return html; @@ -127,7 +161,6 @@ grid.empty(); if (!movies.length) { grid.append('
Catalog is empty
'); - if (Lampa.Selector) Lampa.Selector.update(); return; } movies.forEach(function (m) { @@ -145,7 +178,6 @@ card.on('hover:enter', function () { openMovie(m); }); grid.append(card); }); - if (Lampa.Selector) Lampa.Selector.update(); } // ---------- Component: movie detail ---------- @@ -159,7 +191,16 @@ }; this.start = function () { - if (Lampa.Selector) Lampa.Selector.update(); + // Remote: only "back" is needed on the detail screen. + Lampa.Controller.add('mymovies_detail', { + back: function () { + Lampa.Activity.back(); + }, + gone: function () { + Lampa.Controller.clear('mymovies_detail'); + } + }); + Lampa.Controller.toggle('mymovies_detail'); }; this.render = function () {