Skip to content

Commit

Permalink
changelog:
Browse files Browse the repository at this point in the history
improved local songs page
fixed null local song image if we use play all button
  • Loading branch information
gokadzev committed Jul 27, 2022
1 parent 9d1c628 commit b725661
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/helper/mediaitem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ MediaItem songModelToMediaItem(SongModel song, String songUrl) {
artist: '',
title: song.displayName,
artUri: Uri.parse(''),
extras: {'url': songUrl, 'lowResImage': '', 'ytid': '', 'ogid': song.id},
extras: {
'url': songUrl,
'lowResImage': '',
'ytid': '',
'localSongId': song.id,
'ogid': song.id
},
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class _MyAppState extends State<MyApp> {
userPlaylists = Hive.box('user').get('playlists') ?? [];
userLikedSongsList = Hive.box('user').get('likedSongs') ?? [];
searchHistory = Hive.box('user').get('searchHistory') ?? [];
getLocalSongs();
final Map<String, String> codes = {
'English': 'en',
'Georgian': 'ka',
Expand Down
73 changes: 71 additions & 2 deletions lib/ui/localSongsPage.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand All @@ -8,9 +10,67 @@ import 'package:musify/services/audio_manager.dart';
import 'package:musify/style/appColors.dart';
import 'package:on_audio_query/on_audio_query.dart';

class LocalSongsPage extends StatelessWidget {
class LocalSongsPage extends StatefulWidget {
const LocalSongsPage({Key? key}) : super(key: key);

@override
State<LocalSongsPage> createState() => _LocalSongsPageState();
}

class _LocalSongsPageState extends State<LocalSongsPage> {
final _songsList = [];

bool _isLoading = true;
bool _hasMore = true;
final _itemsPerPage = 15;
var _currentPage = 0;
var _currentLastLoadedId = 0;

@override
void initState() {
super.initState();
_isLoading = true;
_hasMore = true;
_loadMore();
}

@override
void dispose() {
super.dispose();
}

void _loadMore() {
_isLoading = true;
fetch().then((List fetchedList) {
if (!mounted) return;
if (fetchedList.isEmpty) {
setState(() {
_isLoading = false;
_hasMore = false;
});
} else {
setState(() {
_isLoading = false;
_songsList.addAll(fetchedList);
});
}
});
}

Future<List> fetch() async {
final list = [];
final int _count = localSongs.length;
final n = min(_itemsPerPage, _count - _currentPage * _itemsPerPage);
await Future.delayed(const Duration(seconds: 1), () {
for (int i = 0; i < n; i++) {
list.add(localSongs[_currentLastLoadedId]);
_currentLastLoadedId++;
}
});
_currentPage++;
return list;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -131,8 +191,17 @@ class LocalSongsPage extends StatelessWidget {
false, // may be problem with lazyload if it implemented
addRepaintBoundaries: false,
// Need to display a loading tile if more items are coming
itemCount: localSongs.length,
itemCount: _hasMore
? _songsList.length + 1
: _songsList.length,
itemBuilder: (BuildContext context, int index) {
if (index >= _songsList.length) {
if (!_isLoading) {
_loadMore();
}
return Spinner();
}

final lsong = {
'id': index,
'ytid': '',
Expand Down
44 changes: 40 additions & 4 deletions lib/ui/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,46 @@ class AudioAppState extends State<AudioApp> {
quality: 100,
artworkWidth: size.width / 1.2,
artworkHeight: size.width / 1.2,
nullArtworkWidget: Icon(
MdiIcons.musicNoteOutline,
size: 30,
color: accent,
nullArtworkWidget: SizedBox(
width: size.width / 1.2,
height: size.width / 1.2,
child: CachedNetworkImage(
imageUrl: metadata.artUri.toString(),
imageBuilder: (context, imageProvider) =>
DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
placeholder: (context, url) => Spinner(),
errorWidget: (context, url, error) => Container(
width: size.width / 1.2,
height: size.width / 1.2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
gradient: const LinearGradient(
colors: [
Color.fromARGB(30, 255, 255, 255),
Color.fromARGB(30, 233, 233, 233),
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
MdiIcons.musicNoteOutline,
size: size.width / 8,
color: accent,
),
],
),
),
),
),
keepOldArtwork: true,
)
Expand Down

0 comments on commit b725661

Please sign in to comment.