2020-02-21 16:04:02 +01:00
|
|
|
import 'package:intl/intl.dart';
|
2020-03-14 04:14:24 +01:00
|
|
|
import 'package:audio_service/audio_service.dart';
|
2020-02-21 16:04:02 +01:00
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
class EpisodeBrief {
|
|
|
|
final String title;
|
|
|
|
String description;
|
2020-02-21 16:04:02 +01:00
|
|
|
final int pubDate;
|
2020-02-09 13:29:09 +01:00
|
|
|
final int enclosureLength;
|
|
|
|
final String enclosureUrl;
|
|
|
|
final String feedTitle;
|
|
|
|
final String primaryColor;
|
|
|
|
final int liked;
|
|
|
|
final String downloaded;
|
|
|
|
final int duration;
|
|
|
|
final int explicit;
|
2020-02-20 16:44:42 +01:00
|
|
|
final String imagePath;
|
2020-03-14 04:14:24 +01:00
|
|
|
final String mediaId;
|
2020-03-31 18:36:20 +02:00
|
|
|
final int isNew;
|
2020-04-22 20:10:57 +02:00
|
|
|
final int skipSeconds;
|
2020-02-09 13:29:09 +01:00
|
|
|
EpisodeBrief(
|
|
|
|
this.title,
|
|
|
|
this.enclosureUrl,
|
|
|
|
this.enclosureLength,
|
|
|
|
this.pubDate,
|
|
|
|
this.feedTitle,
|
|
|
|
this.primaryColor,
|
|
|
|
this.liked,
|
2020-03-14 04:14:24 +01:00
|
|
|
this.downloaded,
|
2020-02-09 13:29:09 +01:00
|
|
|
this.duration,
|
2020-02-20 16:44:42 +01:00
|
|
|
this.explicit,
|
2020-03-14 04:14:24 +01:00
|
|
|
this.imagePath,
|
2020-03-31 18:36:20 +02:00
|
|
|
this.mediaId,
|
2020-04-22 20:10:57 +02:00
|
|
|
this.isNew,
|
|
|
|
this.skipSeconds);
|
2020-02-21 16:04:02 +01:00
|
|
|
|
2020-03-14 04:14:24 +01:00
|
|
|
String dateToString() {
|
2020-04-22 20:10:57 +02:00
|
|
|
DateTime date = DateTime.fromMillisecondsSinceEpoch(pubDate,isUtc: true);
|
2020-04-01 11:36:45 +02:00
|
|
|
var diffrence = DateTime.now().toUtc().difference(date);
|
2020-03-19 20:58:30 +01:00
|
|
|
if (diffrence.inHours < 1) {
|
|
|
|
return '1 hour ago';
|
|
|
|
} else if (diffrence.inHours < 24) {
|
2020-02-21 16:04:02 +01:00
|
|
|
return '${diffrence.inHours} hours ago';
|
2020-03-19 20:58:30 +01:00
|
|
|
} else if (diffrence.inHours == 24) {
|
|
|
|
return '1 day ago';
|
2020-03-14 04:14:24 +01:00
|
|
|
} else if (diffrence.inDays < 7) {
|
|
|
|
return '${diffrence.inDays} days ago';
|
|
|
|
} else {
|
2020-04-22 20:10:57 +02:00
|
|
|
return DateFormat.yMMMd().format(
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true).toLocal());
|
2020-02-21 16:04:02 +01:00
|
|
|
}
|
2020-03-14 04:14:24 +01:00
|
|
|
}
|
2020-04-22 20:10:57 +02:00
|
|
|
|
2020-03-14 04:14:24 +01:00
|
|
|
MediaItem toMediaItem() {
|
|
|
|
return MediaItem(
|
|
|
|
id: mediaId,
|
|
|
|
title: title,
|
|
|
|
artist: feedTitle,
|
|
|
|
album: feedTitle,
|
2020-04-23 19:46:36 +02:00
|
|
|
// duration: 0,
|
2020-04-22 20:10:57 +02:00
|
|
|
artUri: 'file://$imagePath',
|
|
|
|
extras: {'skip': skipSeconds});
|
2020-03-14 04:14:24 +01:00
|
|
|
}
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|