Skip to content

Commit

Permalink
Return blue theme on failure loading theme image.
Browse files Browse the repository at this point in the history
Ran code through dart format.
  • Loading branch information
Komodo5197 committed Dec 14, 2023
1 parent 185f0b9 commit 6433dd3
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ class LoadQueueOnStartupSelector extends StatelessWidget {
valueListenable: FinampSettingsHelper.finampSettingsListener,
builder: (_, box, __) {
return SwitchListTile.adaptive(
title:
Text(AppLocalizations.of(context)!.autoloadLastQueueOnStartup),
subtitle: Text(AppLocalizations.of(context)!
.autoloadLastQueueOnStartupSubtitle),
value:
FinampSettingsHelper.finampSettings.autoloadLastQueueOnStartup,
title: Text(AppLocalizations.of(context)!.autoloadLastQueueOnStartup),
subtitle: Text(
AppLocalizations.of(context)!.autoloadLastQueueOnStartupSubtitle),
value: FinampSettingsHelper.finampSettings.autoloadLastQueueOnStartup,
onChanged: (value) =>
FinampSettingsHelper.setAutoloadLastQueueOnStartup(value),
);
Expand Down
16 changes: 11 additions & 5 deletions lib/components/PlayerScreen/queue_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ Future<dynamic> showQueueBottomSheet(BuildContext context) {
builder: (context) {
return Consumer(
builder: (BuildContext context, WidgetRef ref, Widget? child) {
final imageTheme = ref.watch(playerScreenThemeProvider(Theme.of(context).brightness));
final imageTheme =
ref.watch(playerScreenThemeProvider(Theme.of(context).brightness));

return AnimatedTheme(
duration: const Duration(milliseconds: 500),
Expand Down Expand Up @@ -728,8 +729,9 @@ class _CurrentTrackState extends State<CurrentTrack> {
AlbumImage(
item: baseItem,
borderRadius: BorderRadius.zero,
itemsToPrecache:
_queueService.getNextXTracksInQueue(3,reverse: 1).map((e) {
itemsToPrecache: _queueService
.getNextXTracksInQueue(3, reverse: 1)
.map((e) {
final item = e.item.extras?["itemJson"] != null
? jellyfin_models.BaseItemDto.fromJson(
e.item.extras!["itemJson"]
Expand Down Expand Up @@ -1434,13 +1436,17 @@ class PreviousTracksSectionHeader extends SliverPersistentHeaderDelegate {
return Icon(
TablerIcons.chevron_up,
size: 28.0,
color: Theme.of(context).brightness == Brightness.light ? Colors.black : Colors.white,
color: Theme.of(context).brightness == Brightness.light
? Colors.black
: Colors.white,
);
} else {
return Icon(
TablerIcons.chevron_down,
size: 28.0,
color: Theme.of(context).brightness == Brightness.light ? Colors.black : Colors.white,
color: Theme.of(context).brightness == Brightness.light
? Colors.black
: Colors.white,
);
}
}),
Expand Down
7 changes: 2 additions & 5 deletions lib/components/PlayerScreen/song_info.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import 'dart:math';

import 'package:audio_service/audio_service.dart';
import 'package:finamp/models/finamp_models.dart';
import 'package:finamp/services/queue_service.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get_it/get_it.dart';

import '../../models/jellyfin_models.dart' as jellyfin_models;
Expand Down Expand Up @@ -154,7 +150,8 @@ class _PlayerScreenAlbumImage extends StatelessWidget {
// Here we get the next 3 queue items so that we
// can precache them (so that the image is already loaded
// when the next song comes on).
itemsToPrecache: queueService.getNextXTracksInQueue(3,reverse: 1).map((e) {
itemsToPrecache:
queueService.getNextXTracksInQueue(3, reverse: 1).map((e) {
final item = e.item.extras?["itemJson"] != null
? jellyfin_models.BaseItemDto.fromJson(
e.item.extras!["itemJson"] as Map<String, dynamic>)
Expand Down
9 changes: 6 additions & 3 deletions lib/components/QueueRestoreScreen/queue_restore_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ class QueueRestoreTile extends StatelessWidget {
if (info.currentTrack == null) {
track = Future.value(null);
} else if (FinampSettingsHelper.finampSettings.isOffline) {
track = Future.value(downloadsHelper.getDownloadedSong(info.currentTrack!)?.song);
track = Future.value(
downloadsHelper.getDownloadedSong(info.currentTrack!)?.song);
} else {
track = jellyfinApiHelper.getItemById(info.currentTrack!).then((x) => x, onError: (_) => null);
track = jellyfinApiHelper
.getItemById(info.currentTrack!)
.then((x) => x, onError: (_) => null);
}

return ListTile(
Expand Down Expand Up @@ -58,7 +61,7 @@ class QueueRestoreTile extends StatelessWidget {
]) +
[
Text(AppLocalizations.of(context)!
.queueRestoreSubtitle2(info.songCount,remainingSongs))
.queueRestoreSubtitle2(info.songCount, remainingSongs))
])),
trailing: IconButton(
icon: const Icon(Icons.arrow_circle_right_outlined),
Expand Down
35 changes: 21 additions & 14 deletions lib/components/album_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AlbumImage extends ConsumerWidget {
const AlbumImage({
Key? key,
this.item,
this.imageListenable,
this.itemsToPrecache,
this.borderRadius,
this.placeholderBuilder,
Expand All @@ -23,6 +24,8 @@ class AlbumImage extends ConsumerWidget {
/// The item to get an image for.
final BaseItemDto? item;

final ProviderListenable<AsyncValue<ImageProvider?>>? imageListenable;

/// A list of items to precache
final List<BaseItemDto>? itemsToPrecache;

Expand All @@ -36,8 +39,8 @@ class AlbumImage extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final borderRadius = this.borderRadius ?? defaultBorderRadius;

if (item == null || item!.imageId == null) {

assert(item == null || imageListenable == null);
if ((item == null || item!.imageId == null) && imageListenable == null) {
return ClipRRect(
borderRadius: borderRadius,
child: const AspectRatio(
Expand All @@ -64,11 +67,13 @@ class AlbumImage extends ConsumerWidget {
(constraints.maxHeight * mediaQuery.devicePixelRatio).toInt();

return BareAlbumImage(
item: item!,
item: item,
imageListenable: imageListenable,
maxWidth: physicalWidth,
maxHeight: physicalHeight,
itemsToPrecache: itemsToPrecache,
placeholderBuilder: placeholderBuilder ?? BareAlbumImage.defaultPlaceholderBuilder,
placeholderBuilder:
placeholderBuilder ?? BareAlbumImage.defaultPlaceholderBuilder,
);
}),
),
Expand All @@ -80,15 +85,17 @@ class AlbumImage extends ConsumerWidget {
class BareAlbumImage extends ConsumerWidget {
const BareAlbumImage({
Key? key,
required this.item,
this.item,
this.imageListenable,
this.maxWidth,
this.maxHeight,
this.errorBuilder = defaultErrorBuilder,
this.placeholderBuilder = defaultPlaceholderBuilder,
this.itemsToPrecache,
}) : super(key: key);

final BaseItemDto item;
final BaseItemDto? item;
final ProviderListenable<AsyncValue<ImageProvider?>>? imageListenable;
final int? maxWidth;
final int? maxHeight;
final WidgetBuilder placeholderBuilder;
Expand All @@ -107,7 +114,7 @@ class BareAlbumImage extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {

assert(item != null || imageListenable != null);
for (final itemToPrecache in itemsToPrecache ?? []) {
ref.listen(
albumImageProvider(AlbumImageRequest(
Expand All @@ -121,14 +128,14 @@ class BareAlbumImage extends ConsumerWidget {
});
}

AsyncValue<ImageProvider?> image =
ref.watch(albumImageProvider(AlbumImageRequest(
item: item,
maxWidth: maxWidth,
maxHeight: maxHeight,
)));
AsyncValue<ImageProvider?> image = ref.watch(imageListenable ??
albumImageProvider(AlbumImageRequest(
item: item!,
maxWidth: maxWidth,
maxHeight: maxHeight,
)));

if (image.hasValue) {
if (image.hasValue && image.value != null) {
return OctoImage(
image: image.value!,
fit: BoxFit.cover,
Expand Down
4 changes: 2 additions & 2 deletions lib/components/now_playing_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ class NowPlayingBar extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
// BottomNavBar's default elevation is 8 (https://api.flutter.dev/flutter/material/BottomNavigationBar/elevation.html)
final queueService = GetIt.instance<QueueService>();
var imageTheme = ref
.watch(playerScreenThemeProvider(Theme.of(context).brightness));
var imageTheme =
ref.watch(playerScreenThemeProvider(Theme.of(context).brightness));

return Hero(
tag: "nowplaying",
Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class Finamp extends StatelessWidget {
PlaybackHistoryScreen.routeName: (context) =>
const PlaybackHistoryScreen(),
LogsScreen.routeName: (context) => const LogsScreen(),
QueueRestoreScreen.routeName: (context) => const QueueRestoreScreen(),
QueueRestoreScreen.routeName: (context) =>
const QueueRestoreScreen(),
SettingsScreen.routeName: (context) =>
const SettingsScreen(),
TranscodingSettingsScreen.routeName: (context) =>
Expand Down
33 changes: 21 additions & 12 deletions lib/models/finamp_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -821,15 +821,20 @@ class FinampStorableQueueInfo {
required this.source,
});

FinampStorableQueueInfo.fromQueueInfo(FinampQueueInfo info, int? seek):
previousTracks=info.previousTracks.map<String>((track) => track.item.extras?["itemJson"]["Id"]).toList(),
currentTrack=info.currentTrack?.item.extras?["itemJson"]["Id"],
currentTrackSeek=seek,
nextUp=info.nextUp.map<String>((track) => track.item.extras?["itemJson"]["Id"]).toList(),
queue=info.queue.map<String>((track) => track.item.extras?["itemJson"]["Id"]).toList(),
creation=DateTime.now().millisecondsSinceEpoch,
source=info.source
;
FinampStorableQueueInfo.fromQueueInfo(FinampQueueInfo info, int? seek)
: previousTracks = info.previousTracks
.map<String>((track) => track.item.extras?["itemJson"]["Id"])
.toList(),
currentTrack = info.currentTrack?.item.extras?["itemJson"]["Id"],
currentTrackSeek = seek,
nextUp = info.nextUp
.map<String>((track) => track.item.extras?["itemJson"]["Id"])
.toList(),
queue = info.queue
.map<String>((track) => track.item.extras?["itemJson"]["Id"])
.toList(),
creation = DateTime.now().millisecondsSinceEpoch,
source = info.source;

@HiveField(0)
List<String> previousTracks;
Expand All @@ -853,12 +858,16 @@ class FinampStorableQueueInfo {
@HiveField(6)
QueueItemSource? source;

String toString(){
@override
String toString() {
return "previous:$previousTracks current:$currentTrack seek:$currentTrackSeek next:$nextUp queue:$queue";
}

int get songCount{
return previousTracks.length + ((currentTrack == null)?0:1) + nextUp.length + queue.length;
int get songCount {
return previousTracks.length +
((currentTrack == null) ? 0 : 1) +
nextUp.length +
queue.length;
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/screens/music_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class _MusicScreenState extends State<MusicScreen>

@override
Widget build(BuildContext context) {
_queueService.performInitialQueueLoad().catchError((x) => errorSnackbar(x,context));
_queueService
.performInitialQueueLoad()
.catchError((x) => errorSnackbar(x, context));
if (_tabController == null) {
_buildTabController();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/player_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class PlayerScreen extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final imageTheme = ref.watch(playerScreenThemeProvider(Theme.of(context).brightness));
final imageTheme =
ref.watch(playerScreenThemeProvider(Theme.of(context).brightness));

return AnimatedTheme(
duration: const Duration(milliseconds: 500),
Expand Down
22 changes: 13 additions & 9 deletions lib/services/album_image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ class AlbumImageRequest {
final int? maxHeight;

@override
bool operator ==(Object other){
return other is AlbumImageRequest && other.maxHeight == maxHeight && other.maxWidth == maxWidth && other.item.id == item.id;
bool operator ==(Object other) {
return other is AlbumImageRequest &&
other.maxHeight == maxHeight &&
other.maxWidth == maxWidth &&
other.item.id == item.id;
}

@override
int get hashCode => Object.hash(item.id, maxHeight, maxWidth);
}

final AutoDisposeFutureProviderFamily<ImageProvider?, AlbumImageRequest>
albumImageProvider =
FutureProvider.autoDispose.family<ImageProvider?, AlbumImageRequest>(
(ref, request) async {
albumImageProvider = FutureProvider.autoDispose
.family<ImageProvider?, AlbumImageRequest>((ref, request) async {
if (request.item.imageId == null) {
return null;
}
Expand Down Expand Up @@ -67,8 +69,10 @@ final AutoDisposeFutureProviderFamily<ImageProvider?, AlbumImageRequest>
// If we've got this far, the download image has failed to verify.
// We recurse, which will either return a NetworkImage or an error depending
// on if the app is offline.
return ref.read(albumImageProvider(AlbumImageRequest(
item: request.item,
maxWidth: request.maxWidth,
maxHeight: request.maxHeight))).value;
return ref
.read(albumImageProvider(AlbumImageRequest(
item: request.item,
maxWidth: request.maxWidth,
maxHeight: request.maxHeight)))
.value;
});
10 changes: 6 additions & 4 deletions lib/services/current_album_image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'album_image_provider.dart';

/// Provider to handle syncing up the current playing item's image provider.
/// Used on the player screen to sync up loading the blurred background.
final currentAlbumImageProvider = FutureProvider.autoDispose<ImageProvider?>((ref) async {
final currentTrack = ref.watch(currentSongProvider.select((data) => data.value?.item));
final currentAlbumImageProvider =
FutureProvider<ImageProvider?>((ref) async {
final currentTrack =
ref.watch(currentSongProvider.select((data) => data.value?.item));
if (currentTrack != null) {
final currentTrackBaseItem = currentTrack.extras?["itemJson"] != null
? BaseItemDto.fromJson(
Expand All @@ -18,8 +20,8 @@ final currentAlbumImageProvider = FutureProvider.autoDispose<ImageProvider?>((re
if (currentTrackBaseItem != null) {
final request = AlbumImageRequest(
item: currentTrackBaseItem,
maxWidth: 100,
maxHeight: 100,
maxHeight: 300,
maxWidth: 300,
);
return ref.read(albumImageProvider(request).future);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/services/finamp_settings_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ class FinampSettingsHelper {
.put("FinampSettings", finampSettingsTemp);
}

static void setAutoloadLastQueueOnStartup(
bool autoloadLastQueueOnStartup) {
static void setAutoloadLastQueueOnStartup(bool autoloadLastQueueOnStartup) {
FinampSettings finampSettingsTemp = finampSettings;
finampSettingsTemp.autoloadLastQueueOnStartup =
autoloadLastQueueOnStartup;
finampSettingsTemp.autoloadLastQueueOnStartup = autoloadLastQueueOnStartup;
Hive.box<FinampSettings>("FinampSettings")
.put("FinampSettings", finampSettingsTemp);
}
Expand Down
Loading

0 comments on commit 6433dd3

Please sign in to comment.