Added search
This commit is contained in:
98
lib/screens/links/ui/link_item.dart
Normal file
98
lib/screens/links/ui/link_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,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import 'package:linkdy/providers/app_status_provider.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/screens/links/ui/link_item.dart';
|
||||
import 'package:linkdy/utils/open_url.dart';
|
||||
|
||||
class Links extends ConsumerWidget {
|
||||
@@ -22,33 +23,6 @@ class Links extends ConsumerWidget {
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
String validateStrings(String? string1, String? string2) {
|
||||
if (string1 != null && string1.isNotEmpty) {
|
||||
return string1;
|
||||
} else if (string2 != null && string2.isNotEmpty) {
|
||||
return string2;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
String dateString(DateTime date) {
|
||||
String addZeros(int value) {
|
||||
return value.toString().padLeft(2, '0');
|
||||
}
|
||||
|
||||
final today = DateTime.now();
|
||||
final yesterday = DateTime.now().subtract(const Duration(days: 1));
|
||||
|
||||
if (date.day == today.day && date.month == today.month && date.year == today.year) {
|
||||
return t.links.dates.todayAt(time: "${addZeros(date.hour)}:${addZeros(date.minute)}");
|
||||
} else if (date.day == yesterday.day && date.month == yesterday.month && date.year == yesterday.year) {
|
||||
return t.links.dates.yesterdayAt(time: "${addZeros(date.hour)}:${addZeros(date.minute)}");
|
||||
} else {
|
||||
return "${date.day}/${date.month}/${date.year} - ${addZeros(date.hour)}:${addZeros(date.minute)}";
|
||||
}
|
||||
}
|
||||
|
||||
void openAddModal() {
|
||||
showGeneralDialog(
|
||||
context: context,
|
||||
@@ -123,72 +97,7 @@ class Links extends ConsumerWidget {
|
||||
final link = bookmarks.value?.content?.results?[index];
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: ref.watch(appStatusProvider).useInAppBrowser == true
|
||||
? () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: link)
|
||||
: () => openUrl(link!.url!),
|
||||
isThreeLine: true,
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(
|
||||
validateStrings(link?.title, link?.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(link?.description, link?.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(
|
||||
link?.tagNames?.map((tag) => "#$tag").join(" ") ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (link?.dateModified != null) ...[
|
||||
if (link?.tagNames?.isNotEmpty == true)
|
||||
Container(
|
||||
width: 1,
|
||||
height: 12,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
Text(
|
||||
dateString(link!.dateModified!),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
LinkItem(bookmark: link!),
|
||||
if (index < bookmarks.value!.content!.results!.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
|
||||
Reference in New Issue
Block a user