prepare for multiple apps

This commit is contained in:
Fabian Freund
2026-04-06 12:23:11 +02:00
parent bd1600e8dc
commit 5afc323f04
904 changed files with 29 additions and 29 deletions
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
class AuthorsHorizontalList extends StatelessWidget {
late final List<Widget> _authors;
AuthorsHorizontalList({
super.key,
required List<FeedAuthor> authors,
Set<String> selectedTags = const {},
void Function(String tagId, bool value)? onTagSelected,
}) {
_authors = authors.map((author) {
final label = Text(
'${author.name ?? ''} ${author.email.mapNotNull((email) => '($email)') ?? ''}'
.trim(),
);
return onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(author.name),
onSelected: (value) {
if (author.name.isNotEmpty) {
onTagSelected(author.name!, value);
}
},
),
) ??
Chip(label: label);
}).toList();
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView.builder(
itemCount: _authors.length,
controller: controller,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _authors[index],
);
},
),
);
}
}
@@ -0,0 +1,210 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
import 'package:weblibre/features/web_feed/data/models/feed_article_query_result.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:weblibre/features/web_feed/extensions/atom.dart';
import 'package:weblibre/features/web_feed/extensions/feed_article.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
import 'package:weblibre/utils/text_highlight.dart';
class FeedArticleCard extends HookConsumerWidget {
static const _matchPrefix = '***';
static const _matchSuffix = '***';
final FeedArticle article;
const FeedArticleCard({super.key, required this.article});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final tags = ref.watch(articleFilterProvider);
final titleHighlight = switch (article) {
final FeedArticleQueryResult result => result.titleHighlight.whenNotEmpty,
_ => null,
};
final searchSnippet = switch (article) {
final FeedArticleQueryResult result =>
result.summarySnippet.whenNotEmpty ??
result.contentSnippet.whenNotEmpty,
_ => null,
};
return Card(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await FeedArticleRoute(articleId: article.id).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
UrlIcon([
article.icon ??
article.links
?.getRelation(FeedLinkRelation.alternate)
?.uri ??
article.siteLink ??
article.feedId.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (titleHighlight.isNotEmpty)
Text.rich(
buildHighlightedText(
titleHighlight!,
Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold,
),
_matchPrefix,
_matchSuffix,
),
),
if (titleHighlight.isEmpty)
Text(
article.displayTitle,
style: theme.textTheme.titleMedium,
),
if (searchSnippet.isNotEmpty)
Text.rich(
buildHighlightedText(
searchSnippet!,
Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(
context,
).colorScheme.onSurfaceVariant,
),
Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(
context,
).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.bold,
),
_matchPrefix,
_matchSuffix,
normalizeWhitespaces: true,
),
),
if (searchSnippet.isEmpty &&
article.summaryPlain != null)
Text(
article.summaryPlain!,
style: theme.textTheme.bodySmall,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
],
),
),
if (article.lastRead != null)
IconButton(
onPressed: () async {
await ref
.read(feedRepositoryProvider.notifier)
.unsetArticleRead(article.id);
},
icon: const Icon(Icons.visibility),
),
],
),
if (article.authors.isNotEmpty || article.tags.isNotEmpty) ...[
const SizedBox(height: 8),
if (article.authors.isNotEmpty)
AuthorsHorizontalList(
authors: article.authors!,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
if (article.tags.isNotEmpty)
TagsHorizontalList(
tags: article.tags!,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
],
const Divider(),
Row(
children: [
Text(
'Published: ${(article.created != null) ? timeago.format(article.created!) : 'N/A'}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
if (article.updated != null &&
article.updated != article.created)
Text(
'Updated: ${timeago.format(article.updated!)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
],
),
],
),
),
),
);
}
}
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
import 'package:weblibre/presentation/widgets/rounded_text.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
class FeedCard extends HookConsumerWidget {
final FeedData feed;
const FeedCard({super.key, required this.feed});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
return Card(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await FeedArticleListRoute(feedId: feed.url).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
UrlIcon([
feed.icon ?? feed.siteLink ?? feed.url.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
feed.title ?? feed.url.host,
style: theme.textTheme.titleMedium,
),
if (feed.description != null)
Text(
feed.description!,
style: theme.textTheme.bodySmall,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
],
),
),
IconButton(
onPressed: () async {
await FeedEditRoute(feedId: feed.url).push(context);
},
icon: const Icon(Icons.edit),
),
],
),
if (feed.authors.isNotEmpty || feed.tags.isNotEmpty) ...[
if (feed.authors.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: AuthorsHorizontalList(authors: feed.authors!),
),
if (feed.tags.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: TagsHorizontalList(tags: feed.tags!),
),
],
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Last fetched: ${(feed.lastFetched != null) ? timeago.format(feed.lastFetched!) : 'N/A'}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
Consumer(
builder: (context, ref, child) {
final countAsync = ref.watch(
unreadFeedArticleCountProvider(feed.url),
);
return countAsync.when(
skipLoadingOnReload: true,
data: (count) {
if (count == null) {
return const SizedBox();
}
return RoundedBackground(
child: Row(
children: [
Icon(
MdiIcons.newspaperVariantMultipleOutline,
size: 18,
color: Theme.of(
context,
).colorScheme.onPrimary,
),
const SizedBox(width: 4),
Text(
count.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(
context,
).colorScheme.onPrimary,
),
),
],
),
);
},
error: (error, stackTrace) => const Text('N/A'),
loading: () => const SizedBox(
height: 16,
width: 16,
child: Center(
child: CircularProgressIndicator(strokeWidth: 2),
),
),
);
},
),
],
),
],
),
),
),
);
}
}
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
final _tagSplitPatter = RegExp(r'[,\s]+');
class TagField extends HookWidget {
final Set<String> initialTags;
final void Function(Set<String> tags) onTagsUpdate;
const TagField({
super.key,
required this.initialTags,
required this.onTagsUpdate,
});
@override
Widget build(BuildContext context) {
final textController = useTextEditingController();
final tags = useState(initialTags);
useOnListenableChange(tags, () {
onTagsUpdate(tags.value);
});
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Tags', style: Theme.of(context).textTheme.labelMedium),
const SizedBox(height: 4),
Wrap(
spacing: 8.0,
children: tags.value
.map(
(tag) => InputChip(
label: Text(tag),
onDeleted: () {
tags.value = {...tags.value}..remove(tag);
},
),
)
.toList(),
),
TextField(
controller: textController,
decoration: const InputDecoration(
hintText: 'tag1, tag2, ...',
prefixIcon: Icon(MdiIcons.tagMultiple),
),
onChanged: (String value) {
if (value.isNotEmpty) {
final values = value.split(_tagSplitPatter);
if (values.length > 1) {
final trimmed = values
.map((str) => str.trim())
.where((str) => str.isNotEmpty);
if (trimmed.isNotEmpty) {
textController.clear();
tags.value = {...tags.value, ...trimmed};
}
}
}
},
onSubmitted: (value) {
if (value.isNotEmpty) {
final values = value
.split(_tagSplitPatter)
.map((str) => str.trim())
.where((str) => str.isNotEmpty)
.toList();
if (values.isNotEmpty) {
textController.clear();
tags.value = {...tags.value, ...values};
}
}
},
),
],
);
}
}
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
class TagsHorizontalList extends StatelessWidget {
late final List<Widget> _tags;
TagsHorizontalList({
super.key,
required List<FeedCategory> tags,
Set<String> selectedTags = const {},
void Function(String tagId, bool value)? onTagSelected,
}) {
_tags = tags.map((tag) {
final label = Text(
'${tag.id} ${tag.title.mapNotNull((title) => '($title)') ?? ''}'.trim(),
);
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child:
onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(tag.id),
onSelected: (value) {
onTagSelected(tag.id, value);
},
),
) ??
Chip(label: label),
);
}).toList();
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView.builder(
itemCount: _tags.length,
controller: controller,
//Improve list performance by not rendering outside screen at all
cacheExtent: 0,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _tags[index],
);
},
),
);
}
}