Skip to content

Commit

Permalink
Remove upcoming broadcast section & tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Dec 9, 2024
1 parent 6fb02b3 commit 37b9913
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
1 change: 0 additions & 1 deletion lib/src/model/broadcast/broadcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ part 'broadcast.freezed.dart';

typedef BroadcastList = ({
IList<Broadcast> active,
IList<Broadcast> upcoming,
IList<Broadcast> past,
int? nextPage,
});
Expand Down
1 change: 0 additions & 1 deletion lib/src/model/broadcast/broadcast_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class BroadcastsPaginator extends _$BroadcastsPaginator {
state = AsyncData(
(
active: broadcastList.active,
upcoming: broadcastList.upcoming,
past: broadcastList.past.addAll(broadcastListNewPage.past),
nextPage: broadcastListNewPage.nextPage,
),
Expand Down
2 changes: 0 additions & 2 deletions lib/src/model/broadcast/broadcast_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ BroadcastList _makeBroadcastResponseFromJson(
) {
return (
active: pick(json, 'active').asListOrThrow(_broadcastFromPick).toIList(),
upcoming:
pick(json, 'upcoming').asListOrThrow(_broadcastFromPick).toIList(),
past: pick(json, 'past', 'currentPageResults')
.asListOrThrow(_broadcastFromPick)
.toIList(),
Expand Down
20 changes: 15 additions & 5 deletions lib/src/utils/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ import 'package:image/image.dart' as img;

import 'package:material_color_utilities/material_color_utilities.dart';

typedef ImageColors = ({
int primaryContainer,
int onPrimaryContainer,
int error,
});

/// A worker that calculates the `primaryContainer` color of a remote image.
///
/// The worker is created by calling [ImageColorWorker.spawn], and the computation
/// is run in a separate isolate.
class ImageColorWorker {
final SendPort _commands;
final ReceivePort _responses;
final Map<int, Completer<(int, int)?>> _activeRequests = {};
final Map<int, Completer<ImageColors?>> _activeRequests = {};
int _idCounter = 0;
bool _closed = false;

bool get closed => _closed;

Future<(int, int)?> getImageColors(String url) async {
Future<ImageColors?> getImageColors(String url) async {
if (_closed) throw StateError('Closed');
final completer = Completer<(int, int)?>.sync();
final completer = Completer<ImageColors?>.sync();
final id = _idCounter++;
_activeRequests[id] = completer;
_commands.send((id, url));
Expand Down Expand Up @@ -64,7 +70,7 @@ class ImageColorWorker {
if (response is RemoteError) {
completer.completeError(response);
} else {
completer.complete(response as (int, int));
completer.complete(response as ImageColors);
}

if (_closed && _activeRequests.isEmpty) _responses.close();
Expand Down Expand Up @@ -102,7 +108,11 @@ class ImageColorWorker {
isDark: false,
contrastLevel: 0.0,
);
final colors = (scheme.primaryContainer, scheme.onPrimaryContainer);
final colors = (
primaryContainer: scheme.primaryContainer,
onPrimaryContainer: scheme.onPrimaryContainer,
error: scheme.error,
);
sendPort.send((id, colors));
} catch (e) {
sendPort.send((id, RemoteError(e.toString(), '')));
Expand Down
18 changes: 11 additions & 7 deletions lib/src/view/broadcast/broadcast_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class BroadcastListScreen extends StatelessWidget {
navigationBar: CupertinoNavigationBar(
middle: title,
automaticBackgroundVisibility: false,
backgroundColor: Colors.transparent,
backgroundColor: Styles.cupertinoAppBarColor
.resolveFrom(context)
.withValues(alpha: 0.0),
border: null,
),
child: const _Body(),
Expand Down Expand Up @@ -137,7 +139,6 @@ class _BodyState extends ConsumerState<_Body> {

final sections = [
(context.l10n.broadcastOngoing, broadcasts.value!.active),
(context.l10n.broadcastUpcoming, broadcasts.value!.upcoming),
(context.l10n.broadcastCompleted, broadcasts.value!.past),
];

Expand Down Expand Up @@ -249,6 +250,7 @@ class BroadcastGridItem extends StatefulWidget {
typedef _CardColors = ({
Color primaryContainer,
Color onPrimaryContainer,
Color error,
});
final Map<ImageProvider, _CardColors> _colorsCache = {};

Expand Down Expand Up @@ -283,10 +285,11 @@ class _BroadcastGridItemState extends State<BroadcastGridItem> {
} else if (widget.worker.closed == false) {
final response = await widget.worker.getImageColors(provider.url);
if (response != null) {
final (primaryContainer, onPrimaryContainer) = response;
final (:primaryContainer, :onPrimaryContainer, :error) = response;
final cardColors = (
primaryContainer: Color(primaryContainer),
onPrimaryContainer: Color(onPrimaryContainer),
error: Color(error),
);
_colorsCache[provider] = cardColors;
if (mounted) {
Expand All @@ -310,6 +313,7 @@ class _BroadcastGridItemState extends State<BroadcastGridItem> {
final subTitleColor =
_cardColors?.onPrimaryContainer.withValues(alpha: 0.7) ??
textShade(context, 0.7);
final liveColor = _cardColors?.error ?? LichessColors.red;

return GestureDetector(
onTap: () {
Expand Down Expand Up @@ -351,10 +355,10 @@ class _BroadcastGridItemState extends State<BroadcastGridItem> {
begin: Alignment.center,
end: Alignment.bottomCenter,
colors: [
backgroundColor.withValues(alpha: 0.10),
backgroundColor.withValues(alpha: 0.0),
backgroundColor.withValues(alpha: 1.0),
],
stops: const [0.5, 1.00],
stops: const [0.7, 1.10],
tileMode: TileMode.clamp,
).createShader(bounds);
},
Expand Down Expand Up @@ -401,12 +405,12 @@ class _BroadcastGridItemState extends State<BroadcastGridItem> {
),
const SizedBox(width: 4.0),
if (widget.broadcast.isLive)
const Text(
Text(
'LIVE',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.red,
color: liveColor,
),
overflow: TextOverflow.ellipsis,
)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/watch/watch_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class _BroadcastWidget extends ConsumerWidget {
),
),
children: [
...CombinedIterableView([data.active, data.upcoming, data.past])
...CombinedIterableView([data.active, data.past])
.take(numberOfItems)
.map((broadcast) => _BroadcastTile(broadcast: broadcast)),
],
Expand Down
3 changes: 1 addition & 2 deletions test/model/broadcast/broadcast_repository_test.dart

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/view/broadcast/broadcasts_list_screen_test.dart

Large diffs are not rendered by default.

0 comments on commit 37b9913

Please sign in to comment.