From 8ca1864351bce9a05e68268678e6485e8ca819a0 Mon Sep 17 00:00:00 2001 From: jscampucci Date: Fri, 5 Jul 2024 15:26:13 +0200 Subject: [PATCH] [video] archive videos --- .gitignore | 3 +- lib/dlForm/formComponents/submit_button.dart | 2 + lib/screens/home.dart | 40 +++++++- lib/translations/en-US.json | 3 +- lib/translations/fr-FR.json | 3 +- lib/videoList/cubit/videos_cubit.dart | 96 +++++++++++--------- lib/videoList/cubit/videos_state.dart | 9 +- pubspec.lock | 2 +- pubspec.yaml | 1 + 9 files changed, 106 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 52a302f..a67ef55 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,5 @@ app.*.map.json /android/app/profile /android/app/release -samples/ \ No newline at end of file +samples/ +apps_logs.txt \ No newline at end of file diff --git a/lib/dlForm/formComponents/submit_button.dart b/lib/dlForm/formComponents/submit_button.dart index d2bd990..aba200c 100644 --- a/lib/dlForm/formComponents/submit_button.dart +++ b/lib/dlForm/formComponents/submit_button.dart @@ -20,6 +20,7 @@ class _SubmitButtonState extends State { void addVideosListener(BuildContext context, DlFormState state) { if (state.isParsed) { + context.read().setGlobalStatus('loaded'); for (Video video in state.videos) { debugPrint('Adding video: $video'); context.read().addVideo(video); @@ -45,6 +46,7 @@ class _SubmitButtonState extends State { }, child: GestureDetector( onTap: () { + context.read().setGlobalStatus('loading'); context.read().parseUrl(); }, child: Container( diff --git a/lib/screens/home.dart b/lib/screens/home.dart index cf84900..7d12dd8 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -47,10 +47,41 @@ class Home extends StatelessWidget { child: BlocConsumer( listener: (context, state) {}, builder: (context, state) { - return ListView.builder( - itemCount: state.videoList.length, + var returnWidget = []; + switch (state.status) { + case 'loading': + returnWidget.add(Center( + child: CircularProgressIndicator())); + case 'error': + returnWidget.add(Center( + child: Text('home_dl_error').tr(), + )); + default: + returnWidget.add(ListView.builder( + itemCount: state.videoList.length, + itemBuilder: (context, index) { + var currentVideo = + state.videoList[index]; + return ListTile( + leading: SizedBox( + width: 72, + height: 48, + child: Image.network( + currentVideo.thumbnail, + fit: BoxFit.cover), + ), + title: Text(currentVideo.title), + subtitle: Text( + '${currentVideo.status} - ${currentVideo.format.format}'), + ); + }, + )); + } + returnWidget.add(ListView.builder( + itemCount: state.archiveList.length, itemBuilder: (context, index) { - var currentVideo = state.videoList[index]; + var currentVideo = + state.archiveList[index]; return ListTile( leading: SizedBox( width: 72, @@ -64,6 +95,9 @@ class Home extends StatelessWidget { '${currentVideo.status} - ${currentVideo.format.format}'), ); }, + )); + return Stack( + children: returnWidget, ); })), ], diff --git a/lib/translations/en-US.json b/lib/translations/en-US.json index ace7174..458df19 100644 --- a/lib/translations/en-US.json +++ b/lib/translations/en-US.json @@ -7,5 +7,6 @@ "download_folder": "Download folder", "en_US": "English", "fr_FR": "French", - "Ok": "OK" + "Ok": "OK", + "home_dl_error": "Error while downloading the video" } \ No newline at end of file diff --git a/lib/translations/fr-FR.json b/lib/translations/fr-FR.json index b0d82df..740f567 100644 --- a/lib/translations/fr-FR.json +++ b/lib/translations/fr-FR.json @@ -7,5 +7,6 @@ "download_folder": "Dossier de téléchargement", "en_US": "Anglais", "fr_FR": "Français", - "Ok": "OK" + "Ok": "OK", + "home_dl_error": "Erreur lors du téléchargement de la vidéo" } \ No newline at end of file diff --git a/lib/videoList/cubit/videos_cubit.dart b/lib/videoList/cubit/videos_cubit.dart index c22bb83..9b7a7c5 100644 --- a/lib/videoList/cubit/videos_cubit.dart +++ b/lib/videoList/cubit/videos_cubit.dart @@ -19,41 +19,54 @@ class VideosCubit extends Cubit { late DLServices dlService; late ConverterService converterService; - final List