*/ private array $paths = []; protected function loaded(array $params = []): void { $this->save = (bool)($params['save'] ?? true); $this->heading->text = $this->save ? 'Sauver la playlist (.FLS)' : 'Charger une playlist (.FLS)'; $this->ok->text = $this->save ? 'Sauver' : 'Charger'; $this->status->text = ''; $dir = $this->wz->storagePath('playlists'); @mkdir($dir, 0777, true); $this->paths = array_values(array_filter(array_map(fn (string $f) => $dir . '/' . $f, scandir($dir) ?: []), fn (string $f) => is_file($f) && Text::extension($f) === 'fls')); $this->lists->items = array_map(fn (string $f) => basename($f), $this->paths); $this->name->text = $this->save ? 'winzik.fls' : ''; $this->browse->enabled = Native::supports($this->save ? 'save' : 'open'); if (!$this->browse->enabled) { $this->hideOnPhone('browse'); // the phone: no file chooser of its own here, the name typed is enough } if ($this->paths === [] && !$this->save) { $this->status->text = 'Aucune liste sauvée pour l\'instant.'; } $this->setFocus($this->save ? $this->name : $this->lists); } public function onListsChange(ListBox $sender, int $index, string $item): void { $this->name->text = $item; } public function onListsActivate(ListBox $sender, int $index, string $item): void { $this->name->text = $item; $this->onOkClick($this->ok); } public function onNameSubmit(TextBox $sender): void { $this->onOkClick($this->ok); } public function onBrowseClick(Button $sender): void { $task = $this->save ? FilePicker::save(['file_name' => 'winzik.fls', 'filters' => ['Fichier liste (FLS)' => ['fls']]]) : FilePicker::open(['filters' => ['Fichier liste (FLS)' => ['fls']]]); $task->then(fn (mixed $file) => is_string($file) && $file !== '' && $this->run($file)); } public function onOkClick(Button $sender): void { $name = basename(trim($this->name->text)); if ($name === '') { $this->status->text = 'Un nom de fichier, svp.'; return; } $this->run($this->wz->storagePath('playlists/' . $name)); } private function run(string $file): bool { if ($this->save) { $ok = $this->wz->saveFls($file); $this->status->text = $ok ? 'Liste sauvée : ' . basename($file) : 'Impossible d\'écrire ' . $file; } else { $ok = $this->wz->loadFls($file); $this->status->text = $ok ? '' : 'Ce n\'est pas un fichier liste (FLS) : ' . basename($file); } if ($ok) { $this->wz->notice($this->save ? 'Liste sauvée' : 'Liste chargée', 3); $this->close(); } return $ok; } public function onCancelClick(Button $sender): void { $this->close(); } }