housekeeping

This commit is contained in:
Moritz Weber 2021-06-20 17:07:12 +02:00
parent a1c9070ed1
commit 0311fcb14f
14 changed files with 71 additions and 73 deletions

View file

@ -39,7 +39,9 @@ class AudioPlayerActor {
}
void _handlePosition(Duration? position, Song? song) {
if (song == null || position == null) return;
if (song == null || position == null) {
return;
}
final int pos = position.inMilliseconds;

View file

@ -58,22 +58,16 @@ class PersistenceActor {
Future<void> init() async {
final shuffleMode = await _persistentStateRepository.shuffleMode;
if (shuffleMode != null) {
_setShuffleMode(shuffleMode, updateQueue: false);
}
_setShuffleMode(shuffleMode, updateQueue: false);
final loopMode = await _persistentStateRepository.loopMode;
if (loopMode != null) {
_setLoopMode(loopMode);
}
_setLoopMode(loopMode);
final queueItems = await _persistentStateRepository.queueItems;
final originalSongs = await _persistentStateRepository.originalSongs;
final addedSongs = await _persistentStateRepository.addedSongs;
final index = await _persistentStateRepository.currentIndex;
if (queueItems != null && index != null) {
_initQueue(queueItems, originalSongs, addedSongs, index);
}
_initQueue(queueItems, originalSongs, addedSongs, index);
}
}

View file

@ -1,4 +1,3 @@
import 'package:flutter_fimber/flutter_fimber.dart';
import 'package:rxdart/rxdart.dart';
import '../../system/models/queue_item_model.dart';
@ -17,7 +16,7 @@ abstract class ManagedQueueInfo {
class ManagedQueue implements ManagedQueueInfo {
ManagedQueue(this._musicDataRepository) : _queue = [];
static final _log = FimberLog('ManagedQueue');
// static final _log = FimberLog('ManagedQueue');
@override
ValueStream<List<Song>> get addedSongsStream => _addedSongsSubject.stream;

View file

@ -42,7 +42,7 @@ class LibraryTabContainer extends StatelessWidget {
],
),
),
IconButton(icon: const Icon(Icons.more_vert), onPressed: () => null),
IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}),
],
),
),

View file

@ -17,17 +17,15 @@ abstract class _AlbumPageStore with Store {
_AlbumPageStore(
this._musicDataInfoRepository,
this.album,
) {
albumSongStream =
_musicDataInfoRepository.getAlbumSongStream(album).asObservable(initialValue: []);
}
);
final Album album;
final MusicDataInfoRepository _musicDataInfoRepository;
@observable
late ObservableStream<List<Song>> albumSongStream;
late ObservableStream<List<Song>> albumSongStream =
_musicDataInfoRepository.getAlbumSongStream(album).asObservable(initialValue: []);
void dispose() {}
}

View file

@ -15,23 +15,20 @@ class ArtistPageStore extends _ArtistPageStore with _$ArtistPageStore {
}
abstract class _ArtistPageStore with Store {
_ArtistPageStore(this._musicDataInfoRepository, this._artist) {
artistAlbumStream =
_musicDataInfoRepository.getArtistAlbumStream(_artist).asObservable(initialValue: []);
artistHighlightedSongStream = _musicDataInfoRepository
.getArtistHighlightedSongStream(_artist)
.asObservable(initialValue: []);
}
_ArtistPageStore(this._musicDataInfoRepository, this._artist);
final MusicDataInfoRepository _musicDataInfoRepository;
final Artist _artist;
@observable
late ObservableStream<List<Album>> artistAlbumStream;
late ObservableStream<List<Album>> artistAlbumStream =
_musicDataInfoRepository.getArtistAlbumStream(_artist).asObservable(initialValue: []);
@observable
late ObservableStream<List<Song>> artistHighlightedSongStream;
late ObservableStream<List<Song>> artistHighlightedSongStream = _musicDataInfoRepository
.getArtistHighlightedSongStream(_artist)
.asObservable(initialValue: []);
void dispose() {}
}

