-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial magnet & app link sharing for android & Linux
- Loading branch information
Showing
17 changed files
with
309 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:pikatorrent/engine/torrent.dart'; | ||
import 'package:pikatorrent/utils/app_links.dart'; | ||
import 'package:pikatorrent/utils/device.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
|
||
class ShareTorrentDialog extends StatelessWidget { | ||
final Torrent torrent; | ||
|
||
const ShareTorrentDialog({ | ||
super.key, | ||
required this.torrent, | ||
}); | ||
|
||
void shareMagnetLink(BuildContext context) async { | ||
shareLink(context, torrent.magnetLink!); | ||
} | ||
|
||
void shareAppLink(BuildContext context) async { | ||
shareLink(context, createAppLink(torrent.magnetLink!)); | ||
} | ||
|
||
void shareLink(BuildContext context, String link) async { | ||
if (isMobile()) { | ||
await Share.share(link); | ||
} else { | ||
Clipboard.setData(ClipboardData(text: link)); | ||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( | ||
content: Text('Link copied'), | ||
backgroundColor: Colors.lightGreen, | ||
)); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('Share Torrent'), | ||
content: torrent.isPrivate! | ||
? const Text('This torrent is private to you and can\'t be shared.') | ||
: null, | ||
actions: torrent.isPrivate! | ||
? [ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
child: const Text('Cancel')) | ||
] | ||
: [ | ||
TextButton( | ||
child: const Text('Magnet link'), | ||
onPressed: () { | ||
shareMagnetLink(context); | ||
Navigator.pop(context); | ||
}, | ||
), | ||
TextButton( | ||
child: const Text('PikaTorrent link'), | ||
onPressed: () { | ||
shareAppLink(context); | ||
Navigator.pop(context); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const appUri = 'https://www.pikatorrent.com/'; | ||
|
||
createAppLink(String link) { | ||
return Uri.encodeFull('$appUri#$link'); | ||
} | ||
|
||
/// get torrent link from an app link created with createAppLink | ||
getTorrentLink(String appLink) { | ||
return appLink.replaceFirst('$appUri#', ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.