mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
add actions
This commit is contained in:
@@ -28,7 +28,7 @@ class ToastOverlay extends StatelessWidget {
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: PhysicalModel(
|
||||
color: ColorScheme.of(context).surface,
|
||||
color: ColorScheme.of(context).surface.withOpacity(1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
elevation: 1,
|
||||
child: Container(
|
||||
|
@@ -10,8 +10,10 @@ import 'package:pixes/components/title_bar.dart';
|
||||
import 'package:pixes/foundation/app.dart';
|
||||
import 'package:pixes/network/download.dart';
|
||||
import 'package:pixes/utils/translation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../utils/io.dart';
|
||||
import 'main_page.dart';
|
||||
|
||||
class DownloadedPage extends StatefulWidget {
|
||||
@@ -208,6 +210,46 @@ class _DownloadedIllustViewPageState extends State<_DownloadedIllustViewPage> wi
|
||||
|
||||
var controller = PageController();
|
||||
|
||||
int currentPage = 0;
|
||||
|
||||
var menuController = FlyoutController();
|
||||
|
||||
Future<File?> getFile() async {
|
||||
var file = File(widget.imagePaths[currentPage]);
|
||||
if(file.existsSync()) {
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
menuController.showFlyout(builder: (context) => MenuFlyout(
|
||||
items: [
|
||||
MenuFlyoutItem(text: Text("Save to".tl), onPressed: () async{
|
||||
var file = await getFile();
|
||||
if(file != null){
|
||||
saveFile(file);
|
||||
}
|
||||
}),
|
||||
MenuFlyoutItem(text: Text("Share".tl), onPressed: () async{
|
||||
var file = await getFile();
|
||||
if(file != null){
|
||||
var ext = file.path.split('.').last;
|
||||
var mediaType = switch(ext){
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'gif' => 'image/gif',
|
||||
'webp' => 'image/webp',
|
||||
_ => 'application/octet-stream'
|
||||
};
|
||||
Share.shareXFiles([XFile(file.path, mimeType: mediaType, name: file.path.split('/').last)]);
|
||||
}
|
||||
}),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaffoldPage(
|
||||
@@ -240,7 +282,9 @@ class _DownloadedIllustViewPageState extends State<_DownloadedIllustViewPage> wi
|
||||
);
|
||||
},
|
||||
onPageChanged: (index) {
|
||||
setState(() {});
|
||||
setState(() {
|
||||
currentPage = index;
|
||||
});
|
||||
},
|
||||
)),
|
||||
Positioned(
|
||||
@@ -259,6 +303,7 @@ class _DownloadedIllustViewPageState extends State<_DownloadedIllustViewPage> wi
|
||||
const Expanded(
|
||||
child: DragToMoveArea(child: SizedBox.expand(),),
|
||||
),
|
||||
buildActions(),
|
||||
if(App.isDesktop)
|
||||
WindowButtons(key: ValueKey(windowButtonKey),),
|
||||
],
|
||||
@@ -295,7 +340,7 @@ class _DownloadedIllustViewPageState extends State<_DownloadedIllustViewPage> wi
|
||||
left: 12,
|
||||
bottom: 8,
|
||||
child: Text(
|
||||
"${controller.page!.toInt() + 1}/${widget.imagePaths.length}",
|
||||
"${currentPage + 1}/${widget.imagePaths.length}",
|
||||
),
|
||||
)
|
||||
],
|
||||
@@ -305,5 +350,33 @@ class _DownloadedIllustViewPageState extends State<_DownloadedIllustViewPage> wi
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildActions() {
|
||||
var width = MediaQuery.of(context).size.width;
|
||||
return FlyoutTarget(
|
||||
controller: menuController,
|
||||
child: width > 600
|
||||
? Button(
|
||||
onPressed: showMenu,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(
|
||||
MdIcons.menu,
|
||||
size: 18,
|
||||
),
|
||||
SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Text('Actions'),
|
||||
],
|
||||
))
|
||||
: IconButton(
|
||||
icon: const Icon(
|
||||
MdIcons.more_horiz,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: showMenu),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pixes/components/animated_image.dart';
|
||||
import 'package:pixes/components/loading.dart';
|
||||
import 'package:pixes/components/message.dart';
|
||||
@@ -15,6 +16,7 @@ import 'package:pixes/pages/image_page.dart';
|
||||
import 'package:pixes/pages/search_page.dart';
|
||||
import 'package:pixes/pages/user_info_page.dart';
|
||||
import 'package:pixes/utils/translation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../components/md.dart';
|
||||
|
||||
@@ -203,18 +205,21 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
top = (top + offset).clamp(minValue, maxValue);
|
||||
animationController.value = (top - minValue) / (maxValue - minValue);
|
||||
}
|
||||
|
||||
void _handlePointerUp(DragEndDetails details) {
|
||||
var speed = details.primaryVelocity ?? 0;
|
||||
const minShouldTransitionSpeed = 1000;
|
||||
if(speed > minShouldTransitionSpeed) {
|
||||
animationController.forward();
|
||||
} else if(speed < minShouldTransitionSpeed) {
|
||||
} else if(speed < 0 - minShouldTransitionSpeed) {
|
||||
animationController.reverse();
|
||||
} else {
|
||||
_handlePointerCancel();
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePointerCancel() {
|
||||
if(animationController.value == 1 || animationController.value == 0) return;
|
||||
if(animationController.value >= 0.5 ) {
|
||||
animationController.forward();
|
||||
} else {
|
||||
@@ -261,6 +266,16 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
onPointerDown: (event) {
|
||||
_recognizer.addPointer(event);
|
||||
},
|
||||
onPointerSignal: (event) {
|
||||
if(event is PointerScrollEvent) {
|
||||
var offset = (event).scrollDelta.dy;
|
||||
if(offset < 0) {
|
||||
animationController.reverse();
|
||||
} else {
|
||||
animationController.forward();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Card(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(8)),
|
||||
backgroundColor:
|
||||
@@ -275,6 +290,7 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
buildTop(),
|
||||
buildStats(),
|
||||
buildTags(),
|
||||
buildMoreActions(),
|
||||
SelectableText("${"Artwork ID".tl}: ${widget.illust.id}\n${"Artist ID".tl}: ${widget.illust.author.id}", style: TextStyle(color: ColorScheme.of(context).outline),).paddingLeft(4),
|
||||
const SizedBox(height: 8,)
|
||||
],
|
||||
@@ -395,14 +411,14 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
),
|
||||
))
|
||||
else if (!widget.illust.author.isFollowed)
|
||||
Button(onPressed: follow, child: Text("Follow".tl).fixWidth(56))
|
||||
Button(onPressed: follow, child: Text("Follow".tl).fixWidth(62))
|
||||
else
|
||||
Button(
|
||||
onPressed: follow,
|
||||
child: Text(
|
||||
"Unfollow".tl,
|
||||
style: TextStyle(color: ColorScheme.of(context).error),
|
||||
).fixWidth(56),
|
||||
).fixWidth(62),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -412,29 +428,29 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
|
||||
bool isBookmarking = false;
|
||||
|
||||
void favorite([String type = "public"]) async{
|
||||
if(isBookmarking) return;
|
||||
setState(() {
|
||||
isBookmarking = true;
|
||||
});
|
||||
var method = widget.illust.isBookmarked ? "delete" : "add";
|
||||
var res = await Network().addBookmark(widget.illust.id.toString(), method, type);
|
||||
if(res.error) {
|
||||
if(mounted) {
|
||||
context.showToast(message: "Network Error");
|
||||
}
|
||||
} else {
|
||||
widget.illust.isBookmarked = !widget.illust.isBookmarked;
|
||||
widget.favoriteCallback?.call(widget.illust.isBookmarked);
|
||||
}
|
||||
setState(() {
|
||||
isBookmarking = false;
|
||||
});
|
||||
}
|
||||
|
||||
Iterable<Widget> buildActions(double width) sync* {
|
||||
yield const SizedBox(width: 8,);
|
||||
|
||||
void favorite() async{
|
||||
if(isBookmarking) return;
|
||||
setState(() {
|
||||
isBookmarking = true;
|
||||
});
|
||||
var method = widget.illust.isBookmarked ? "delete" : "add";
|
||||
var res = await Network().addBookmark(widget.illust.id.toString(), method);
|
||||
if(res.error) {
|
||||
if(mounted) {
|
||||
context.showToast(message: "Network Error");
|
||||
}
|
||||
} else {
|
||||
widget.illust.isBookmarked = !widget.illust.isBookmarked;
|
||||
widget.favoriteCallback?.call(widget.illust.isBookmarked);
|
||||
}
|
||||
setState(() {
|
||||
isBookmarking = false;
|
||||
});
|
||||
}
|
||||
|
||||
void download() {
|
||||
DownloadManager().addDownloadingTask(widget.illust);
|
||||
setState(() {});
|
||||
@@ -629,6 +645,87 @@ class _BottomBarState extends State<_BottomBar> with TickerProviderStateMixin{
|
||||
),
|
||||
).paddingVertical(8).paddingHorizontal(2);
|
||||
}
|
||||
|
||||
Widget buildMoreActions() {
|
||||
return Row(
|
||||
children: [
|
||||
Button(
|
||||
onPressed: () => favorite("private"),
|
||||
child: SizedBox(
|
||||
height: 28,
|
||||
child: Row(
|
||||
children: [
|
||||
if(isBookmarking)
|
||||
const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: ProgressRing(strokeWidth: 2,),
|
||||
)
|
||||
else if(widget.illust.isBookmarked)
|
||||
Icon(
|
||||
Icons.favorite,
|
||||
color: ColorScheme.of(context).error,
|
||||
size: 18,
|
||||
)
|
||||
else
|
||||
const Icon(
|
||||
Icons.favorite_border,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8,),
|
||||
if(widget.illust.isBookmarked)
|
||||
Text("Cancel".tl)
|
||||
else
|
||||
Text("Private".tl)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8,),
|
||||
Button(
|
||||
onPressed: () {
|
||||
Share.share("${widget.illust.title}\nhttps://pixiv.net/artworks/${widget.illust.id}");
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 28,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.share,
|
||||
color: ColorScheme.of(context).error,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8,),
|
||||
Text("Share".tl)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8,),
|
||||
Button(
|
||||
onPressed: () {
|
||||
var text = "https://pixiv.net/artworks/${widget.illust.id}";
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
showToast(context, message: "Copied".tl);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 28,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.copy,
|
||||
color: ColorScheme.of(context).error,
|
||||
size: 18,
|
||||
),
|
||||
const SizedBox(width: 8,),
|
||||
Text("Link".tl)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingHorizontal(4).paddingBottom(4);
|
||||
}
|
||||
}
|
||||
|
||||
class _CommentsPage extends StatefulWidget {
|
||||
|
@@ -2,10 +2,15 @@ import 'dart:io';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
import 'package:pixes/components/md.dart';
|
||||
import 'package:pixes/components/page_route.dart';
|
||||
import 'package:pixes/foundation/app.dart';
|
||||
import 'package:pixes/foundation/cache_manager.dart';
|
||||
import 'package:pixes/foundation/image_provider.dart';
|
||||
import 'package:pixes/pages/main_page.dart';
|
||||
import 'package:pixes/utils/io.dart';
|
||||
import 'package:pixes/utils/translation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class ImagePage extends StatefulWidget {
|
||||
@@ -14,15 +19,15 @@ class ImagePage extends StatefulWidget {
|
||||
final String url;
|
||||
|
||||
static show(String url) {
|
||||
App.rootNavigatorKey.currentState?.push(
|
||||
AppPageRoute(builder: (context) => ImagePage(url)));
|
||||
App.rootNavigatorKey.currentState
|
||||
?.push(AppPageRoute(builder: (context) => ImagePage(url)));
|
||||
}
|
||||
|
||||
@override
|
||||
State<ImagePage> createState() => _ImagePageState();
|
||||
}
|
||||
|
||||
class _ImagePageState extends State<ImagePage> with WindowListener{
|
||||
class _ImagePageState extends State<ImagePage> with WindowListener {
|
||||
int windowButtonKey = 0;
|
||||
|
||||
@override
|
||||
@@ -53,14 +58,15 @@ class _ImagePageState extends State<ImagePage> with WindowListener{
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaffoldPage(
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||
content: Stack(
|
||||
color: FluentTheme.of(context).micaBackgroundColor,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: PhotoView(
|
||||
backgroundDecoration: const BoxDecoration(
|
||||
color: Colors.transparent
|
||||
),
|
||||
Positioned.fill(
|
||||
child: PhotoView(
|
||||
backgroundDecoration: BoxDecoration(
|
||||
color: FluentTheme.of(context).micaBackgroundColor),
|
||||
filterQuality: FilterQuality.medium,
|
||||
imageProvider: widget.url.startsWith("file://")
|
||||
? FileImage(File(widget.url.replaceFirst("file://", "")))
|
||||
@@ -74,16 +80,22 @@ class _ImagePageState extends State<ImagePage> with WindowListener{
|
||||
height: 36,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 6,),
|
||||
const SizedBox(
|
||||
width: 6,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(FluentIcons.back).paddingAll(2),
|
||||
onPressed: () => context.pop()
|
||||
),
|
||||
onPressed: () => context.pop()),
|
||||
const Expanded(
|
||||
child: DragToMoveArea(child: SizedBox.expand(),),
|
||||
child: DragToMoveArea(
|
||||
child: SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
if(App.isDesktop)
|
||||
WindowButtons(key: ValueKey(windowButtonKey),),
|
||||
buildActions(),
|
||||
if (App.isDesktop)
|
||||
WindowButtons(
|
||||
key: ValueKey(windowButtonKey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -92,4 +104,73 @@ class _ImagePageState extends State<ImagePage> with WindowListener{
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
var menuController = FlyoutController();
|
||||
|
||||
Future<File?> getFile() async{
|
||||
if (widget.url.startsWith("file://")) {
|
||||
return File(widget.url.replaceFirst("file://", ""));
|
||||
}
|
||||
var res = await CacheManager().findCache(widget.url);
|
||||
if(res == null){
|
||||
return null;
|
||||
}
|
||||
return File(res);
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
menuController.showFlyout(builder: (context) => MenuFlyout(
|
||||
items: [
|
||||
MenuFlyoutItem(text: Text("Save to".tl), onPressed: () async{
|
||||
var file = await getFile();
|
||||
if(file != null){
|
||||
saveFile(file);
|
||||
}
|
||||
}),
|
||||
MenuFlyoutItem(text: Text("Share".tl), onPressed: () async{
|
||||
var file = await getFile();
|
||||
if(file != null){
|
||||
var ext = file.path.split('.').last;
|
||||
var mediaType = switch(ext){
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'gif' => 'image/gif',
|
||||
'webp' => 'image/webp',
|
||||
_ => 'application/octet-stream'
|
||||
};
|
||||
Share.shareXFiles([XFile(file.path, mimeType: mediaType, name: file.path.split('/').last)]);
|
||||
}
|
||||
}),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
Widget buildActions() {
|
||||
var width = MediaQuery.of(context).size.width;
|
||||
return FlyoutTarget(
|
||||
controller: menuController,
|
||||
child: width > 600
|
||||
? Button(
|
||||
onPressed: showMenu,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(
|
||||
MdIcons.menu,
|
||||
size: 18,
|
||||
),
|
||||
SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Text('Actions'),
|
||||
],
|
||||
))
|
||||
: IconButton(
|
||||
icon: const Icon(
|
||||
MdIcons.more_horiz,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: showMenu),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -43,11 +43,28 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
||||
|
||||
void follow() async{
|
||||
if(isFollowing) return;
|
||||
String type = "";
|
||||
if(!data!.isFollowed) {
|
||||
await flyoutController.showFlyout(
|
||||
navigatorKey: App.rootNavigatorKey.currentState,
|
||||
builder: (context) =>
|
||||
MenuFlyout(
|
||||
items: [
|
||||
MenuFlyoutItem(text: Text("Public".tl),
|
||||
onPressed: () => type = "public"),
|
||||
MenuFlyoutItem(text: Text("Private".tl),
|
||||
onPressed: () => type = "private"),
|
||||
],
|
||||
));
|
||||
}
|
||||
if(type.isEmpty && !data!.isFollowed) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isFollowing = true;
|
||||
});
|
||||
var method = data!.isFollowed ? "delete" : "add";
|
||||
var res = await Network().follow(data!.id.toString(), method);
|
||||
var res = await Network().follow(data!.id.toString(), method, type);
|
||||
if(res.error) {
|
||||
if(mounted) {
|
||||
context.showToast(message: "Network Error");
|
||||
@@ -61,6 +78,8 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
||||
});
|
||||
}
|
||||
|
||||
var flyoutController = FlyoutController();
|
||||
|
||||
Widget buildUser() {
|
||||
return SliverToBoxAdapter(
|
||||
child: Column(
|
||||
@@ -112,7 +131,10 @@ class _UserInfoPageState extends LoadingState<UserInfoPage, UserDetails> {
|
||||
),
|
||||
))
|
||||
else if (!data!.isFollowed)
|
||||
Button(onPressed: follow, child: Text("Follow".tl))
|
||||
FlyoutTarget(
|
||||
controller: flyoutController,
|
||||
child: Button(onPressed: follow, child: Text("Follow".tl))
|
||||
)
|
||||
else
|
||||
Button(
|
||||
onPressed: follow,
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
||||
import 'package:pixes/foundation/app.dart';
|
||||
|
||||
extension FSExt on FileSystemEntity {
|
||||
Future<void> deleteIfExists() async {
|
||||
@@ -43,4 +48,24 @@ String bytesToText(int bytes) {
|
||||
} else {
|
||||
return "${(bytes / 1024 / 1024 / 1024).toStringAsFixed(2)} GB";
|
||||
}
|
||||
}
|
||||
|
||||
void saveFile(File file) async{
|
||||
if(App.isDesktop) {
|
||||
var fileName = file.path.split('/').last;
|
||||
final FileSaveLocation? result =
|
||||
await getSaveLocation(suggestedName: fileName);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Uint8List fileData = await file.readAsBytes();
|
||||
String mimeType = 'image/${fileName.split('.').last}';
|
||||
final XFile textFile = XFile.fromData(
|
||||
fileData, mimeType: mimeType, name: fileName);
|
||||
await textFile.saveTo(result.path);
|
||||
} else {
|
||||
final params = SaveFileDialogParams(sourceFilePath: file.path);
|
||||
await FlutterFileDialog.saveFile(params: params);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user