Skip to content

Commit

Permalink
Minor change for gallery when displayed as share mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Aug 12, 2024
1 parent f599d52 commit 32a42df
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 45 deletions.
8 changes: 8 additions & 0 deletions lib/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'tags.dart';
import 'task.dart';
import 'token.dart';
import 'user.dart';
import '../globals.dart';

part 'client.g.dart';

Expand Down Expand Up @@ -245,6 +246,12 @@ abstract class _EHApi {
@Query("tag") String? tag,
@Query("category") String? category,
@CancelRequest() CancelToken? cancel});
@PUT('/shared_token')
@MultiPart()
Future<ApiResult<SharedTokenWithUrl>> shareGallery(@Part(name: "gid") int gid,
{@Part(name: "expired") int? expired,
@Part(name: "type") String type = "gallery",
@CancelRequest() CancelToken? cancel});

@GET('/tag/{id}')
// ignore: unused_element
Expand Down Expand Up @@ -437,6 +444,7 @@ class EHApi extends __EHApi {
"jpn_title": jpnTitle?.toString(),
"max_length": maxLength?.toString(),
"export_ad": exportAd?.toString(),
"share": shareToken,
};
queries.removeWhere((key, value) => value == null);
final newUri = uri
Expand Down
52 changes: 52 additions & 0 deletions lib/api/client.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/api/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ class SharedToken {
}
}
}

@JsonSerializable(createToJson: false)
class SharedTokenWithUrl {
const SharedTokenWithUrl({
required this.token,
required this.url,
});
final SharedToken token;
final String url;
factory SharedTokenWithUrl.fromJson(Map<String, dynamic> json) =>
_$SharedTokenWithUrlFromJson(json);
}
6 changes: 6 additions & 0 deletions lib/api/token.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/api/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ enum UserPermission with EnumFlag {
readGallery,
editGallery,
deleteGallery,
manageTasks;
manageTasks,
shareGallery;

String localText(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
Expand All @@ -22,11 +23,13 @@ enum UserPermission with EnumFlag {
return i18n.deleteGallery;
case UserPermission.manageTasks:
return i18n.manageTasks;
case UserPermission.shareGallery:
return i18n.shareGallery;
}
}
}

const userPermissionAll = 15;
const userPermissionAll = 31;

class UserPermissions {
UserPermissions(this.code);
Expand Down
27 changes: 15 additions & 12 deletions lib/components/gallery_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,21 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
controller: controller,
slivers: [
SliverAppBar(
leading: IconButton(
icon: Icon(widget.isSelectMode ? Icons.close : Icons.arrow_back),
onPressed: () {
if (widget.isSelectMode) {
if (widget.onSelectChanged != null) {
widget.onSelectChanged!(false);
}
} else {
context.canPop() ? context.pop() : context.go("/");
}
},
),
leading: shareToken != null && !widget.isSelectMode
? Container()
: IconButton(
icon: Icon(
widget.isSelectMode ? Icons.close : Icons.arrow_back),
onPressed: () {
if (widget.isSelectMode) {
if (widget.onSelectChanged != null) {
widget.onSelectChanged!(false);
}
} else {
context.canPop() ? context.pop() : context.go("/");
}
},
),
title: SelectableText(widget.gData.meta.preferredTitle,
maxLines: 1, minLines: 1),
actions: [
Expand Down
51 changes: 29 additions & 22 deletions lib/components/gallery_info_desktop.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:eh_downloader_flutter/globals.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -94,28 +95,34 @@ class GalleryInfoDesktop extends StatelessWidget {
SizedBox(
width: 170,
child: Column(children: [
SelectableText.rich(TextSpan(
text: gData.meta.category,
style: TextStyle(color: cs.secondary),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.pushNamed("/galleries",
queryParameters: {
"category": gData.meta.category
});
})),
SelectableText.rich(TextSpan(
text: gData.meta.uploader,
style: TextStyle(color: cs.secondary),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.pushNamed("/galleries",
queryParameters: {
"uploader": gData.meta.uploader
});
})),
shareToken != null
? SelectableText(gData.meta.category,
style: TextStyle(color: cs.secondary))
: SelectableText.rich(TextSpan(
text: gData.meta.category,
style: TextStyle(color: cs.secondary),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.pushNamed("/galleries",
queryParameters: {
"category": gData.meta.category
});
})),
shareToken != null
? SelectableText(gData.meta.uploader,
style: TextStyle(color: cs.secondary))
: SelectableText.rich(TextSpan(
text: gData.meta.uploader,
style: TextStyle(color: cs.secondary),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.pushNamed("/galleries",
queryParameters: {
"uploader": gData.meta.uploader
});
})),
_KeyValue(
"${i18n.posted}${i18n.colon}",
DateFormat.yMd(locale)
Expand Down
5 changes: 4 additions & 1 deletion lib/components/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class TagWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final t =
Text(name ?? (tag.tag.contains(':') ? tag.tag.split(':')[1] : tag.tag));
if (shareToken != null) return t;
return InkWell(
onTap: () {
context.pushNamed("/galleries",
Expand All @@ -18,6 +21,6 @@ class TagWidget extends StatelessWidget {
},
extra: GalleriesPageExtra(translatedTag: tag.translated));
},
child: Text(name ?? (tag.tag.contains(':') ? tag.tag.split(':')[1] : tag.tag)));
child: t);
}
}
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,6 @@
}
}
},
"enableServerTiming": "Enable server time tracking"
"enableServerTiming": "Enable server time tracking",
"shareGallery": "Share gallery"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,6 @@
}
}
},
"enableServerTiming": "测量服务器所用时间"
"enableServerTiming": "测量服务器所用时间",
"shareGallery": "分享画廊"
}
16 changes: 10 additions & 6 deletions lib/pages/gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ class _GalleryPage extends State<GalleryPage>
return Scaffold(
appBar: _data == null
? AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
context.canPop() ? context.pop() : context.go("/gallery");
},
),
leading: shareToken != null
? Container()
: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
context.canPop()
? context.pop()
: context.go("/gallery");
},
),
title: Text(title),
actions: [
buildThemeModeIcon(context),
Expand Down

0 comments on commit 32a42df

Please sign in to comment.