Skip to content

Commit

Permalink
fix notifying
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Nov 13, 2024
1 parent 4b6fb99 commit a23577f
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 123 deletions.
51 changes: 5 additions & 46 deletions lib/common/view/four_images_grid.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import 'dart:typed_data';

import 'package:flutter/material.dart';

class FourImagesGrid extends StatelessWidget {
const FourImagesGrid({
super.key,
required this.images,
this.fit = BoxFit.cover,
});

final Set<Uint8List> images;
final BoxFit fit;
final List<Widget> images;

@override
Widget build(BuildContext context) {
Expand All @@ -20,16 +16,10 @@ class FourImagesGrid extends StatelessWidget {
child: Row(
children: [
Expanded(
child: _Image(
bytes: images.elementAt(0),
fit: fit,
),
child: images.elementAt(0),
),
Expanded(
child: _Image(
bytes: images.elementAt(1),
fit: fit,
),
child: images.elementAt(1),
),
],
),
Expand All @@ -38,16 +28,10 @@ class FourImagesGrid extends StatelessWidget {
child: Row(
children: [
Expanded(
child: _Image(
bytes: images.elementAt(2),
fit: fit,
),
child: images.elementAt(2),
),
Expanded(
child: _Image(
bytes: images.elementAt(3),
fit: fit,
),
child: images.elementAt(3),
),
],
),
Expand All @@ -56,28 +40,3 @@ class FourImagesGrid extends StatelessWidget {
);
}
}

class _Image extends StatelessWidget {
final Uint8List bytes;

const _Image({
required this.bytes,
required this.fit,
});

final BoxFit fit;

@override
Widget build(BuildContext context) {
const quality = FilterQuality.medium;
const height = double.infinity;
const width = double.infinity;
return Image.memory(
bytes,
height: height,
width: width,
fit: fit,
filterQuality: quality,
);
}
}
53 changes: 15 additions & 38 deletions lib/common/view/round_image_container.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';

Expand All @@ -10,11 +8,11 @@ import 'theme.dart';
class RoundImageContainer extends StatelessWidget {
const RoundImageContainer({
super.key,
this.images,
required this.images,
required this.fallBackText,
});

final Set<Uint8List>? images;
final List<Widget> images;
final String fallBackText;

@override
Expand All @@ -27,52 +25,31 @@ class RoundImageContainer extends StatelessWidget {
color: theme.shadowColor.withOpacity(0.4),
);

if (images?.length == 1) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: MemoryImage(images!.first),
fit: BoxFit.fitHeight,
filterQuality: FilterQuality.medium,
),
boxShadow: [
boxShadow,
],
),
);
if (images.length == 1) {
return images.first;
}

