mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 09:09:29 +01:00
Compare commits
3 Commits
ee2a276f2f
...
aaab1d1278
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaab1d1278 | ||
|
|
42ff02f88e | ||
|
|
d18ca13f48 |
@ -2,32 +2,66 @@
|
||||
import { SubsonicClient } from "./util/subsonic.ts";
|
||||
import { sleep } from "./util/util.ts";
|
||||
|
||||
async function getArtistId(
|
||||
client: SubsonicClient,
|
||||
artist: string,
|
||||
): Promise<string> {
|
||||
const { xml } = await client.get("getArtists");
|
||||
|
||||
return xml.querySelector(
|
||||
`artist[name='${artist.replaceAll("'", "\\'")}']`,
|
||||
)?.id!;
|
||||
}
|
||||
|
||||
async function getAlbumId(
|
||||
client: SubsonicClient,
|
||||
album: string,
|
||||
): Promise<string> {
|
||||
const { xml } = await client.get("getAlbumList2", [
|
||||
["type", "newest"],
|
||||
]);
|
||||
|
||||
return xml.querySelector(
|
||||
`album[name='${album.replaceAll("'", "\\'")}']`,
|
||||
)?.id!;
|
||||
}
|
||||
|
||||
async function getSongId(
|
||||
client: SubsonicClient,
|
||||
album: string,
|
||||
track: number,
|
||||
): Promise<string> {
|
||||
const { xml: albumsXml } = await client.get("getAlbumList2", [
|
||||
["type", "newest"],
|
||||
]);
|
||||
const albumId = albumsXml.querySelector(
|
||||
`album[name='${album.replaceAll("'", "\\'")}']`,
|
||||
)?.id;
|
||||
const albumId = await getAlbumId(client, album);
|
||||
|
||||
const { xml: songsXml } = await client.get("getAlbum", [["id", albumId!]]);
|
||||
return songsXml.querySelector(`song[track='${track}']`)?.id!;
|
||||
const { xml } = await client.get("getAlbum", [["id", albumId!]]);
|
||||
return xml.querySelector(`song[track='${track}']`)?.id!;
|
||||
}
|
||||
|
||||
async function scrobbleTrack(
|
||||
client: SubsonicClient,
|
||||
songId: string,
|
||||
album: string,
|
||||
track: number,
|
||||
) {
|
||||
const songId = await getSongId(client, album, track);
|
||||
|
||||
await client.get("scrobble", [
|
||||
["id", songId!],
|
||||
["submission", "true"],
|
||||
]);
|
||||
}
|
||||
|
||||
async function starAlbum(client: SubsonicClient, album: string) {
|
||||
const albumId = await getAlbumId(client, album);
|
||||
|
||||
await client.get("star", [["albumId", albumId]]);
|
||||
}
|
||||
|
||||
async function starArtist(client: SubsonicClient, artist: string) {
|
||||
const artistId = await getArtistId(client, artist);
|
||||
|
||||
await client.get("star", [["artistId", artistId]]);
|
||||
}
|
||||
|
||||
async function createPlaylist(
|
||||
client: SubsonicClient,
|
||||
name: string,
|
||||
@ -44,17 +78,11 @@ async function createPlaylist(
|
||||
}
|
||||
|
||||
async function setupTestData(client: SubsonicClient) {
|
||||
await scrobbleTrack(
|
||||
client,
|
||||
await getSongId(client, "Retroconnaissance EP", 1),
|
||||
);
|
||||
await scrobbleTrack(client, "Retroconnaissance EP", 1);
|
||||
await sleep(1_000);
|
||||
await scrobbleTrack(
|
||||
client,
|
||||
await getSongId(client, "Retroconnaissance EP", 2),
|
||||
);
|
||||
await scrobbleTrack(client, "Retroconnaissance EP", 2);
|
||||
await sleep(1_000);
|
||||
await scrobbleTrack(client, await getSongId(client, "Kosmonaut", 1));
|
||||
await scrobbleTrack(client, "Kosmonaut", 1);
|
||||
|
||||
await createPlaylist(client, "Playlist 1", [
|
||||
{ album: "Retroconnaissance EP", track: 2 },
|
||||
@ -65,6 +93,9 @@ async function setupTestData(client: SubsonicClient) {
|
||||
{ album: "I Don't Know What I'm Doing", track: 10 },
|
||||
{ album: "I Don't Know What I'm Doing", track: 11 },
|
||||
]);
|
||||
|
||||
await starAlbum(client, "Kosmonaut");
|
||||
await starArtist(client, "Ugress");
|
||||
}
|
||||
|
||||
async function setupNavidrome() {
|
||||
|
||||
@ -10,7 +10,7 @@ import '../state/database.dart';
|
||||
import '../state/settings.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 30;
|
||||
const kPageSize = 60;
|
||||
|
||||
class AlbumsGrid extends HookConsumerWidget {
|
||||
const AlbumsGrid({super.key});
|
||||
|
||||
81
lib/app/lists/artists_list.dart
Normal file
81
lib/app/lists/artists_list.dart
Normal file
@ -0,0 +1,81 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
|
||||
import '../../sources/models.dart';
|
||||
import '../hooks/use_paging_controller.dart';
|
||||
import '../state/database.dart';
|
||||
import '../state/settings.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 30;
|
||||
|
||||
typedef _ArtistItem = ({Artist artist, int? albumCount});
|
||||
|
||||
class ArtistsList extends HookConsumerWidget {
|
||||
const ArtistsList({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final db = ref.watch(databaseProvider);
|
||||
final sourceId = ref.watch(sourceIdProvider);
|
||||
|
||||
final controller = usePagingController<int, _ArtistItem>(
|
||||
getNextPageKey: (state) =>
|
||||
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
||||
fetchPage: (pageKey) async {
|
||||
final albumCount = db.albums.id.count();
|
||||
|
||||
final query =
|
||||
db.artists.select().join([
|
||||
leftOuterJoin(
|
||||
db.albums,
|
||||
db.albums.artistId.equalsExp(db.artists.id),
|
||||
),
|
||||
])
|
||||
..addColumns([albumCount])
|
||||
..where(
|
||||
db.artists.sourceId.equals(sourceId) &
|
||||
db.albums.sourceId.equals(sourceId),
|
||||
)
|
||||
..groupBy([db.artists.sourceId, db.artists.id])
|
||||
..orderBy([OrderingTerm.asc(db.artists.name)])
|
||||
..limit(kPageSize, offset: (pageKey - 1) * kPageSize);
|
||||
|
||||
return (await query.get())
|
||||
.map(
|
||||
(row) => (
|
||||
artist: row.readTable(db.artists),
|
||||
albumCount: row.read(albumCount),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
},
|
||||
);
|
||||
|
||||
return PagingListener(
|
||||
controller: controller,
|
||||
builder: (context, state, fetchNextPage) {
|
||||
return PagedSliverList(
|
||||
state: state,
|
||||
fetchNextPage: fetchNextPage,
|
||||
builderDelegate: PagedChildBuilderDelegate<_ArtistItem>(
|
||||
itemBuilder: (context, item, index) {
|
||||
final (:artist, :albumCount) = item;
|
||||
|
||||
return ArtistListTile(
|
||||
artist: artist,
|
||||
albumCount: albumCount,
|
||||
onTap: () async {
|
||||
context.push('/artist/${artist.id}');
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,3 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
@ -33,19 +32,26 @@ class AlbumGridTile extends HookConsumerWidget {
|
||||
}
|
||||
|
||||
class ArtistListTile extends StatelessWidget {
|
||||
const ArtistListTile({super.key});
|
||||
const ArtistListTile({
|
||||
super.key,
|
||||
required this.artist,
|
||||
this.albumCount,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
final Artist artist;
|
||||
final int? albumCount;
|
||||
final void Function()? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: CircleClip(
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: 'https://placehold.net/400x400.png',
|
||||
placeholder: (context, url) => CircularProgressIndicator(),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
),
|
||||
child: CoverArtImage(coverArt: artist.coverArt),
|
||||
),
|
||||
title: Text('Some Artist'),
|
||||
title: Text(artist.name),
|
||||
subtitle: albumCount != null ? Text('$albumCount albums') : null,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
|
||||
import '../lists/albums_grid.dart';
|
||||
import '../lists/artists_list.dart';
|
||||
import '../state/services.dart';
|
||||
import '../util/custom_scroll_fix.dart';
|
||||
|
||||
@ -210,7 +210,7 @@ class _NewWidgetState extends State<NewWidget>
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
sliver: AlbumsGrid(),
|
||||
sliver: ArtistsList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../services/sync_services.dart';
|
||||
import '../../services/sync_service.dart';
|
||||
import 'database.dart';
|
||||
import 'settings.dart';
|
||||
import 'source.dart';
|
||||
|
||||
@ -119,14 +119,14 @@ class CustomScrollController extends ScrollController {
|
||||
ScrollContext context,
|
||||
ScrollPosition? oldPosition,
|
||||
) {
|
||||
debugPrint('$debugLabel-createScrollPosition: $isActive');
|
||||
// debugPrint('$debugLabel-createScrollPosition: $isActive');
|
||||
|
||||
return parent.createScrollPosition(physics, context, oldPosition);
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(ScrollPosition position) {
|
||||
debugPrint('$debugLabel-attach: $isActive');
|
||||
// debugPrint('$debugLabel-attach: $isActive');
|
||||
|
||||
super.attach(position);
|
||||
if (isActive && !parent.positions.contains(position)) {
|
||||
@ -136,7 +136,7 @@ class CustomScrollController extends ScrollController {
|
||||
|
||||
@override
|
||||
void detach(ScrollPosition position) {
|
||||
debugPrint('$debugLabel-detach: $isActive');
|
||||
// debugPrint('$debugLabel-detach: $isActive');
|
||||
|
||||
if (parent.positions.contains(position)) {
|
||||
parent.detach(position);
|
||||
@ -146,7 +146,7 @@ class CustomScrollController extends ScrollController {
|
||||
}
|
||||
|
||||
void forceDetach() {
|
||||
debugPrint('$debugLabel-forceDetach: $isActive');
|
||||
// debugPrint('$debugLabel-forceDetach: $isActive');
|
||||
|
||||
for (final position in positions) {
|
||||
if (parent.positions.contains(position)) {
|
||||
@ -156,7 +156,7 @@ class CustomScrollController extends ScrollController {
|
||||
}
|
||||
|
||||
void forceAttach() {
|
||||
debugPrint('$debugLabel-forceAttach: $isActive');
|
||||
// debugPrint('$debugLabel-forceAttach: $isActive');
|
||||
|
||||
for (final position in positions) {
|
||||
if (!parent.positions.contains(position)) {
|
||||
@ -167,7 +167,7 @@ class CustomScrollController extends ScrollController {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
debugPrint('$debugLabel-dispose: $isActive');
|
||||
// debugPrint('$debugLabel-dispose: $isActive');
|
||||
|
||||
forceDetach();
|
||||
super.dispose();
|
||||
|
||||
@ -437,6 +437,7 @@ extension ArtistToDb on models.Artist {
|
||||
id: id,
|
||||
name: name,
|
||||
starred: Value(starred),
|
||||
coverArt: Value(coverArt),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -708,8 +708,19 @@ class Artists extends Table with TableInfo<Artists, models.Artist> {
|
||||
requiredDuringInsert: false,
|
||||
$customConstraints: '',
|
||||
);
|
||||
static const VerificationMeta _coverArtMeta = const VerificationMeta(
|
||||
'coverArt',
|
||||
);
|
||||
late final GeneratedColumn<String> coverArt = GeneratedColumn<String>(
|
||||
'cover_art',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
$customConstraints: '',
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [sourceId, id, name, starred];
|
||||
List<GeneratedColumn> get $columns => [sourceId, id, name, starred, coverArt];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
@ -749,6 +760,12 @@ class Artists extends Table with TableInfo<Artists, models.Artist> {
|
||||
starred.isAcceptableOrUnknown(data['starred']!, _starredMeta),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('cover_art')) {
|
||||
context.handle(
|
||||
_coverArtMeta,
|
||||
coverArt.isAcceptableOrUnknown(data['cover_art']!, _coverArtMeta),
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -770,6 +787,10 @@ class Artists extends Table with TableInfo<Artists, models.Artist> {
|
||||
DriftSqlType.dateTime,
|
||||
data['${effectivePrefix}starred'],
|
||||
),
|
||||
coverArt: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}cover_art'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -792,12 +813,14 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
final Value<String> id;
|
||||
final Value<String> name;
|
||||
final Value<DateTime?> starred;
|
||||
final Value<String?> coverArt;
|
||||
final Value<int> rowid;
|
||||
const ArtistsCompanion({
|
||||
this.sourceId = const Value.absent(),
|
||||
this.id = const Value.absent(),
|
||||
this.name = const Value.absent(),
|
||||
this.starred = const Value.absent(),
|
||||
this.coverArt = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
ArtistsCompanion.insert({
|
||||
@ -805,6 +828,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
required String id,
|
||||
required String name,
|
||||
this.starred = const Value.absent(),
|
||||
this.coverArt = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : sourceId = Value(sourceId),
|
||||
id = Value(id),
|
||||
@ -814,6 +838,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
Expression<String>? id,
|
||||
Expression<String>? name,
|
||||
Expression<DateTime>? starred,
|
||||
Expression<String>? coverArt,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
@ -821,6 +846,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
if (id != null) 'id': id,
|
||||
if (name != null) 'name': name,
|
||||
if (starred != null) 'starred': starred,
|
||||
if (coverArt != null) 'cover_art': coverArt,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
@ -830,6 +856,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
Value<String>? id,
|
||||
Value<String>? name,
|
||||
Value<DateTime?>? starred,
|
||||
Value<String?>? coverArt,
|
||||
Value<int>? rowid,
|
||||
}) {
|
||||
return ArtistsCompanion(
|
||||
@ -837,6 +864,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
starred: starred ?? this.starred,
|
||||
coverArt: coverArt ?? this.coverArt,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
@ -856,6 +884,9 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
if (starred.present) {
|
||||
map['starred'] = Variable<DateTime>(starred.value);
|
||||
}
|
||||
if (coverArt.present) {
|
||||
map['cover_art'] = Variable<String>(coverArt.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
@ -869,6 +900,7 @@ class ArtistsCompanion extends UpdateCompanion<models.Artist> {
|
||||
..write('id: $id, ')
|
||||
..write('name: $name, ')
|
||||
..write('starred: $starred, ')
|
||||
..write('coverArt: $coverArt, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
@ -2864,6 +2896,7 @@ typedef $ArtistsCreateCompanionBuilder =
|
||||
required String id,
|
||||
required String name,
|
||||
Value<DateTime?> starred,
|
||||
Value<String?> coverArt,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $ArtistsUpdateCompanionBuilder =
|
||||
@ -2872,6 +2905,7 @@ typedef $ArtistsUpdateCompanionBuilder =
|
||||
Value<String> id,
|
||||
Value<String> name,
|
||||
Value<DateTime?> starred,
|
||||
Value<String?> coverArt,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
@ -2902,6 +2936,11 @@ class $ArtistsFilterComposer extends Composer<_$SubtracksDatabase, Artists> {
|
||||
column: $table.starred,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get coverArt => $composableBuilder(
|
||||
column: $table.coverArt,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $ArtistsOrderingComposer extends Composer<_$SubtracksDatabase, Artists> {
|
||||
@ -2931,6 +2970,11 @@ class $ArtistsOrderingComposer extends Composer<_$SubtracksDatabase, Artists> {
|
||||
column: $table.starred,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get coverArt => $composableBuilder(
|
||||
column: $table.coverArt,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $ArtistsAnnotationComposer
|
||||
@ -2953,6 +2997,9 @@ class $ArtistsAnnotationComposer
|
||||
|
||||
GeneratedColumn<DateTime> get starred =>
|
||||
$composableBuilder(column: $table.starred, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get coverArt =>
|
||||
$composableBuilder(column: $table.coverArt, builder: (column) => column);
|
||||
}
|
||||
|
||||
class $ArtistsTableManager
|
||||
@ -2990,12 +3037,14 @@ class $ArtistsTableManager
|
||||
Value<String> id = const Value.absent(),
|
||||
Value<String> name = const Value.absent(),
|
||||
Value<DateTime?> starred = const Value.absent(),
|
||||
Value<String?> coverArt = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => ArtistsCompanion(
|
||||
sourceId: sourceId,
|
||||
id: id,
|
||||
name: name,
|
||||
starred: starred,
|
||||
coverArt: coverArt,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback:
|
||||
@ -3004,12 +3053,14 @@ class $ArtistsTableManager
|
||||
required String id,
|
||||
required String name,
|
||||
Value<DateTime?> starred = const Value.absent(),
|
||||
Value<String?> coverArt = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => ArtistsCompanion.insert(
|
||||
sourceId: sourceId,
|
||||
id: id,
|
||||
name: name,
|
||||
starred: starred,
|
||||
coverArt: coverArt,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
|
||||
@ -65,6 +65,7 @@ CREATE TABLE artists(
|
||||
id TEXT NOT NULL,
|
||||
name TEXT NOT NULL COLLATE NOCASE,
|
||||
starred DATETIME,
|
||||
cover_art TEXT,
|
||||
PRIMARY KEY (source_id, id),
|
||||
FOREIGN KEY (source_id) REFERENCES sources (id) ON DELETE CASCADE
|
||||
) WITH Artist;
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:octo_image/octo_image.dart';
|
||||
|
||||
import '../app/state/settings.dart';
|
||||
import '../app/state/source.dart';
|
||||
|
||||
class CoverArtImage extends HookConsumerWidget {
|
||||
@ -20,30 +19,39 @@ class CoverArtImage extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final source = ref.watch(sourceProvider);
|
||||
final sourceId = ref.watch(sourceIdProvider);
|
||||
|
||||
final imageProviderKeys = [source, coverArt, thumbnail];
|
||||
final buildImageProvider = useCallback(
|
||||
() => CachedNetworkImageProvider(
|
||||
coverArt != null
|
||||
? source.coverArtUri(coverArt!, thumbnail: thumbnail).toString()
|
||||
: 'https://placehold.net/400x400.png',
|
||||
),
|
||||
imageProviderKeys,
|
||||
final imageUrl = coverArt != null
|
||||
? source.coverArtUri(coverArt!, thumbnail: thumbnail).toString()
|
||||
: 'https://placehold.net/400x400.png';
|
||||
|
||||
return BaseImage(
|
||||
imageUrl: imageUrl,
|
||||
// can't use the URL because of token auth, which is a cache-buster
|
||||
cacheKey: '$sourceId$coverArt$thumbnail',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final imageProvider = useState(buildImageProvider());
|
||||
useEffect(
|
||||
() {
|
||||
imageProvider.value = buildImageProvider();
|
||||
return;
|
||||
},
|
||||
imageProviderKeys,
|
||||
);
|
||||
class BaseImage extends HookConsumerWidget {
|
||||
const BaseImage({
|
||||
super.key,
|
||||
required this.imageUrl,
|
||||
this.cacheKey,
|
||||
this.fit = BoxFit.cover,
|
||||
});
|
||||
|
||||
return OctoImage(
|
||||
image: imageProvider.value,
|
||||
placeholderBuilder: (context) => Icon(Symbols.album_rounded),
|
||||
errorBuilder: (context, error, trace) => Icon(Icons.error),
|
||||
final String imageUrl;
|
||||
final String? cacheKey;
|
||||
final BoxFit fit;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: imageUrl,
|
||||
cacheKey: cacheKey,
|
||||
placeholder: (context, url) => Icon(Symbols.cached_rounded),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fit: BoxFit.cover,
|
||||
fadeOutDuration: Duration(milliseconds: 100),
|
||||
fadeInDuration: Duration(milliseconds: 200),
|
||||
|
||||
@ -22,9 +22,12 @@ void main() async {
|
||||
.insertOnConflictUpdate(
|
||||
SubsonicSettingsCompanion.insert(
|
||||
sourceId: Value(1),
|
||||
address: Uri.parse('http://10.0.2.2:4533'),
|
||||
username: 'admin',
|
||||
password: 'password',
|
||||
address: Uri.parse('http://demo.subsonic.org'),
|
||||
username: 'guest1',
|
||||
password: 'guest',
|
||||
// address: Uri.parse('http://10.0.2.2:4533'),
|
||||
// username: 'admin',
|
||||
// password: 'password',
|
||||
useTokenAuth: Value(true),
|
||||
),
|
||||
);
|
||||
|
||||
@ -8,8 +8,7 @@ abstract class Artist with _$Artist {
|
||||
required String id,
|
||||
required String name,
|
||||
DateTime? starred,
|
||||
Uri? smallImage,
|
||||
Uri? largeImage,
|
||||
String? coverArt,
|
||||
}) = _Artist;
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$Artist {
|
||||
|
||||
String get id; String get name; DateTime? get starred; Uri? get smallImage; Uri? get largeImage;
|
||||
String get id; String get name; DateTime? get starred; String? get coverArt;
|
||||
/// Create a copy of Artist
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@ -25,16 +25,16 @@ $ArtistCopyWith<Artist> get copyWith => _$ArtistCopyWithImpl<Artist>(this as Art
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is Artist&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.starred, starred) || other.starred == starred)&&(identical(other.smallImage, smallImage) || other.smallImage == smallImage)&&(identical(other.largeImage, largeImage) || other.largeImage == largeImage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is Artist&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.starred, starred) || other.starred == starred)&&(identical(other.coverArt, coverArt) || other.coverArt == coverArt));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,starred,smallImage,largeImage);
|
||||
int get hashCode => Object.hash(runtimeType,id,name,starred,coverArt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Artist(id: $id, name: $name, starred: $starred, smallImage: $smallImage, largeImage: $largeImage)';
|
||||
return 'Artist(id: $id, name: $name, starred: $starred, coverArt: $coverArt)';
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ abstract mixin class $ArtistCopyWith<$Res> {
|
||||
factory $ArtistCopyWith(Artist value, $Res Function(Artist) _then) = _$ArtistCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String id, String name, DateTime? starred, Uri? smallImage, Uri? largeImage
|
||||
String id, String name, DateTime? starred, String? coverArt
|
||||
});
|
||||
|
||||
|
||||
@ -62,14 +62,13 @@ class _$ArtistCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of Artist
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? starred = freezed,Object? smallImage = freezed,Object? largeImage = freezed,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? starred = freezed,Object? coverArt = freezed,}) {
|
||||
return _then(_self.copyWith(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,starred: freezed == starred ? _self.starred : starred // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,smallImage: freezed == smallImage ? _self.smallImage : smallImage // ignore: cast_nullable_to_non_nullable
|
||||
as Uri?,largeImage: freezed == largeImage ? _self.largeImage : largeImage // ignore: cast_nullable_to_non_nullable
|
||||
as Uri?,
|
||||
as DateTime?,coverArt: freezed == coverArt ? _self.coverArt : coverArt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
@ -154,10 +153,10 @@ return $default(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String name, DateTime? starred, Uri? smallImage, Uri? largeImage)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String name, DateTime? starred, String? coverArt)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Artist() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeImage);case _:
|
||||
return $default(_that.id,_that.name,_that.starred,_that.coverArt);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
@ -175,10 +174,10 @@ return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeIm
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String name, DateTime? starred, Uri? smallImage, Uri? largeImage) $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String name, DateTime? starred, String? coverArt) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Artist():
|
||||
return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeImage);case _:
|
||||
return $default(_that.id,_that.name,_that.starred,_that.coverArt);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
@ -195,10 +194,10 @@ return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeIm
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String name, DateTime? starred, Uri? smallImage, Uri? largeImage)? $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String name, DateTime? starred, String? coverArt)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Artist() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeImage);case _:
|
||||
return $default(_that.id,_that.name,_that.starred,_that.coverArt);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
@ -210,14 +209,13 @@ return $default(_that.id,_that.name,_that.starred,_that.smallImage,_that.largeIm
|
||||
|
||||
|
||||
class _Artist implements Artist {
|
||||
const _Artist({required this.id, required this.name, this.starred, this.smallImage, this.largeImage});
|
||||
const _Artist({required this.id, required this.name, this.starred, this.coverArt});
|
||||
|
||||
|
||||
@override final String id;
|
||||
@override final String name;
|
||||
@override final DateTime? starred;
|
||||
@override final Uri? smallImage;
|
||||
@override final Uri? largeImage;
|
||||
@override final String? coverArt;
|
||||
|
||||
/// Create a copy of Artist
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@ -229,16 +227,16 @@ _$ArtistCopyWith<_Artist> get copyWith => __$ArtistCopyWithImpl<_Artist>(this, _
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Artist&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.starred, starred) || other.starred == starred)&&(identical(other.smallImage, smallImage) || other.smallImage == smallImage)&&(identical(other.largeImage, largeImage) || other.largeImage == largeImage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Artist&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.starred, starred) || other.starred == starred)&&(identical(other.coverArt, coverArt) || other.coverArt == coverArt));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,starred,smallImage,largeImage);
|
||||
int get hashCode => Object.hash(runtimeType,id,name,starred,coverArt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Artist(id: $id, name: $name, starred: $starred, smallImage: $smallImage, largeImage: $largeImage)';
|
||||
return 'Artist(id: $id, name: $name, starred: $starred, coverArt: $coverArt)';
|
||||
}
|
||||
|
||||
|
||||
@ -249,7 +247,7 @@ abstract mixin class _$ArtistCopyWith<$Res> implements $ArtistCopyWith<$Res> {
|
||||
factory _$ArtistCopyWith(_Artist value, $Res Function(_Artist) _then) = __$ArtistCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String id, String name, DateTime? starred, Uri? smallImage, Uri? largeImage
|
||||
String id, String name, DateTime? starred, String? coverArt
|
||||
});
|
||||
|
||||
|
||||
@ -266,14 +264,13 @@ class __$ArtistCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of Artist
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? starred = freezed,Object? smallImage = freezed,Object? largeImage = freezed,}) {
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? starred = freezed,Object? coverArt = freezed,}) {
|
||||
return _then(_Artist(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,starred: freezed == starred ? _self.starred : starred // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,smallImage: freezed == smallImage ? _self.smallImage : smallImage // ignore: cast_nullable_to_non_nullable
|
||||
as Uri?,largeImage: freezed == largeImage ? _self.largeImage : largeImage // ignore: cast_nullable_to_non_nullable
|
||||
as Uri?,
|
||||
as DateTime?,coverArt: freezed == coverArt ? _self.coverArt : coverArt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -2,12 +2,11 @@ import 'package:xml/xml.dart';
|
||||
|
||||
import '../models.dart';
|
||||
|
||||
Artist mapArtist(XmlElement e, XmlElement? info) => Artist(
|
||||
Artist mapArtist(XmlElement e) => Artist(
|
||||
id: e.getAttribute('id')!,
|
||||
name: e.getAttribute('name')!,
|
||||
starred: DateTime.tryParse(e.getAttribute('starred').toString()),
|
||||
smallImage: Uri.tryParse(info?.getElement('smallImageUrl')?.innerText ?? ''),
|
||||
largeImage: Uri.tryParse(info?.getElement('largeImageUrl')?.innerText ?? ''),
|
||||
coverArt: e.getAttribute('coverArt'),
|
||||
);
|
||||
|
||||
Album mapAlbum(
|
||||
|
||||
@ -42,19 +42,13 @@ class SubsonicSource implements MusicSource {
|
||||
|
||||
@override
|
||||
Stream<Artist> allArtists() async* {
|
||||
final getArtistsRes = await _pool.withResource(
|
||||
final res = await _pool.withResource(
|
||||
() => client.get('getArtists'),
|
||||
);
|
||||
|
||||
yield* _pool.forEach(getArtistsRes.xml.findAllElements('artist'), (
|
||||
artist,
|
||||
) async {
|
||||
final res = await client.get('getArtistInfo2', {
|
||||
'id': artist.getAttribute('id')!,
|
||||
});
|
||||
|
||||
return mapArtist(artist, res.xml.getElement('artistInfo2'));
|
||||
});
|
||||
yield* Stream.fromIterable(
|
||||
res.xml.findAllElements('artist').map(mapArtist),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import 'package:subtracks/database/database.dart';
|
||||
import 'package:subtracks/services/sync_services.dart';
|
||||
import 'package:subtracks/services/sync_service.dart';
|
||||
import 'package:subtracks/sources/subsonic/source.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import 'package:test/test.dart';
|
||||
import '../util/subsonic.dart';
|
||||
|
||||
void main() {
|
||||
groupByTestServer((client) {
|
||||
groupByTestServer((server, client) {
|
||||
late SubsonicSource source;
|
||||
|
||||
setUp(() async {
|
||||
@ -29,7 +29,7 @@ void main() {
|
||||
expect(kosmo.created.compareTo(DateTime.now()), lessThan(0));
|
||||
expect(kosmo.coverArt?.length, greaterThan(0));
|
||||
expect(kosmo.year, equals(2006));
|
||||
expect(kosmo.starred, isNull);
|
||||
expect(kosmo.starred?.compareTo(DateTime.now()), lessThan(0));
|
||||
expect(kosmo.genre, equals('Electronic'));
|
||||
|
||||
final retro = items.firstWhere(
|
||||
@ -39,6 +39,9 @@ void main() {
|
||||
(a) => a.name == "I Don't Know What I'm Doing",
|
||||
);
|
||||
|
||||
expect(retro.starred, isNull);
|
||||
expect(dunno.starred, isNull);
|
||||
|
||||
expect(kosmo.recentRank, equals(0));
|
||||
expect(kosmo.frequentRank, equals(1));
|
||||
|
||||
@ -53,6 +56,19 @@ void main() {
|
||||
final items = await source.allArtists().toList();
|
||||
|
||||
expect(items.length, equals(2));
|
||||
|
||||
final brad = items.firstWhere((a) => a.name == 'Brad Sucks');
|
||||
|
||||
expect(brad.id.length, greaterThan(0));
|
||||
expect(brad.starred, isNull);
|
||||
|
||||
if (![Servers.gonic].contains(server)) {
|
||||
expect(brad.coverArt?.length, greaterThan(0));
|
||||
}
|
||||
|
||||
final ugress = items.firstWhere((a) => a.name == 'Ugress');
|
||||
|
||||
expect(ugress.starred?.compareTo(DateTime.now()), lessThan(0));
|
||||
});
|
||||
|
||||
test('allSongs', () async {
|
||||
|
||||
@ -23,12 +23,14 @@ Map<Servers, SubsonicClient> testServerClients() => {
|
||||
),
|
||||
};
|
||||
|
||||
void groupByTestServer(void Function(SubsonicClient client) callback) {
|
||||
void groupByTestServer(
|
||||
void Function(Servers server, SubsonicClient client) callback,
|
||||
) {
|
||||
final clients = testServerClients();
|
||||
|
||||
for (final MapEntry(key: server, value: client) in clients.entries) {
|
||||
group(server.name, () {
|
||||
callback(client);
|
||||
callback(server, client);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user