View file

@ -12,7 +12,7 @@ class Header extends StatelessWidget {
const Text('Home', style: TEXT_HEADER),
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () => null,
onPressed: () {},
),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,

View file

@ -50,7 +50,7 @@ class Highlight extends StatelessWidget {
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Text(
const Text(
'Architects',
style: TEXT_SMALL_SUBTITLE,
maxLines: 2,
@ -62,7 +62,7 @@ class Highlight extends StatelessWidget {
),
IconButton(
padding: EdgeInsets.zero,
icon: Icon(
icon: const Icon(
Icons.play_circle_fill_rounded,
size: 48.0,
),

View file

@ -76,12 +76,8 @@ class SongListTile extends StatelessWidget {
break;
}
final EdgeInsets padding = (onTapMore != null)
? const EdgeInsets.only(left: HORIZONTAL_PADDING)
: const EdgeInsets.only(left: HORIZONTAL_PADDING, right: 16.0);
return ListTile(
contentPadding: padding,
contentPadding: const EdgeInsets.only(left: HORIZONTAL_PADDING),
leading: SizedBox(
height: 56,
width: 56,
@ -103,12 +99,11 @@ class SongListTile extends StatelessWidget {
size: 14.0,
color: Colors.white.withOpacity(0.4),
),
if (onTapMore != null)
IconButton(
icon: const Icon(Icons.more_vert),
iconSize: 20.0,
onPressed: () => onTapMore(),
),
IconButton(
icon: const Icon(Icons.more_vert),
iconSize: 20.0,
onPressed: () => onTapMore(),
),
],
),
);

View file

@ -268,7 +268,6 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
@override
Future<void> setLoopMode(LoopMode loopMode) async {
if (loopMode == null) return;
await _audioPlayer.setLoopMode(loopMode.toJA());
}
@ -301,12 +300,16 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
/// extend the loaded audiosource, when seeking to previous/next
Future<bool> _updateLoadedQueue(int? newIndex) async {
_log.d('updateLoadedQueue: $newIndex');
if (!isQueueLoaded || newIndex == null) return false;
if (!isQueueLoaded || newIndex == null) {
return false;
}
_log.d('[$_loadStartIndex, $_loadEndIndex]');
if (_loadStartIndex == _loadEndIndex ||
(_loadStartIndex == 0 && _loadEndIndex == _queue.length)) return false;
(_loadStartIndex == 0 && _loadEndIndex == _queue.length)) {
return false;
}
if (_loadStartIndex < _loadEndIndex) {
_log.d('base case');
@ -387,15 +390,12 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
}
void _updateCurrentIndex(int? apIndex) {
if (apIndex == null) return;
if (_loadStartIndex == null || _loadEndIndex == null) {
_currentIndexSubject.add(apIndex); // why?
if (apIndex == null || !isQueueLoaded) {
return;
}
int result;
if (_audioSource != null && _audioSource.length == _queue.length) {
if (_audioSource.length == _queue.length) {
_log.d('EVERYTHING LOADED');
result = apIndex;
} else if (_loadStartIndex < _loadEndIndex) {
@ -435,7 +435,9 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
}
bool _isQueueIndexInSaveInterval(int index) {
if (_audioSource.length == _queue.length) return index < _queue.length;
if (_audioSource.length == _queue.length) {
return index < _queue.length;
}
final int leftBorder = (_loadStartIndex + LOAD_INTERVAL - 1) % _queue.length;
final int rightBorder = (_loadEndIndex - LOAD_INTERVAL + 1) % _queue.length;

View file

@ -3,36 +3,38 @@ import 'song_model.dart';
class QueueItemModel extends QueueItem {
QueueItemModel(
this.song, {
SongModel song, {
required int originalIndex,
QueueItemType type = QueueItemType.standard,
}) : super(song, originalIndex: originalIndex, type: type);
@override
SongModel song;
}
extension IntToQueueItemType on int {
QueueItemType toQueueItemType() {
switch(this) {
case 1: return QueueItemType.predecessor;
case 2: return QueueItemType.successor;
case 3: return QueueItemType.added;
default: return QueueItemType.standard;
switch (this) {
case 1:
return QueueItemType.predecessor;
case 2:
return QueueItemType.successor;
case 3:
return QueueItemType.added;
default:
return QueueItemType.standard;
}
}
}
extension QueueItemTypeToInt on QueueItemType {
int toInt() {
switch(this) {
case QueueItemType.predecessor:
switch (this) {
case QueueItemType.predecessor:
return 1;
case QueueItemType.successor:
return 2;
case QueueItemType.added:
return 3;
default: return 0;
default:
return 0;
}
}
}
}

View file

@ -194,7 +194,9 @@ class AudioPlayerRepositoryImpl implements AudioPlayerRepository {
}
}
if (changed) _queueSubject.add(queue);
if (changed) {
_queueSubject.add(queue);
}
}
void _updateCurrentSong(List<Song>? queue, int? index) {

View file

@ -82,7 +82,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
if (song.likeCount < 5) {
final newSong = (song as SongModel).copyWith(likeCount: song.likeCount + 1);
_songUpdateSubject.add({song.path: newSong});
_musicDataSource.incrementLikeCount(song as SongModel);
_musicDataSource.incrementLikeCount(song);
}
}
@ -105,7 +105,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
if (song.blocked != blocked) {
final newSong = (song as SongModel).copyWith(blocked: blocked);
_songUpdateSubject.add({song.path: newSong});
_musicDataSource.setSongBlocked(song as SongModel, blocked);
_musicDataSource.setSongBlocked(song, blocked);
}
}
@ -119,7 +119,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
Future<void> incrementPlayCount(Song song) async {
final newSong = (song as SongModel).copyWith(playCount: song.playCount + 1);
_songUpdateSubject.add({song.path: newSong});
_musicDataSource.incrementPlayCount(song as SongModel);
_musicDataSource.incrementPlayCount(song);
}
@override
@ -132,7 +132,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
Future<void> resetLikeCount(Song song) async {
final newSong = (song as SongModel).copyWith(likeCount: 0);
_songUpdateSubject.add({song.path: newSong});
_musicDataSource.resetLikeCount(song as SongModel);
_musicDataSource.resetLikeCount(song);
}
@override
@ -152,7 +152,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
SongModel newSong;
if (song.next == '') {
final successor = await _musicDataSource.getSuccessor(song as SongModel);
newSong = (song as SongModel).copyWith(next: successor?.path ?? '');
newSong = song.copyWith(next: successor?.path ?? '');
} else {
newSong = (song as SongModel).copyWith(next: '');
}
@ -165,7 +165,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
SongModel newSong;
if (song.previous == '') {
final predecessor = await _musicDataSource.getPredecessor(song as SongModel);
newSong = (song as SongModel).copyWith(previous: predecessor?.path ?? '');
newSong = song.copyWith(previous: predecessor?.path ?? '');
} else {
newSong = (song as SongModel).copyWith(previous: '');
}
@ -178,7 +178,9 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
..sort(
(a, b) {
final r = -a.likeCount.compareTo(b.likeCount);
if (r != 0) return r;
if (r != 0) {
return r;
}
return -a.playCount.compareTo(b.playCount);
},
);
@ -187,8 +189,12 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
List<Album> _sortArtistAlbums(List<Album> albums) {
return albums
..sort((a, b) {
if (b.pubYear == null) return -1;
if (a.pubYear == null) return 1;
if (b.pubYear == null) {
return -1;
}
if (a.pubYear == null) {
return 1;
}
return -a.pubYear!.compareTo(b.pubYear!);
});
}

View file

@ -1,5 +1,6 @@
name: mucke
description: music player
publish_to: none
version: 1.0.0+1