From 1d5359e645c44ab5a6812d9d68acebde483cd7b6 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 9 Nov 2021 15:27:26 -0800 Subject: [PATCH] start of profile server manager --- lib/models/profileservers.dart | 7 +++-- lib/views/contactsview.dart | 14 +++++++-- lib/views/profileServersView.dart | 50 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 lib/views/profileServersView.dart diff --git a/lib/models/profileservers.dart b/lib/models/profileservers.dart index cb86d392..51a1a34e 100644 --- a/lib/models/profileservers.dart +++ b/lib/models/profileservers.dart @@ -14,10 +14,10 @@ class ProfileServerListState extends ChangeNotifier { return idx >= 0 ? _servers[idx] : null; } - void updateServerCache(String onion, String status) { + void updateServerCache(String onion, String description, String status) { int idx = _servers.indexWhere((element) => element.onion == onion); if (idx >= 0) { - _servers[idx] = RemoteServerInfoState(onion: onion, status: status); + _servers[idx] = RemoteServerInfoState(onion: onion, description: description, status: status); } else { print("Tried to update server cache without a starting state...this is probably an error"); } @@ -31,6 +31,7 @@ class ProfileServerListState extends ChangeNotifier { class RemoteServerInfoState extends ChangeNotifier { final String onion; final String status; + final String description; - RemoteServerInfoState({required this.onion, required this.status}); + RemoteServerInfoState({required this.onion, required this.description, required this.status}); } diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 990899f3..9a19d982 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -112,7 +112,15 @@ class _ContactsViewState extends State { Clipboard.setData(new ClipboardData(text: Provider.of(context, listen: false).onion)); })); - // TODO servers + // Manage servers + if (Provider.of(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) { + actions.add(IconButton( + icon: Icon(CwtchIcons.dns_24px), + tooltip: "Manage known servers", //AppLocalizations.of(context)!.copyAddress, + onPressed: () { + _pushServers(); + })); + } // Search contacts actions.add(IconButton( @@ -162,12 +170,12 @@ class _ContactsViewState extends State { )); } - void _pushTorStatus() { + void _pushServers() { Navigator.of(context).push(MaterialPageRoute( builder: (BuildContext context) { return MultiProvider( providers: [Provider.value(value: Provider.of(context))], - child: TorStatusView(), + child: ProfileServersView(), ); }, )); diff --git a/lib/views/profileServersView.dart b/lib/views/profileServersView.dart new file mode 100644 index 00000000..2b9b99c9 --- /dev/null +++ b/lib/views/profileServersView.dart @@ -0,0 +1,50 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + + +class ProfileServersView extends StatefulWidget { + @override + _ProfileServersView createState() => _ProfileServersView(); +} + +class _ProfileServersView extends State { + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text( MediaQuery.of(context).size.width > 600 ? AppLocalizations.of(context)!.serversManagerTitleLong : AppLocalizations.of(context)!.serversManagerTitleShort), + //actions: getActions(), + ), + body: Consumer( + builder: (context, svrs, child) { + final tiles = svrs.servers.map((ServerInfoState server) { + return ChangeNotifierProvider.value( + value: server, + builder: (context, child) => RepaintBoundary(child: ServerRow()), + ); + }, + ); + + final divided = ListTile.divideTiles( + context: context, + tiles: tiles, + ).toList(); + + if (tiles.isEmpty) { + return Center( + child: Text( + AppLocalizations.of(context)!.unlockServerTip, + textAlign: TextAlign.center, + )); + } + + return ListView(children: divided); + }, + )); + } \ No newline at end of file