1
0
mirror of https://github.com/stonega/tsacdop synced 2024-12-15 09:57:19 +01:00
tsacdop-podcast-app-android/lib/type/episodebrief.dart
stonegate b619be9a9b Search ui changed a lot, add podcast detail panel.
Update audio service to latest version.
2020-07-22 17:34:32 +08:00

79 lines
2.0 KiB
Dart

import 'dart:ui';
import 'package:intl/intl.dart';
import 'package:audio_service/audio_service.dart';
class EpisodeBrief {
final String title;
final String description;
final int pubDate;
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;
final int isNew;
final int skipSeconds;
final int downloadDate;
EpisodeBrief(
this.title,
this.enclosureUrl,
this.enclosureLength,
this.pubDate,
this.feedTitle,
this.primaryColor,
this.liked,
this.downloaded,
this.duration,
this.explicit,
this.imagePath,
this.mediaId,
this.isNew,
this.skipSeconds,
{this.description = '',
this.downloadDate = 0})
: assert(enclosureUrl != null);
String ateToString() {
DateTime date = DateTime.fromMillisecondsSinceEpoch(pubDate, isUtc: true);
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,
duration: Duration.zero,
artUri: 'file://$imagePath',
extras: {'skip': skipSeconds});
}
@override
bool operator ==(Object episode) =>
episode is EpisodeBrief &&
episode.title == title &&
episode.enclosureUrl == enclosureUrl;
@override
int get hashCode => hashValues(enclosureUrl, title);
}