notification changes

- add like button
- switch to rounded icons
This commit is contained in:
Moritz Weber 2022-12-29 17:16:30 +01:00
parent edd9558755
commit 07e916e08b
61 changed files with 91 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -1,4 +1,5 @@
import '../repositories/audio_player_repository.dart';
import '../repositories/music_data_repository.dart';
import '../repositories/platform_integration_repository.dart';
import '../usecases/seek_to_next.dart';
@ -7,17 +8,19 @@ class PlatformIntegrationActor {
this._platformIntegrationInfoRepository,
this._seekToNext,
this._audioPlayerRepository,
this._musicDataRepository,
) {
_platformIntegrationInfoRepository.eventStream
.listen((event) => _handlePlatformIntegrationEvent(event));
}
final AudioPlayerRepository _audioPlayerRepository;
final MusicDataRepository _musicDataRepository;
final PlatformIntegrationInfoRepository _platformIntegrationInfoRepository;
final SeekToNext _seekToNext;
void _handlePlatformIntegrationEvent(PlatformIntegrationEvent event) {
Future<void> _handlePlatformIntegrationEvent(PlatformIntegrationEvent event) async {
switch (event.type) {
case PlatformIntegrationEventType.play:
_audioPlayerRepository.play();
@ -36,6 +39,13 @@ class PlatformIntegrationActor {
case PlatformIntegrationEventType.seek:
_seekToPosition(event.payload!['position'] as Duration);
break;
case PlatformIntegrationEventType.like:
final path = event.payload?['path'];
if (path != null) {
final song = await _musicDataRepository.getSongByPath(path as String);
_musicDataRepository.incrementLikeCount(song);
}
break;
}
}

View file

@ -62,6 +62,7 @@ abstract class MusicDataRepository extends MusicDataInfoRepository {
Future<Song> resetSkipCount(Song song);
Future<void> setLikeCount(List<Song> songs, int count);
Future<void> incrementLikeCount(Song song);
Future<Song> incrementPlayCount(Song song);

View file

@ -2,12 +2,6 @@ import '../entities/event.dart';
import '../entities/playback_event.dart';
import '../entities/song.dart';
/*
- position
- controls (playbackState)
*/
abstract class PlatformIntegrationInfoRepository {
Stream<PlatformIntegrationEvent> get eventStream;
@ -16,7 +10,6 @@ abstract class PlatformIntegrationInfoRepository {
abstract class PlatformIntegrationRepository extends PlatformIntegrationInfoRepository {
void handlePlaybackEvent(PlaybackEvent playbackEvent);
void setCurrentSong(Song? song);
// void setQueue(List<Song> queue);
}
class PlatformIntegrationEvent extends Event {
@ -32,4 +25,5 @@ enum PlatformIntegrationEventType {
skipNext,
skipPrevious,
seek,
like,
}

View file

@ -349,6 +349,7 @@ Future<void> setupGetIt() async {
getIt(),
getIt(),
getIt(),
getIt(),
),
);

View file

@ -9,6 +9,50 @@ import '../models/playback_event_model.dart';
import '../models/song_model.dart';
import 'platform_integration_data_source.dart';
const favs = [
MediaControl(
androidIcon: 'drawable/favorite_0',
label: 'Like',
action: MediaAction.rewind,
),
MediaControl(
androidIcon: 'drawable/favorite_1',
label: 'Like',
action: MediaAction.rewind,
),
MediaControl(
androidIcon: 'drawable/favorite_2',
label: 'Like',
action: MediaAction.rewind,
),
MediaControl(
androidIcon: 'drawable/favorite_3',
label: 'Like',
action: MediaAction.rewind,
),
];
const playCtrl = MediaControl(
androidIcon: 'drawable/play',
label: 'Play',
action: MediaAction.play,
);
const pauseCtrl = MediaControl(
androidIcon: 'drawable/pause',
label: 'Pause',
action: MediaAction.pause,
);
const nextCtrl = MediaControl(
androidIcon: 'drawable/skip_next',
label: 'Next',
action: MediaAction.skipToNext,
);
const prevCtrl = MediaControl(
androidIcon: 'drawable/skip_prev',
label: 'Previous',
action: MediaAction.skipToPrevious,
);
class PlatformIntegrationDataSourceImpl extends BaseAudioHandler
implements PlatformIntegrationDataSource {
PlatformIntegrationDataSourceImpl();
@ -52,6 +96,13 @@ class PlatformIntegrationDataSourceImpl extends BaseAudioHandler
));
}
@override
Future<void> rewind() async {
_log.d('rewind -> like');
_eventSubject.add(PlatformIntegrationEvent(
type: PlatformIntegrationEventType.like, payload: {'path': mediaItem.value?.id}));
}
@override
Future<void> click([MediaButton button = MediaButton.media]) async {
_log.i(button.toString());
@ -89,39 +140,45 @@ class PlatformIntegrationDataSourceImpl extends BaseAudioHandler
@override
Future<void> handlePlaybackEvent(PlaybackEventModel pe) async {
final mi = mediaItem.value;
final int likeCount = mi == null ? 0 : mi.extras!['likeCount'] as int;
if (pe.processingState == ProcessingState.ready) {
final timeDelta = DateTime.now().difference(pe.updateTime);
if (pe.playing) {
playbackState.add(playbackState.value.copyWith(
controls: [MediaControl.skipToPrevious, MediaControl.pause, MediaControl.skipToNext],
controls: [favs[likeCount], prevCtrl, pauseCtrl, nextCtrl],
systemActions: const {
MediaAction.seek,
},
playing: true,
processingState: AudioProcessingState.ready,
updatePosition: pe.updatePosition + timeDelta,
androidCompactActionIndices: [0, 2, 3],
));
} else {
playbackState.add(playbackState.value.copyWith(
controls: [MediaControl.skipToPrevious, MediaControl.play, MediaControl.skipToNext],
controls: [favs[likeCount], prevCtrl, playCtrl, nextCtrl],
systemActions: const {
MediaAction.seek,
},
processingState: AudioProcessingState.ready,
updatePosition: pe.updatePosition + timeDelta,
playing: false,
androidCompactActionIndices: [0, 2, 3],
));
}
} else if (pe.processingState == ProcessingState.completed) {
final timeDelta = DateTime.now().difference(pe.updateTime);
playbackState.add(playbackState.value.copyWith(
controls: [MediaControl.skipToPrevious, MediaControl.play, MediaControl.skipToNext],
controls: [favs[likeCount], prevCtrl, playCtrl, nextCtrl],
systemActions: const {
MediaAction.seek,
},
processingState: AudioProcessingState.ready,
updatePosition: pe.updatePosition + timeDelta,
playing: false,
androidCompactActionIndices: [0, 2, 3],
));
} else if (pe.processingState == ProcessingState.none) {
stop();
@ -133,6 +190,17 @@ class PlatformIntegrationDataSourceImpl extends BaseAudioHandler
@override
Future<void> setCurrentSong(SongModel? songModel) async {
mediaItem.add(songModel?.toMediaItem());
if (songModel != null) {
final state = playbackState.value;
final controls = state.controls.sublist(1);
final timeDelta = state.playing ? DateTime.now().difference(state.updateTime) : Duration.zero;
playbackState.add(playbackState.value.copyWith(
controls: [favs[songModel.likeCount]] + controls,
updatePosition: state.updatePosition + timeDelta,
));
}
}
}

View file

@ -175,6 +175,12 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
}
}
@override
Future<void> incrementLikeCount(Song song) async {
final count = song.likeCount < MAX_LIKE_COUNT ? song.likeCount + 1 : 0;
await setLikeCount([song], count);
}
@override
Future<Song> resetSkipCount(Song song) async {
final newSong = (song as SongModel).copyWith(skipCount: 0);