Skip to content

Commit 777e5ed

Browse files
committed
feat: adapt client UI to mobile interfaces
1 parent 8ac5487 commit 777e5ed

14 files changed

+643
-179
lines changed

app/app_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, page: ft.Page):
4848
self.sidebar = NavigationSidebar(self)
4949
self.left_navigation_menu = LeftNavigationMenu(self)
5050

51-
self.page.snack_bar_area = ft.Container()
51+
self.snack_bar_area = ft.Container()
5252
self.dialog_area = ft.Container()
5353
self.complete_page = ft.Row(
5454
expand=True,
@@ -57,10 +57,10 @@ def __init__(self, page: ft.Page):
5757
ft.VerticalDivider(width=1),
5858
self.content_area,
5959
self.dialog_area,
60-
self.page.snack_bar_area,
60+
self.snack_bar_area,
6161
]
6262
)
63-
self.snack_bar = ShowSnackBar(self.page)
63+
self.snack_bar = ShowSnackBar(self)
6464
self.subprocess_start_up_info = utils.get_startup_info()
6565
self.record_card_manager = RecordingCardManager(self)
6666
self.record_manager = RecordingManager(self)

app/ui/components/recording_dialog.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ async def update_format_options(e):
9393
menu_height=200
9494
)
9595

96-
format_row = ft.Row([media_type_dropdown, record_format_field], expand=True)
96+
if self.app.is_mobile:
97+
media_type_dropdown.width = 500
98+
record_format_field.width = 500
99+
format_row = ft.Column([media_type_dropdown, record_format_field], expand=True)
100+
else:
101+
format_row = ft.Row([media_type_dropdown, record_format_field], expand=True)
97102

98103
recording_dir_field = ft.TextField(
99104
label=self._["input_save_path"],

app/ui/components/search_dialog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(self, home_page, on_close=None):
3030
border_radius=5,
3131
border_color=ft.Colors.GREY_400,
3232
focused_border_color=ft.Colors.BLUE,
33-
cursor_color=ft.Colors.BLACK,
3433
hint_style=ft.TextStyle(color=ft.Colors.GREY_500, size=14),
3534
)
3635
self.actions = [

app/ui/components/show_snackbar.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
class ShowSnackBar:
5-
def __init__(self, page):
6-
self.page = page
5+
def __init__(self, app):
6+
self.app = app
77

88
async def show_snack_bar(self, message, bgcolor=None, duration=1500, action=None, emoji=None,
99
show_close_icon=False):
@@ -16,10 +16,12 @@ async def show_snack_bar(self, message, bgcolor=None, duration=1500, action=None
1616
action=action,
1717
bgcolor=bgcolor,
1818
duration=duration,
19-
margin=ft.margin.only(left=self.page.width - 300, top=0, right=10, bottom=10),
2019
show_close_icon=show_close_icon
2120
)
2221

22+
if not self.app.is_mobile:
23+
snack_bar.margin = ft.margin.only(left=self.app.page.width - 300, top=0, right=10, bottom=10)
24+
2325
snack_bar.open = True
24-
self.page.snack_bar_area.content = snack_bar
25-
self.page.update()
26+
self.app.snack_bar_area.content = snack_bar
27+
self.app.page.update()

app/ui/components/video_player.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,18 @@ def close_dialog(_):
3737
dialog.open = False
3838
self.app.dialog_area.update()
3939

40+
is_mobile = self.app.is_mobile
41+
42+
if is_mobile:
43+
video_width = 320
44+
video_height = 180
45+
else:
46+
video_width = 800
47+
video_height = 450
48+
4049
video = ft.Video(
41-
width=800,
42-
height=450,
50+
width=video_width,
51+
height=video_height,
4352
playlist=[ft.VideoMedia(video_source)],
4453
autoplay=True
4554
)
@@ -63,13 +72,46 @@ async def open_in_browser(_):
6372
else:
6473
actions.insert(0, ft.TextButton(self._["copy_video_url"], on_click=copy_source))
6574

66-
dialog = ft.AlertDialog(
67-
modal=True,
68-
title=ft.Text(title),
69-
content=video,
70-
actions=actions,
71-
actions_alignment=ft.MainAxisAlignment.END
72-
)
75+
if is_mobile:
76+
actions_row = ft.Row(
77+
controls=actions,
78+
spacing=5,
79+
alignment=ft.MainAxisAlignment.CENTER,
80+
wrap=True,
81+
)
82+
83+
video_container = ft.Container(
84+
content=video,
85+
alignment=ft.alignment.center,
86+
width=video_width,
87+
height=video_height,
88+
)
89+
90+
dialog = ft.AlertDialog(
91+
modal=True,
92+
title=ft.Text(title, overflow=ft.TextOverflow.ELLIPSIS, max_lines=1, size=14),
93+
content=ft.Column(
94+
[
95+
video_container,
96+
actions_row
97+
],
98+
spacing=5,
99+
alignment=ft.MainAxisAlignment.CENTER,
100+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
101+
tight=True,
102+
),
103+
actions=[],
104+
inset_padding=ft.padding.only(left=10, right=10, top=5, bottom=5),
105+
content_padding=ft.padding.only(left=5, right=5, top=5, bottom=0),
106+
)
107+
else:
108+
dialog = ft.AlertDialog(
109+
modal=True,
110+
title=ft.Text(title),
111+
content=video,
112+
actions=actions,
113+
actions_alignment=ft.MainAxisAlignment.END
114+
)
73115
dialog.open = True
74116
self.app.dialog_area.content = dialog
75117
self.app.dialog_area.update()

app/ui/layout/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

app/ui/layout/responsive_layout.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import flet as ft
2+
3+
from ...app_manager import App
4+
from ...utils.logger import logger
5+
6+
7+
def is_mobile_device(page: ft.Page) -> bool:
8+
return page.width < 768
9+
10+
11+
def setup_responsive_layout(page: ft.Page, app: App) -> None:
12+
if is_mobile_device(page):
13+
logger.info("mobile device detected, enable mobile layout")
14+
app.is_mobile = True
15+
app.left_navigation_menu.width = 0
16+
app.left_navigation_menu.visible = False
17+
18+
app.bottom_navigation = ft.NavigationBar(
19+
destinations=[
20+
ft.NavigationBarDestination(icon=ft.Icons.HOME, label="首页"),
21+
ft.NavigationBarDestination(icon=ft.Icons.SETTINGS, label="设置"),
22+
ft.NavigationBarDestination(icon=ft.Icons.DRIVE_FILE_MOVE, label="存储"),
23+
ft.NavigationBarDestination(icon=ft.Icons.INFO, label="关于"),
24+
],
25+
on_change=lambda e: page.go(f"/{['home', 'settings', 'storage', 'about'][e.control.selected_index]}"),
26+
)
27+
28+
app.content_area.expand = True
29+
30+
app.complete_page = ft.Column(
31+
expand=True,
32+
spacing=0,
33+
controls=[
34+
app.content_area,
35+
app.bottom_navigation,
36+
app.dialog_area,
37+
app.snack_bar_area
38+
]
39+
)
40+
else:
41+
logger.info("desktop device detected, enable desktop layout")
42+
app.is_mobile = False
43+
app.complete_page = ft.Row(
44+
expand=True,
45+
controls=[
46+
app.left_navigation_menu,
47+
ft.VerticalDivider(width=1),
48+
app.content_area,
49+
app.dialog_area,
50+
app.snack_bar_area,
51+
]
52+
)

0 commit comments

Comments
 (0)