Skip to content

Commit

Permalink
Fix #80
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKun committed Sep 1, 2023
1 parent 5d2b64c commit e37825e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Improved save video page by separating options in tabs
- Fixed calendar page resetting to current date after returning from save video page for past dates
- Fixed videoplayer showing some landscape videos rotated in preview
- Fixed movie deletion not updating the movie list correctly

## v1.5.1 - 02/2023
- Improved movies viewer page ordering movies by most recent
Expand Down
102 changes: 45 additions & 57 deletions lib/pages/home/create_movie/widgets/view_movies_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:share_plus/share_plus.dart';
import 'package:video_thumbnail/video_thumbnail.dart';

import '../../../../utils/constants.dart';
import '../../../../utils/lazy_future_builder.dart';
import '../../../../utils/theme.dart';
import '../../../../utils/utils.dart';

Expand All @@ -22,16 +21,12 @@ class ViewMovies extends StatefulWidget {

class _ViewMoviesState extends State<ViewMovies> {
List<String>? allMovies;
Map<String, Uint8List?> thumbnails = {};
final mediaStore = MediaStore();

@override
void initState() {
super.initState();
Future.delayed(const Duration(milliseconds: 250), () {
allMovies = Utils.getAllMovies(fullPath: true);
setState(() {});
});
allMovies = Utils.getAllMovies(fullPath: true);
}

@override
Expand All @@ -58,40 +53,38 @@ class _ViewMoviesState extends State<ViewMovies> {
children: [
const SizedBox(height: 10),
Expanded(
child: GridView.builder(
physics: const BouncingScrollPhysics(),
addAutomaticKeepAlives: true,
cacheExtent: 99999,
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: allMovies!.length,
itemBuilder: (context, index) {
final movie = allMovies![index];
return LazyFutureBuilder(
future: () => getThumbnail(movie),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: SizedBox(
height: 30,
width: 30,
child: Padding(
padding: EdgeInsets.all(4.0),
child: CircularProgressIndicator(),
),
),
);
}
child: FutureBuilder(
future: getThumbnails(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: SizedBox(
height: 30,
width: 30,
child: Padding(
padding: EdgeInsets.all(4.0),
child: CircularProgressIndicator(),
),
),
);
}

if (snapshot.hasError) {
return Text(
'${snapshot.error}',
);
}
if (snapshot.hasError) {
return Text(
'${snapshot.error}',
);
}
return GridView.builder(
physics: const BouncingScrollPhysics(),
addAutomaticKeepAlives: true,
cacheExtent: 99999,
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
),
itemCount: allMovies!.length,
itemBuilder: (context, index) {
final movie = allMovies![index];
return Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
Expand All @@ -101,7 +94,7 @@ class _ViewMoviesState extends State<ViewMovies> {
Align(
alignment: Alignment.center,
child: Image.memory(
snapshot.data as Uint8List,
snapshot.data![index] as Uint8List,
),
),
Align(
Expand Down Expand Up @@ -154,8 +147,7 @@ class _ViewMoviesState extends State<ViewMovies> {
),
const SizedBox(height: 5.0),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_ViewMoviesPlayButton(
filePath: movie,
Expand Down Expand Up @@ -198,9 +190,7 @@ class _ViewMoviesState extends State<ViewMovies> {
Navigator.pop(context);
},
style: TextButton.styleFrom(
foregroundColor: ThemeService().isDarkTheme()
? AppColors.light
: AppColors.dark,
foregroundColor: ThemeService().isDarkTheme() ? AppColors.light : AppColors.dark,
),
child: Text('no'.tr),
),
Expand Down Expand Up @@ -232,19 +222,17 @@ class _ViewMoviesState extends State<ViewMovies> {
);
}

Future<Uint8List?> getThumbnail(String video) async {
if (thumbnails.containsKey(video)) {
return thumbnails[video];
Future<List<Uint8List?>> getThumbnails() async {
final thumbnails = <Uint8List?>[];
for (final video in allMovies!) {
final thumbnail = await VideoThumbnail.thumbnailData(
video: File(video).path,
imageFormat: ImageFormat.JPEG,
quality: 14,
);
thumbnails.add(thumbnail);
}
final thumbnail = await VideoThumbnail.thumbnailData(
video: File(video).path,
imageFormat: ImageFormat.JPEG,
quality: 15,
);
setState(() {
thumbnails[video] = thumbnail;
});
return thumbnail;
return thumbnails;
}
}

Expand Down

0 comments on commit e37825e

Please sign in to comment.