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

94 lines
2.6 KiB
Dart
Raw Normal View History

import 'package:intl/intl.dart';
import 'package:audio_service/audio_service.dart';
2020-02-09 13:29:09 +01:00
class EpisodeBrief {
final String title;
final String description;
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;
final String imagePath;
final String mediaId;
2020-03-31 18:36:20 +02:00
final int isNew;
final int skipSeconds;
final int downloadDate;
2020-02-09 13:29:09 +01:00
EpisodeBrief(
this.title,
this.enclosureUrl,
this.enclosureLength,
this.pubDate,
this.feedTitle,
this.primaryColor,
this.liked,
this.downloaded,
2020-02-09 13:29:09 +01:00
this.duration,
this.explicit,
this.imagePath,
2020-03-31 18:36:20 +02:00
this.mediaId,
this.isNew,
this.skipSeconds,
{this.description = '',
this.downloadDate = 0})
: assert(enclosureUrl != null);
String dateToString() {
2020-06-05 20:33:47 +02:00
DateTime date = DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true);
2020-04-01 11:36:45 +02:00
var diffrence = DateTime.now().toUtc().difference(date);
if (diffrence.inHours < 1) {
return '1 hour ago';
} else if (diffrence.inHours < 24) {
return '${diffrence.inHours} hours ago';
} else if (diffrence.inHours == 24) {
return '1 day ago';
} else if (diffrence.inDays < 7) {
return '${diffrence.inDays} days ago';
} else {
return DateFormat.yMMMd().format(
DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true).toLocal());
}
}
String downloadDateToString() {
DateTime date = DateTime.fromMillisecondsSinceEpoch(downloadDate);
var diffrence = DateTime.now().toUtc().difference(date);
if (diffrence.inHours < 1) {
return '1 hour ago';
} else if (diffrence.inHours < 24) {
return '${diffrence.inHours} hours ago';
} else if (diffrence.inHours == 24) {
return '1 day ago';
} else if (diffrence.inDays < 7) {
return '${diffrence.inDays} days ago';
} else {
return DateFormat.yMMMd().format(
DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true).toLocal());
}
}
MediaItem toMediaItem() {
return MediaItem(
id: mediaId,
title: title,
artist: feedTitle,
album: feedTitle,
2020-06-05 20:33:47 +02:00
// duration: 0,
artUri: 'file://$imagePath',
extras: {'skip': skipSeconds});
}
2020-06-05 20:33:47 +02:00
@override
2020-06-16 06:40:51 +02:00
bool operator == (Object episode) =>
2020-06-05 20:33:47 +02:00
episode is EpisodeBrief &&
episode.title == title &&
episode.enclosureUrl == enclosureUrl;
@override
2020-06-16 06:40:51 +02:00
int get hashCode => enclosureUrl.hashCode + title.hashCode;
2020-02-09 13:29:09 +01:00
}