[videos] archive videos

This commit is contained in:
jscampucci 2024-07-09 10:48:53 +02:00
parent 8ca1864351
commit c693d5ce94
6 changed files with 64 additions and 56 deletions

View File

@ -35,29 +35,22 @@ class Home extends StatelessWidget {
fit: BoxFit.cover,
),
),
child: Column(
children: <Widget>[
SizedBox(height: 10),
Text('home_intro').tr(),
SizedBox(height: 10),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: DlForm()),
Flexible(
child: BlocConsumer<VideosCubit, VideosState>(
listener: (context, state) {},
builder: (context, state) {
var returnWidget = <Widget>[];
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<VideosCubit, VideosState>(
listener: (context, state) {},
builder: (context, state) {
return Column(
children: <Widget>[
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();

View File

@ -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"
}

View File

@ -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"
}

View File

@ -59,10 +59,14 @@ class VideosCubit extends Cubit<VideosState> {
emit(VideosState(videoList: nVideoList));
}
void archiveVideo(Video video) {
Future<void> 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<void> startConverter() async {
@ -145,7 +149,7 @@ class VideosCubit extends Cubit<VideosState> {
}
}
await changeStatus(video, 'done');
archiveVideo(video.copyWith(status: 'done'));
await archiveVideo(video.copyWith(status: 'done'));
debugPrint('File moved to ${newFile.path}');
}
}

View File

@ -10,5 +10,14 @@ final class VideosState {
this.videoList = const [],
this.archiveList = const []});
VideosState copyWith(
{String? status, List<Video>? videoList, List<Video>? archiveList}) {
return VideosState(
status: status ?? this.status,
videoList: videoList ?? this.videoList,
archiveList: archiveList ?? this.archiveList,
);
}
List<Object> get props => [videoList, status, archiveList];
}

View File

@ -3,7 +3,7 @@ description: noTube
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 0.0.18
version: 0.0.20
environment:
sdk: ">=3.0.0 <4.0.0"