if (images?.isNotEmpty == true) {
if (images!.length >= 4) {
if (images.isNotEmpty) {
if (images.length >= 4) {
return Container(
decoration: BoxDecoration(
boxShadow: [
boxShadow,
],
),
child: FourImagesGrid(
images: images!,
images: images,
),
);
} else if (images!.length >= 2) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fitHeight,
image: MemoryImage(images!.first),
} else if (images.length >= 2) {
return Stack(
children: [
images.first,
YaruClip.diagonal(
position: YaruDiagonalClip.bottomLeft,
child: images.elementAt(1),
),
boxShadow: [
boxShadow,
],
),
child: YaruClip.diagonal(
position: YaruDiagonalClip.bottomLeft,
child: Image.memory(
images!.elementAt(1),
fit: BoxFit.fitHeight,
filterQuality: FilterQuality.medium,
),
),
],
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/local_audio/local_audio_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class LocalAudioModel extends SafeChangeNotifier {
}) =>
_service.findLocalCovers(audios: audios, limit: limit);

List<Audio> findUniqueAlbumAudios(List<Audio> audios) =>
_service.findUniqueAlbumAudios(audios);

List<String>? get failedImports => _service.failedImports;

List<String>? findAllAlbums({
Expand Down
17 changes: 11 additions & 6 deletions lib/local_audio/local_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@ class LocalAudioService {
}) {
final images = <Uint8List>{};

final albumAudios = <Audio>[];
for (var audio in audios) {
if (albumAudios.none((a) => a.album == audio.album)) {
albumAudios.add(audio);
}
}
List<Audio> albumAudios = findUniqueAlbumAudios(audios);

for (var audio in albumAudios) {
var uint8list = _localCoverService.get(audio.albumId);
Expand All @@ -182,6 +177,16 @@ class LocalAudioService {
return images;
}

List<Audio> findUniqueAlbumAudios(List<Audio> audios) {
final albumAudios = <Audio>[];
for (var audio in audios) {
if (albumAudios.none((a) => a.album == audio.album)) {
albumAudios.add(audio);
}
}
return albumAudios;
}

LocalSearchResult? search(String? query) {
if (query == null) return null;
if (query.isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion lib/local_audio/local_cover_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LocalCoverModel extends SafeChangeNotifier {
final LocalCoverService _localCoverService;
StreamSubscription<bool>? _propertiesChangedSub;

Map<String, Uint8List?> get store => _localCoverService.store;
int get storeLength => _localCoverService.storeLength;
Uint8List? get(String? albumId) => _localCoverService.get(albumId);

Future<Uint8List?> getCover({
Expand Down
7 changes: 4 additions & 3 deletions lib/local_audio/local_cover_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LocalCoverService {
Stream<bool> get propertiesChanged => _propertiesChangedController.stream;

var _store = <String, Uint8List?>{};
Map<String, Uint8List?> get store => _store;
int get storeLength => _store.length;

Future<Uint8List?> getCover({
required String albumId,
Expand All @@ -28,10 +28,11 @@ class LocalCoverService {
.firstWhereOrNull((e) => e.bytes.isNotEmpty)
?.bytes,
);
_propertiesChangedController.add(true);
if (cover != null) {
_propertiesChangedController.add(true);
}
return cover;
}

return null;
}

Expand Down
10 changes: 3 additions & 7 deletions lib/local_audio/view/artist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import '../../common/view/explore_online_popup.dart';
import '../../common/view/header_bar.dart';
import '../../common/view/icons.dart';
import '../../common/view/like_all_icon.dart';
import '../../common/view/round_image_container.dart';
import '../../common/view/search_button.dart';
import '../../common/view/sliver_audio_page_control_panel.dart';
import '../../common/view/sliver_audio_tile_list.dart';
Expand All @@ -25,6 +24,7 @@ import '../../search/search_type.dart';
import '../local_audio_model.dart';
import 'album_page.dart';
import 'album_view.dart';
import 'artist_round_image_container.dart';
import 'genre_page.dart';

class ArtistPage extends StatelessWidget with WatchItMixin {
Expand Down Expand Up @@ -101,12 +101,8 @@ class ArtistPage extends StatelessWidget with WatchItMixin {
child: AudioPageHeader(
imageRadius: BorderRadius.circular(10000),
title: artistAudios?.firstOrNull?.artist ?? '',
image: RoundImageContainer(
images: artistAudios == null
? null
: model.findLocalCovers(audios: artistAudios!),
fallBackText: pageId,
),
image:
ArtistRoundImageContainer(artistAudios: artistAudios),
subTitle: artistAudios?.firstOrNull?.genre,
label: context.l10n.artist,
onLabelTab: onAlbumTap,
Expand Down
39 changes: 39 additions & 0 deletions lib/local_audio/view/artist_round_image_container.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import '../../common/data/audio.dart';
import '../../common/view/cover_background.dart';
import '../../common/view/round_image_container.dart';
import '../local_audio_model.dart';
import 'local_cover.dart';
import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';

class ArtistRoundImageContainer extends StatelessWidget {
const ArtistRoundImageContainer({
super.key,
required this.artistAudios,
});

final List<Audio>? artistAudios;

@override
Widget build(BuildContext context) {
return RoundImageContainer(
images: artistAudios == null
? []
: di<LocalAudioModel>()
.findUniqueAlbumAudios(artistAudios!)
.where(
(e) => e.albumId != null && e.path != null,
)
.map(
(e) => LocalCover(
albumId: e.albumId!,
path: e.path!,
fallback: const CoverBackground(),
fit: BoxFit.cover,
),
)
.toList(),
fallBackText: artistAudios?.firstOrNull?.artist ?? 'a',
);
}
}
7 changes: 3 additions & 4 deletions lib/local_audio/view/artists_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../local_audio_model.dart';
import 'artist_page.dart';
import 'artist_round_image_container.dart';

class ArtistsView extends StatelessWidget {
const ArtistsView({
Expand Down Expand Up @@ -43,7 +44,6 @@ class ArtistsView extends StatelessWidget {
itemBuilder: (context, index) {
final artistName = artists!.elementAt(index);
final artistAudios = model.findTitlesOfArtist(artistName);
final images = model.findLocalCovers(audios: artistAudios ?? []);

final text = artists!.elementAt(index);

Expand All @@ -70,9 +70,8 @@ class ArtistsView extends StatelessWidget {
SizedBox(
width: double.infinity,
height: double.infinity,
child: RoundImageContainer(
images: images,
fallBackText: text,
child: ArtistRoundImageContainer(
artistAudios: artistAudios,
),
),
ArtistVignette(text: text),
Expand Down
2 changes: 1 addition & 1 deletion lib/local_audio/view/genres_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GenresView extends StatelessWidget {
width: double.infinity,
height: double.infinity,
child: RoundImageContainer(
images: const {},
images: [],
fallBackText: text,
),
),
Expand Down
Loading

0 comments on commit a23577f

Please sign in to comment.