Skip to content

Commit

Permalink
feat: show post info for moebooru
Browse files Browse the repository at this point in the history
  • Loading branch information
khoadng committed Jun 27, 2023
1 parent 9a8458e commit 92a5d68
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 38 deletions.
33 changes: 33 additions & 0 deletions lib/boorus/core/feats/tags/tag_group_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Package imports:
import 'package:equatable/equatable.dart';

// Project imports:
import 'package:boorusama/boorus/core/feats/tags/tags.dart';

class TagGroupItem extends Equatable {
const TagGroupItem({
required this.category,
required this.groupName,
required this.tags,
required this.order,
});

final int category;
final String groupName;
final List<Tag> tags;
final TagCategoryOrder order;

@override
List<Object?> get props => [category, groupName, tags, order];
}

extension TagGroupItemX on TagGroupItem {
List<String> extractRawTag(TagCategory category) =>
tags.where((e) => category == e.category).map((e) => e.rawName).toList();

List<String> extractArtistTags() => extractRawTag(TagCategory.artist);
List<String> extractCharacterTags() => extractRawTag(TagCategory.charater);
List<String> extractGeneralTags() => extractRawTag(TagCategory.general);
List<String> extractMetaTags() => extractRawTag(TagCategory.meta);
List<String> extractCopyRightTags() => extractRawTag(TagCategory.copyright);
}
2 changes: 2 additions & 0 deletions lib/boorus/core/feats/tags/tags.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'blacklisted_tags_repository.dart';
export 'empty_tag_repository.dart';
export 'favorite_tag.dart';
export 'favorite_tag_hive_object.dart';
export 'favorite_tag_repository.dart';
Expand All @@ -11,6 +12,7 @@ export 'tag_cacher.dart';
export 'tag_category.dart';
export 'tag_colors.dart';
export 'tag_filter_category.dart';
export 'tag_group_item.dart';
export 'tag_info_service.dart';
export 'tag_repository.dart';
export 'tags_notifier.dart';
Expand Down
17 changes: 1 addition & 16 deletions lib/boorus/core/feats/tags/tags_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package imports:
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

