tsacdop-podcast-app-android/lib/type/searchpodcast.dart

79 lines
1.9 KiB
Dart
Raw Normal View History

import 'dart:ui';
2020-02-09 13:29:09 +01:00
import 'package:json_annotation/json_annotation.dart';
part 'searchpodcast.g.dart';
@JsonSerializable()
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;
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);
}
class _ConvertP<P> implements JsonConverter<P, Object> {
2020-02-09 13:29:09 +01:00
const _ConvertP();
@override
P fromJson(Object json) {
2020-02-09 13:29:09 +01:00
return OnlinePodcast.fromJson(json) as P;
}
2020-02-09 13:29:09 +01:00
@override
Object toJson(P object) {
2020-02-09 13:29:09 +01:00
return object;
}
}
@JsonSerializable()
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;
@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;
final String id;
2020-02-09 13:29:09 +01:00
OnlinePodcast(
{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) =>
_$OnlinePodcastFromJson(json);
2020-02-09 13:29:09 +01:00
Map<String, dynamic> toJson() => _$OnlinePodcastToJson(this);
@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) {
2020-07-26 15:48:30 +02:00
// ignore: avoid_returning_null
2020-07-26 12:20:42 +02:00
return null;
}
return (latestPubDate - earliestPubDate) ~/ count;
}
}