mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-26 08:54:42 +01:00
Add places to search suggestion
This commit is contained in:
parent
88727f1818
commit
ac6b3586d3
2 changed files with 66 additions and 0 deletions
|
@ -11,6 +11,7 @@ import 'package:nc_photos/entity/person.dart';
|
|||
import 'package:nc_photos/entity/tag.dart';
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/use_case/list_album.dart';
|
||||
import 'package:nc_photos/use_case/list_location_group.dart';
|
||||
import 'package:nc_photos/use_case/list_person.dart';
|
||||
import 'package:nc_photos/use_case/list_tag.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
@ -51,6 +52,17 @@ class HomeSearchPersonResult implements HomeSearchResult {
|
|||
final Person person;
|
||||
}
|
||||
|
||||
class HomeSearchLocationResult implements HomeSearchResult {
|
||||
const HomeSearchLocationResult(this.location);
|
||||
|
||||
@override
|
||||
toString() => "$runtimeType {"
|
||||
"location: $location, "
|
||||
"}";
|
||||
|
||||
final LocationGroup location;
|
||||
}
|
||||
|
||||
abstract class HomeSearchSuggestionBlocEvent {
|
||||
const HomeSearchSuggestionBlocEvent();
|
||||
}
|
||||
|
@ -200,6 +212,19 @@ class HomeSearchSuggestionBloc
|
|||
} catch (e) {
|
||||
_log.warning("[_onEventPreloadData] Failed while ListPerson", e);
|
||||
}
|
||||
try {
|
||||
final locations = await ListLocationGroup(_c)(account);
|
||||
// replace duplicated entries in name by the one in countryCode
|
||||
final map = <String, LocationGroup>{};
|
||||
for (final l in locations.name + locations.countryCode) {
|
||||
map[l.place] = l;
|
||||
}
|
||||
product.addAll(map.values.map((e) => _LocationSearcheable(e)));
|
||||
_log.info(
|
||||
"[_onEventPreloadData] Loaded ${locations.name.length + locations.countryCode.length} locations");
|
||||
} catch (e) {
|
||||
_log.warning("[_onEventPreloadData] Failed while ListLocationGroup", e);
|
||||
}
|
||||
|
||||
_setSearchItems(product);
|
||||
}
|
||||
|
@ -262,3 +287,15 @@ class _PersonSearcheable implements _Searcheable {
|
|||
|
||||
final Person person;
|
||||
}
|
||||
|
||||
class _LocationSearcheable implements _Searcheable {
|
||||
const _LocationSearcheable(this.location);
|
||||
|
||||
@override
|
||||
toKeywords() => [location.place.toCi()];
|
||||
|
||||
@override
|
||||
toResult() => HomeSearchLocationResult(location);
|
||||
|
||||
final LocationGroup location;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,11 @@ import 'package:nc_photos/exception_util.dart' as exception_util;
|
|||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:nc_photos/theme.dart';
|
||||
import 'package:nc_photos/use_case/list_location_group.dart';
|
||||
import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
|
||||
import 'package:nc_photos/widget/page_visibility_mixin.dart';
|
||||
import 'package:nc_photos/widget/person_browser.dart';
|
||||
import 'package:nc_photos/widget/place_browser.dart';
|
||||
import 'package:nc_photos/widget/tag_browser.dart';
|
||||
|
||||
class HomeSearchSuggestionController {
|
||||
|
@ -133,6 +135,14 @@ class _HomeSearchSuggestionState extends State<HomeSearchSuggestion>
|
|||
}
|
||||
}
|
||||
|
||||
void _onLocationPressed(_LocationListItem item) {
|
||||
if (mounted) {
|
||||
Navigator.of(context).pushNamed(PlaceBrowser.routeName,
|
||||
arguments: PlaceBrowserArguments(
|
||||
widget.account, item.location.place, item.location.countryCode));
|
||||
}
|
||||
}
|
||||
|
||||
void _transformItems(List<HomeSearchResult> results) {
|
||||
final items = () sync* {
|
||||
for (final r in results) {
|
||||
|
@ -142,6 +152,8 @@ class _HomeSearchSuggestionState extends State<HomeSearchSuggestion>
|
|||
yield _TagListItem(r.tag, onTap: _onTagPressed);
|
||||
} else if (r is HomeSearchPersonResult) {
|
||||
yield _PersonListItem(r.person, onTap: _onPersonPressed);
|
||||
} else if (r is HomeSearchLocationResult) {
|
||||
yield _LocationListItem(r.location, onTap: _onLocationPressed);
|
||||
} else {
|
||||
_log.warning("[_transformItems] Unknown type: ${r.runtimeType}");
|
||||
}
|
||||
|
@ -213,3 +225,20 @@ class _PersonListItem implements _ListItem {
|
|||
final Person person;
|
||||
final void Function(_PersonListItem)? onTap;
|
||||
}
|
||||
|
||||
class _LocationListItem implements _ListItem {
|
||||
const _LocationListItem(
|
||||
this.location, {
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
buildWidget(BuildContext context) => ListTile(
|
||||
leading: const Icon(Icons.location_on_outlined),
|
||||
title: Text(location.place),
|
||||
onTap: onTap == null ? null : () => onTap!(this),
|
||||
);
|
||||
|
||||
final LocationGroup location;
|
||||
final void Function(_LocationListItem)? onTap;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue