Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces ExtendedEnum with dart's enhanced enum concept #165

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/src/endpoints/me.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,28 @@ class Me extends _MeEndpointBase {
}
}

class FollowingType extends ExtendedEnum {
const FollowingType(String key) : super(key);
enum FollowingType {
artist(key: 'artist'),
user(key: 'user');

static const artist = FollowingType('artist');
static const user = FollowingType('user');
}
const FollowingType({required String key}) : _key = key;

class TimeRange {
final String _key;
}

const TimeRange(this._key);

enum TimeRange {
/// Consists of several years of data and including all new data as it becomes available
static const longTerm = TimeRange('long_term');
longTerm(key: 'long_term'),

/// Consists of approximately last 6 months
static const mediumTerm = TimeRange('medium_term');
mediumTerm(key: 'medium_term'),

/// Consists of approximately last 4 weeks
static const shortTerm = TimeRange('short_term');
shortTerm(key: 'short_term');

const TimeRange({required String key}) : _key = key;

final String _key;
}

enum _TopItemsType { artists, tracks }
28 changes: 11 additions & 17 deletions lib/src/endpoints/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Search extends EndpointPaging {
/// content that is playable in that market is returned.
BundledPages get(
String searchQuery, {
Iterable<SearchType> types = SearchType.all,
Iterable<SearchType> types = SearchType.values,
Market? market,
}) {
var type = types.map((type) => type._key).join(',');
Expand All @@ -44,21 +44,15 @@ class Search extends EndpointPaging {
}

/// Type for narrowing the search results
class SearchType extends ExtendedEnum {
const SearchType(String key) : super(key);
enum SearchType {
album(key: 'album'),
artist(key: 'artist'),
playlist(key: 'playlist'),
track(key: 'track'),
show(key: 'show'),
episode(key: 'episode');

static const album = SearchType('album');
static const artist = SearchType('artist');
static const playlist = SearchType('playlist');
static const track = SearchType('track');
static const show = SearchType('show');
static const episode = SearchType('episode');
static const all = [
SearchType.album,
SearchType.artist,
SearchType.playlist,
SearchType.track,
SearchType.show,
SearchType.episode,
];
const SearchType({required String key}) : _key = key;

final String _key;
}
9 changes: 0 additions & 9 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,3 @@ Iterable<List<T>> batches<T>(Iterable<T> source, int size) sync* {
}
if (accumulator != null) yield accumulator;
}

class ExtendedEnum {
final String _key;

const ExtendedEnum(this._key);

@override
String toString() => _key;
}