// Project imports:
Expand Down Expand Up @@ -33,6 +32,7 @@ class TagsNotifier extends Notifier<List<TagGroupItem>?> {
.groupBy((e) => e.category)
.entries
.map((e) => TagGroupItem(
category: e.key.index,
groupName: tagCategoryToString(e.key),
tags: e.value,
order: tagCategoryToOrder(e.key),
Expand All @@ -46,21 +46,6 @@ class TagsNotifier extends Notifier<List<TagGroupItem>?> {
}
}

class TagGroupItem extends Equatable {
const TagGroupItem({
required this.groupName,
required this.tags,
required this.order,
});

final String groupName;
final List<Tag> tags;
final TagCategoryOrder order;

@override
List<Object?> get props => [groupName, tags, order];
}

String tagCategoryToString(TagCategory category) => switch (category) {
TagCategory.artist => 'Artist',
TagCategory.charater => 'Character',
Expand Down
1 change: 0 additions & 1 deletion lib/boorus/gelbooru/gelbooru_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:boorusama/api/rule34xxx/rule34xxx_api.dart';
import 'package:boorusama/boorus/core/feats/boorus/boorus.dart';
import 'package:boorusama/boorus/core/feats/downloads/downloads.dart';
import 'package:boorusama/boorus/core/feats/posts/posts.dart';
import 'package:boorusama/boorus/core/feats/tags/empty_tag_repository.dart';
import 'package:boorusama/boorus/core/feats/tags/tags.dart';
import 'package:boorusama/boorus/core/provider.dart';
import 'package:boorusama/boorus/gelbooru/feats/autocomplete/autocomplete_providers.dart';
Expand Down
38 changes: 38 additions & 0 deletions lib/boorus/moebooru/pages/posts/moebooru_information_section.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:flutter_riverpod/flutter_riverpod.dart';

// Project imports:
import 'package:boorusama/boorus/core/feats/posts/posts.dart';
import 'package:boorusama/boorus/core/feats/tags/tags.dart';
import 'package:boorusama/boorus/core/widgets/posts/information_section.dart';

class MoebooruInformationSection extends ConsumerWidget {
const MoebooruInformationSection({
super.key,
required this.post,
});

final Post post;

@override
Widget build(BuildContext context, WidgetRef ref) {
final tags = ref.watch(tagsProvider);
final characterTags =
tags?.map((e) => e.extractCharacterTags()).expand((e) => e).toList();
final artistTags =
tags?.map((e) => e.extractArtistTags()).expand((e) => e).toList();
final copyRightTags =
tags?.map((e) => e.extractCopyRightTags()).expand((e) => e).toList();

return InformationSection(
characterTags: characterTags ?? [],
artistTags: artistTags ?? [],
copyrightTags: copyRightTags ?? [],
createdAt: post.createdAt ?? DateTime.now(),
source: post.source,
);
}
}
71 changes: 50 additions & 21 deletions lib/boorus/moebooru/pages/posts/moebooru_post_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:boorusama/flutter.dart';
import 'package:boorusama/foundation/i18n.dart';
import 'package:boorusama/foundation/theme/theme_mode.dart';
import 'package:boorusama/widgets/widgets.dart';
import 'moebooru_information_section.dart';

class MoebooruPostDetailsPage extends ConsumerStatefulWidget {
const MoebooruPostDetailsPage({
Expand Down Expand Up @@ -80,24 +81,50 @@ class _MoebooruPostDetailsPageState
@override
int get initialPage => widget.initialPage;

@override
void initState() {
super.initState();
ref.read(tagsProvider.notifier).load(posts[widget.initialPage].tags);
}

@override
Widget build(BuildContext context) {
return DetailsPage(
controller: controller,
intitialIndex: widget.initialPage,
onExit: widget.onExit,
onPageChanged: onSwiped,
bottomSheet: (page) => Column(
mainAxisSize: MainAxisSize.min,
children: [
if (posts[page].isVideo)
ValueListenableBuilder<VideoProgress>(
valueListenable: videoProgress,
builder: (_, progress, __) =>
BooruVideoProgressBar(progress: progress),
onPageChanged: (page) {
ref.read(tagsProvider.notifier).load(posts[page].tags);
onSwiped(page);
},
bottomSheet: (page) {
return Container(
decoration: BoxDecoration(
color: context.theme.scaffoldBackgroundColor.withOpacity(0.8),
border: Border(
top: BorderSide(
color: context.theme.dividerColor,
width: 1,
),
),
MoebooruPostActionToolbar(post: posts[page]),
],
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (posts[page].isVideo)
ValueListenableBuilder<VideoProgress>(
valueListenable: videoProgress,
builder: (_, progress, __) =>
BooruVideoProgressBar(progress: progress),
),
MoebooruInformationSection(
post: posts[page],
),
MoebooruPostActionToolbar(post: posts[page]),
],
),
);
},
targetSwipeDownBuilder: (context, page) => SwipeTargetImage(
imageUrl: posts[page].thumbnailImageUrl,
aspectRatio: posts[page].aspectRatio,
Expand Down Expand Up @@ -128,8 +155,6 @@ class _MoebooruPostDetailsPageState
post: widget.posts[currentPage],
),
],
onExpanded: (currentPage) =>
ref.read(tagsProvider.notifier).load(posts[currentPage].tags),
);
}

Expand Down Expand Up @@ -191,6 +216,17 @@ class _MoebooruPostDetailsPageState
if (!expandedOnCurrentPage)
SizedBox(height: MediaQuery.of(context).size.height),
if (expandedOnCurrentPage) ...[
MoebooruInformationSection(post: post),
const Divider(
thickness: 1.5,
height: 4,
),
FileDetailsSection(
post: post,
),
const Divider(
thickness: 1.5,
),
Padding(
padding: const EdgeInsets.all(8),
child: PostTagList(
Expand All @@ -202,13 +238,6 @@ class _MoebooruPostDetailsPageState
),
),
),
const Divider(
thickness: 1.5,
height: 4,
),
FileDetailsSection(
post: post,
),
post.source.whenWeb(
(source) => SourceSection(source: source),
() => const SizedBox.shrink(),
Expand Down

0 comments on commit 92a5d68

Please sign in to comment.