Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Fix continue without and other bugs (#256)
Browse files Browse the repository at this point in the history
* use enum for section kind

* fix the no live stream bug

* separate course section and live stream section

* separate course card and small stream card

* reduce logged in

* fetch live now thumbnails

* fetch live now thumbnails

* fetch live now thumbnails
  • Loading branch information
Sainaamr authored Jan 29, 2024
1 parent 9ae60a0 commit eebf259
Show file tree
Hide file tree
Showing 12 changed files with 550 additions and 448 deletions.
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

0 comments on commit eebf259

Please sign in to comment.