mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: Implemented History Panel for reusing previously used Magnet & Torrent Links (#245)
This commit is contained in:
1 parent
39202b44a1
commit
32e3620f5e
6 files changed
+594
-376
No files matched your search
@@ -65,6 +65,9 @@
|
|||||||
"extensionInstallSuccess": "Installed successfully",
|
"extensionInstallSuccess": "Installed successfully",
|
||||||
"extensionUpdateSuccess": "Updated successfully",
|
"extensionUpdateSuccess": "Updated successfully",
|
||||||
"extensionDelete": "Delete Extension",
|
"extensionDelete": "Delete Extension",
|
||||||
"extensionAlreadyLatest": "It's already the latest version"
|
"extensionAlreadyLatest": "It's already the latest version",
|
||||||
|
"history": "History",
|
||||||
|
"clearHistory": "Clear History",
|
||||||
|
"noHistoryFound": "No History Found"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,10 +4,10 @@ import 'package:file_picker/file_picker.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:gopeed/app/modules/history/controller/history_controller.dart';
|
||||||
|
import 'package:gopeed/app/modules/history/views/history_view.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
import 'package:rounded_loading_button/rounded_loading_button.dart';
|
import 'package:rounded_loading_button/rounded_loading_button.dart';
|
||||||
|
|
||||||
import '../../../../api/api.dart';
|
import '../../../../api/api.dart';
|
||||||
import '../../../../api/model/create_task.dart';
|
import '../../../../api/model/create_task.dart';
|
||||||
import '../../../../api/model/options.dart';
|
import '../../../../api/model/options.dart';
|
||||||
@@ -32,6 +32,7 @@ class CreateView extends GetView<CreateController> {
|
|||||||
final _httpCookieController = TextEditingController();
|
final _httpCookieController = TextEditingController();
|
||||||
final _httpRefererController = TextEditingController();
|
final _httpRefererController = TextEditingController();
|
||||||
final _btTrackerController = TextEditingController();
|
final _btTrackerController = TextEditingController();
|
||||||
|
final _historyController = HistoryController();
|
||||||
|
|
||||||
final _availableSchemes = ["http:", "https:", "magnet:"];
|
final _availableSchemes = ["http:", "https:", "magnet:"];
|
||||||
|
|
||||||
@@ -91,121 +92,200 @@ class CreateView extends GetView<CreateController> {
|
|||||||
FocusScope.of(context).requestFocus(FocusNode());
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding:
|
||||||
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _resolveFormKey,
|
key: _resolveFormKey,
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
child: Column(children: [
|
child: Column(
|
||||||
Row(children: [
|
children: [
|
||||||
Expanded(
|
Row(children: [
|
||||||
child: TextFormField(
|
Expanded(
|
||||||
autofocus: true,
|
child: TextFormField(
|
||||||
controller: _urlController,
|
autofocus: true,
|
||||||
minLines: 1,
|
controller: _urlController,
|
||||||
maxLines: 5,
|
minLines: 1,
|
||||||
decoration: InputDecoration(
|
maxLines: 5,
|
||||||
hintText: _hitText(),
|
decoration: InputDecoration(
|
||||||
hintStyle: const TextStyle(fontSize: 12),
|
hintText: _hitText(),
|
||||||
labelText: 'downloadLink'.tr,
|
hintStyle: const TextStyle(fontSize: 12),
|
||||||
icon: const Icon(Icons.link),
|
labelText: 'downloadLink'.tr,
|
||||||
suffixIcon: IconButton(
|
icon: const Icon(Icons.link),
|
||||||
onPressed: () {
|
suffixIcon: IconButton(
|
||||||
_urlController.clear();
|
onPressed: () {
|
||||||
controller.clearFileDataUri();
|
_urlController.clear();
|
||||||
},
|
controller.clearFileDataUri();
|
||||||
icon: const Icon(Icons.clear),
|
},
|
||||||
),
|
icon: const Icon(Icons.clear),
|
||||||
),
|
),
|
||||||
validator: (v) {
|
),
|
||||||
return v!.trim().isNotEmpty
|
validator: (v) {
|
||||||
? null
|
return v!.trim().isNotEmpty
|
||||||
: 'downloadLinkValid'.tr;
|
? null
|
||||||
},
|
: 'downloadLinkValid'.tr;
|
||||||
onChanged: (v) async {
|
},
|
||||||
controller.clearFileDataUri();
|
onChanged: (v) async {
|
||||||
if (controller.oldUrl.value.isEmpty) {
|
controller.clearFileDataUri();
|
||||||
recognizeMagnetUri(v);
|
if (controller.oldUrl.value.isEmpty) {
|
||||||
}
|
recognizeMagnetUri(v);
|
||||||
controller.oldUrl.value = v;
|
}
|
||||||
},
|
controller.oldUrl.value = v;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.folder_open),
|
||||||
|
onPressed: () async {
|
||||||
|
var pr = await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ["torrent"]);
|
||||||
|
if (pr != null) {
|
||||||
|
if (!Util.isWeb()) {
|
||||||
|
_urlController.text = pr.files[0].path ?? "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_urlController.text = pr.files[0].name;
|
||||||
|
controller.setFileDataUri(pr.files[0].bytes!);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.history_rounded),
|
||||||
|
onPressed: () async {
|
||||||
|
List<String> resultOfHistories =
|
||||||
|
await _historyController.getAllHistory();
|
||||||
|
// reversing: display last entered history first
|
||||||
|
List<String> reverseResultOfHistories =
|
||||||
|
resultOfHistories.reversed.toList();
|
||||||
|
// show dialog box to list history
|
||||||
|
if (context.mounted) {
|
||||||
|
showGeneralDialog(
|
||||||
|
barrierColor: Colors.black.withOpacity(0.5),
|
||||||
|
transitionBuilder: (context, a1, a2, widget) {
|
||||||
|
return Transform.scale(
|
||||||
|
scale: a1.value,
|
||||||
|
child: Opacity(
|
||||||
|
opacity: a1.value,
|
||||||
|
child: HistoryView(
|
||||||
|
isHistoryListEmpty:
|
||||||
|
reverseResultOfHistories.isEmpty,
|
||||||
|
historyList: ListView.builder(
|
||||||
|
itemCount: reverseResultOfHistories.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_urlController.text =
|
||||||
|
reverseResultOfHistories[index];
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: MouseRegion(
|
||||||
|
cursor: SystemMouseCursors.click,
|
||||||
|
child: Container(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8.0,
|
||||||
|
vertical: 8.0,
|
||||||
|
),
|
||||||
|
margin:
|
||||||
|
const EdgeInsets.symmetric(
|
||||||
|
horizontal: 10.0,
|
||||||
|
vertical: 8.0,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.background,
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.circular(10.0),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
reverseResultOfHistories[index]
|
||||||
|
.toString(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
transitionDuration:
|
||||||
|
const Duration(milliseconds: 250),
|
||||||
|
barrierDismissible: true,
|
||||||
|
barrierLabel: '',
|
||||||
|
context: context,
|
||||||
|
pageBuilder: (context, animation1, animation2) {
|
||||||
|
return const Text('PAGE BUILDER');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
//.where((e) => e != null).map((e) => e!).toList(),
|
||||||
|
),
|
||||||
|
Obx(
|
||||||
|
() => Visibility(
|
||||||
|
visible: controller.showAdvanced.value,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 40, top: 15),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
TabBar(
|
||||||
|
controller: controller.advancedTabController,
|
||||||
|
tabs: const [
|
||||||
|
Tab(
|
||||||
|
text: 'HTTP',
|
||||||
|
),
|
||||||
|
Tab(
|
||||||
|
text: 'BitTorrent',
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
AutoScaleTabBarView(
|
||||||
|
controller: controller.advancedTabController,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _httpUaController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'User-Agent',
|
||||||
|
)),
|
||||||
|
TextFormField(
|
||||||
|
controller: _httpCookieController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Cookie',
|
||||||
|
)),
|
||||||
|
TextFormField(
|
||||||
|
controller: _httpRefererController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Referer',
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: _btTrackerController,
|
||||||
|
maxLines: 5,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Trakers',
|
||||||
|
hintText: 'addTrackerHit'.tr,
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
),
|
||||||
icon: const Icon(Icons.folder_open),
|
),
|
||||||
onPressed: () async {
|
Center(
|
||||||
var pr = await FilePicker.platform.pickFiles(
|
child: Padding(
|
||||||
type: FileType.custom,
|
|
||||||
allowedExtensions: ["torrent"]);
|
|
||||||
if (pr != null) {
|
|
||||||
if (!Util.isWeb()) {
|
|
||||||
_urlController.text = pr.files[0].path ?? "";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_urlController.text = pr.files[0].name;
|
|
||||||
controller.setFileDataUri(pr.files[0].bytes!);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
//.where((e) => e != null).map((e) => e!).toList(),
|
|
||||||
),
|
|
||||||
Obx(() => Visibility(
|
|
||||||
visible: controller.showAdvanced.value,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 40, top: 15),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
TabBar(
|
|
||||||
controller: controller.advancedTabController,
|
|
||||||
tabs: const [
|
|
||||||
Tab(
|
|
||||||
text: 'HTTP',
|
|
||||||
),
|
|
||||||
Tab(
|
|
||||||
text: 'BitTorrent',
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
AutoScaleTabBarView(
|
|
||||||
controller: controller.advancedTabController,
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
TextFormField(
|
|
||||||
controller: _httpUaController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'User-Agent',
|
|
||||||
)),
|
|
||||||
TextFormField(
|
|
||||||
controller: _httpCookieController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Cookie',
|
|
||||||
)),
|
|
||||||
TextFormField(
|
|
||||||
controller: _httpRefererController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Referer',
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
TextFormField(
|
|
||||||
controller: _btTrackerController,
|
|
||||||
maxLines: 5,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Trakers',
|
|
||||||
hintText: 'addTrackerHit'.tr,
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))),
|
|
||||||
Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 15),
|
padding: const EdgeInsets.only(top: 15),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -241,8 +321,12 @@ class CreateView extends GetView<CreateController> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
]))),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -273,9 +357,9 @@ class CreateView extends GetView<CreateController> {
|
|||||||
// check if is multi line urls
|
// check if is multi line urls
|
||||||
final urls = Util.textToLines(_urlController.text);
|
final urls = Util.textToLines(_urlController.text);
|
||||||
ResolveResult rr;
|
ResolveResult rr;
|
||||||
bool isMuiltiLine = false;
|
bool isMultiLine = false;
|
||||||
if (urls.length > 1) {
|
if (urls.length > 1) {
|
||||||
isMuiltiLine = true;
|
isMultiLine = true;
|
||||||
rr = ResolveResult(
|
rr = ResolveResult(
|
||||||
res: Resource(
|
res: Resource(
|
||||||
files: urls
|
files: urls
|
||||||
@@ -287,12 +371,14 @@ class CreateView extends GetView<CreateController> {
|
|||||||
final submitUrl = Util.isWeb() && controller.fileDataUri.isNotEmpty
|
final submitUrl = Util.isWeb() && controller.fileDataUri.isNotEmpty
|
||||||
? controller.fileDataUri.value
|
? controller.fileDataUri.value
|
||||||
: _urlController.text;
|
: _urlController.text;
|
||||||
|
// add final submitUrl to the history
|
||||||
|
_historyController.addHistory(submitUrl);
|
||||||
rr = await resolve(Request(
|
rr = await resolve(Request(
|
||||||
url: submitUrl,
|
url: submitUrl,
|
||||||
extra: parseReqExtra(_urlController.text),
|
extra: parseReqExtra(_urlController.text),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
await _showResolveDialog(rr, isMuiltiLine);
|
await _showResolveDialog(rr, isMultiLine);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showErrorMessage(e);
|
showErrorMessage(e);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class HistoryController {
|
||||||
|
// Get History in List<String>
|
||||||
|
Future<List<String>> getAllHistory() async {
|
||||||
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||||
|
List<String>? historyList = preferences.getStringList('history');
|
||||||
|
if(historyList == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return historyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Existing History & Add New History
|
||||||
|
void addHistory(String historyText) async {
|
||||||
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||||
|
List<String> existingHistoryData = await getAllHistory();
|
||||||
|
existingHistoryData.add(historyText);
|
||||||
|
preferences.setStringList('history', existingHistoryData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearHistory() async {
|
||||||
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||||
|
preferences.remove('history');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:gopeed/app/modules/history/controller/history_controller.dart';
|
||||||
|
|
||||||
|
class HistoryView extends StatefulWidget {
|
||||||
|
const HistoryView({
|
||||||
|
super.key,
|
||||||
|
required this.isHistoryListEmpty,
|
||||||
|
required this.historyList,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool isHistoryListEmpty;
|
||||||
|
final Widget historyList;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HistoryView> createState() => _HistoryViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HistoryViewState extends State<HistoryView> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final Size size = MediaQuery.sizeOf(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
body: Dialog(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
child: Container(
|
||||||
|
width: size.width * 0.8,
|
||||||
|
height: size.height * 0.8,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(
|
||||||
|
Icons.history_rounded,
|
||||||
|
size: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.headlineSmall
|
||||||
|
?.fontSize,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8.0),
|
||||||
|
Text(
|
||||||
|
'history'.tr,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
HistoryController _controller = HistoryController();
|
||||||
|
_controller.clearHistory();
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
tooltip: "clearHistory".tr,
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.history_toggle_off_rounded,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.close_rounded,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: widget.isHistoryListEmpty
|
||||||
|
? <Widget>[
|
||||||
|
const Icon(
|
||||||
|
Icons.manage_history_rounded,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10.0),
|
||||||
|
Text(
|
||||||
|
'noHistoryFound'.tr,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: <Widget>[
|
||||||
|
Expanded(child: widget.historyList),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+247
-255
File diff suppressed because it is too large.
Load diff
@@ -41,7 +41,7 @@ dependencies:
|
|||||||
context_menus: ^1.0.2
|
context_menus: ^1.0.2
|
||||||
json_annotation: ^4.8.1
|
json_annotation: ^4.8.1
|
||||||
dio: ^5.2.1
|
dio: ^5.2.1
|
||||||
path_provider: ^2.0.11
|
path_provider: ^2.1.1
|
||||||
file_picker: 5.3.1
|
file_picker: 5.3.1
|
||||||
macos_secure_bookmarks: ^0.2.1
|
macos_secure_bookmarks: ^0.2.1
|
||||||
rounded_loading_button: ^2.1.0
|
rounded_loading_button: ^2.1.0
|
||||||
|
|||||||
Reference in new issue
Block a user