Use in app browser setting

This commit is contained in:
Juan Gilsanz Polo
2024-02-23 23:41:24 +01:00
parent d689fd0eaa
commit a11355227c
9 changed files with 40 additions and 31 deletions

View File

@@ -3,4 +3,5 @@ class SharedPreferencesKeys {
static const selectedTheme = "selectedTheme"; static const selectedTheme = "selectedTheme";
static const useDynamicTheme = "useDynamicTheme"; static const useDynamicTheme = "useDynamicTheme";
static const selectedColor = "selectedColor"; static const selectedColor = "selectedColor";
static const useInAppBrowser = "useInAppBrowser";
} }

View File

@@ -4,9 +4,9 @@
/// To regenerate, run: `dart run slang` /// To regenerate, run: `dart run slang`
/// ///
/// Locales: 2 /// Locales: 2
/// Strings: 188 (94 per locale) /// Strings: 192 (96 per locale)
/// ///
/// Built on 2024-02-23 at 21:28 UTC /// Built on 2024-02-23 at 22:17 UTC
// coverage:ignore-file // coverage:ignore-file
// ignore_for_file: type=lint // ignore_for_file: type=lint
@@ -351,6 +351,8 @@ class _StringsSettingsGeneralSettingsEn {
String get generalSettingsDescription => 'General tweaks for the application.'; String get generalSettingsDescription => 'General tweaks for the application.';
String get disconnectFromServer => 'Disconnect from server'; String get disconnectFromServer => 'Disconnect from server';
late final _StringsSettingsGeneralSettingsDisconnectModalEn disconnectModal = _StringsSettingsGeneralSettingsDisconnectModalEn._(_root); late final _StringsSettingsGeneralSettingsDisconnectModalEn disconnectModal = _StringsSettingsGeneralSettingsDisconnectModalEn._(_root);
String get useInAppBrowser => 'Use in app browser';
String get useInAppBrowserDescription => 'Opens the bookmarks with the integrated browser instead of with the system browser.';
} }
// Path: settings.generalSettings.disconnectModal // Path: settings.generalSettings.disconnectModal
@@ -591,6 +593,8 @@ class _StringsSettingsGeneralSettingsEs implements _StringsSettingsGeneralSettin
@override String get generalSettingsDescription => 'Ajustes generales para la aplicación.'; @override String get generalSettingsDescription => 'Ajustes generales para la aplicación.';
@override String get disconnectFromServer => 'Desconectar del servidor'; @override String get disconnectFromServer => 'Desconectar del servidor';
@override late final _StringsSettingsGeneralSettingsDisconnectModalEs disconnectModal = _StringsSettingsGeneralSettingsDisconnectModalEs._(_root); @override late final _StringsSettingsGeneralSettingsDisconnectModalEs disconnectModal = _StringsSettingsGeneralSettingsDisconnectModalEs._(_root);
@override String get useInAppBrowser => 'Usar navegador de la aplicación';
@override String get useInAppBrowserDescription => 'Abre los marcadores con el navegador integrado en vez de con el navegador del sietema.';
} }
// Path: settings.generalSettings.disconnectModal // Path: settings.generalSettings.disconnectModal
@@ -686,6 +690,8 @@ extension on Translations {
case 'settings.generalSettings.disconnectFromServer': return 'Disconnect from server'; case 'settings.generalSettings.disconnectFromServer': return 'Disconnect from server';
case 'settings.generalSettings.disconnectModal.title': return 'Disconnect'; case 'settings.generalSettings.disconnectModal.title': return 'Disconnect';
case 'settings.generalSettings.disconnectModal.description': return 'Are you sure you want to disconnect from the server?\nYou will be redirected to the initial setup.'; case 'settings.generalSettings.disconnectModal.description': return 'Are you sure you want to disconnect from the server?\nYou will be redirected to the initial setup.';
case 'settings.generalSettings.useInAppBrowser': return 'Use in app browser';
case 'settings.generalSettings.useInAppBrowserDescription': return 'Opens the bookmarks with the integrated browser instead of with the system browser.';
case 'webview.goBack': return 'Go back'; case 'webview.goBack': return 'Go back';
case 'webview.goForward': return 'Go forward'; case 'webview.goForward': return 'Go forward';
case 'webview.reload': return 'Reload'; case 'webview.reload': return 'Reload';
@@ -788,6 +794,8 @@ extension on _StringsEs {
case 'settings.generalSettings.disconnectFromServer': return 'Desconectar del servidor'; case 'settings.generalSettings.disconnectFromServer': return 'Desconectar del servidor';
case 'settings.generalSettings.disconnectModal.title': return 'Desconectar'; case 'settings.generalSettings.disconnectModal.title': return 'Desconectar';
case 'settings.generalSettings.disconnectModal.description': return '¿Estás seguro que deseas desconectarte del servidor?\nSerás redirigido a la configuración inicial.'; case 'settings.generalSettings.disconnectModal.description': return '¿Estás seguro que deseas desconectarte del servidor?\nSerás redirigido a la configuración inicial.';
case 'settings.generalSettings.useInAppBrowser': return 'Usar navegador de la aplicación';
case 'settings.generalSettings.useInAppBrowserDescription': return 'Abre los marcadores con el navegador integrado en vez de con el navegador del sietema.';
case 'webview.goBack': return 'Ir atrás'; case 'webview.goBack': return 'Ir atrás';
case 'webview.goForward': return 'Ir adelante'; case 'webview.goForward': return 'Ir adelante';
case 'webview.reload': return 'Recargar'; case 'webview.reload': return 'Recargar';

View File

@@ -92,7 +92,9 @@
"disconnectModal": { "disconnectModal": {
"title": "Disconnect", "title": "Disconnect",
"description": "Are you sure you want to disconnect from the server?\nYou will be redirected to the initial setup." "description": "Are you sure you want to disconnect from the server?\nYou will be redirected to the initial setup."
} },
"useInAppBrowser": "Use in app browser",
"useInAppBrowserDescription": "Opens the bookmarks with the integrated browser instead of with the system browser."
} }
}, },
"webview": { "webview": {

View File

@@ -92,7 +92,9 @@
"disconnectModal": { "disconnectModal": {
"title": "Desconectar", "title": "Desconectar",
"description": "¿Estás seguro que deseas desconectarte del servidor?\nSerás redirigido a la configuración inicial." "description": "¿Estás seguro que deseas desconectarte del servidor?\nSerás redirigido a la configuración inicial."
} },
"useInAppBrowser": "Usar navegador de la aplicación",
"useInAppBrowserDescription": "Abre los marcadores con el navegador integrado en vez de con el navegador del sietema."
} }
}, },
"webview": { "webview": {

View File

@@ -5,11 +5,13 @@ class AppStatusModel {
bool supportsDynamicTheme; bool supportsDynamicTheme;
bool useDynamicTheme; bool useDynamicTheme;
int selectedColor; int selectedColor;
bool useInAppBrowser;
AppStatusModel({ AppStatusModel({
this.selectedTheme = SelectedTheme.system, this.selectedTheme = SelectedTheme.system,
this.supportsDynamicTheme = false, this.supportsDynamicTheme = false,
this.useDynamicTheme = true, this.useDynamicTheme = true,
this.selectedColor = 0, this.selectedColor = 0,
this.useInAppBrowser = true,
}); });
} }

View File

@@ -18,6 +18,7 @@ class AppStatus extends _$AppStatus {
selectedColor: sharedPreferences.getInt(SharedPreferencesKeys.selectedColor) ?? 0, selectedColor: sharedPreferences.getInt(SharedPreferencesKeys.selectedColor) ?? 0,
selectedTheme: SelectedTheme.values[sharedPreferences.getInt(SharedPreferencesKeys.selectedTheme) ?? 0], selectedTheme: SelectedTheme.values[sharedPreferences.getInt(SharedPreferencesKeys.selectedTheme) ?? 0],
useDynamicTheme: sharedPreferences.getBool(SharedPreferencesKeys.useDynamicTheme) ?? true, useDynamicTheme: sharedPreferences.getBool(SharedPreferencesKeys.useDynamicTheme) ?? true,
useInAppBrowser: sharedPreferences.getBool(SharedPreferencesKeys.useInAppBrowser) ?? true,
); );
} }
@@ -42,6 +43,12 @@ class AppStatus extends _$AppStatus {
ref.read(sharedPreferencesProvider).setInt(SharedPreferencesKeys.selectedColor, value); ref.read(sharedPreferencesProvider).setInt(SharedPreferencesKeys.selectedColor, value);
ref.notifyListeners(); ref.notifyListeners();
} }
void setUseInAppBrowser(bool value) {
state.useInAppBrowser = value;
ref.read(sharedPreferencesProvider).setBool(SharedPreferencesKeys.useInAppBrowser, value);
ref.notifyListeners();
}
} }
@riverpod @riverpod

