Skip to content

Commit

Permalink
continue video-bottom-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
petrichor-hl committed Dec 26, 2023
1 parent b346b34 commit 43f3890
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 152 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {
DeviceOrientation.portraitUp,
]);
await Supabase.initialize(
url: 'https://kpaxjjmelbqpllxenpxz.supabase.co',
url: '',
anonKey: '',
authFlowType: AuthFlowType.pkce,
);
Expand Down
33 changes: 13 additions & 20 deletions lib/screens/film_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _FilmDetailState extends State<FilmDetail> {

late final _futureMovie = _fetchMovie();

List<String> downloadedEpisodeIds = [];
final List<String> _downloadedEpisodeIds = [];

Future<void> _fetchMovie() async {
final filmInfo = await supabase
Expand Down Expand Up @@ -152,7 +152,7 @@ class _FilmDetailState extends State<FilmDetail> {
if (existingDownloadedFilm != null) {
for (var season in existingDownloadedFilm.offlineSeasons) {
for (var episode in season.offlineEpisodes) {
downloadedEpisodeIds.add(episode.episodeId);
_downloadedEpisodeIds.add(episode.episodeId);
}
}
}
Expand Down Expand Up @@ -322,6 +322,8 @@ class _FilmDetailState extends State<FilmDetail> {
Gỡ bỏ giới hạn của chiều cao của BottomSheet
*/
isScrollControlled: true,
// Không hoạt động useSafeArea
// useSafeArea: true,
);
},
borderRadius: BorderRadius.circular(8),
Expand Down Expand Up @@ -349,9 +351,6 @@ class _FilmDetailState extends State<FilmDetail> {
width: double.infinity,
child: FilledButton.icon(
onPressed: () {
// final episodeId = _seasons[0]['episode'][0]['id'];
final episodeId = _film.seasons[0].episodes[0].episodeId;
final isDownloaded = downloadedEpisodeIds.contains(episodeId);
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => MultiBlocProvider(
Expand All @@ -363,19 +362,13 @@ class _FilmDetailState extends State<FilmDetail> {
create: (ctx) => VideoPlayControlCubit(),
),
],
child: isDownloaded
? VideoPlayerView(
title: _film.name,
videoLink: isMovie
? '${appDir.path}/episode/$episodeId.mp4'
: '${appDir.path}/episode/${_film.id}/$episodeId.mp4',
videoLocation: 'local',
)
: VideoPlayerView(
title: _film.name,
videoLink:
_film.seasons[0].episodes[0].linkEpisode,
),
child: VideoPlayerView(
filmId: _film.id,
seasons: _film.seasons,
downloadedEpisodeIds: _downloadedEpisodeIds,
firstEpisodeToPlay: _film.seasons[0].episodes[0],
firstSeasonIndex: 0,
),
),
),
);
Expand All @@ -399,7 +392,7 @@ class _FilmDetailState extends State<FilmDetail> {
firstEpisodeId: _film.seasons[0].episodes[0].episodeId,
firstEpisodeLink: _film.seasons[0].episodes[0].linkEpisode,
runtime: _film.seasons[0].episodes[0].runtime,
isEpisodeDownloaded: downloadedEpisodeIds
isEpisodeDownloaded: _downloadedEpisodeIds
.contains(_film.seasons[0].episodes[0].episodeId),
),
const SizedBox(height: 6),
Expand Down Expand Up @@ -515,7 +508,7 @@ class _FilmDetailState extends State<FilmDetail> {
_film.seasons,
isMovie,
widget.filmId,
downloadedEpisodeIds,
_downloadedEpisodeIds,
),
],
).animate().fade().slideY(
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/person_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class _PersonDetailState extends State<PersonDetail> {
clipBehavior: Clip.antiAlias,
child: _person['profile_path'] != null
? Image.network(
'https://image.tmdb.org/t/p/w440_and_h660_face${_person['profile_path']}',
'https://image.tmdb.org/t/p/w440_and_h660_face/${_person['profile_path']}',
width: 160,
)
: const SizedBox(
Expand Down
40 changes: 20 additions & 20 deletions lib/widgets/downloaded_page/downloaded_episode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,26 +332,26 @@ class _DownloadedEpisodeState extends State<DownloadedEpisode> {
});
}
: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => MultiBlocProvider(
providers: [
BlocProvider(
create: (ctx) => VideoSliderCubit(),
),
BlocProvider(
create: (ctx) => VideoPlayControlCubit(),
),
],
child: VideoPlayerView(
title: widget.offlineEpisode.title,
videoLink:
'${appDir.path}/episode/${widget.filmId}/${widget.offlineEpisode.episodeId}.mp4',
videoLocation: 'local',
),
),
),
);
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (ctx) => MultiBlocProvider(
// providers: [
// BlocProvider(
// create: (ctx) => VideoSliderCubit(),
// ),
// BlocProvider(
// create: (ctx) => VideoPlayControlCubit(),
// ),
// ],
// child: VideoPlayerView(
// title: widget.offlineEpisode.title,
// videoLink:
// '${appDir.path}/episode/${widget.filmId}/${widget.offlineEpisode.episodeId}.mp4',
// videoLocation: 'local',
// ),
// ),
// ),
// );
},
onLongPress: () {
widget.turnOnMultiSelectMode();
Expand Down
38 changes: 19 additions & 19 deletions lib/widgets/downloaded_page/offline_movie_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,25 @@ class _OfflineMovieUIState extends State<OfflineMovieUI> {
});
}
: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => MultiBlocProvider(
providers: [
BlocProvider(
create: (ctx) => VideoSliderCubit(),
),
BlocProvider(
create: (ctx) => VideoPlayControlCubit(),
),
],
child: VideoPlayerView(
title: widget.offlineMovie.name,
videoLink: '${appDir.path}/episode/${episode.episodeId}.mp4',
videoLocation: 'local',
),
),
),
);
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (ctx) => MultiBlocProvider(
// providers: [
// BlocProvider(
// create: (ctx) => VideoSliderCubit(),
// ),
// BlocProvider(
// create: (ctx) => VideoPlayControlCubit(),
// ),
// ],
// child: VideoPlayerView(
// title: widget.offlineMovie.name,
// videoLink: '${appDir.path}/episode/${episode.episodeId}.mp4',
// videoLocation: 'local',
// ),
// ),
// ),
// );
},
onLongPress: () {
widget.turnOnMultiSelectMode();
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/film_detail/download_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:movie_app/models/offfline_season.dart';
import 'package:movie_app/models/offline_episode.dart';
import 'package:movie_app/models/offline_film.dart';
import 'package:movie_app/screens/film_detail.dart';
import 'package:movie_app/widgets/film_detail/episode_ui.dart';
import 'package:movie_app/widgets/film_detail/episode_ui_first.dart';
import 'package:path_provider/path_provider.dart';

class DownloadButton extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:movie_app/cubits/video_play_control/video_play_control_cubit.dart';
import 'package:movie_app/cubits/video_slider/video_slider_cubit.dart';
import 'package:movie_app/data/downloaded_film.dart';
import 'package:movie_app/database/database_utils.dart';
import 'package:movie_app/models/episode.dart';
import 'package:movie_app/models/offfline_season.dart';
import 'package:movie_app/models/offline_episode.dart';
import 'package:movie_app/models/offline_film.dart';
import 'package:movie_app/screens/film_detail.dart';
import 'package:movie_app/widgets/video_player/video_player_view.dart';
import 'package:path_provider/path_provider.dart';

enum DownloadState {
Expand All @@ -22,21 +18,23 @@ enum DownloadState {
downloaded,
}

class EpisodeUI extends StatefulWidget {
const EpisodeUI({
class EpisodeUIFrist extends StatefulWidget {
const EpisodeUIFrist({
required this.episode,
required this.isEpisodeDownloaded,
required this.watchEpisode,
super.key,
});

final Episode episode;
final bool isEpisodeDownloaded;
final void Function() watchEpisode;

@override
State<EpisodeUI> createState() => _EpisodeState();
State<EpisodeUIFrist> createState() => _EpisodeUIFristState();
}

class _EpisodeState extends State<EpisodeUI> {
class _EpisodeUIFristState extends State<EpisodeUIFrist> {
late DownloadState downloadState =
widget.isEpisodeDownloaded ? DownloadState.downloaded : DownloadState.ready;
double progress = 0;
Expand All @@ -49,31 +47,7 @@ class _EpisodeState extends State<EpisodeUI> {
padding: const EdgeInsets.only(bottom: 30),
child: InkWell(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => MultiBlocProvider(
providers: [
BlocProvider(
create: (ctx) => VideoSliderCubit(),
),
BlocProvider(
create: (ctx) => VideoPlayControlCubit(),
),
],
child: downloadState == DownloadState.ready
? VideoPlayerView(
title: widget.episode.title,
videoLink: widget.episode.linkEpisode,
)
: VideoPlayerView(
title: widget.episode.title,
videoLink:
'${appDir.path}/episode/${filmInfo['film_id']}/${widget.episode.episodeId}.mp4',
videoLocation: 'local',
),
),
),
);
widget.watchEpisode();
},
splashColor: const Color.fromARGB(255, 52, 52, 52),
borderRadius: BorderRadius.circular(4),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/film_detail/segment_compose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:movie_app/models/poster.dart';
import 'package:movie_app/models/season.dart';
import 'package:movie_app/screens/film_detail.dart';
import 'package:movie_app/widgets/film_detail/grid_shimmer.dart';
import 'package:movie_app/widgets/film_detail/list_episodes.dart';
import 'package:movie_app/widgets/film_detail/vertical_list_episodes.dart';
import 'package:movie_app/widgets/grid/grid_films.dart';
import 'package:movie_app/widgets/grid/grid_persons.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:movie_app/cubits/video_play_control/video_play_control_cubit.dart';
import 'package:movie_app/cubits/video_slider/video_slider_cubit.dart';
import 'package:movie_app/models/season.dart';
import 'package:movie_app/screens/film_detail.dart';
import 'package:movie_app/widgets/film_detail/episode_ui.dart';
import 'package:movie_app/widgets/film_detail/episode_ui_first.dart';
import 'package:movie_app/widgets/video_player/video_player_view.dart';

class ListEpisodes extends StatefulWidget {
const ListEpisodes(
Expand Down Expand Up @@ -58,10 +62,33 @@ class _ListEpisodesState extends State<ListEpisodes> {
...(widget.seasons[selectedSeason].episodes).map(
(e) {
// print('episode_id = ${e['id']}');
return EpisodeUI(
return EpisodeUIFrist(
key: ValueKey(e.episodeId),
episode: e,
isEpisodeDownloaded: widget.downloadedEpisodeIds.contains(e.episodeId),
watchEpisode: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => MultiBlocProvider(
providers: [
BlocProvider(
create: (ctx) => VideoSliderCubit(),
),
BlocProvider(
create: (ctx) => VideoPlayControlCubit(),
),
],
child: VideoPlayerView(
filmId: offlineData['film_id'],
seasons: widget.seasons,
downloadedEpisodeIds: widget.downloadedEpisodeIds,
firstEpisodeToPlay: e,
firstSeasonIndex: selectedSeason,
),
),
),
);
},
);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/grid/grid_persons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GridPersons extends StatelessWidget {
: ClipRRect(
borderRadius: BorderRadius.circular(7),
child: Image.network(
'https://www.themoviedb.org/t/p/w276_and_h350_face${personsData[index]['person']['profile_path']}',
'https://www.themoviedb.org/t/p/w276_and_h350_face/${personsData[index]['person']['profile_path']}',
width: double.infinity, // minus border's width = 1
height: 155,
fit: BoxFit.cover,
Expand Down
Loading

0 comments on commit 43f3890

Please sign in to comment.