app/modules/settings/settings.py

437 lines
16 KiB
Python
Raw Normal View History

2024-04-19 16:59:43 +00:00
import flet as ft
from utils import AppView, Title
2024-04-20 08:00:17 +00:00
from .functions import Theme, config
2024-04-19 16:59:43 +00:00
2024-04-19 20:02:44 +00:00
2024-04-19 16:59:43 +00:00
def Settings(page: ft.Page):
2024-04-19 19:39:11 +00:00
settingsContainer = ft.ListView(
2024-04-19 20:02:44 +00:00
expand=True,
2024-04-19 19:39:11 +00:00
)
2024-04-19 20:02:44 +00:00
settingsContainer.controls.append(ft.Text('General'))
2024-04-20 08:00:17 +00:00
def _on_name_change(e: ft.ControlEvent):
2024-04-20 08:00:17 +00:00
newName = ft.CupertinoTextField(value=config.get('general', 'name'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Full name'),
content=newName,
actions=[
ft.CupertinoButton(
'Save',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(
dlg,
'open',
False,
2024-04-20 08:00:17 +00:00
),
config.save(
'general',
'name',
2024-04-20 08:00:17 +00:00
newName.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(dlg, 'open', False),
2024-04-20 16:59:36 +00:00
page.update(),
2024-04-20 08:00:17 +00:00
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_phone_change(e: ft.ControlEvent):
2024-04-20 08:00:17 +00:00
newPhone = ft.CupertinoTextField(value=config.get('general', 'phone'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Mobile'),
content=newPhone,
actions=[
ft.CupertinoButton(
'Save',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(
dlg,
'open',
False,
2024-04-20 08:00:17 +00:00
),
config.save(
'general',
'phone',
2024-04-20 08:00:17 +00:00
newPhone.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(dlg, 'open', False),
2024-04-20 16:59:36 +00:00
page.update(),
2024-04-20 08:00:17 +00:00
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_email_change(e: ft.ControlEvent):
2024-04-20 08:00:17 +00:00
newEmail = ft.CupertinoTextField(value=config.get('general', 'email'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your Email'),
content=newEmail,
actions=[
ft.CupertinoButton(
'Save',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(
dlg,
'open',
False,
2024-04-20 08:00:17 +00:00
),
config.save(
'general',
'email',
2024-04-20 08:00:17 +00:00
newEmail.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(dlg, 'open', False),
2024-04-20 16:59:36 +00:00
page.update(),
2024-04-20 08:00:17 +00:00
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
def _on_nid_change(e: ft.ControlEvent):
2024-04-20 08:00:17 +00:00
newNID = ft.CupertinoTextField(value=config.get('general', 'nid'))
dlg = ft.CupertinoAlertDialog(
modal=True,
title=ft.Text('Enter your NID'),
content=newNID,
actions=[
ft.CupertinoButton(
'Save',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(
dlg,
'open',
False,
2024-04-20 08:00:17 +00:00
),
config.save(
'general',
'nid',
2024-04-20 08:00:17 +00:00
newNID.value,
),
page.update(),
),
),
ft.CupertinoButton(
'Close',
on_click=lambda _: (
2024-04-20 08:00:17 +00:00
setattr(dlg, 'open', False),
2024-04-20 16:59:36 +00:00
page.update(),
2024-04-20 08:00:17 +00:00
),
),
],
)
page.dialog = dlg
dlg.open = True
page.update()
2024-04-19 19:39:11 +00:00
generalSettings = ft.Container(
content=ft.Column(
controls=[
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.PERSON),
2024-04-19 20:02:44 +00:00
title=ft.Text('Username'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'The greeting message',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
2024-04-20 08:00:17 +00:00
on_click=_on_name_change,
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.PHONE),
2024-04-19 20:02:44 +00:00
title=ft.Text('Phone'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'Personal Phone number',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
2024-04-20 08:00:17 +00:00
on_click=_on_phone_change,
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.EMAIL),
2024-04-19 20:02:44 +00:00
title=ft.Text('Email'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'Personal Email',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
2024-04-20 08:00:17 +00:00
on_click=_on_email_change,
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Icon(ft.icons.CARD_TRAVEL),
2024-04-19 20:02:44 +00:00
title=ft.Text('NID'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'National Idenity Number',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
2024-04-20 08:00:17 +00:00
on_click=_on_nid_change,
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
],
),
2024-04-19 19:39:11 +00:00
)
settingsContainer.controls.append(
2024-04-19 20:02:44 +00:00
generalSettings,
2024-04-19 19:39:11 +00:00
)
2024-04-20 08:00:17 +00:00
# settingsContainer.controls.append(ft.Divider())
# settingsContainer.controls.append(ft.Text('Notifications'))
# notificationsSettings = ft.Container(
# content=ft.Column(
# controls=[
# ft.Card(
# content=ft.Container(
# ink=True,
# content=ft.Column(
# [
# ft.ListTile(
# leading=ft.Icon(ft.icons.TELEGRAM),
# title=ft.Text('Telegram'),
# subtitle=ft.Text(
# 'Telegram Notifications for reminders and Bill pays',
# ),
# ),
# ],
# ),
# padding=10,
# on_click=lambda _: print('clicked username'),
# ),
# ),
# ],
# ),
# )
# settingsContainer.controls.append(
# notificationsSettings,
# )
2024-04-19 19:39:11 +00:00
settingsContainer.controls.append(ft.Divider())
2024-04-19 20:02:44 +00:00
settingsContainer.controls.append(ft.Text('Apps'))
2024-04-19 19:39:11 +00:00
appsSettings = ft.Container(
content=ft.Column(
controls=[
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Image(
border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN,
2024-04-19 20:02:44 +00:00
src='https://asset.brandfetch.io/idZJsIaold/id9-VJM_HU.png',
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
title=ft.Text('Dhiraagu'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'An ISP Service.',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
on_click=lambda _: page.go('/settings/dhiraagu'),
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Image(
border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN,
2024-04-19 20:02:44 +00:00
src='https://asset.brandfetch.io/idR1xFKHLD/idu6J-WQsm.jpeg',
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
title=ft.Text('Ooredoo'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'An ISP Service.',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
on_click=lambda _: page.go('/settings/ooredoo'),
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Image(
border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN,
2024-04-19 20:02:44 +00:00
src='https://www.stelco.com.mv/wp-content/uploads/2022/02/unnamed.png',
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
title=ft.Text('STELCO'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'Electricity Bills',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
on_click=lambda _: page.go('/settings/stelco'),
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Image(
border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN,
2024-04-19 20:02:44 +00:00
src='https://asset.brandfetch.io/idOZWUOUm-/idNastd9Bg.jpeg',
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
title=ft.Text('MWSC'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'Water Bills',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
on_click=lambda _: page.go('/settings/mwsc'),
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
ft.Card(
content=ft.Container(
ink=True,
content=ft.Column(
[
ft.ListTile(
leading=ft.Image(
border_radius=ft.border_radius.all(10),
fit=ft.ImageFit.CONTAIN,
2024-04-19 20:02:44 +00:00
src='https://asset.brandfetch.io/idLMZnv5SC/iduyX4keYN.jpeg',
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
title=ft.Text('Medianet'),
2024-04-19 19:39:11 +00:00
subtitle=ft.Text(
2024-04-19 20:02:44 +00:00
'Online Television Service',
2024-04-19 19:39:11 +00:00
),
),
2024-04-19 20:02:44 +00:00
],
2024-04-19 19:39:11 +00:00
),
padding=10,
on_click=lambda _: page.go('/settings/medianet'),
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
],
),
2024-04-19 19:39:11 +00:00
)
settingsContainer.controls.append(appsSettings)
settingsContainer.controls.append(ft.Divider())
2024-04-19 20:02:44 +00:00
settingsContainer.controls.append(ft.Text('Theme'))
def _on_theme_change(e: ft.ControlEvent):
2024-04-20 08:00:17 +00:00
if page.theme_mode == ft.ThemeMode.LIGHT:
e.value = False
2024-04-20 16:59:36 +00:00
config.save('general', 'theme', 'dark')
2024-04-20 08:00:17 +00:00
else:
e.value = True
2024-04-20 16:59:36 +00:00
config.save('general', 'theme', 'light')
2024-04-20 08:00:17 +00:00
Theme(page).change(
(
ft.ThemeMode.DARK
if page.theme_mode == ft.ThemeMode.LIGHT
else ft.ThemeMode.LIGHT
),
2024-04-20 08:00:17 +00:00
)
2024-04-19 19:39:11 +00:00
themeSettings = ft.Container(
content=ft.Column(
controls=[
ft.Card(
content=ft.Container(
content=ft.Container(
ft.Switch(
2024-04-19 20:02:44 +00:00
label=' Switch to dark theme',
on_change=_on_theme_change,
2024-04-20 08:00:17 +00:00
value=True,
2024-04-19 19:39:11 +00:00
),
),
padding=10,
on_click=None,
2024-04-19 20:02:44 +00:00
),
2024-04-19 19:39:11 +00:00
),
2024-04-19 20:02:44 +00:00
],
),
2024-04-19 19:39:11 +00:00
)
settingsContainer.controls.append(themeSettings)
2024-04-19 16:59:43 +00:00
return AppView(
2024-04-19 20:02:44 +00:00
'/settings',
2024-04-19 16:59:43 +00:00
[
ft.AppBar(
leading=ft.IconButton(
ft.icons.ARROW_BACK_IOS_NEW_ROUNDED,
2024-04-19 20:02:44 +00:00
on_click=lambda _: page.go('/'),
2024-04-19 16:59:43 +00:00
),
title=ft.Text(Title(str(__file__))),
2024-04-19 20:02:44 +00:00
bgcolor=ft.colors.TRANSPARENT,
2024-04-19 16:59:43 +00:00
),
2024-04-19 20:02:44 +00:00
settingsContainer,
2024-04-19 16:59:43 +00:00
],
)