Skip to content

Commit

Permalink
Merge pull request #1680 from nextcloud/fix/neon_framework/user-statu…
Browse files Browse the repository at this point in the history
…s-icon
  • Loading branch information
provokateurin authored Feb 29, 2024
2 parents 9127ae4 + a4d6702 commit 80a1fdf
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion external/nextcloud-server
Submodule nextcloud-server updated 2473 files
5 changes: 3 additions & 2 deletions packages/neon/neon_dashboard/lib/src/pages/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ class DashboardMainPage extends StatelessWidget {

return _buildStatus(
context: context,
icon: NeonServerIcon(
icon: 'user-status-$statusIcon',
icon: NeonUserStatusIcon(
type: statusIcon,
size: 20,
),
label: Text(label.toString()),
onPressed: () async {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 5 additions & 2 deletions packages/neon_framework/lib/src/widgets/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:neon_framework/src/utils/user_status_clear_at.dart';
import 'package:neon_framework/src/widgets/account_tile.dart';
import 'package:neon_framework/src/widgets/error.dart';
import 'package:neon_framework/src/widgets/linear_progress_indicator.dart';
import 'package:neon_framework/src/widgets/server_icon.dart';
import 'package:neon_framework/src/widgets/user_status_icon.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
import 'package:nextcloud/user_status.dart' as user_status;
Expand Down Expand Up @@ -832,7 +832,10 @@ class _NeonUserStatusDialogState extends State<NeonUserStatusDialog> {
return buildCard(
selected: types.contains(status?.status),
child: ListTile(
leading: NeonServerIcon(icon: 'user-status-${onlineStatus.key}'),
leading: NeonUserStatusIcon(
type: onlineStatus.key,
size: 24,
),
title: Text(
title,
overflow: TextOverflow.ellipsis,
Expand Down
9 changes: 6 additions & 3 deletions packages/neon_framework/lib/src/widgets/user_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:neon_framework/src/theme/icons.dart';
import 'package:neon_framework/src/theme/sizes.dart';
import 'package:neon_framework/src/utils/provider.dart';
import 'package:neon_framework/src/widgets/image.dart';
import 'package:neon_framework/src/widgets/server_icon.dart';
import 'package:neon_framework/src/widgets/user_status_icon.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/user_status.dart' as user_status;

Expand Down Expand Up @@ -151,8 +151,11 @@ class NeonUserStatusIndicator extends StatelessWidget {
);
} else if (result.hasData) {
final type = result.requireData.status;
if (type == user_status.$Type.dnd || (!hasEmoji && type != user_status.$Type.offline)) {
child = NeonServerIcon(icon: 'user-status-$type');
if (type == user_status.$Type.dnd || !hasEmoji) {
child = NeonUserStatusIcon(
type: type,
size: 16,
);
} else if (hasEmoji) {
child = Text(
result.data!.icon!,
Expand Down
53 changes: 53 additions & 0 deletions packages/neon_framework/lib/src/widgets/user_status_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:neon_framework/src/theme/colors.dart';
import 'package:nextcloud/user_status.dart' as user_status;

const _minus45Rad = -45 * pi / 180;

/// Displays the current user status [type] as an icon.
class NeonUserStatusIcon extends StatelessWidget {
/// Creates a new user status icon.
const NeonUserStatusIcon({
required this.type,
this.size,
super.key,
});

/// The type of the user status.
final user_status.$Type type;

/// The size of the icon.
final double? size;

@override
Widget build(BuildContext context) => switch (type) {
user_status.$Type.online => Icon(
size: size,
Icons.circle,
color: NcColors.success,
),
user_status.$Type.dnd => Icon(
size: size,
MdiIcons.minusCircle,
color: NcColors.error,
),
user_status.$Type.away => Transform.rotate(
angle: _minus45Rad,
child: Icon(
size: size,
MdiIcons.moonWaningCrescent,
color: NcColors.warning,
),
),
user_status.$Type.invisible => Icon(
size: size,
Icons.circle_outlined,
color: Theme.of(context).colorScheme.onBackground,
),
user_status.$Type.offline || user_status.$Type.busy => const SizedBox.shrink(),
_ => throw UnimplementedError(type.value),
};
}
1 change: 1 addition & 0 deletions packages/neon_framework/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export 'package:neon_framework/src/widgets/list_view.dart';
export 'package:neon_framework/src/widgets/relative_time.dart';
export 'package:neon_framework/src/widgets/server_icon.dart';
export 'package:neon_framework/src/widgets/user_avatar.dart' hide NeonUserStatusIndicator;
export 'package:neon_framework/src/widgets/user_status_icon.dart';
Binary file modified packages/neon_framework/test/goldens/user_status_dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/neon_framework/test/user_avatar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void main() {
group('Status indicator', () {
for (final (status, icon, textMatcher, iconMatcher) in [
(user_status.$Type.offline, '😀', findsOne, findsNothing),
(user_status.$Type.offline, null, findsNothing, findsNothing),
(user_status.$Type.offline, null, findsNothing, findsOne),
(user_status.$Type.online, '😀', findsOne, findsNothing),
(user_status.$Type.online, null, findsNothing, findsOne),
(user_status.$Type.dnd, '😀', findsNothing, findsOne),
Expand Down Expand Up @@ -95,7 +95,7 @@ void main() {
await tester.pumpAndSettle();

expect(find.byType(Text), textMatcher);
expect(find.byType(NeonServerIcon), iconMatcher);
expect(find.byType(NeonUserStatusIcon), iconMatcher);
});
}
});
Expand Down

0 comments on commit 80a1fdf

Please sign in to comment.