Renamed links to bookmarks
This commit is contained in:
314
lib/screens/bookmarks/ui/add_bookmark_modal.dart
Normal file
314
lib/screens/bookmarks/ui/add_bookmark_modal.dart
Normal file
@@ -0,0 +1,314 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:easy_autocomplete/easy_autocomplete.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/add_bookmark.provider.dart';
|
||||
import 'package:linkdy/widgets/section_label.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
|
||||
class AddBookmarkModal extends ConsumerWidget {
|
||||
final bool fullscreen;
|
||||
|
||||
const AddBookmarkModal({
|
||||
Key? key,
|
||||
required this.fullscreen,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Dialog.fullscreen(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: CloseButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: Text(t.bookmarks.addBookmark.addBookmark),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: ref.watch(addBookmarkProvider).checkBookmark != null
|
||||
? () => ref.read(addBookmarkProvider.notifier).addBookmark()
|
||||
: null,
|
||||
icon: const Icon(Icons.save_rounded),
|
||||
tooltip: t.generic.save,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: const _ModalContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ModalContent extends ConsumerWidget {
|
||||
const _ModalContent({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = ref.watch(addBookmarkProvider);
|
||||
|
||||
final tags = ref.watch(getTagsProvider);
|
||||
|
||||
return ListView(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.bookmarkUrl,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.urlController,
|
||||
onChanged: ref.read(addBookmarkProvider.notifier).validateUrl,
|
||||
enabled: provider.checkBookmarkLoadStatus != LoadStatus.loading,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.link_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
errorText: provider.urlError,
|
||||
labelText: t.bookmarks.addBookmark.url,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: provider.checkBookmarkLoadStatus == null &&
|
||||
provider.urlError == null &&
|
||||
provider.urlController.text != ""
|
||||
? () => ref.read(addBookmarkProvider.notifier).checkUrlDetails()
|
||||
: null,
|
||||
style: ButtonStyle(
|
||||
foregroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? const MaterialStatePropertyAll(Colors.green)
|
||||
: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? const MaterialStatePropertyAll(Colors.red)
|
||||
: null,
|
||||
backgroundColor: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? MaterialStatePropertyAll(Colors.green.withOpacity(0.15))
|
||||
: provider.checkBookmarkLoadStatus == LoadStatus.loaded
|
||||
? MaterialStatePropertyAll(Colors.red.withOpacity(0.15))
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (provider.checkBookmarkLoadStatus == null) Text(t.bookmarks.addBookmark.validateUrl),
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.loading) ...[
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
height: 12,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.checkingUrl),
|
||||
],
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.loaded) ...[
|
||||
const Icon(Icons.check_circle_rounded),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.urlValid),
|
||||
],
|
||||
if (provider.checkBookmarkLoadStatus == LoadStatus.error) ...[
|
||||
const Icon(Icons.error_rounded),
|
||||
const SizedBox(width: 8),
|
||||
Text(t.bookmarks.addBookmark.cannotCheckUrl),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.bookmarkDetails,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.titleController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.title_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.title,
|
||||
hintText: provider.checkBookmark?.metadata?.title,
|
||||
floatingLabelBehavior:
|
||||
provider.checkBookmark != null ? FloatingLabelBehavior.always : FloatingLabelBehavior.auto,
|
||||
helperText: t.bookmarks.addBookmark.leaveEmptyUseWebsiteTitle,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextFormField(
|
||||
controller: provider.descriptionController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.description_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.description,
|
||||
hintText: provider.checkBookmark?.metadata?.description,
|
||||
floatingLabelBehavior:
|
||||
provider.checkBookmark != null ? FloatingLabelBehavior.always : FloatingLabelBehavior.auto,
|
||||
helperText: t.bookmarks.addBookmark.leaveEmptyUseWebsiteDescription,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.tags,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
if (tags.isLoading == false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
if (provider.checkBookmark != null)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: EasyAutocomplete(
|
||||
controller: provider.tagsController,
|
||||
onChanged: ref.read(addBookmarkProvider.notifier).validateTagInput,
|
||||
suggestions: tags.value?.content?.results?.map((t) => t.name!).toList() ?? [],
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.tags,
|
||||
errorText: provider.tagsError,
|
||||
),
|
||||
suggestionBuilder: (data) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
data,
|
||||
style: TextStyle(fontSize: 16, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
onSubmitted: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? (v) {
|
||||
ref.read(addBookmarkProvider.notifier).setTags([...provider.tags, v]);
|
||||
ref.read(addBookmarkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
onPressed: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? () {
|
||||
ref
|
||||
.read(addBookmarkProvider.notifier)
|
||||
.setTags([...provider.tags, provider.tagsController.text]);
|
||||
ref.read(addBookmarkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.check_rounded),
|
||||
tooltip: t.bookmarks.addBookmark.addTag,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (provider.checkBookmark != null) const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: provider.tags.isNotEmpty
|
||||
? ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: provider.tags.length,
|
||||
separatorBuilder: (context, index) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) => InputChip(
|
||||
label: Text(provider.tags[index]),
|
||||
onDeleted: () => ref
|
||||
.read(addBookmarkProvider.notifier)
|
||||
.setTags(provider.tags.where((tag) => tag != provider.tags[index]).toList()),
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
t.bookmarks.addBookmark.noTagsAdded,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.bookmarks.addBookmark.others,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
child: TextFormField(
|
||||
controller: provider.notesController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.note_rounded),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.bookmarks.addBookmark.notes,
|
||||
helperText: t.generic.optional,
|
||||
),
|
||||
autocorrect: false,
|
||||
expands: true,
|
||||
minLines: null,
|
||||
maxLines: null,
|
||||
textAlignVertical: TextAlignVertical.top,
|
||||
enabled: provider.checkBookmark != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
title: Text(t.bookmarks.addBookmark.markAsUnread),
|
||||
value: provider.markAsUnread,
|
||||
onChanged: provider.checkBookmark != null
|
||||
? (v) => ref.read(addBookmarkProvider.notifier).updateMarkAsUnread(v)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
98
lib/screens/bookmarks/ui/bookmark_item.dart
Normal file
98
lib/screens/bookmarks/ui/bookmark_item.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
import 'package:linkdy/providers/app_status_provider.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/utils/date_to_string.dart';
|
||||
import 'package:linkdy/utils/open_url.dart';
|
||||
|
||||
class LinkItem extends ConsumerWidget {
|
||||
final Bookmark bookmark;
|
||||
|
||||
const LinkItem({
|
||||
Key? key,
|
||||
required this.bookmark,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
String validateStrings(String? string1, String? string2) {
|
||||
if (string1 != null && string1.isNotEmpty) {
|
||||
return string1;
|
||||
} else if (string2 != null && string2.isNotEmpty) {
|
||||
return string2;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
onTap: ref.watch(appStatusProvider).useInAppBrowser == true
|
||||
? () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: bookmark)
|
||||
: () => openUrl(bookmark.url!),
|
||||
isThreeLine: true,
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
validateStrings(bookmark.title, bookmark.websiteTitle),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
validateStrings(bookmark.description, bookmark.websiteDescription),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
bookmark.tagNames?.map((tag) => "#$tag").join(" ") ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (bookmark.dateModified != null) ...[
|
||||
if (bookmark.tagNames?.isNotEmpty == true)
|
||||
Container(
|
||||
width: 1,
|
||||
height: 12,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
Text(
|
||||
dateToString(bookmark.dateModified!),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
119
lib/screens/bookmarks/ui/bookmarks.dart
Normal file
119
lib/screens/bookmarks/ui/bookmarks.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/add_bookmark_modal.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class BookmarksScreen extends ConsumerWidget {
|
||||
const BookmarksScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bookmarks = ref.watch(bookmarksRequestProvider);
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
void openAddModal() {
|
||||
showGeneralDialog(
|
||||
context: context,
|
||||
barrierColor: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)) ? Colors.transparent : Colors.black54,
|
||||
transitionBuilder: (context, anim1, anim2, child) {
|
||||
return SlideTransition(
|
||||
position: Tween(begin: const Offset(0, 1), end: const Offset(0, 0)).animate(
|
||||
CurvedAnimation(parent: anim1, curve: Curves.easeInOutCubicEmphasized),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
pageBuilder: (context, animation, secondaryAnimation) => AddBookmarkModal(fullscreen: width <= 700),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: SliverAppBar.large(
|
||||
pinned: true,
|
||||
floating: true,
|
||||
centerTitle: false,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
title: Text(t.bookmarks.bookmarks),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (context) => RefreshIndicator(
|
||||
displacement: 120,
|
||||
onRefresh: () => ref.refresh(bookmarksRequestProvider.future),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
if (bookmarks.isLoading && !bookmarks.isRefreshing)
|
||||
const SliverFillRemaining(
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (bookmarks.value != null && bookmarks.value!.successful == false)
|
||||
const SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Icon(Icons.error),
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isEmpty)
|
||||
const SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Text("No bookmarks"),
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isNotEmpty)
|
||||
SliverList.builder(
|
||||
itemCount: bookmarks.value!.content!.results!.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
// index == bookmarks.value!.content!.results!.length -> itemCount + 1
|
||||
if (index == bookmarks.value!.content!.results!.length) {
|
||||
// Bottom gap for FAB
|
||||
return const SizedBox(height: 80);
|
||||
}
|
||||
final link = bookmarks.value?.content?.results?[index];
|
||||
return Column(
|
||||
children: [
|
||||
LinkItem(bookmark: link!),
|
||||
if (index < bookmarks.value!.content!.results!.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Divider(
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: openAddModal,
|
||||
child: const Icon(Icons.add_rounded),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user