mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-18 18:14:21 +01:00
add quick action and desktop, bookmark add edit dialog
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:flutter_pinned_shortcut_plus/flutter_pinned_shortcut_plus.dart';
|
||||
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/bookmark_edit_dialog.dart';
|
||||
import 'package:nowser/component/cust_state.dart';
|
||||
import 'package:nowser/component/deletable_list_mixin.dart';
|
||||
import 'package:nowser/component/url_list_item_componnet.dart';
|
||||
@@ -21,6 +28,10 @@ class _BookmarkRouter extends CustState<BookmarkRouter>
|
||||
|
||||
@override
|
||||
Future<void> onReady(BuildContext context) async {
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> reload() async {
|
||||
bookmarks = await BookmarkDB.all();
|
||||
setState(() {});
|
||||
}
|
||||
@@ -59,6 +70,36 @@ class _BookmarkRouter extends CustState<BookmarkRouter>
|
||||
url: bookmark.url ?? "",
|
||||
);
|
||||
|
||||
List<Widget> slidableActionList = [];
|
||||
if (Platform.isAndroid) {
|
||||
slidableActionList.add(SlidableAction(
|
||||
onPressed: (context) {
|
||||
doAddPinnedShortcut(bookmark);
|
||||
},
|
||||
backgroundColor: Colors.green,
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.add_home,
|
||||
label: 'Desktop',
|
||||
));
|
||||
}
|
||||
slidableActionList.add(SlidableAction(
|
||||
onPressed: (context) {
|
||||
doEdit(bookmark);
|
||||
},
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.edit,
|
||||
label: 'Edit',
|
||||
));
|
||||
|
||||
main = Slidable(
|
||||
endActionPane: ActionPane(
|
||||
motion: ScrollMotion(),
|
||||
children: slidableActionList,
|
||||
),
|
||||
child: main,
|
||||
);
|
||||
|
||||
main = wrapListItem(main, onTap: () {
|
||||
RouterUtil.back(context, bookmark.url);
|
||||
}, onSelect: () {
|
||||
@@ -86,4 +127,36 @@ class _BookmarkRouter extends CustState<BookmarkRouter>
|
||||
selectedIds.clear();
|
||||
}
|
||||
}
|
||||
|
||||
final _flutterPinnedShortcutPlugin = FlutterPinnedShortcut();
|
||||
|
||||
Future<void> doAddPinnedShortcut(Bookmark bookmark) async {
|
||||
File? file;
|
||||
if (StringUtil.isNotBlank(bookmark.favicon)) {
|
||||
// use favicon as icon
|
||||
file = await DefaultCacheManager().getSingleFile(bookmark.favicon!);
|
||||
} else {
|
||||
// use default image as icon
|
||||
// file =
|
||||
print("favicon not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtil.isBlank(bookmark.title) ||
|
||||
StringUtil.isBlank(bookmark.url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_flutterPinnedShortcutPlugin.createPinnedShortcut(
|
||||
id: StringUtil.rndNameStr(10),
|
||||
label: bookmark.title!,
|
||||
action: bookmark.url!,
|
||||
iconAssetName: "assets/logo_android.png",
|
||||
iconUri: Uri.file(file.path).toString());
|
||||
}
|
||||
|
||||
Future<void> doEdit(Bookmark bookmark) async {
|
||||
await BookmarkEditDialog.show(context, bookmark);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,15 +40,53 @@ class _IndexRouter extends CustState<IndexRouter>
|
||||
|
||||
// start build-in
|
||||
buildInRelayProvider.start();
|
||||
|
||||
if (PlatformUtil.isAndroid()) {
|
||||
var intent = await getInitialIntent();
|
||||
if (intent != null) {
|
||||
if (intent.categories != null &&
|
||||
intent.categories!.contains("android.intent.category.LAUNCHER") &&
|
||||
intent.extra != null &&
|
||||
intent.extra!["flutter_pinned_shortcuts"] != null) {
|
||||
var url = intent.extra!["flutter_pinned_shortcuts"];
|
||||
print("find url! $url");
|
||||
webProvider.checkAndOpenUrl(url);
|
||||
} else {
|
||||
dohandleInitialIntent(context, intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
quickActions.initialize((shortcutType) {
|
||||
print("find quickAction $shortcutType");
|
||||
webProvider.checkAndOpenUrl(shortcutType);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget doBuild(BuildContext context) {
|
||||
if (PlatformUtil.isAndroid()) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
handleInitialIntent(context);
|
||||
});
|
||||
}
|
||||
// if (PlatformUtil.isAndroid()) {
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// var intent = await getInitialIntent();
|
||||
// if (intent != null) {
|
||||
// if (intent.categories != null &&
|
||||
// intent.categories!.contains("android.intent.category.LAUNCHER") &&
|
||||
// intent.extra != null &&
|
||||
// intent.extra!["flutter_pinned_shortcuts"] != null) {
|
||||
// var url = intent.extra!["flutter_pinned_shortcuts"];
|
||||
// print("find url! $url");
|
||||
// webProvider.checkAndOpenUrl(url);
|
||||
// } else {
|
||||
// dohandleInitialIntent(context, intent);
|
||||
// }
|
||||
// }
|
||||
|
||||
// quickActions.initialize((shortcutType) {
|
||||
// print("find quickAction $shortcutType");
|
||||
// webProvider.checkAndOpenUrl(shortcutType);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
remoteSigningProvider.updateContext(context);
|
||||
webProvider.checkBlank();
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class _WebControlComponent extends State<WebControlComponent> {
|
||||
onTap: () {
|
||||
var webInfo = webProvider.currentWebInfo();
|
||||
if (webInfo != null) {
|
||||
webProvider.addBookmark(webInfo);
|
||||
webProvider.addBookmark(context, webInfo);
|
||||
widget.closeControl();
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user