intermediate
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/settings.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'save_settings.g.dart';
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:lensai/features/bangs/data/models/bang.dart';
|
||||
import 'package:lensai/features/bangs/domain/providers/bangs.dart';
|
||||
import 'package:lensai/features/bangs/domain/repositories/data.dart';
|
||||
import 'package:lensai/features/kagi/data/entities/modes.dart';
|
||||
import 'package:lensai/features/settings/data/models/settings.dart';
|
||||
import 'package:lensai/features/settings/data/repositories/settings_repository.dart';
|
||||
import 'package:lensai/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/bang_group_list_tile.dart';
|
||||
import 'package:lensai/features/settings/presentation/widgets/custom_list_tile.dart';
|
||||
import 'package:lensai/features/settings/utils/session_link_extractor.dart';
|
||||
import 'package:lensai/presentation/hooks/listenable_callback.dart';
|
||||
import 'package:lensai/utils/ui_helper.dart' as ui_helper;
|
||||
import 'package:lensai/features/user/data/models/settings.dart';
|
||||
import 'package:lensai/features/user/domain/providers/cache.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/cache.dart';
|
||||
import 'package:lensai/features/user/domain/repositories/settings.dart';
|
||||
|
||||
class SettingsScreen extends HookConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -44,40 +39,7 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final settings = ref.watch(
|
||||
settingsRepositoryProvider.select(
|
||||
(value) => value.valueOrNull ?? Settings.withDefaults(),
|
||||
),
|
||||
);
|
||||
|
||||
final kagiSessionTextController = useTextEditingController(
|
||||
text: settings.kagiSession,
|
||||
);
|
||||
final hideSessionText = useState(true);
|
||||
|
||||
useListenableCallback(kagiSessionTextController, () async {
|
||||
var text = kagiSessionTextController.text;
|
||||
if (Uri.tryParse(text) case final Uri uri) {
|
||||
if (extractKagiSession(uri) case final String session) {
|
||||
text = session;
|
||||
}
|
||||
}
|
||||
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) => currentSettings.copyWith.kagiSession(text),
|
||||
);
|
||||
});
|
||||
|
||||
ref.listen(
|
||||
settingsRepositoryProvider.select(
|
||||
(settings) => settings.valueOrNull?.kagiSession,
|
||||
), (previous, next) {
|
||||
if (next != null &&
|
||||
next.isNotEmpty &&
|
||||
kagiSessionTextController.text != next) {
|
||||
kagiSessionTextController.text = next;
|
||||
}
|
||||
});
|
||||
final settings = ref.watch(settingsRepositoryProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Settings')),
|
||||
@@ -87,67 +49,6 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
children: [
|
||||
_buildSection(theme, 'Kagi'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 8,
|
||||
),
|
||||
child: TextField(
|
||||
enableIMEPersonalizedLearning: false,
|
||||
autocorrect: false,
|
||||
controller: kagiSessionTextController,
|
||||
obscureText: hideSessionText.value,
|
||||
decoration: InputDecoration(
|
||||
label: const Text('Kagi Session Token'),
|
||||
hintText: 'https://kagi.com/search?token=...',
|
||||
helperMaxLines: 2,
|
||||
helper: Markdown(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.zero,
|
||||
data:
|
||||
'You can visit your [Kagi Account Settings](user_details) to get your Session Link.',
|
||||
onTapLink: (text, href, title) async {
|
||||
if (href == 'user_details') {
|
||||
await ui_helper.launchUrlFeedback(
|
||||
context,
|
||||
Uri.parse(
|
||||
'https://kagi.com/settings?p=user_details',
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
hideSessionText.value = !hideSessionText.value;
|
||||
},
|
||||
icon: Icon(
|
||||
hideSessionText.value
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Show Early Access Features'),
|
||||
subtitle: const Text(
|
||||
"Displays Kagi's early access features in the UI. As an Ultimate subscriber, you will likely want to have this enabled.",
|
||||
),
|
||||
value: settings.showEarlyAccessFeatures,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.showEarlyAccessFeatures(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
_buildSection(theme, 'General'),
|
||||
Padding(
|
||||
padding:
|
||||
@@ -232,19 +133,6 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Launch Links Externally'),
|
||||
subtitle: const Text(
|
||||
'Opens all links (except for kagi.com) in your default browser.',
|
||||
),
|
||||
value: settings.launchUrlExternal,
|
||||
onChanged: (value) async {
|
||||
await ref.read(saveSettingsControllerProvider.notifier).save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.launchUrlExternal(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Enable Reader Mode'),
|
||||
subtitle: const Text(
|
||||
@@ -261,77 +149,6 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
_buildSection(theme, 'Appearance'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const CustomListTile(
|
||||
title: 'Quick Action',
|
||||
subtitle:
|
||||
'Appears in the browser app bar between website title and tab count.',
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Center(
|
||||
child: SegmentedButton<KagiTool>(
|
||||
emptySelectionAllowed: true,
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: KagiTool.search,
|
||||
icon: Icon(KagiTool.search.icon),
|
||||
label: const Text('Search'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: KagiTool.summarizer,
|
||||
icon: Icon(KagiTool.summarizer.icon),
|
||||
label: const Text('Summarizer'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: KagiTool.assistant,
|
||||
icon: Icon(KagiTool.assistant.icon),
|
||||
label: const Text('Assistant'),
|
||||
),
|
||||
],
|
||||
selected: {
|
||||
if (settings.quickAction != null)
|
||||
settings.quickAction!,
|
||||
},
|
||||
onSelectionChanged: (value) async {
|
||||
await ref
|
||||
.read(saveSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.quickAction(
|
||||
value.isNotEmpty ? value.first : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SwitchListTile.adaptive(
|
||||
title: const Text('Quick Action - STT'),
|
||||
subtitle: const Text(
|
||||
'Quick option will open with speech-to-text input.',
|
||||
),
|
||||
value: settings.quickActionVoiceInput,
|
||||
onChanged: (settings.quickAction != null)
|
||||
? (value) async {
|
||||
await ref
|
||||
.read(saveSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) => currentSettings.copyWith
|
||||
.quickActionVoiceInput(value),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
_buildSection(theme, 'Content Blocking'),
|
||||
_buildSubSection(theme, 'Lists'),
|
||||
const SizedBox(
|
||||
@@ -354,7 +171,7 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final size = ref.watch(
|
||||
bangIconCacheSizeMegabytesProvider.select(
|
||||
iconCacheSizeMegabytesProvider.select(
|
||||
(value) => value.valueOrNull,
|
||||
),
|
||||
);
|
||||
@@ -384,8 +201,8 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
suffix: FilledButton.icon(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(bangDataRepositoryProvider.notifier)
|
||||
.clearIconData();
|
||||
.read(cacheRepositoryProvider.notifier)
|
||||
.clearCache();
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Clear'),
|
||||
|
||||
Reference in New Issue
Block a user