global search: added ad hoc search shortcut suggestion
This commit is contained in:
parent
a95670c341
commit
7013f5ab93
5 changed files with 37 additions and 8 deletions
|
@ -149,11 +149,14 @@ class MainActivity : FlutterActivity() {
|
|||
)
|
||||
}
|
||||
Intent.ACTION_SEARCH -> {
|
||||
return hashMapOf(
|
||||
val viewUri = intent.dataString
|
||||
return if (viewUri != null) hashMapOf(
|
||||
"action" to "view",
|
||||
"uri" to viewUri,
|
||||
"mimeType" to intent.getStringExtra(SearchManager.EXTRA_DATA_KEY),
|
||||
) else hashMapOf(
|
||||
"action" to "search",
|
||||
"query" to intent.getStringExtra(SearchManager.QUERY),
|
||||
"mimeType" to intent.getStringExtra(SearchManager.EXTRA_DATA_KEY),
|
||||
"uri" to intent.dataString
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
|
|
|
@ -2,6 +2,7 @@ package deckers.thibault.aves
|
|||
|
||||
import android.app.SearchManager
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentResolver
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
|
@ -45,6 +46,10 @@ class SearchSuggestionsProvider : MethodChannel.MethodCallHandler, ContentProvid
|
|||
|
||||
val matrixCursor = MatrixCursor(columns)
|
||||
context?.let { context ->
|
||||
val searchShortcutTitle = "${context.resources.getString(R.string.search_shortcut_short_label)} $query"
|
||||
val searchShortcutIcon = context.resourceUri(R.mipmap.ic_shortcut_search)
|
||||
matrixCursor.addRow(arrayOf(null, null, null, searchShortcutTitle, null, searchShortcutIcon))
|
||||
|
||||
runBlocking {
|
||||
getSuggestions(context, query).forEach {
|
||||
val data = it["data"]
|
||||
|
@ -170,5 +175,14 @@ class SearchSuggestionsProvider : MethodChannel.MethodCallHandler, ContentProvid
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Context.resourceUri(resourceId: Int): Uri = with(resources) {
|
||||
Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||
.authority(getResourcePackageName(resourceId))
|
||||
.appendPath(getResourceTypeName(resourceId))
|
||||
.appendPath(getResourceEntryName(resourceId))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ Future<List<Map<String, String?>>> _getSuggestions(dynamic args) async {
|
|||
final query = args['query'];
|
||||
final locale = args['locale'];
|
||||
if (query is String && locale is String) {
|
||||
final entries = await metadataDb.searchEntries(query, limit: 10);
|
||||
final entries = await metadataDb.searchEntries(query, limit: 9);
|
||||
suggestions.addAll(entries.map((entry) {
|
||||
final date = entry.bestDate;
|
||||
return {
|
||||
|
|
|
@ -40,7 +40,7 @@ class HomePage extends StatefulWidget {
|
|||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
AvesEntry? _viewerEntry;
|
||||
String? _shortcutRouteName;
|
||||
String? _shortcutRouteName, _shortcutSearchQuery;
|
||||
List<String>? _shortcutFilters;
|
||||
|
||||
static const allowedShortcutRoutes = [CollectionPage.routeName, AlbumListPage.routeName, SearchPage.routeName];
|
||||
|
@ -76,7 +76,6 @@ class _HomePageState extends State<HomePage> {
|
|||
final action = intentData['action'];
|
||||
switch (action) {
|
||||
case 'view':
|
||||
case 'search':
|
||||
_viewerEntry = await _initViewerEntry(
|
||||
uri: intentData['uri'],
|
||||
mimeType: intentData['mimeType'],
|
||||
|
@ -92,6 +91,10 @@ class _HomePageState extends State<HomePage> {
|
|||
String? pickMimeTypes = intentData['mimeType'];
|
||||
debugPrint('pick mimeType=$pickMimeTypes');
|
||||
break;
|
||||
case 'search':
|
||||
_shortcutRouteName = SearchPage.routeName;
|
||||
_shortcutSearchQuery = intentData['query'];
|
||||
break;
|
||||
default:
|
||||
// do not use 'route' as extra key, as the Flutter framework acts on it
|
||||
final extraRoute = intentData['page'];
|
||||
|
@ -157,7 +160,10 @@ class _HomePageState extends State<HomePage> {
|
|||
);
|
||||
case SearchPage.routeName:
|
||||
return SearchPageRoute(
|
||||
delegate: CollectionSearchDelegate(source: source),
|
||||
delegate: CollectionSearchDelegate(
|
||||
source: source,
|
||||
initialQuery: _shortcutSearchQuery,
|
||||
),
|
||||
);
|
||||
case CollectionPage.routeName:
|
||||
default:
|
||||
|
|
|
@ -42,7 +42,13 @@ class CollectionSearchDelegate {
|
|||
MimeFilter(MimeTypes.svg),
|
||||
];
|
||||
|
||||
CollectionSearchDelegate({required this.source, this.parentCollection});
|
||||
CollectionSearchDelegate({
|
||||
required this.source,
|
||||
this.parentCollection,
|
||||
String? initialQuery,
|
||||
}) {
|
||||
query = initialQuery ?? '';
|
||||
}
|
||||
|
||||
Widget buildLeading(BuildContext context) {
|
||||
return Navigator.canPop(context)
|
||||
|
|
Loading…
Reference in a new issue