2021-02-26 16:08:48 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
|
|
|
|
import '../../youtube_explode_dart.dart';
|
|
|
|
|
2021-02-26 16:18:51 +01:00
|
|
|
/// This list contains search videos.
|
2021-02-26 16:08:48 +01:00
|
|
|
class SearchList extends DelegatingList<SearchVideo> {
|
|
|
|
final Stream<SearchVideo> _stream;
|
|
|
|
|
|
|
|
///
|
|
|
|
SearchList._(List<SearchVideo> base, this._stream) : super(base);
|
|
|
|
|
|
|
|
///
|
|
|
|
static Future<SearchList> create(Stream<SearchVideo> stream) async {
|
|
|
|
Stream<SearchVideo> broadcast;
|
|
|
|
broadcast = stream.asBroadcastStream(onCancel: (subscription) {
|
|
|
|
subscription.pause();
|
|
|
|
}, onListen: (subscription) {
|
|
|
|
subscription.resume();
|
|
|
|
});
|
|
|
|
final base = await broadcast.take(20).toList();
|
|
|
|
return SearchList._(base, broadcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
Future<SearchList> nextPage() async {
|
|
|
|
final base = await _stream.take(20).toList();
|
|
|
|
return SearchList._(base, _stream);
|
|
|
|
}
|
|
|
|
}
|