Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix continue without and other bugs #256

Merged
merged 9 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/models/video/stream_state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ class StreamState {
final bool isLoading;
final List<Stream>? streams;
final List<Stream>? liveStreams;
final List<String>? thumbnails;
final AppError? error;
final Progress? progress;
final bool isWatched;
final String? videoSource;
final List<Tuple2<Stream, String>>? streamsWithThumb;
final List<Tuple2<Stream, String>>? liveStreamsWithThumb;
final List<Tuple2<Stream, String>>? displayedStreams;
final String selectedFilterOption;

const StreamState({
this.isLoading = false,
this.streams,
this.liveStreams,
this.thumbnails,
this.error,
this.progress,
this.isWatched = false,
this.videoSource,
this.streamsWithThumb,
this.liveStreamsWithThumb,
this.displayedStreams,
this.selectedFilterOption = 'Oldest First',
});
Expand All @@ -42,19 +42,20 @@ class StreamState {
String? videoSource,
Map<int, String>? downloadedVideos,
List<Tuple2<Stream, String>>? streamsWithThumb,
List<Tuple2<Stream, String>>? liveStreamsWithThumb,
List<Tuple2<Stream, String>>? displayedStreams,
String? selectedFilterOption,
}) {
return StreamState(
isLoading: isLoading ?? this.isLoading,
streams: streams ?? this.streams,
liveStreams: liveStreams ?? this.liveStreams,
thumbnails: thumbnails ?? this.thumbnails,
error: error ?? this.error,
progress: progress ?? this.progress,
isWatched: isWatched ?? this.isWatched,
videoSource: videoSource ?? this.videoSource,
streamsWithThumb: streamsWithThumb ?? this.streamsWithThumb,
liveStreamsWithThumb: liveStreamsWithThumb ?? this.liveStreamsWithThumb,
displayedStreams: displayedStreams ?? this.displayedStreams,
selectedFilterOption: selectedFilterOption ?? this.selectedFilterOption,
);
Expand All @@ -65,11 +66,11 @@ class StreamState {
isLoading: isLoading,
streams: streams,
liveStreams: liveStreams,
thumbnails: thumbnails,
progress: progress,
isWatched: isWatched,
videoSource: videoSource,
streamsWithThumb: streamsWithThumb,
liveStreamsWithThumb: liveStreamsWithThumb,
displayedStreams: displayedStreams,
error: null,
);
Expand All @@ -80,11 +81,11 @@ class StreamState {
isLoading: isLoading,
streams: streams,
liveStreams: liveStreams,
thumbnails: thumbnails,
progress: progress,
isWatched: isWatched,
videoSource: videoSource,
streamsWithThumb: streamsWithThumb,
liveStreamsWithThumb: liveStreamsWithThumb,
displayedStreams: displayedStreams,
error: null,
);
Expand Down
1 change: 1 addition & 0 deletions lib/utils/section_kind.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum SectionKind { livestreams, myCourses, publicCourses }
58 changes: 41 additions & 17 deletions lib/view_models/stream_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ class StreamViewModel extends StateNotifier<StreamState> {
}
}



void updatedDisplayedStreams(List<Tuple2<Stream, String>> allStreams) {
state = state.copyWith(displayedStreams: allStreams);
}

void setUpDisplayedCourses(List<Tuple2<Stream, String>> allStreams) {
updatedDisplayedStreams(
CourseUtils.sortStreams(allStreams, state.selectedFilterOption),
);
}

void updateSelectedFilterOption(
String option,
List<Tuple2<Stream, String>> allStreams,
) {
state = state.copyWith(selectedFilterOption: option);
updatedDisplayedStreams(
CourseUtils.sortStreams(allStreams, state.selectedFilterOption),
);
}

/// This asynchronous function fetches thumbnails for all available streams in the current state.
/// only if there are streams in the current state.
/// It initiates fetching of thumbnails for each stream by invoking `fetchThumbnailForStream`.
Expand All @@ -47,23 +69,25 @@ class StreamViewModel extends StateNotifier<StreamState> {
setUpDisplayedCourses(fetchedStreamsWithThumbnails);
}

void updatedDisplayedStreams(List<Tuple2<Stream, String>> allStreams) {
state = state.copyWith(displayedStreams: allStreams);
}

void setUpDisplayedCourses(List<Tuple2<Stream, String>> allStreams) {
updatedDisplayedStreams(
CourseUtils.sortStreams(allStreams, state.selectedFilterOption),
);
}

void updateSelectedFilterOption(
String option,
List<Tuple2<Stream, String>> allStreams,
) {
state = state.copyWith(selectedFilterOption: option);
updatedDisplayedStreams(
CourseUtils.sortStreams(allStreams, state.selectedFilterOption),
/// This asynchronous function fetches thumbnails for all available live streams in the current state.
/// only if there are live streams in the current state.
/// It initiates fetching of thumbnails for each live stream by invoking `fetchThumbnailForStream`.
Future<void> fetchLiveThumbnails() async {
if (state.liveStreams == null) {
return;
}
var fetchLiveThumbnailTasks = <Future<Tuple2<Stream, String>>>[];
for (var stream in state.liveStreams!) {
fetchLiveThumbnailTasks.add(
fetchStreamThumbnail(stream.id)
.then((thumbnail) => Tuple2(stream, thumbnail)),
);
}
var fetchedStreamsWithThumbnails =
await Future.wait(fetchLiveThumbnailTasks);
state = state.copyWith(
liveStreamsWithThumb: fetchedStreamsWithThumbnails,
isLoading: false,
);
}

Expand Down
Loading
Loading