2020-07-22 11:34:32 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
part 'searchpodcast.g.dart';
|
|
|
|
|
|
|
|
@JsonSerializable()
|
2020-07-22 11:34:32 +02:00
|
|
|
class SearchPodcast<P> {
|
2020-02-09 13:29:09 +01:00
|
|
|
@_ConvertP()
|
|
|
|
final List<P> results;
|
|
|
|
@JsonKey(name: 'next_offset')
|
|
|
|
final int nextOffset;
|
|
|
|
final int total;
|
|
|
|
final int count;
|
2020-07-22 11:34:32 +02:00
|
|
|
SearchPodcast({this.results, this.nextOffset, this.total, this.count});
|
|
|
|
factory SearchPodcast.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$SearchPodcastFromJson<P>(json);
|
2020-02-09 13:29:09 +01:00
|
|
|
Map<String, dynamic> toJson() => _$SearchPodcastToJson(this);
|
|
|
|
}
|
|
|
|
|
2020-07-22 11:34:32 +02:00
|
|
|
class _ConvertP<P> implements JsonConverter<P, Object> {
|
2020-02-09 13:29:09 +01:00
|
|
|
const _ConvertP();
|
|
|
|
@override
|
2020-07-22 11:34:32 +02:00
|
|
|
P fromJson(Object json) {
|
2020-02-09 13:29:09 +01:00
|
|
|
return OnlinePodcast.fromJson(json) as P;
|
|
|
|
}
|
2020-07-22 11:34:32 +02:00
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
2020-07-22 11:34:32 +02:00
|
|
|
Object toJson(P object) {
|
2020-02-09 13:29:09 +01:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@JsonSerializable()
|
2020-07-22 11:34:32 +02:00
|
|
|
class OnlinePodcast {
|
2020-02-09 13:29:09 +01:00
|
|
|
@JsonKey(name: 'earliest_pub_date_ms')
|
|
|
|
final int earliestPubDate;
|
|
|
|
@JsonKey(name: 'title_original')
|
|
|
|
final String title;
|
|
|
|
final String rss;
|
2020-07-22 11:34:32 +02:00
|
|
|
@JsonKey(name: 'latest_pub_date_ms')
|
|
|
|
final int latestPubDate;
|
2020-02-09 13:29:09 +01:00
|
|
|
@JsonKey(name: 'description_original')
|
|
|
|
final String description;
|
|
|
|
@JsonKey(name: 'total_episodes')
|
|
|
|
final int count;
|
|
|
|
final String image;
|
|
|
|
@JsonKey(name: 'publisher_original')
|
|
|
|
final String publisher;
|
2020-07-22 11:34:32 +02:00
|
|
|
final String id;
|
2020-02-09 13:29:09 +01:00
|
|
|
OnlinePodcast(
|
2020-07-22 11:34:32 +02:00
|
|
|
{this.earliestPubDate,
|
|
|
|
this.title,
|
|
|
|
this.count,
|
|
|
|
this.description,
|
|
|
|
this.image,
|
|
|
|
this.latestPubDate,
|
|
|
|
this.rss,
|
|
|
|
this.publisher,
|
|
|
|
this.id});
|
2020-02-09 13:29:09 +01:00
|
|
|
factory OnlinePodcast.fromJson(Map<String, dynamic> json) =>
|
2020-07-22 11:34:32 +02:00
|
|
|
_$OnlinePodcastFromJson(json);
|
2020-02-09 13:29:09 +01:00
|
|
|
Map<String, dynamic> toJson() => _$OnlinePodcastToJson(this);
|
2020-07-22 11:34:32 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object onlinePodcast) =>
|
|
|
|
onlinePodcast is OnlinePodcast && onlinePodcast.id == id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode => hashValues(id, title);
|
|
|
|
|
|
|
|
int get interval {
|
2020-07-26 12:20:42 +02:00
|
|
|
if (count < 1) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-07-22 11:34:32 +02:00
|
|
|
return (latestPubDate - earliestPubDate) ~/ count;
|
|
|
|
}
|
|
|
|
}
|