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 2ca44a1
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 119 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,
);
}
}
56 changes: 17 additions & 39 deletions lib/common/view/round_image_container.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import 'dart:typed_data';

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

import '../../extensions/build_context_x.dart';
import 'four_images_grid.dart';
import 'theme.dart';

class RoundImageContainer extends StatelessWidget {
class RoundImageContainer extends StatelessWidget with WatchItMixin {
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 +26,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
19 changes: 16 additions & 3 deletions lib/local_audio/view/artist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../../common/view/adaptive_container.dart';
import '../../common/view/audio_page_header.dart';
import '../../common/view/audio_page_type.dart';
import '../../common/view/avatar_play_button.dart';
import '../../common/view/cover_background.dart';
import '../../common/view/explore_online_popup.dart';
import '../../common/view/header_bar.dart';
import '../../common/view/icons.dart';
Expand All @@ -26,6 +27,7 @@ import '../local_audio_model.dart';
import 'album_page.dart';
import 'album_view.dart';
import 'genre_page.dart';
import 'local_cover.dart';

class ArtistPage extends StatelessWidget with WatchItMixin {
const ArtistPage({
Expand Down Expand Up @@ -102,9 +104,20 @@ class ArtistPage extends StatelessWidget with WatchItMixin {
imageRadius: BorderRadius.circular(10000),
title: artistAudios?.firstOrNull?.artist ?? '',
image: RoundImageContainer(
images: artistAudios == null
? null
: model.findLocalCovers(audios: artistAudios!),
images: model
.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: pageId,
),
subTitle: artistAudios?.firstOrNull?.genre,
Expand Down
20 changes: 17 additions & 3 deletions lib/local_audio/view/artists_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../common/view/cover_background.dart';
import '../../common/view/no_search_result_page.dart';
import '../../common/view/round_image_container.dart';
import '../../common/view/sliver_fill_remaining_progress.dart';
Expand All @@ -11,6 +12,7 @@ import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../local_audio_model.dart';
import 'artist_page.dart';
import 'local_cover.dart';

class ArtistsView extends StatelessWidget {
const ArtistsView({
Expand Down Expand Up @@ -43,14 +45,13 @@ 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);

return YaruSelectableContainer(
selected: false,
onTap: () {
final artist = artistAudios?.firstOrNull?.artist;
final artist = artistAudios.firstOrNull?.artist;
if (artist == null) {
showSnackBar(
context: context,
Expand All @@ -71,7 +72,20 @@ class ArtistsView extends StatelessWidget {
width: double.infinity,
height: double.infinity,
child: RoundImageContainer(
images: images,
images: model
.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: 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 2ca44a1

Please sign in to comment.