2022-07-27 07:30:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-16 11:10:58 +00:00
|
|
|
import "package:intl/intl.dart";
|
2022-07-27 07:30:51 +00:00
|
|
|
import 'package:photos/ente_theme_data.dart';
|
2023-11-01 06:43:15 +00:00
|
|
|
import "package:photos/models/search/recent_searches.dart";
|
2022-09-14 08:40:35 +00:00
|
|
|
import 'package:photos/models/search/search_result.dart';
|
2023-02-24 07:56:33 +00:00
|
|
|
import "package:photos/models/search/search_types.dart";
|
2023-10-16 11:15:28 +00:00
|
|
|
import "package:photos/theme/ente_theme.dart";
|
2022-09-14 08:33:12 +00:00
|
|
|
import 'package:photos/ui/viewer/search/result/search_result_page.dart';
|
|
|
|
import 'package:photos/ui/viewer/search/result/search_thumbnail_widget.dart';
|
2022-07-27 07:30:51 +00:00
|
|
|
import 'package:photos/utils/navigation_util.dart';
|
|
|
|
|
2022-09-14 08:33:12 +00:00
|
|
|
class SearchResultWidget extends StatelessWidget {
|
|
|
|
final SearchResult searchResult;
|
|
|
|
final Future<int>? resultCount;
|
|
|
|
final Function? onResultTap;
|
2022-07-28 05:08:20 +00:00
|
|
|
|
2022-09-14 08:33:12 +00:00
|
|
|
const SearchResultWidget(
|
|
|
|
this.searchResult, {
|
|
|
|
Key? key,
|
|
|
|
this.resultCount,
|
|
|
|
this.onResultTap,
|
|
|
|
}) : super(key: key);
|
2022-07-27 07:30:51 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-14 08:33:12 +00:00
|
|
|
final heroTagPrefix = searchResult.heroTag();
|
2023-10-16 11:15:28 +00:00
|
|
|
final textTheme = getEnteTextTheme(context);
|
2022-09-14 08:33:12 +00:00
|
|
|
|
2022-07-27 07:30:51 +00:00
|
|
|
return GestureDetector(
|
2022-08-02 05:04:12 +00:00
|
|
|
behavior: HitTestBehavior.opaque,
|
2022-08-05 16:56:06 +00:00
|
|
|
child: Container(
|
2023-10-16 14:06:14 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
2023-10-25 05:19:25 +00:00
|
|
|
border: Border.all(
|
|
|
|
color: getEnteColorScheme(context).strokeFainter,
|
|
|
|
),
|
2023-10-16 14:06:14 +00:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SearchThumbnailWidget(
|
|
|
|
searchResult.previewThumbnail(),
|
|
|
|
heroTagPrefix,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
2023-10-25 05:19:25 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 2),
|
|
|
|
child: Column(
|
2022-08-11 14:45:42 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-08-13 13:13:31 +00:00
|
|
|
SizedBox(
|
|
|
|
width: 220,
|
|
|
|
child: Text(
|
2022-09-14 08:33:12 +00:00
|
|
|
searchResult.name(),
|
2023-10-25 05:19:25 +00:00
|
|
|
style: textTheme.body,
|
2022-08-13 13:13:31 +00:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
2022-08-11 14:45:42 +00:00
|
|
|
),
|
2023-10-25 05:19:25 +00:00
|
|
|
const SizedBox(height: 4),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
_resultTypeName(searchResult.type()),
|
|
|
|
style: textTheme.smallMuted,
|
|
|
|
),
|
|
|
|
FutureBuilder<int>(
|
|
|
|
future: resultCount ??
|
|
|
|
Future.value(searchResult.resultFiles().length),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData && snapshot.data! > 0) {
|
|
|
|
final noOfMemories = snapshot.data;
|
2023-10-16 14:06:14 +00:00
|
|
|
|
2023-10-25 05:19:25 +00:00
|
|
|
return Text(
|
2023-12-16 11:10:58 +00:00
|
|
|
" \u2022 " +
|
|
|
|
(noOfMemories! > 9999
|
|
|
|
? NumberFormat().format(noOfMemories)
|
|
|
|
: noOfMemories.toString()),
|
2023-10-25 05:19:25 +00:00
|
|
|
style: textTheme.smallMuted,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2023-08-19 11:39:56 +00:00
|
|
|
),
|
2022-08-11 14:45:42 +00:00
|
|
|
],
|
|
|
|
),
|
2023-10-16 14:06:14 +00:00
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Icon(
|
2022-08-11 14:45:42 +00:00
|
|
|
Icons.chevron_right,
|
|
|
|
color: Theme.of(context).colorScheme.subTextColor,
|
2022-07-28 13:22:53 +00:00
|
|
|
),
|
2023-10-16 14:06:14 +00:00
|
|
|
),
|
|
|
|
],
|
2022-07-27 07:30:51 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
2023-11-01 11:18:03 +00:00
|
|
|
RecentSearches().add(searchResult.name());
|
2023-11-01 06:43:15 +00:00
|
|
|
|
2022-09-14 08:33:12 +00:00
|
|
|
if (onResultTap != null) {
|
|
|
|
onResultTap!();
|
|
|
|
} else {
|
|
|
|
routeToPage(
|
|
|
|
context,
|
2023-09-22 18:16:16 +00:00
|
|
|
SearchResultPage(
|
|
|
|
searchResult,
|
|
|
|
enableGrouping: searchResult.type() != ResultType.magic,
|
|
|
|
),
|
2022-09-14 08:33:12 +00:00
|
|
|
);
|
|
|
|
}
|
2022-07-27 07:30:51 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-09-14 09:11:29 +00:00
|
|
|
|
|
|
|
String _resultTypeName(ResultType type) {
|
|
|
|
switch (type) {
|
|
|
|
case ResultType.collection:
|
|
|
|
return "Album";
|
|
|
|
case ResultType.year:
|
|
|
|
return "Year";
|
|
|
|
case ResultType.month:
|
|
|
|
return "Month";
|
|
|
|
case ResultType.file:
|
2022-12-26 17:22:17 +00:00
|
|
|
return "File name";
|
2022-09-14 09:11:29 +00:00
|
|
|
case ResultType.event:
|
|
|
|
return "Day";
|
|
|
|
case ResultType.location:
|
2022-09-15 04:44:09 +00:00
|
|
|
return "Location";
|
2022-09-15 04:29:46 +00:00
|
|
|
case ResultType.fileType:
|
|
|
|
return "Type";
|
2022-09-15 04:44:09 +00:00
|
|
|
case ResultType.fileExtension:
|
2022-12-26 17:22:17 +00:00
|
|
|
return "File extension";
|
2022-11-05 05:30:03 +00:00
|
|
|
case ResultType.fileCaption:
|
2022-11-05 14:06:03 +00:00
|
|
|
return "Description";
|
2023-09-22 18:16:16 +00:00
|
|
|
case ResultType.magic:
|
|
|
|
return "Magic";
|
2023-10-16 11:07:36 +00:00
|
|
|
case ResultType.shared:
|
|
|
|
return "Shared";
|
2022-09-14 09:11:29 +00:00
|
|
|
default:
|
|
|
|
return type.name.toUpperCase();
|
|
|
|
}
|
|
|
|
}
|
2022-07-27 07:30:51 +00:00
|
|
|
}
|