diff options
Diffstat (limited to 'lib/views')
-rw-r--r-- | lib/views/info_view.dart | 36 | ||||
-rw-r--r-- | lib/views/main_view.dart | 2 | ||||
-rw-r--r-- | lib/views/recipe_view.dart | 72 | ||||
-rw-r--r-- | lib/views/settings_view.dart | 4 |
4 files changed, 54 insertions, 60 deletions
diff --git a/lib/views/info_view.dart b/lib/views/info_view.dart index e2faeab..04c3887 100644 --- a/lib/views/info_view.dart +++ b/lib/views/info_view.dart @@ -14,8 +14,9 @@ class InfoView extends StatefulWidget { } class _InfoViewState extends State<InfoView> { - String websiteUrl = "https://davidpkj.github.io/kulinar_app.html"; - String sourceCodeUrl = "https://github.com/davidpkj/kulinar_app"; + String websiteURL = "https://davidpenkowoj.de"; + String sourceCodeURL = "http://git.davidpenkowoj.de/kulinar_app.git"; + String privacyNoticeURL = "https://davidpenkowoj.de/static/files/privacy-notice.html"; @override Widget build(BuildContext context) { @@ -38,26 +39,36 @@ class _InfoViewState extends State<InfoView> { ), ListTile( title: Text(AppLocalizations.of(context)!.info3, style: cDefaultTextStyle), - subtitle: Text(websiteUrl, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), + subtitle: Text(websiteURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), trailing: IconButton( icon: Icon(Icons.north_east_rounded), onPressed: () { - _launchURL(Uri.parse(websiteUrl)); + _launchURL(Uri.parse(websiteURL)); }, ), ), ListTile( title: Text(AppLocalizations.of(context)!.info4, style: cDefaultTextStyle), - subtitle: Text(sourceCodeUrl, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), + subtitle: Text(sourceCodeURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), trailing: IconButton( icon: Icon(Icons.north_east_rounded), onPressed: () { - _launchURL(Uri.parse(sourceCodeUrl)); + _launchURL(Uri.parse(sourceCodeURL)); }, ), ), ListTile( title: Text(AppLocalizations.of(context)!.info5, style: cDefaultTextStyle), + subtitle: Text(privacyNoticeURL, style: cDetailsTextStyle, overflow: TextOverflow.ellipsis), + trailing: IconButton( + icon: Icon(Icons.north_east_rounded), + onPressed: () { + _launchURL(Uri.parse(privacyNoticeURL)); + }, + ), + ), + ListTile( + title: Text(AppLocalizations.of(context)!.info6, style: cDefaultTextStyle), trailing: IconButton( icon: Icon(Icons.launch_rounded), onPressed: () { @@ -65,6 +76,15 @@ class _InfoViewState extends State<InfoView> { }, ), ), +/* ListTile( + title: Text(AppLocalizations.of(context)!.info7, style: cDefaultTextStyle), + trailing: IconButton( + icon: Icon(Icons.launch_rounded), + onPressed: () { + Navigator.push(context, SlideFromRightRoute(child: ChangelogView())); + }, + ), + ), */ ], ), ); @@ -81,9 +101,9 @@ class _InfoViewState extends State<InfoView> { _launchURL(Uri url) async { if (await canLaunchUrl(url)) { - await launchUrl(url); + await launchUrl(url, mode: LaunchMode.externalApplication); } else { - throw 'Could not launch $url'; + print('Could not launch $url'); } } } diff --git a/lib/views/main_view.dart b/lib/views/main_view.dart index 678db4a..97ad04e 100644 --- a/lib/views/main_view.dart +++ b/lib/views/main_view.dart @@ -90,7 +90,7 @@ class _MainViewState extends State<MainView> with SingleTickerProviderStateMixin onPressed: () async { await Navigator.push( context, - SlideFromBottomRoute(child: RecipeView(readonly: false)), + SlideFromBottomRoute(child: RecipeView()), ); setState(() {}); diff --git a/lib/views/recipe_view.dart b/lib/views/recipe_view.dart index a0304c3..92a50b7 100644 --- a/lib/views/recipe_view.dart +++ b/lib/views/recipe_view.dart @@ -3,13 +3,13 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:kulinar_app/constants.dart'; -import 'package:kulinar_app/models/data/shoplist_data_class.dart'; import 'package:kulinar_app/views/image_view.dart'; import 'package:kulinar_app/models/recipe_class.dart'; import 'package:kulinar_app/widgets/toastbar_widget.dart'; import 'package:kulinar_app/models/data/recipe_data_class.dart'; import 'package:kulinar_app/widgets/page_route_transitions.dart'; import 'package:kulinar_app/widgets/utility_icon_row_widget.dart'; +import 'package:kulinar_app/models/data/shoplist_data_class.dart'; import 'package:kulinar_app/models/data/settings_data_class.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; @@ -21,10 +21,9 @@ import 'package:http/http.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class RecipeView extends StatefulWidget { - const RecipeView({Key? key, this.remote = false, required this.readonly, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key); + const RecipeView({Key? key, this.remote = false, this.recipe, this.redrawCallback, this.showToastCallback}) : super(key: key); final bool remote; - final bool readonly; final Recipe? recipe; final Function? redrawCallback; final Function? showToastCallback; @@ -41,7 +40,7 @@ class _RecipeViewState extends State<RecipeView> { final FocusNode _detailsTitleFocus = FocusNode(); final FocusNode _detailsTextFocus = FocusNode(); Recipe _unsavedRecipe = Recipe(); - bool _readonlyOverride = false; + bool _isEditModeEnabled = false; Recipe? _removedRecipe; @override @@ -52,6 +51,7 @@ class _RecipeViewState extends State<RecipeView> { if (_unsavedRecipe.isDefault()) { _controller1.clear(); _controller2.clear(); + _isEditModeEnabled = true; } else { _controller1.text = _unsavedRecipe.title ?? ""; _controller2.text = _unsavedRecipe.description ?? ""; @@ -97,16 +97,16 @@ class _RecipeViewState extends State<RecipeView> { _unsavedRecipe.title = _controller1.text; _unsavedRecipe.description = _controller2.text; - if (!widget.readonly) { - RecipeData.recipeList.add(_unsavedRecipe); + if (_isEditModeEnabled) { + if (!RecipeData.recipeList.contains(_unsavedRecipe)) RecipeData.recipeList.add(_unsavedRecipe); RecipeData.save(); } + _isEditModeEnabled = false; + if (widget.recipe == null) { Navigator.pop(context); } else { - _readonlyOverride = false; - setState(() {}); } } @@ -131,13 +131,6 @@ class _RecipeViewState extends State<RecipeView> { setState(() {}); } - bool _isEditingAllowed() { - if (_readonlyOverride) return true; - if (!widget.readonly) return true; - - return false; - } - // TODO: FIXME: This might introduce bugs later (sanetize); maybe use FileHandler? void downloadRecipe(BuildContext context, Recipe recipe) async { RecipeData.recipeList.add(recipe); @@ -186,13 +179,12 @@ class _RecipeViewState extends State<RecipeView> { // _buildAppBarPhotoActions(recipe), return UtilityIconRow( remote: widget.remote, - readonly: !_isEditingAllowed(), + isEditModeEnabled: _isEditModeEnabled, unsavedRecipe: _unsavedRecipe, pickImageCallback: _pickImage, removeImageCallback: _removeImage, removeRecipeCallback: _removeRecipe, downloadRecipeCallback: downloadRecipe, - isEditingAllowedCallback: _isEditingAllowed, cacheUnsavedRecipeCallback: _cacheUnsavedRecipe, ); } @@ -205,7 +197,7 @@ class _RecipeViewState extends State<RecipeView> { controller: _controller1, style: cRecipeTitleStyle, cursorColor: cPrimaryColor, - enabled: _isEditingAllowed(), + enabled: _isEditModeEnabled, focusNode: _detailsTitleFocus, textInputAction: TextInputAction.next, decoration: InputDecoration( @@ -257,7 +249,7 @@ class _RecipeViewState extends State<RecipeView> { Widget _buildDescriptionInput() { return Padding( padding: const EdgeInsets.all(18.0), - child: _isEditingAllowed() ? _buildInputDescriptuion() : _buildMarkdownDescription(), + child: _isEditModeEnabled ? _buildInputDescriptuion() : _buildMarkdownDescription(), ); } @@ -287,30 +279,7 @@ class _RecipeViewState extends State<RecipeView> { selectable: true, onTapLink: (text, href, title) => null, imageBuilder: (uri, title, alt) => Container(), - styleSheet: MarkdownStyleSheet( - tableBody: cRecipeDescriptionStyle, - a: cRecipeDescriptionStyle, - p: cRecipeDescriptionStyle, - h1: cRecipeSubtitleStyle, - h2: cRecipeSubtitleStyle, - h3: cRecipeSubtitleStyle, - h4: cRecipeSubtitleStyle, - h5: cRecipeSubtitleStyle, - h6: cRecipeSubtitleStyle, -/* TODO: remove code and quote block - blockquoteDecoration: BoxDecoration(color: Color.fromARGB(255, 255, 13, 13)), - code: cDetailsTextStyle, -*/ - listIndent: 15.0, - listBullet: cRecipeDescriptionStyle, - listBulletPadding: EdgeInsets.only(right: 10.0), - horizontalRuleDecoration: BoxDecoration( - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - ), + // styleSheet: CustomMarkdownStyle(), ); } @@ -321,6 +290,12 @@ class _RecipeViewState extends State<RecipeView> { void _addToShoppingList(BuildContext _) { final _ingredients = _unsavedRecipe.description!.split("\n")..retainWhere((element) => element.startsWith("- ")); + if (_ingredients.isEmpty) { + // TODO: translation + widget.showToastCallback!("No ingredients found", ""); + return; + } + for (String _ingredient in _ingredients) { String _item = _ingredient.substring(2).trim(); @@ -333,10 +308,7 @@ class _RecipeViewState extends State<RecipeView> { if (widget.showToastCallback != null) { // TODO: translation - widget.showToastCallback!("Added to Shoplist", "Ok", () { - _addRecipe(passedRecipe: _removedRecipe); - widget.redrawCallback!(); - }); + widget.showToastCallback!("Added to Shoplist", ""); } } @@ -403,7 +375,7 @@ class _RecipeViewState extends State<RecipeView> { PreferredSizeWidget _buildAppBar(BuildContext context, Recipe recipe) { String _title = AppLocalizations.of(context)!.mode1; - if (_isEditingAllowed()) _title = AppLocalizations.of(context)!.mode2; + if (_isEditModeEnabled) _title = AppLocalizations.of(context)!.mode2; return AppBar( title: Text(_title), @@ -418,7 +390,7 @@ class _RecipeViewState extends State<RecipeView> { } Widget _buildAppBarCheckActions() { - if (_isEditingAllowed()) { + if (_isEditModeEnabled) { return IconButton( icon: Icon(Icons.check), onPressed: _addRecipe, @@ -427,7 +399,7 @@ class _RecipeViewState extends State<RecipeView> { return IconButton( icon: Icon(Icons.edit), onPressed: () { - _readonlyOverride = true; + _isEditModeEnabled = true; setState(() {}); }, diff --git a/lib/views/settings_view.dart b/lib/views/settings_view.dart index d217bb7..9bbde49 100644 --- a/lib/views/settings_view.dart +++ b/lib/views/settings_view.dart @@ -80,7 +80,9 @@ class _SettingsViewState extends State<SettingsView> { onPressed: () async { final _file = await FileHandler.pickDeserializableFile(context); - await FileHandler.deserializeFile(context, _file!); + if (_file == null) return; + + await FileHandler.deserializeFile(context, _file); setState(() {}); }, |