0.6.1 - UI Fixes

This commit is contained in:
exttex 2020-10-20 21:55:14 +02:00
parent 1384aedb35
commit df3b7d3d63
16 changed files with 215 additions and 34 deletions

View file

@ -49,8 +49,10 @@ class Cache {
@JsonKey(ignore: true)
StreamSubscription sleepTimer;
@JsonKey(defaultValue: [])
List<String> searchHistory;
//Search history
@JsonKey(name: 'searchHistory2', toJson: _searchHistoryToJson, fromJson: _searchHistoryFromJson)
List<SearchHistoryItem> searchHistory;
//If download threads warning was shown
@JsonKey(defaultValue: false)
@ -65,6 +67,23 @@ class Cache {
return libraryTracks.contains(t.id);
}
//Add to history
void addToSearchHistory(dynamic item) async {
if (searchHistory == null)
searchHistory = [];
if (item is Track)
searchHistory.add(SearchHistoryItem(item, SearchHistoryItemType.TRACK));
if (item is Album)
searchHistory.add(SearchHistoryItem(item, SearchHistoryItemType.ALBUM));
if (item is Artist)
searchHistory.add(SearchHistoryItem(item, SearchHistoryItemType.ARTIST));
if (item is Playlist)
searchHistory.add(SearchHistoryItem(item, SearchHistoryItemType.PLAYLIST));
await save();
}
//Save, load
static Future<String> getPath() async {
return p.join((await getApplicationDocumentsDirectory()).path, 'metacache.json');
@ -89,4 +108,45 @@ class Cache {
//JSON
factory Cache.fromJson(Map<String, dynamic> json) => _$CacheFromJson(json);
Map<String, dynamic> toJson() => _$CacheToJson(this);
//Search History JSON
static List<SearchHistoryItem> _searchHistoryFromJson(List<dynamic> json) {
return (json??[]).map<SearchHistoryItem>((i) => _searchHistoryItemFromJson(i)).toList();
}
static SearchHistoryItem _searchHistoryItemFromJson(Map<String, dynamic> json) {
SearchHistoryItemType type = SearchHistoryItemType.values[json['type']];
dynamic data;
switch (type) {
case SearchHistoryItemType.TRACK:
data = Track.fromJson(json['data']);
break;
case SearchHistoryItemType.ALBUM:
data = Album.fromJson(json['data']);
break;
case SearchHistoryItemType.ARTIST:
data = Artist.fromJson(json['data']);
break;
case SearchHistoryItemType.PLAYLIST:
data = Playlist.fromJson(json['data']);
break;
}
return SearchHistoryItem(data, type);
}
static List<Map<String, dynamic>> _searchHistoryToJson(List<SearchHistoryItem> data) => (data??[]).map<Map<String, dynamic>>((i) => {"type": i.type.index, "data": i.data.toJson()}).toList();
}
@JsonSerializable()
class SearchHistoryItem {
dynamic data;
SearchHistoryItemType type;
SearchHistoryItem(this.data, this.type);
}
enum SearchHistoryItemType {
TRACK,
ALBUM,
ARTIST,
PLAYLIST
}

View file

@ -32,7 +32,7 @@ Cache _$CacheFromJson(Map<String, dynamic> json) {
..trackSort = _$enumDecodeNullable(_$SortTypeEnumMap, json['trackSort']) ??
SortType.DEFAULT
..searchHistory =
(json['searchHistory'] as List)?.map((e) => e as String)?.toList() ?? []
Cache._searchHistoryFromJson(json['searchHistory2'] as List)
..threadsWarning = json['threadsWarning'] as bool ?? false;
}
@ -46,7 +46,7 @@ Map<String, dynamic> _$CacheToJson(Cache instance) => <String, dynamic>{
'libraryPlaylistSort':
_$PlaylistSortTypeEnumMap[instance.libraryPlaylistSort],
'trackSort': _$SortTypeEnumMap[instance.trackSort],
'searchHistory': instance.searchHistory,
'searchHistory2': Cache._searchHistoryToJson(instance.searchHistory),
'threadsWarning': instance.threadsWarning,
};
@ -110,3 +110,23 @@ const _$PlaylistSortTypeEnumMap = {
PlaylistSortType.USER: 'USER',
PlaylistSortType.TRACK_COUNT: 'TRACK_COUNT',
};
SearchHistoryItem _$SearchHistoryItemFromJson(Map<String, dynamic> json) {
return SearchHistoryItem(
json['data'],
_$enumDecodeNullable(_$SearchHistoryItemTypeEnumMap, json['type']),
);
}
Map<String, dynamic> _$SearchHistoryItemToJson(SearchHistoryItem instance) =>
<String, dynamic>{
'data': instance.data,
'type': _$SearchHistoryItemTypeEnumMap[instance.type],
};
const _$SearchHistoryItemTypeEnumMap = {
SearchHistoryItemType.TRACK: 'TRACK',
SearchHistoryItemType.ALBUM: 'ALBUM',
SearchHistoryItemType.ARTIST: 'ARTIST',
SearchHistoryItemType.PLAYLIST: 'PLAYLIST',
};

View file

@ -115,7 +115,7 @@ class DeezerAPI {
//Search
Future<SearchResults> search(String query) async {
Map<dynamic, dynamic> data = await callApi('deezer.pageSearch', params: {
'nb': 50,
'nb': 128,
'query': query,
'start': 0
});

View file

@ -456,7 +456,7 @@ class AudioPlayerTask extends BackgroundAudioTask {
MediaAction.seekTo,
MediaAction.seekForward,
MediaAction.seekBackward,
//MediaAction.stop
MediaAction.stop
],
processingState: _getProcessingState(),
playing: _player.playing,