💄 Optimized album page

This commit is contained in:
LittleSheep 2024-07-26 17:35:54 +08:00
parent 277ba69513
commit ae87e9ad31
4 changed files with 167 additions and 118 deletions

View File

@ -177,8 +177,6 @@ class AuthProvider extends GetConnect {
Get.find<WebSocketProvider>().connect();
Get.find<WebSocketProvider>().notifyPrefetch();
await refreshAuthorizeStatus();
await refreshUserProfile();
return credentials!;
}

View File

@ -11,11 +11,12 @@ import 'package:solian/services.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/app_bar_leading.dart';
import 'package:solian/widgets/attachments/attachment_item.dart';
import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/feed/feed_list.dart';
import 'package:solian/widgets/sized_container.dart';
import '../../widgets/attachments/attachment_list.dart';
class AccountProfilePage extends StatefulWidget {
final String name;
@ -31,6 +32,7 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
PagingController(firstPageKey: 0);
bool _isBusy = true;
bool _showMature = false;
Account? _userinfo;
@ -59,8 +61,11 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
.get('/attachments?take=10&offset=$pageKey&author=${widget.name}');
if (resp.statusCode == 200) {
final result = PaginationResult.fromJson(resp.body);
final out = result.data?.map((e) => Attachment.fromJson(e)).toList();
if (out != null && out.length >= 10) {
final out = result.data
?.map((e) => Attachment.fromJson(e))
.where((x) => x.mimetype.split('/').firstOrNull == 'image')
.toList();
if (out != null && result.data!.length >= 10) {
_albumPagingController.appendPage(out, pageKey + out.length);
} else if (out != null) {
_albumPagingController.appendLastPage(out);
@ -90,10 +95,12 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
floating: true,
toolbarHeight: SolianTheme.toolbarHeight(context),
leadingWidth: 24,
leading: AppBarLeadingButton.adaptive(context),
automaticallyImplyLeading: false,
flexibleSpace: Row(
children: [
const SizedBox(width: 16),
AppBarLeadingButton.adaptive(context) ??
const SizedBox(width: 8),
const SizedBox(width: 8),
if (_userinfo != null)
AccountAvatar(content: _userinfo!.avatar, radius: 16),
const SizedBox(width: 12),
@ -152,6 +159,7 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
onRefresh: () =>
Future.sync(() => _albumPagingController.refresh()),
child: PagedGridView<int, Attachment>(
padding: EdgeInsets.zero,
pagingController: _albumPagingController,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
@ -172,15 +180,19 @@ class _AccountProfilePageState extends State<AccountProfilePage> {
),
child: ClipRRect(
borderRadius: radius,
child: AttachmentItem(
child: AttachmentListEntry(
item: item,
parentId: 'album',
showMature: _showMature,
onReveal: (value) {
setState(() => _showMature = value);
},
),
),
);
},
),
),
).paddingAll(16),
),
),
],

View File

@ -52,7 +52,7 @@ class _SignInPopupState extends State<SignInPopup> with ProtocolListener {
}
void performAction() async {
final AuthProvider provider = Get.find();
final AuthProvider auth = Get.find();
final username = _usernameController.value.text;
final password = _passwordController.value.text;
@ -61,7 +61,9 @@ class _SignInPopupState extends State<SignInPopup> with ProtocolListener {
setState(() => _isBusy = true);
try {
await provider.signin(context, username, password);
await auth.signin(context, username, password);
await auth.refreshAuthorizeStatus();
await auth.refreshUserProfile();
} on RiskyAuthenticateException catch (e) {
showDialog(
context: context,

View File

@ -107,113 +107,16 @@ class _AttachmentListState extends State<AttachmentList> {
}
Widget _buildEntry(Attachment? element, int idx) {
if (element == null) {
return Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.close, size: 32),
const SizedBox(height: 8),
Text(
'attachmentLoadFailed'.tr,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
'attachmentLoadFailedCaption'.tr,
textAlign: TextAlign.center,
),
],
),
),
);
}
return GestureDetector(
child: Container(
width: widget.width ?? MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: widget.attachmentsId.length > 1
? Border.symmetric(
vertical: BorderSide(
width: 0.3,
color: Theme.of(context).dividerColor,
),
)
: null,
),
child: Stack(
fit: StackFit.expand,
children: [
AttachmentItem(
parentId: widget.parentId,
key: Key('a${element.uuid}'),
return AttachmentListEntry(
item: element,
badge: _attachmentsMeta.length > 1 && !widget.isGrid
? '${idx + 1}/${_attachmentsMeta.length}'
: null,
showHideButton: !element.isMature || _showMature,
onHide: () {
setState(() => _showMature = false);
},
),
if (element.isMature && !_showMature)
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
),
),
),
if (element.isMature && !_showMature)
Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.visibility_off,
color: Colors.white,
size: 32,
),
const SizedBox(height: 8),
Text(
'matureContent'.tr,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
Text(
'matureContentCaption'.tr,
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
],
),
),
onTap: () {
if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) {
setState(() => _showMature = true);
} else if (['image'].contains(element.mimetype.split('/').first)) {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AttachmentListFullScreen(
parentId: widget.parentId,
attachment: element,
),
),
);
}
width: widget.width,
badgeContent: '${idx + 1}/${_attachmentsMeta.length}',
showBadge: _attachmentsMeta.length > 1 && !widget.isGrid,
showBorder: widget.attachmentsId.length > 1,
showMature: _showMature,
onReveal: (value) {
setState(() => _showMature = value);
},
);
}
@ -301,3 +204,137 @@ class _AttachmentListState extends State<AttachmentList> {
);
}
}
class AttachmentListEntry extends StatelessWidget {
final String parentId;
final Attachment? item;
final String? badgeContent;
final double? width;
final bool showBorder;
final bool showBadge;
final bool showMature;
final Function(bool) onReveal;
const AttachmentListEntry({
super.key,
required this.parentId,
required this.onReveal,
this.item,
this.badgeContent,
this.width,
this.showBorder = false,
this.showBadge = false,
this.showMature = false,
});
@override
Widget build(BuildContext context) {
if (item == null) {
return Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.close, size: 32),
const SizedBox(height: 8),
Text(
'attachmentLoadFailed'.tr,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
'attachmentLoadFailedCaption'.tr,
textAlign: TextAlign.center,
),
],
),
),
);
}
return GestureDetector(
child: Container(
width: width ?? MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: showBorder
? Border.symmetric(
vertical: BorderSide(
width: 0.3,
color: Theme.of(context).dividerColor,
),
)
: null,
),
child: Stack(
fit: StackFit.expand,
children: [
AttachmentItem(
parentId: parentId,
key: Key('a${item!.uuid}'),
item: item!,
badge: showBadge ? badgeContent : null,
showHideButton: !item!.isMature || showMature,
onHide: () {
onReveal(false);
},
),
if (item!.isMature && !showMature)
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
),
),
),
if (item!.isMature && !showMature)
Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.visibility_off,
color: Colors.white,
size: 32,
),
const SizedBox(height: 8),
Text(
'matureContent'.tr,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
Text(
'matureContentCaption'.tr,
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
],
),
),
onTap: () {
if (!showMature && item!.isMature) {
onReveal(true);
} else if (['image'].contains(item!.mimetype.split('/').first)) {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AttachmentListFullScreen(
parentId: parentId,
attachment: item!,
),
),
);
}
},
);
}
}