mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54:19 +01:00
input and search
This commit is contained in:
@@ -56,6 +56,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"ConnectType": MessageLookupByLibrary.simpleMessage("ConnectType"),
|
||||
"Connect_by": MessageLookupByLibrary.simpleMessage("Connect by"),
|
||||
"Copy_success": MessageLookupByLibrary.simpleMessage("Copy success"),
|
||||
"Custom": MessageLookupByLibrary.simpleMessage("Custom"),
|
||||
"Dark": MessageLookupByLibrary.simpleMessage("Dark"),
|
||||
"Decrypt04_name":
|
||||
MessageLookupByLibrary.simpleMessage("Decrypt (NIP-04)"),
|
||||
@@ -86,6 +87,8 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"Historys": MessageLookupByLibrary.simpleMessage("Historys"),
|
||||
"Input_can_not_be_null":
|
||||
MessageLookupByLibrary.simpleMessage("Input can\'t be null"),
|
||||
"Input_search_url_des":
|
||||
MessageLookupByLibrary.simpleMessage("Please input searching url"),
|
||||
"Keys_Manager": MessageLookupByLibrary.simpleMessage("Keys Manager"),
|
||||
"Language": MessageLookupByLibrary.simpleMessage("Language"),
|
||||
"Light": MessageLookupByLibrary.simpleMessage("Light"),
|
||||
|
||||
@@ -52,6 +52,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"ConnectType": MessageLookupByLibrary.simpleMessage("链接类型"),
|
||||
"Connect_by": MessageLookupByLibrary.simpleMessage("链接"),
|
||||
"Copy_success": MessageLookupByLibrary.simpleMessage("复制成功"),
|
||||
"Custom": MessageLookupByLibrary.simpleMessage("自定义"),
|
||||
"Dark": MessageLookupByLibrary.simpleMessage("深色"),
|
||||
"Decrypt04_name": MessageLookupByLibrary.simpleMessage("解密 (NIP-04)"),
|
||||
"Decrypt44_name": MessageLookupByLibrary.simpleMessage("解密 (NIP-44)"),
|
||||
@@ -74,6 +75,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"Get_Relays": MessageLookupByLibrary.simpleMessage("获取中继"),
|
||||
"Historys": MessageLookupByLibrary.simpleMessage("历史"),
|
||||
"Input_can_not_be_null": MessageLookupByLibrary.simpleMessage("输入不能为空"),
|
||||
"Input_search_url_des": MessageLookupByLibrary.simpleMessage("请输入搜索链接"),
|
||||
"Keys_Manager": MessageLookupByLibrary.simpleMessage("秘钥管理"),
|
||||
"Language": MessageLookupByLibrary.simpleMessage("语言"),
|
||||
"Light": MessageLookupByLibrary.simpleMessage("浅色"),
|
||||
|
||||
@@ -889,6 +889,26 @@ class S {
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// `Custom`
|
||||
String get Custom {
|
||||
return Intl.message(
|
||||
'Custom',
|
||||
name: 'Custom',
|
||||
desc: '',
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// `Please input searching url`
|
||||
String get Input_search_url_des {
|
||||
return Intl.message(
|
||||
'Please input searching url',
|
||||
name: 'Input_search_url_des',
|
||||
desc: '',
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppLocalizationDelegate extends LocalizationsDelegate<S> {
|
||||
|
||||
@@ -82,5 +82,7 @@
|
||||
"Search_Engine": "Search Engine",
|
||||
"About": "About",
|
||||
"About_Me": "About Me",
|
||||
"Privacy": "Privacy"
|
||||
"Privacy": "Privacy",
|
||||
"Custom": "Custom",
|
||||
"Input_search_url_des": "Please input searching url"
|
||||
}
|
||||
@@ -82,5 +82,7 @@
|
||||
"Search_Engine": "搜索引擎",
|
||||
"About": "关于",
|
||||
"About_Me": "关于我",
|
||||
"Privacy": "隐私"
|
||||
"Privacy": "隐私",
|
||||
"Custom": "自定义",
|
||||
"Input_search_url_des": "请输入搜索链接"
|
||||
}
|
||||
@@ -79,6 +79,8 @@ class SettingProvider extends ChangeNotifier {
|
||||
|
||||
int? get tableMode => _settingData!.tableMode;
|
||||
|
||||
String? get searchEngine => _settingData!.searchEngine;
|
||||
|
||||
set settingData(SettingData o) {
|
||||
_settingData = o;
|
||||
saveAndNotifyListeners();
|
||||
@@ -144,6 +146,11 @@ class SettingProvider extends ChangeNotifier {
|
||||
saveAndNotifyListeners();
|
||||
}
|
||||
|
||||
set searchEngine(String? o) {
|
||||
_settingData!.searchEngine = o;
|
||||
saveAndNotifyListeners();
|
||||
}
|
||||
|
||||
Future<void> saveAndNotifyListeners({bool updateUI = true}) async {
|
||||
_settingData!.updatedTime = DateTime.now().millisecondsSinceEpoch;
|
||||
var m = _settingData!.toJson();
|
||||
@@ -187,6 +194,8 @@ class SettingData {
|
||||
|
||||
int? tableMode;
|
||||
|
||||
String? searchEngine;
|
||||
|
||||
/// updated time
|
||||
late int updatedTime;
|
||||
|
||||
@@ -202,6 +211,7 @@ class SettingData {
|
||||
this.fontFamily,
|
||||
this.fontSize,
|
||||
this.tableMode,
|
||||
this.searchEngine,
|
||||
this.updatedTime = 0,
|
||||
});
|
||||
|
||||
@@ -220,6 +230,7 @@ class SettingData {
|
||||
backgroundImage = json['backgroundImage'];
|
||||
fontSize = json['fontSize'];
|
||||
tableMode = json['tableMode'];
|
||||
searchEngine = json['searchEngine'];
|
||||
if (json['updatedTime'] != null) {
|
||||
updatedTime = json['updatedTime'];
|
||||
} else {
|
||||
@@ -240,6 +251,7 @@ class SettingData {
|
||||
data['fontFamily'] = this.fontFamily;
|
||||
data['fontSize'] = this.fontSize;
|
||||
data['tableMode'] = this.tableMode;
|
||||
data['searchEngine'] = this.searchEngine;
|
||||
data['updatedTime'] = this.updatedTime;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/text_input/text_input_dialog.dart';
|
||||
|
||||
import '../../component/enum_selector_component.dart';
|
||||
import '../../const/base.dart';
|
||||
@@ -45,6 +47,7 @@ class _SettingRouter extends State<SettingRouter> {
|
||||
|
||||
initI18nList(s);
|
||||
initThemeStyleList(s);
|
||||
initSearchEngineList(s);
|
||||
|
||||
Widget titleWidget = Container(
|
||||
alignment: Alignment.topLeft,
|
||||
@@ -75,8 +78,9 @@ class _SettingRouter extends State<SettingRouter> {
|
||||
));
|
||||
configList.add(SettingItemComponent(
|
||||
s.Search_Engine,
|
||||
value: "https://www.baidu.com/",
|
||||
showTopBorder: true,
|
||||
onTap: pickSearchEngine,
|
||||
child: getSearchEngineWidget(settingProvider.searchEngine),
|
||||
));
|
||||
var configListWidget = genConfigListWidget(configList, themeData);
|
||||
|
||||
@@ -261,4 +265,52 @@ class _SettingRouter extends State<SettingRouter> {
|
||||
}
|
||||
return themeStyleList![0];
|
||||
}
|
||||
|
||||
List<EnumObj>? searchEngineList;
|
||||
|
||||
void initSearchEngineList(S s) {
|
||||
if (searchEngineList == null) {
|
||||
searchEngineList = [];
|
||||
searchEngineList!
|
||||
.add(EnumObj("https://duckduckgo.com/?&q=", "DuckDuckGo"));
|
||||
searchEngineList!
|
||||
.add(EnumObj("https://www.google.com/search?q=", "Google"));
|
||||
searchEngineList!.add(EnumObj("https://www.bing.com/search?q=", "Bing"));
|
||||
searchEngineList!.add(EnumObj("", s.Custom));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickSearchEngine() async {
|
||||
EnumObj? resultEnumObj =
|
||||
await EnumSelectorComponent.show(context, searchEngineList!);
|
||||
if (resultEnumObj != null) {
|
||||
if (StringUtil.isNotBlank(resultEnumObj.value)) {
|
||||
settingProvider.searchEngine = resultEnumObj.value;
|
||||
resetTheme();
|
||||
return;
|
||||
}
|
||||
|
||||
// custom config search engine
|
||||
var value = await TextInputDialog.show(context, s.Input_search_url_des);
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
settingProvider.searchEngine = resultEnumObj.value;
|
||||
resetTheme();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget getSearchEngineWidget(String? value) {
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
return Container(
|
||||
width: 180,
|
||||
child: Text(
|
||||
value!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Text("DuckDuckGo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nowser/component/qrscanner.dart';
|
||||
import 'package:nowser/main.dart';
|
||||
import 'package:nowser/util/router_util.dart';
|
||||
|
||||
import '../../const/base.dart';
|
||||
@@ -54,7 +55,7 @@ class _WebUrlInputRouter extends State<WebUrlInputRouter> {
|
||||
decoration: const InputDecoration(border: OutlineInputBorder()),
|
||||
focusNode: focusNode,
|
||||
onSubmitted: (value) {
|
||||
RouterUtil.back(context, value);
|
||||
checkAndBack(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -83,9 +84,7 @@ class _WebUrlInputRouter extends State<WebUrlInputRouter> {
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
var url = await QRScanner.show(context);
|
||||
if (StringUtil.isNotBlank(url) && url!.startsWith("http")) {
|
||||
RouterUtil.back(context, url);
|
||||
}
|
||||
checkAndBack(url);
|
||||
},
|
||||
child: Icon(Icons.qr_code_scanner),
|
||||
),
|
||||
@@ -103,4 +102,21 @@ class _WebUrlInputRouter extends State<WebUrlInputRouter> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void checkAndBack(String? value) {
|
||||
if (StringUtil.isNotBlank(value) && value!.startsWith("http")) {
|
||||
RouterUtil.back(context, value);
|
||||
return;
|
||||
}
|
||||
// TODO check if this is a url without http or https, add and open it !
|
||||
|
||||
// search
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
String? searchUrl = settingProvider.searchEngine;
|
||||
searchUrl ??= "https://duckduckgo.com/?&q=";
|
||||
searchUrl += value!;
|
||||
print(searchUrl);
|
||||
RouterUtil.back(context, searchUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user