Skip to content

Commit

Permalink
feat: if type is text, copy it to clipboard or open it as link
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed May 7, 2022
1 parent 00c0433 commit 50110e7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 119 deletions.
2 changes: 1 addition & 1 deletion lib/conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import 'screens/share.dart';
const List<int> 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;
Expand Down
230 changes: 131 additions & 99 deletions lib/dialogs/receive.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -53,111 +54,142 @@ class _ReceiverDialogState extends State<ReceiverDialog> {
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),
),
),
),
),
],
),
),
);
}
2 changes: 1 addition & 1 deletion lib/logic/services/receiver_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
22 changes: 5 additions & 17 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,13 @@ class _HomeScreenState extends State<HomeScreen> {
),
TransparentButtonBackground.purpleLight,
),
// TransparentButton(
// SizedBox(
// height: 20,
// width: 20,
// child: Icon(context.watch<ThemeManager>().icon,
// color: Colors.deepPurple.shade700, size: 20)),
// () => context.read<ThemeManager>().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,
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 50110e7

Please sign in to comment.