mirror of
https://github.com/feeddeck/feeddeck.git
synced 2026-04-29 19:11:45 -05:00
This commit improves / simplifies the media handling within the app. Until now we always had to provide the type of the media file (item media / source icon) when we wanted to display it. This is now not necessary anymore. Instead we always display the image from it's original path when the url starts with "http://" or "https://". Additionally we also check the platform to proxy the image request on the web. If the image doesn't start with "http://" or "https://" we always try to display the image from the Supabase storage. For this we also adjusted the corresponding Deno function, so that we check if the image starts with "http://" or "https://" before we upload it to the Supabase storage. If this is the case we upload the source icon to the Supabase storage. If the upload fails, we will use the original path of the icon. Last but not least this commit also introduces our own "CachedNetworkImage" widget, which wraps the original "CachedNetworkImage" widget. Our own widget will ensure that we use the correct url for the image request, so that we do not have to use this function all over the app anymore. Later this widget can also be used to introduce our own cache manager.
115 lines
3.1 KiB
Dart
115 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
import 'package:feeddeck/models/source.dart';
|
|
import 'package:feeddeck/utils/constants.dart';
|
|
import 'package:feeddeck/widgets/source/source_icon.dart';
|
|
|
|
/// The [ItemSource] widget is used to display the source of an item above the
|
|
/// item title.
|
|
class ItemSource extends StatelessWidget {
|
|
const ItemSource({
|
|
super.key,
|
|
required this.sourceTitle,
|
|
required this.sourceSubtitle,
|
|
required this.sourceType,
|
|
required this.sourceIcon,
|
|
required this.itemPublishedAt,
|
|
required this.itemIsRead,
|
|
});
|
|
|
|
final String sourceTitle;
|
|
final String sourceSubtitle;
|
|
final FDSourceType sourceType;
|
|
final String? sourceIcon;
|
|
final int itemPublishedAt;
|
|
final bool itemIsRead;
|
|
|
|
/// [_buildTime] returns a widget with the relative time differenc to when the
|
|
/// item was published and an unread identicator if the state of the item is
|
|
/// `unread`.
|
|
Widget _buildTime() {
|
|
final publishedAt = DateTime.fromMillisecondsSinceEpoch(
|
|
itemPublishedAt * 1000,
|
|
);
|
|
|
|
return Row(
|
|
children: [
|
|
Text(
|
|
timeago.format(
|
|
publishedAt,
|
|
locale: 'en_short',
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: Constants.spacingSmall),
|
|
child: Icon(
|
|
Icons.circle,
|
|
color: !itemIsRead ? Constants.primary : Colors.transparent,
|
|
size: 8,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.only(
|
|
bottom: Constants.spacingSmall,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.only(
|
|
right: Constants.spacingMiddle,
|
|
),
|
|
child: SourceIcon(
|
|
type: sourceType,
|
|
icon: sourceIcon,
|
|
size: 32,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
Characters(sourceTitle)
|
|
.replaceAll(Characters(''), Characters('\u{200B}'))
|
|
.toString(),
|
|
maxLines: 1,
|
|
style: const TextStyle(
|
|
overflow: TextOverflow.ellipsis,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 10,
|
|
),
|
|
),
|
|
Text(
|
|
Characters(sourceSubtitle)
|
|
.replaceAll(Characters(''), Characters('\u{200B}'))
|
|
.toString(),
|
|
maxLines: 1,
|
|
style: const TextStyle(
|
|
overflow: TextOverflow.ellipsis,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 8,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.only(
|
|
left: Constants.spacingMiddle,
|
|
),
|
|
child: _buildTime(),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|