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