From c693d5ce9426810c1be59d6a7b85b2bf714927d4 Mon Sep 17 00:00:00 2001 From: jscampucci Date: Tue, 9 Jul 2024 10:48:53 +0200 Subject: [PATCH] [videos] archive videos --- lib/screens/home.dart | 93 +++++++++++++-------------- lib/translations/en-US.json | 3 +- lib/translations/fr-FR.json | 3 +- lib/videoList/cubit/videos_cubit.dart | 10 ++- lib/videoList/cubit/videos_state.dart | 9 +++ pubspec.yaml | 2 +- 6 files changed, 64 insertions(+), 56 deletions(-) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 7d12dd8..a3addff 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -35,29 +35,22 @@ class Home extends StatelessWidget { fit: BoxFit.cover, ), ), - child: Column( - children: [ - SizedBox(height: 10), - Text('home_intro').tr(), - SizedBox(height: 10), - Padding( - padding: EdgeInsets.symmetric(horizontal: 20), - child: DlForm()), - Flexible( - child: BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - 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( + child: BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + return Column( + children: [ + SizedBox(height: 10), + Text('home_intro').tr(), + SizedBox(height: 10), + Padding( + padding: EdgeInsets.symmetric(horizontal: 20), + child: DlForm()), + state.status == 'loading' + ? Center(child: CircularProgressIndicator()) + : Flexible( + flex: 5, + child: ListView.builder( itemCount: state.videoList.length, itemBuilder: (context, index) { var currentVideo = @@ -75,33 +68,33 @@ class Home extends StatelessWidget { '${currentVideo.status} - ${currentVideo.format.format}'), ); }, - )); - } - returnWidget.add(ListView.builder( - itemCount: state.archiveList.length, - itemBuilder: (context, index) { - var currentVideo = - state.archiveList[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}'), - ); - }, - )); - return Stack( - children: returnWidget, - ); - })), - ], - ), + )), + state.archiveList.length > 0 + ? Flexible( + flex: 1, + child: ListView.builder( + itemCount: state.archiveList.length, + itemBuilder: (context, index) { + var currentVideo = + state.archiveList[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}'), + ); + }, + )) + : SizedBox(), + ], + ); + }), ), ) : CircularProgressIndicator(); diff --git a/lib/translations/en-US.json b/lib/translations/en-US.json index 458df19..efac62b 100644 --- a/lib/translations/en-US.json +++ b/lib/translations/en-US.json @@ -8,5 +8,6 @@ "en_US": "English", "fr_FR": "French", "Ok": "OK", - "home_dl_error": "Error while downloading the video" + "home_dl_error": "Error while downloading the video", + "home_archive": "Archive" } \ No newline at end of file diff --git a/lib/translations/fr-FR.json b/lib/translations/fr-FR.json index 740f567..c9f614d 100644 --- a/lib/translations/fr-FR.json +++ b/lib/translations/fr-FR.json @@ -8,5 +8,6 @@ "en_US": "Anglais", "fr_FR": "Français", "Ok": "OK", - "home_dl_error": "Erreur lors du téléchargement de la vidéo" + "home_dl_error": "Erreur lors du téléchargement de la vidéo", + "home_archive": "Archive" } \ No newline at end of file diff --git a/lib/videoList/cubit/videos_cubit.dart b/lib/videoList/cubit/videos_cubit.dart index 9b7a7c5..2736fab 100644 --- a/lib/videoList/cubit/videos_cubit.dart +++ b/lib/videoList/cubit/videos_cubit.dart @@ -59,10 +59,14 @@ class VideosCubit extends Cubit { emit(VideosState(videoList: nVideoList)); } - void archiveVideo(Video video) { + Future archiveVideo(Video video) async { debugPrint('Archiving video: ${video.title} ${video.format.format}'); var nVideoList = state.videoList.where((v) => v.id != video.id).toList(); - emit(VideosState(videoList: nVideoList, archiveList: [video])); + var archivedVideos = state.archiveList.toList(); + debugPrint('Archived videos before: ${archivedVideos.length}'); + archivedVideos.add(video); + debugPrint('Archived videos after: $archivedVideos'); + emit(state.copyWith(videoList: nVideoList, archiveList: archivedVideos)); } Future startConverter() async { @@ -145,7 +149,7 @@ class VideosCubit extends Cubit { } } await changeStatus(video, 'done'); - archiveVideo(video.copyWith(status: 'done')); + await archiveVideo(video.copyWith(status: 'done')); debugPrint('File moved to ${newFile.path}'); } } diff --git a/lib/videoList/cubit/videos_state.dart b/lib/videoList/cubit/videos_state.dart index 3a8c37a..8cbfc6d 100644 --- a/lib/videoList/cubit/videos_state.dart +++ b/lib/videoList/cubit/videos_state.dart @@ -10,5 +10,14 @@ final class VideosState { this.videoList = const [], this.archiveList = const []}); + VideosState copyWith( + {String? status, List