View File

@@ -1,26 +0,0 @@
import 'package:flutter/material.dart';
import 'package:linkdy/i18n/strings.g.dart';
class ErrorSaveLink extends StatelessWidget {
const ErrorSaveLink({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(t.generic.error),
content: Text(t.links.addLink.errorSavingLink),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(t.generic.close),
),
],
),
],
);
}
}

View File

@@ -7,9 +7,11 @@ import 'package:linkdy/screens/links/provider/links.provider.dart';
import 'package:linkdy/screens/links/ui/add_link_modal.dart'; import 'package:linkdy/screens/links/ui/add_link_modal.dart';
import 'package:linkdy/providers/app_status_provider.dart';
import 'package:linkdy/providers/router_provider.dart'; import 'package:linkdy/providers/router_provider.dart';
import 'package:linkdy/router/paths.dart'; import 'package:linkdy/router/paths.dart';
import 'package:linkdy/i18n/strings.g.dart'; import 'package:linkdy/i18n/strings.g.dart';
import 'package:linkdy/utils/open_url.dart';
class Links extends ConsumerWidget { class Links extends ConsumerWidget {
const Links({Key? key}) : super(key: key); const Links({Key? key}) : super(key: key);
@@ -122,7 +124,9 @@ class Links extends ConsumerWidget {
return Column( return Column(
children: [ children: [
ListTile( ListTile(
onTap: () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: link), onTap: ref.watch(appStatusProvider).useInAppBrowser == true
? () => ref.watch(routerProvider).push(RoutesPaths.webview, extra: link)
: () => openUrl(link!.url!),
isThreeLine: true, isThreeLine: true,
title: Padding( title: Padding(
padding: const EdgeInsets.only(bottom: 4), padding: const EdgeInsets.only(bottom: 4),

View File

@@ -4,6 +4,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:linkdy/i18n/strings.g.dart'; import 'package:linkdy/i18n/strings.g.dart';
import 'package:linkdy/screens/settings/ui/general_settings/disconnect_modal.dart'; import 'package:linkdy/screens/settings/ui/general_settings/disconnect_modal.dart';
import 'package:linkdy/providers/app_status_provider.dart';
class GeneralSettings extends ConsumerWidget { class GeneralSettings extends ConsumerWidget {
const GeneralSettings({Key? key}) : super(key: key); const GeneralSettings({Key? key}) : super(key: key);
@@ -15,6 +17,13 @@ class GeneralSettings extends ConsumerWidget {
), ),
body: ListView( body: ListView(
children: [ children: [
SwitchListTile(
title: Text(t.settings.generalSettings.useInAppBrowser),
subtitle: Text(t.settings.generalSettings.useInAppBrowserDescription),
value: ref.watch(appStatusProvider).useInAppBrowser,
onChanged: ref.read(appStatusProvider.notifier).setUseInAppBrowser,
),
const SizedBox(height: 16),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [