Skip to content

Commit c5a0670

Browse files
committed
feat: refactor main UI
1 parent 889d65b commit c5a0670

18 files changed

Lines changed: 1126 additions & 1041 deletions

lib/hooks/use_fvp_player.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ FvpPlayer useFvpPlayer(BuildContext context) {
131131
final isCompleted =
132132
useListenableSelector(controller, () => controller.value.isCompleted);
133133

134-
final double aspect = useMemoized(
135-
() => size.width != 0 && size.height != 0 ? size.width / size.height : 0,
134+
final double? aspect = useMemoized(
135+
() =>
136+
size.width != 0 && size.height != 0 ? size.width / size.height : null,
136137
[size.width, size.height]);
137138

138139
final seeking = useState(false);

lib/models/storages/storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:iris/models/storages/ftp.dart';
66
import 'package:iris/models/storages/local.dart';
77
import 'package:iris/models/storages/webdav.dart';
88
import 'package:iris/utils/platform.dart';
9-
import 'package:iris/widgets/popup.dart';
9+
import 'package:iris/widgets/iris_popup.dart';
1010
import 'package:iris/pages/storages/storages.dart';
1111
import 'package:iris/store/use_storage_store.dart';
1212

lib/models/store/ui_state.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ abstract class UiState with _$UiState {
99
const factory UiState({
1010
@Default(false) bool isAlwaysOnTop,
1111
@Default(false) bool isFullScreen,
12+
@Default(false) bool isPlayerExpanded,
1213
}) = _UiState;
1314

1415
factory UiState.fromJson(Map<String, dynamic> json) =>

lib/pages/home/history.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:iris/store/use_history_store.dart';
1111
import 'package:iris/store/use_play_queue_store.dart';
1212
import 'package:iris/utils/file_size_convert.dart';
1313
import 'package:iris/utils/get_localizations.dart';
14-
import 'package:iris/widgets/app_chip.dart';
14+
import 'package:iris/widgets/iris_chip.dart';
1515
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
1616

1717
class History extends HookWidget {
@@ -84,14 +84,14 @@ class History extends HookWidget {
8484
if ((progress.duration.inMilliseconds -
8585
progress.position.inMilliseconds) <=
8686
5000) {
87-
return AppChip(text: '100%');
87+
return IRISChip(text: '100%');
8888
}
8989
final String progressString =
9090
(progress.position.inMilliseconds /
9191
progress.duration.inMilliseconds *
9292
100)
9393
.toStringAsFixed(0);
94-
return AppChip(text: '$progressString %');
94+
return IRISChip(text: '$progressString %');
9595
} else {
9696
return const SizedBox();
9797
}
@@ -109,7 +109,7 @@ class History extends HookWidget {
109109
mainAxisSize: MainAxisSize.min,
110110
children: [
111111
const SizedBox(width: 4),
112-
AppChip(
112+
IRISChip(
113113
text: subtitleType,
114114
primary: true,
115115
),

lib/pages/home/home.dart

Lines changed: 45 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import 'package:flutter_hooks/flutter_hooks.dart';
44
import 'package:flutter_zustand/flutter_zustand.dart';
55
import 'package:iris/hooks/use_fvp_player.dart';
66
import 'package:iris/hooks/use_media_kit_player.dart';
7-
import 'package:iris/models/player.dart';
87
import 'package:iris/models/store/app_state.dart';
98
import 'package:iris/pages/player/iris_player.dart';
9+
import 'package:iris/pages/storages/storages.dart';
1010
import 'package:iris/store/use_app_store.dart';
11+
import 'package:iris/store/use_ui_store.dart';
1112

1213
class Home extends HookWidget {
1314
const Home({super.key});
@@ -16,69 +17,56 @@ class Home extends HookWidget {
1617
Widget build(BuildContext context) {
1718
final playerBackend =
1819
useAppStore().select(context, (state) => state.playerBackend);
20+
final isPlayerExpanded =
21+
useUiStore().select(context, (state) => state.isPlayerExpanded);
1922

20-
final playerState = useState<MediaPlayer?>(null);
21-
22-
void handlePlayerCreated(MediaPlayer player) {
23-
WidgetsBinding.instance.addPostFrameCallback((_) {
24-
if (context.mounted) {
25-
playerState.value = player;
26-
}
27-
});
28-
}
29-
30-
final Widget playerHost;
31-
switch (playerBackend) {
32-
case PlayerBackend.mediaKit:
33-
playerHost = _MediaKitPlayerHost(onPlayerCreated: handlePlayerCreated);
34-
break;
35-
case PlayerBackend.fvp:
36-
playerHost = _FvpPlayerHost(onPlayerCreated: handlePlayerCreated);
37-
break;
38-
}
23+
final IrisPlayer player = () {
24+
switch (playerBackend) {
25+
case PlayerBackend.mediaKit:
26+
return IrisPlayer(
27+
key: const ValueKey('media-kit'),
28+
playerHooks: useMediaKitPlayer,
29+
);
30+
case PlayerBackend.fvp:
31+
return IrisPlayer(
32+
key: const ValueKey('fvp'),
33+
playerHooks: useFvpPlayer,
34+
);
35+
}
36+
}();
3937

4038
return AnnotatedRegion(
41-
value: const SystemUiOverlayStyle(
42-
statusBarIconBrightness: Brightness.light,
43-
statusBarColor: Colors.transparent,
44-
systemNavigationBarColor: Colors.transparent,
39+
value: SystemUiOverlayStyle(
40+
statusBarIconBrightness: isPlayerExpanded
41+
? Brightness.light
42+
: Theme.of(context).brightness == Brightness.dark
43+
? Brightness.light
44+
: Brightness.dark,
45+
statusBarColor: isPlayerExpanded
46+
? const Color.fromRGBO(0, 0, 0, 0.5)
47+
: Theme.of(context).colorScheme.surface,
48+
systemNavigationBarColor: isPlayerExpanded ? null : Colors.transparent,
4549
),
4650
child: Scaffold(
47-
backgroundColor: Color(0xFF2f2f2f),
48-
body: Stack(
49-
children: [
50-
playerHost,
51-
if (playerState.value != null)
52-
IrisPlayer(player: playerState.value!)
53-
],
51+
body: SafeArea(
52+
left: !isPlayerExpanded,
53+
top: !isPlayerExpanded,
54+
right: !isPlayerExpanded,
55+
bottom: !isPlayerExpanded,
56+
child: Stack(
57+
children: [
58+
Positioned(
59+
left: 0,
60+
top: 48,
61+
right: 0,
62+
bottom: 112,
63+
child: Storages(),
64+
),
65+
player,
66+
],
67+
),
5468
),
5569
),
5670
);
5771
}
5872
}
59-
60-
class _MediaKitPlayerHost extends HookWidget {
61-
final ValueChanged<MediaPlayer> onPlayerCreated;
62-
63-
const _MediaKitPlayerHost({required this.onPlayerCreated});
64-
65-
@override
66-
Widget build(BuildContext context) {
67-
final player = useMediaKitPlayer(context);
68-
onPlayerCreated(player);
69-
return Container(); // Doesn't build any UI itself.
70-
}
71-
}
72-
73-
class _FvpPlayerHost extends HookWidget {
74-
final ValueChanged<MediaPlayer> onPlayerCreated;
75-
76-
const _FvpPlayerHost({required this.onPlayerCreated});
77-
78-
@override
79-
Widget build(BuildContext context) {
80-
final player = useFvpPlayer(context);
81-
onPlayerCreated(player);
82-
return Container(); // Doesn't build any UI itself.
83-
}
84-
}

0 commit comments

Comments
 (0)