-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CastIt.Android] Added two blocs to avoid rebuilding the ui in the lists
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
CastIt.Android/lib/application/played_file_item/played_file_item_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:castit/application/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'played_file_item_bloc.freezed.dart'; | ||
part 'played_file_item_event.dart'; | ||
part 'played_file_item_state.dart'; | ||
|
||
class PlayedFileItemBloc extends Bloc<PlayedFileItemEvent, PlayedFileItemState> { | ||
final ServerWsBloc _serverWsBloc; | ||
|
||
PlayedFileItemBloc(this._serverWsBloc) : super(const PlayedFileItemState.notPlaying()) { | ||
_serverWsBloc.fileChanged.stream.listen((event) { | ||
final file = event.item2; | ||
add(PlayedFileItemEvent.playing( | ||
id: file.id, | ||
playListId: file.playListId, | ||
playedPercentage: file.playedPercentage, | ||
fullTotalDuration: file.fullTotalDuration, | ||
)); | ||
}); | ||
} | ||
|
||
@override | ||
Stream<PlayedFileItemState> mapEventToState(PlayedFileItemEvent event) async* { | ||
final s = event.map( | ||
playing: (e) => PlayedFileItemState.playing( | ||
id: e.id, | ||
playListId: e.playListId, | ||
playedPercentage: e.playedPercentage, | ||
fullTotalDuration: e.fullTotalDuration, | ||
), | ||
endReached: (_) => const PlayedFileItemState.notPlaying(), | ||
); | ||
|
||
yield s; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
CastIt.Android/lib/application/played_file_item/played_file_item_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
part of 'played_file_item_bloc.dart'; | ||
|
||
@freezed | ||
class PlayedFileItemEvent with _$PlayedFileItemEvent { | ||
factory PlayedFileItemEvent.playing({ | ||
required int id, | ||
required int playListId, | ||
required double playedPercentage, | ||
required String fullTotalDuration, | ||
}) = _Playing; | ||
|
||
factory PlayedFileItemEvent.endReached() = _EndReached; | ||
} |
13 changes: 13 additions & 0 deletions
13
CastIt.Android/lib/application/played_file_item/played_file_item_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
part of 'played_file_item_bloc.dart'; | ||
|
||
@freezed | ||
class PlayedFileItemState with _$PlayedFileItemState { | ||
const factory PlayedFileItemState.notPlaying() = _NotPlayingState; | ||
|
||
const factory PlayedFileItemState.playing({ | ||
required int id, | ||
required int playListId, | ||
required double playedPercentage, | ||
required String fullTotalDuration, | ||
}) = _LoadedState; | ||
} |
33 changes: 33 additions & 0 deletions
33
CastIt.Android/lib/application/played_play_list_item/played_play_list_item_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:castit/application/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'played_play_list_item_bloc.freezed.dart'; | ||
part 'played_play_list_item_event.dart'; | ||
part 'played_play_list_item_state.dart'; | ||
|
||
class PlayedPlayListItemBloc extends Bloc<PlayedPlayListItemEvent, PlayedPlayListItemState> { | ||
final ServerWsBloc _serverWsBloc; | ||
|
||
PlayedPlayListItemBloc(this._serverWsBloc) : super(const PlayedPlayListItemState.notPlaying()) { | ||
_serverWsBloc.fileLoaded.stream.listen((file) { | ||
add(PlayedPlayListItemEvent.playing(id: file.playListId, totalDuration: file.playListTotalDuration!)); | ||
}); | ||
|
||
_serverWsBloc.fileEndReached.stream.listen((file) { | ||
add(PlayedPlayListItemEvent.endReached()); | ||
}); | ||
} | ||
|
||
@override | ||
Stream<PlayedPlayListItemState> mapEventToState(PlayedPlayListItemEvent event) async* { | ||
final s = event.map( | ||
playing: (e) => PlayedPlayListItemState.playing(id: e.id, totalDuration: e.totalDuration), | ||
endReached: (_) => const PlayedPlayListItemState.notPlaying(), | ||
); | ||
|
||
yield s; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
CastIt.Android/lib/application/played_play_list_item/played_play_list_item_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'played_play_list_item_bloc.dart'; | ||
|
||
@freezed | ||
class PlayedPlayListItemEvent with _$PlayedPlayListItemEvent { | ||
factory PlayedPlayListItemEvent.playing({ | ||
required int id, | ||
required String totalDuration, | ||
}) = _Playing; | ||
|
||
factory PlayedPlayListItemEvent.endReached() = _EndReached; | ||
} |
11 changes: 11 additions & 0 deletions
11
CastIt.Android/lib/application/played_play_list_item/played_play_list_item_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'played_play_list_item_bloc.dart'; | ||
|
||
@freezed | ||
class PlayedPlayListItemState with _$PlayedPlayListItemState { | ||
const factory PlayedPlayListItemState.notPlaying() = _NotPlayingState; | ||
|
||
const factory PlayedPlayListItemState.playing({ | ||
required int id, | ||
required String totalDuration, | ||
}) = _LoadedState; | ||
} |