From d9180794404f28ebc8fe3233114c7d2b4f5dae36 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 9 Feb 2021 09:12:47 +1100 Subject: [PATCH] Cleanup --- lib/l10n | 2 +- lib/preferences.dart | 20 ------ lib/settings/login.dart | 125 ++++++++++++++++++++++--------------- lib/settings/settings.dart | 8 +-- lib/widget/drawer.dart | 3 +- 5 files changed, 80 insertions(+), 78 deletions(-) diff --git a/lib/l10n b/lib/l10n index ef139565..c342d99f 160000 --- a/lib/l10n +++ b/lib/l10n @@ -1 +1 @@ -Subproject commit ef139565bba4fcd5889aa242a0062827eab5eceb +Subproject commit c342d99f068f8ac662dfb729fea0b5867aac1cc6 diff --git a/lib/preferences.dart b/lib/preferences.dart index b4512d30..ea43720f 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -83,24 +83,4 @@ class InvenTreePreferences { } InvenTreePreferences._internal(); - - // Load saved login details, and attempt connection - void loadLoginDetails(BuildContext context) async { - - print("Loading login details"); - - await InvenTreeAPI().connectToServer(context); - } - - void saveLoginDetails(BuildContext context, String server, String username, String password) async { - - SharedPreferences prefs = await SharedPreferences.getInstance(); - - await prefs.setString(_SERVER, server); - await prefs.setString(_USERNAME, username); - await prefs.setString(_PASSWORD, password); - - // Reconnect the API - await InvenTreeAPI().connectToServer(context); - } } \ No newline at end of file diff --git a/lib/settings/login.dart b/lib/settings/login.dart index 868760dd..c4380b98 100644 --- a/lib/settings/login.dart +++ b/lib/settings/login.dart @@ -166,7 +166,7 @@ class _InvenTreeLoginSettingsState extends State { return null; } - void _selectProfile(UserProfile profile) async { + void _selectProfile(BuildContext context, UserProfile profile) async { // Mark currently selected profile as unselected final selected = await UserProfileDBManager().getSelectedProfile(); @@ -180,6 +180,9 @@ class _InvenTreeLoginSettingsState extends State { await UserProfileDBManager().updateProfile(profile); _reload(); + + // Attempt server login (this will load the newly selected profile + InvenTreeAPI().connect(context); } void _deleteProfile(UserProfile profile) async { @@ -219,60 +222,78 @@ class _InvenTreeLoginSettingsState extends State { List children = []; - for (int idx = 0; idx < profiles.length; idx++) { + if (profiles.length > 0) { + for (int idx = 0; idx < profiles.length; idx++) { + UserProfile profile = profiles[idx]; - UserProfile profile = profiles[idx]; - - children.add(ListTile( - title: Text( + children.add(ListTile( + title: Text( profile.name, - ), - subtitle: Text(profile.server), - trailing: profile.selected ? FaIcon(FontAwesomeIcons.checkCircle) : null, - onLongPress: () { - showDialog( - context: context, - builder: (BuildContext context) { - return SimpleDialog( - title: Text(profile.name), - children: [ - SimpleDialogOption( - onPressed: () { - Navigator.of(context).pop(); - _selectProfile(profile); - }, - child: Text(I18N.of(context).profileSelect), - ), - SimpleDialogOption( - onPressed: () { - Navigator.of(context).pop(); - _editProfile(context, userProfile: profile); - }, - child: Text(I18N.of(context).profileEdit), - ), - SimpleDialogOption( - onPressed: () { - // Navigator.of(context, rootNavigator: true).pop(); - confirmationDialog( - context, - I18N.of(context).delete, - "Delete this profile?", - onAccept: () { - _deleteProfile(profile); - } - ); - }, - child: Text(I18N.of(context).profileDelete), - ) - ], - ); - } - ); - }, - onTap: () { + ), + subtitle: Text(profile.server), + trailing: profile.selected + ? FaIcon(FontAwesomeIcons.checkCircle) + : null, + onLongPress: () { + showDialog( + context: context, + builder: (BuildContext context) { + return SimpleDialog( + title: Text(profile.name), + children: [ + SimpleDialogOption( + onPressed: () { + Navigator.of(context).pop(); + _selectProfile(context, profile); + }, + child: Text(I18N + .of(context) + .profileSelect), + ), + SimpleDialogOption( + onPressed: () { + Navigator.of(context).pop(); + _editProfile(context, userProfile: profile); + }, + child: Text(I18N + .of(context) + .profileEdit), + ), + SimpleDialogOption( + onPressed: () { + // Navigator.of(context, rootNavigator: true).pop(); + confirmationDialog( + context, + I18N + .of(context) + .delete, + "Delete this profile?", + onAccept: () { + _deleteProfile(profile); + } + ); + }, + child: Text(I18N + .of(context) + .profileDelete), + ) + ], + ); + } + ); + }, + onTap: () { - }, - )); + }, + )); + } + } else { + // No profile available! + children.add( + ListTile( + title: Text("No profiles available"), + ) + ); } return Scaffold( diff --git a/lib/settings/settings.dart b/lib/settings/settings.dart index ffd2731a..0661ddff 100644 --- a/lib/settings/settings.dart +++ b/lib/settings/settings.dart @@ -30,15 +30,15 @@ class _InvenTreeSettingsState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text("InvenTree Settings"), + title: Text(I18N.of(context).settings), ), body: Center( child: ListView( children: [ ListTile( - title: Text(I18N.of(context).serverSettings), - subtitle: Text("Configure server and login settings"), - leading: FaIcon(FontAwesomeIcons.server), + title: Text(I18N.of(context).profile), + subtitle: Text("Configure user profile settings"), + leading: FaIcon(FontAwesomeIcons.user), onTap: _editServerSettings, ), Divider(), diff --git a/lib/widget/drawer.dart b/lib/widget/drawer.dart index cc9ec7b2..b412da5e 100644 --- a/lib/widget/drawer.dart +++ b/lib/widget/drawer.dart @@ -3,6 +3,7 @@ import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/widget/company_list.dart'; import 'package:InvenTree/widget/search.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:InvenTree/api.dart'; @@ -155,7 +156,7 @@ class InvenTreeDrawer extends StatelessWidget { */ new Divider(), new ListTile( - title: new Text("Settings"), + title: new Text(I18N.of(context).settings), leading: new Icon(Icons.settings), onTap: _settings, ),