diff --git a/lib/conf.dart b/lib/conf.dart index 3659efd..f74f6a8 100644 --- a/lib/conf.dart +++ b/lib/conf.dart @@ -32,7 +32,7 @@ import 'screens/share.dart'; const List ports = [50500, 50050]; // only for fetching update -const String currentVersion = '3.1'; +const String currentVersion = '3.3.0'; const String multipleFilesDelimiter = '|sharik|'; const Sources source = Sources.gitHub; diff --git a/lib/dialogs/receive.dart b/lib/dialogs/receive.dart index b1b4848..2f6cd8c 100644 --- a/lib/dialogs/receive.dart +++ b/lib/dialogs/receive.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -53,111 +54,142 @@ class _ReceiverDialogState extends State { scrollable: true, elevation: 0, insetPadding: const EdgeInsets.all(24), - title: Text( - context.l.sharingReceiver, - style: GoogleFonts.getFont( - context.l.fontComfortaa, - fontWeight: FontWeight.w700, - ), - ), + title: _titleWidget(context), content: receiverService.receivers.isEmpty - ? SizedBox( - height: 42, - child: Center( - child: Stack( - children: [ - Center( - child: SizedBox( - height: 42, - width: 42, - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - context.t.colorScheme.secondary - .withOpacity(0.8), - ), - ), - ), - ), - ], - ), - ), - ) - : SizedBox( - width: double.maxFinite, - child: Column( - children: [ - SizedBox( - height: receiverService.receivers.length * 60, - child: Theme( - data: context.t.copyWith( - splashColor: - context.t.dividerColor.withOpacity(0.08), - highlightColor: Colors.transparent, - ), - child: ListView.builder( - itemCount: receiverService.receivers.length, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (_, e) => ListTile( - hoverColor: - context.t.dividerColor.withOpacity(0.04), - // todo text styling - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - leading: Icon( - SharingObject( - name: receiverService.receivers[e].name, - data: receiverService.receivers[e].name, - type: receiverService.receivers[e].type, - ).icon, - ), - // todo style colors - title: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Text( - receiverService.receivers[e].name, - style: GoogleFonts.getFont('Andika'), - ), - ), - subtitle: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Text( - '${receiverService.receivers[e].os} • ${receiverService.receivers[e].addr.ip}:${receiverService.receivers[e].addr.port}', - style: GoogleFonts.getFont('Andika'), - ), - ), - onTap: () { - launch( - 'http://${receiverService.receivers[e].addr.ip}:${receiverService.receivers[e].addr.port}', - ); - }, - ), - ), - ), - ), - ], - ), - ), + ? _loadingWidget(context) + : _mainWidget(context), actions: [ - DialogTextButton( - context.l.sharingNetworkInterfaces, - receiverService.loaded - ? () async { - final s = receiverService.ipService.selectedInterface; - await openDialog( - context, - PickNetworkDialog(receiverService.ipService), - ); - } - : null, - ), - DialogTextButton(context.l.generalClose, () { - Navigator.of(context).pop(); - }), + _networkInterfaceButton(context), + _closeButton(context), const SizedBox(width: 4), ], ); }, ); } + + Text _titleWidget(BuildContext context) => + Text( + context.l.sharingReceiver, + style: GoogleFonts.getFont( + context.l.fontComfortaa, + fontWeight: FontWeight.w700, + ), + ); + + DialogTextButton _networkInterfaceButton(BuildContext context) => + DialogTextButton( + context.l.sharingNetworkInterfaces, + receiverService.loaded + ? () async { + final s = receiverService.ipService.selectedInterface; + await openDialog( + context, + PickNetworkDialog(receiverService.ipService), + ); + } + : null, + ); + + DialogTextButton _closeButton(BuildContext context) => + DialogTextButton(context.l.generalClose, () { + Navigator.of(context).pop(); + }); + + SizedBox _mainWidget(BuildContext context) => + SizedBox( + width: double.maxFinite, + child: Column( + children: [ + SizedBox( + height: receiverService.receivers.length * 60, + child: Theme( + data: context.t.copyWith( + splashColor: + context.t.dividerColor.withOpacity(0.08), + highlightColor: Colors.transparent, + ), + child: _receivedListWidget(context), + ), + ), + ], + ), + ); + + ListView _receivedListWidget(BuildContext context) => + ListView.builder( + itemCount: receiverService.receivers.length, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (_, e) { + final receivedObject = receiverService.receivers[e]; + return ListTile( + hoverColor: + context.t.dividerColor.withOpacity(0.04), + // todo text styling + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + leading: Icon( + SharingObject( + name: receivedObject.name, + data: receivedObject.name, + type: receivedObject.type, + ).icon, + ), + // todo style colors + title: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Text(receivedObject.name, style: GoogleFonts.getFont('Andika')), + ), + subtitle: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Text( + '${receivedObject.os} • ${receivedObject.addr.ip}:${receivedObject.addr.port}', + style: GoogleFonts.getFont('Andika'), + ), + ), + onTap: () => _useReceivedObject(receivedObject), + ); + }, + ); + + void _useReceivedObject(Receiver receiver) { + final name = receiver.name; + switch(receiver.type) { + case SharingObjectType.text: + if (name.startsWith('http')) { + launch(name); + } else { + Clipboard.setData(ClipboardData(text: name)); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Text is copied!')), + ); + } + Navigator.of(context).pop(); + break; + default: + launch('http://${receiver.addr.ip}:${receiver.addr.port}'); + } + } + + SizedBox _loadingWidget(BuildContext context) => + SizedBox( + height: 42, + child: Center( + child: Stack( + children: [ + Center( + child: SizedBox( + height: 42, + width: 42, + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + context.t.colorScheme.secondary + .withOpacity(0.8), + ), + ), + ), + ), + ], + ), + ), + ); } diff --git a/lib/logic/services/receiver_service.dart b/lib/logic/services/receiver_service.dart index db4fa77..4c03af3 100644 --- a/lib/logic/services/receiver_service.dart +++ b/lib/logic/services/receiver_service.dart @@ -93,7 +93,7 @@ class ReceiverService extends ChangeNotifier { .get(Uri.parse('http://${addr.ip}:${addr.port}/sharik.json')) .timeout(const Duration(seconds: 3)); - print('${addr.ip}:${addr.port}: $result'); + print('${addr.ip}:${addr.port}: ${result.body}'); return Receiver.fromJson(addr: addr, json: result.body); } catch (error) { print('${addr.ip}:${addr.port}: $error'); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 0b5974c..10aeb5b 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -190,25 +190,13 @@ class _HomeScreenState extends State { ), TransparentButtonBackground.purpleLight, ), - // TransparentButton( - // SizedBox( - // height: 20, - // width: 20, - // child: Icon(context.watch().icon, - // color: Colors.deepPurple.shade700, size: 20)), - // () => context.read().change(), - // TransparentButtonBackground.purpleLight), const Spacer(), - TransparentButton( - Text( - 'sharik v$currentVersion →', - style: GoogleFonts.jetBrainsMono( - fontSize: 16, - color: Colors.deepPurple.shade700, - ), + Text( + 'sharik v$currentVersion', + style: GoogleFonts.jetBrainsMono( + fontSize: 16, + color: Colors.deepPurple.shade700, ), - () {}, - TransparentButtonBackground.purpleLight, ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 1356b84..75095e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ homepage: https://github.com/marchellodev/sharik repository: https://github.com/marchellodev/sharik issue_tracker: https://github.com/marchellodev/sharik/issues publish_to: none -version: 3.2.0+15 +version: 3.3.0 environment: sdk: '>=2.12.0 <3.0.0'