Skip to content

Commit

Permalink
refactor(neon_news,neon_notes,neon_notifications): replace long press…
Browse files Browse the repository at this point in the history
… actions with swipe-to-dismiss

Signed-off-by: satvik2131 <satvik213161@gmail.com>
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
satvik2131 authored and provokateurin committed Jul 16, 2024
1 parent b62709c commit 4e9662d
Show file tree
Hide file tree
Showing 7 changed files with 435 additions and 402 deletions.
251 changes: 129 additions & 122 deletions packages/neon/neon_news/lib/src/widgets/articles_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,145 +142,152 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
news.Article article,
news.Feed feed,
) =>
ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
article.title,
style: article.unread
? null
: Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor),
),
),
if (article.mediaThumbnail != null)
NeonUriImage(
uri: Uri.parse(article.mediaThumbnail!),
size: const Size(100, 50),
fit: BoxFit.cover,
account: NeonProvider.of<Account>(context),
),
],
),
subtitle: Row(
children: [
Container(
margin: const EdgeInsets.only(
top: 8,
bottom: 8,
right: 8,
Dismissible(
key: Key(article.id.toString()),
direction: DismissDirection.startToEnd,
behavior: HitTestBehavior.translucent,
background: Container(color: Colors.red),
onDismissed: (_) {
if (article.unread) {
widget.bloc.markArticleAsRead(article);
} else {
widget.bloc.markArticleAsUnread(article);
}
},
child: ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
article.title,
style: article.unread
? null
: Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor),
),
),
child: NewsFeedIcon(
feed: feed,
size: smallIconSize,
borderRadius: const BorderRadius.all(Radius.circular(2)),
if (article.mediaThumbnail != null)
NeonUriImage(
uri: Uri.parse(article.mediaThumbnail!),
size: const Size(100, 50),
fit: BoxFit.cover,
account: NeonProvider.of<Account>(context),
),
],
),
subtitle: Row(
children: [
Container(
margin: const EdgeInsets.only(
top: 8,
bottom: 8,
right: 8,
),
child: NewsFeedIcon(
feed: feed,
size: smallIconSize,
borderRadius: const BorderRadius.all(Radius.circular(2)),
),
),
),
RelativeTime(
date: DateTimeUtils.fromSecondsSinceEpoch(
tz.UTC,
article.pubDate,
RelativeTime(
date: DateTimeUtils.fromSecondsSinceEpoch(
tz.UTC,
article.pubDate,
),
style: const TextStyle(
fontWeight: FontWeight.w300,
fontSize: 12,
),
),
style: const TextStyle(
fontWeight: FontWeight.w300,
fontSize: 12,
const SizedBox(
width: 5,
),
),
const SizedBox(
width: 5,
),
Flexible(
child: Text(
feed.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
Flexible(
child: Text(
feed.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
trailing: IconButton(
onPressed: () {
if (article.starred) {
widget.bloc.unstarArticle(article);
} else {
widget.bloc.starArticle(article);
}
},
tooltip: article.starred
? NewsLocalizations.of(context).articleUnstar
: NewsLocalizations.of(context).articleStar,
icon: Icon(
article.starred ? AdaptiveIcons.star : AdaptiveIcons.star_outline,
color: Theme.of(context).colorScheme.primary,
),
],
),
trailing: IconButton(
onPressed: () {
if (article.starred) {
widget.bloc.unstarArticle(article);
} else {
widget.bloc.starArticle(article);
}
},
tooltip:
article.starred ? NewsLocalizations.of(context).articleUnstar : NewsLocalizations.of(context).articleStar,
icon: Icon(
article.starred ? AdaptiveIcons.star : AdaptiveIcons.star_outline,
color: Theme.of(context).colorScheme.primary,
),
),
onLongPress: () {
if (article.unread) {
widget.bloc.markArticleAsRead(article);
} else {
widget.bloc.markArticleAsUnread(article);
}
},
onTap: () async {
final viewType = options.articleViewTypeOption.value;
String? bodyData;
try {
bodyData = _fixArticleBody(article.body);
} on Exception catch (error, stackTrace) {
_log.warning(
'Could not parse the body of ${article.title}',
error,
stackTrace,
);
}
onTap: () async {
final viewType = options.articleViewTypeOption.value;
String? bodyData;
try {
bodyData = _fixArticleBody(article.body);
} on Exception catch (error, stackTrace) {
_log.warning(
'Could not parse the body of ${article.title}',
error,
stackTrace,
);
}

final account = NeonProvider.of<Account>(context);
final account = NeonProvider.of<Account>(context);

if ((viewType == ArticleViewType.direct || article.url == null) && bodyData != null) {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => NewsArticlePage(
bloc: NewsArticleBloc(
if ((viewType == ArticleViewType.direct || article.url == null) && bodyData != null) {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => NewsArticlePage(
bloc: NewsArticleBloc(
articlesBloc: widget.bloc,
account: account,
article: article,
),
articlesBloc: widget.bloc,
account: account,
article: article,
useWebView: false,
bodyData: bodyData,
url: article.url,
),
articlesBloc: widget.bloc,
useWebView: false,
bodyData: bodyData,
url: article.url,
),
),
);
} else if (viewType == ArticleViewType.internalBrowser &&
article.url != null &&
NeonPlatform.instance.canUseWebView) {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => NewsArticlePage(
bloc: NewsArticleBloc(
);
} else if (viewType == ArticleViewType.internalBrowser &&
article.url != null &&
NeonPlatform.instance.canUseWebView) {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => NewsArticlePage(
bloc: NewsArticleBloc(
articlesBloc: widget.bloc,
account: account,
article: article,
),
articlesBloc: widget.bloc,
account: account,
article: article,
useWebView: true,
url: article.url,
),
articlesBloc: widget.bloc,
useWebView: true,
url: article.url,
),
),
);
} else {
if (article.unread) {
widget.bloc.markArticleAsRead(article);
}
if (article.url != null) {
await launchUrlString(
article.url!,
mode: LaunchMode.externalApplication,
);
} else {
if (article.unread) {
widget.bloc.markArticleAsRead(article);
}
if (article.url != null) {
await launchUrlString(
article.url!,
mode: LaunchMode.externalApplication,
);
}
}
}
},
},
),
);

String _fixArticleBody(String b) => _fixArticleBodyElement(html_parser.parse(b).documentElement!).outerHtml;
Expand Down
Loading

0 comments on commit 4e9662d

Please sign in to comment.