Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions openandroidinstaller/openandroidinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from flet import (
AppBar,
Banner,
Button,
Column,
Container,
ElevatedButton,
Icon,
Image,
Page,
Expand Down Expand Up @@ -134,9 +134,12 @@ def __init__(self, state: AppState):
# stack of previous default views for the back-button
self.previous_views: List = []

def build(self):
self.view.controls.append(self.state.default_views.pop())
return self.view
# Pop the first view and display it
first_view = self.state.default_views.pop()
if hasattr(first_view, '_init_content'):
first_view._init_content()
self.view.controls.append(first_view)
self.controls = [self.view]

def to_previous_view(self, e):
"""Method to display the previous view."""
Expand All @@ -157,7 +160,10 @@ def to_next_view(self, e):
self.view.controls = []
# if there are default views left, display them first
if self.state.default_views:
self.view.controls.append(self.state.default_views.pop())
next_view = self.state.default_views.pop()
if hasattr(next_view, '_init_content'):
next_view._init_content()
self.view.controls.append(next_view)
elif self.state.steps:
self.view.controls.append(
StepView(
Expand All @@ -168,7 +174,10 @@ def to_next_view(self, e):
)
elif self.state.final_default_views:
# here we expect the install view to populate the step views again if necessary
self.view.controls.append(self.state.final_default_views.pop())
next_view = self.state.final_default_views.pop()
if hasattr(next_view, '_init_content'):
next_view._init_content()
self.view.controls.append(next_view)

# else:
# # display the final view
Expand All @@ -181,13 +190,21 @@ def configure(page: Page):
"""Configure the application."""
# Configure the application base page
page.title = "OpenAndroidInstaller"
page.theme_mode = "light"
page.theme_mode = ft.ThemeMode.LIGHT
page.theme = ft.Theme(
color_scheme=ft.ColorScheme(
surface=ft.Colors.WHITE,
surface_variant=ft.Colors.WHITE,
surface_tint=ft.Colors.TRANSPARENT,
),
)
page.window.height = 900
page.window.width = int(1.5 * page.window.height)
page.window.top = 100
page.window.left = 120
page.scroll = "adaptive"
page.horizontal_alignment = "center"
page.scroll = ft.ScrollMode.ADAPTIVE
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.bgcolor = ft.Colors.WHITE
page.window.min_width = 1000
page.window.min_height = 600

Expand Down Expand Up @@ -235,9 +252,9 @@ def main(page: Page, test: bool = False, test_config: str = "sargo"):
bgcolor="#00d886",
actions=[
Container(
content=ElevatedButton(
content=Button(
icon=Icons.QUESTION_MARK_ROUNDED,
text="FAQ",
content="FAQ",
on_click=lambda _: webbrowser.open(
"https://openandroidinstaller.org/faq.html"
),
Expand All @@ -246,9 +263,9 @@ def main(page: Page, test: bool = False, test_config: str = "sargo"):
tooltip="Frequently asked questions and encountered issues.",
),
Container(
content=ElevatedButton(
content=Button(
icon=Icons.FEEDBACK_OUTLINED,
text="Give feedback",
content="Give feedback",
on_click=lambda _: webbrowser.open(
"https://openandroidinstaller.org/feedback.html"
),
Expand All @@ -257,9 +274,9 @@ def main(page: Page, test: bool = False, test_config: str = "sargo"):
tooltip="Give feedback about your experience with OpenAndroidInstaller",
),
Container(
content=ElevatedButton(
content=Button(
icon=Icons.BUG_REPORT_OUTLINED,
text="Report a bug",
content="Report a bug",
on_click=lambda _: webbrowser.open(
"https://github.com/openandroidinstaller-dev/openandroidinstaller/issues"
),
Expand All @@ -272,7 +289,7 @@ def main(page: Page, test: bool = False, test_config: str = "sargo"):

# display a warnings banner
def close_banner(e):
banner.open = False
page.pop_dialog()
page.update()

banner = Banner(
Expand All @@ -282,11 +299,10 @@ def close_banner(e):
"These instructions only work if you follow every section and step precisely. Do not continue after something fails!"
),
actions=[
TextButton("I understand", on_click=close_banner),
TextButton(content="I understand", on_click=close_banner),
],
)
page.overlay.append(banner)
banner.open = True
page.show_dialog(banner)

# create the State object
state = AppState(
Expand Down Expand Up @@ -323,8 +339,8 @@ def startup(test: bool, test_config: str, logging_path: str):
logger.add(f"{logging_path}/openandroidinstaller.log")

# start the app
ft.app(
target=functools.partial(main, test=test, test_config=test_config),
ft.run(
functools.partial(main, test=test, test_config=test_config),
assets_dir="assets",
)

Expand Down
4 changes: 3 additions & 1 deletion openandroidinstaller/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# You should have received a copy of the GNU General Public License along with OpenAndroidInstaller.
# If not, see <https://www.gnu.org/licenses/>."""
# Author: Tobias Sterbak
import webbrowser

import flet as ft


Expand All @@ -26,7 +28,7 @@ class Markdown(ft.Markdown):
def __init__(self, *args, **kwargs):
super().__init__(
selectable=True,
on_tap_link=lambda e: self.page.launch_url(e.data),
on_tap_link=lambda e: webbrowser.open(e.data),
*args,
**kwargs,
)
63 changes: 29 additions & 34 deletions openandroidinstaller/views/addon_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import webbrowser
from typing import Callable

import flet as ft
from app_state import AppState
from flet import (
AlertDialog,
Button,
Column,
Divider,
ElevatedButton,
FilePicker,
FilePickerResultEvent,
FilledButton,
OutlinedButton,
Row,
Expand All @@ -43,8 +42,9 @@ def __init__(
):
super().__init__(state=state)
self.on_confirm = on_confirm
self._init_content()

def build(self):
def _init_content(self):
# dialog box to explain OS images and recovery
self.dlg_explain_addons = AlertDialog(
modal=True,
Expand Down Expand Up @@ -75,14 +75,13 @@ def build(self):
""",
),
actions=[
TextButton("Close", on_click=self.close_close_explain_addons_dlg),
TextButton(content="Close", on_click=self.close_close_explain_addons_dlg),
],
actions_alignment="end",
actions_alignment=ft.MainAxisAlignment.END,
shape=ContinuousRectangleBorder(radius=0),
)

# initialize file pickers
self.pick_addons_dialog = FilePicker(on_result=self.pick_addons_result)
# initialize file picker (no longer needed as overlay control in Flet v1)
self.selected_addons = Text("Selected addons: ")

# initialize and manage button state.
Expand All @@ -92,12 +91,11 @@ def build(self):
# self.confirm_button.disabled = True
# self.pick_addons_dialog.on_result = self.enable_button_if_ready

# attach hidden dialogues
self.right_view.controls.append(self.pick_addons_dialog)
# attach controls directly (no more hidden FilePicker overlays)

# create help/info button to show the help dialog
info_button = OutlinedButton(
"What kind of addons?",
content="What kind of addons?",
on_click=self.open_explain_addons_dlg,
expand=True,
icon=Icons.HELP_OUTLINE_OUTLINED,
Expand All @@ -124,8 +122,8 @@ def build(self):
Text("Here you can download the F-Droid App-Store:"),
Row(
[
ElevatedButton(
"Download F-Droid App-Store",
Button(
content="Download F-Droid App-Store",
icon=Icons.DOWNLOAD_OUTLINED,
on_click=lambda _: webbrowser.open(
"https://f-droid.org/en/packages/org.fdroid.fdroid.privileged.ota/"
Expand All @@ -139,8 +137,8 @@ def build(self):
),
Row(
[
ElevatedButton(
"Download Google Apps",
Button(
content="Download Google Apps",
icon=Icons.DOWNLOAD_OUTLINED,
on_click=lambda _: webbrowser.open(
"https://wiki.lineageos.org/gapps#downloads"
Expand All @@ -152,8 +150,8 @@ def build(self):
Text("Here you can download MicroG:"),
Row(
[
ElevatedButton(
"Download MicroG",
Button(
content="Download MicroG",
icon=Icons.DOWNLOAD_OUTLINED,
on_click=lambda _: webbrowser.open(
"https://github.com/FriendlyNeighborhoodShane/MinMicroG-abuse-CI/releases"
Expand All @@ -169,17 +167,13 @@ def build(self):
# attach the controls for uploading addons
self.right_view.controls.extend(
[
Text("Select addons:", style="titleSmall"),
Text("Select addons:", style=ft.TextThemeStyle.TITLE_SMALL),
Row(
[
FilledButton(
"Pick the addons you want to install",
content="Pick the addons you want to install",
icon=Icons.UPLOAD_FILE,
on_click=lambda _: self.pick_addons_dialog.pick_files(
allow_multiple=True,
file_type="custom",
allowed_extensions=["zip"],
),
on_click=self.handle_pick_addons,
expand=True,
),
]
Expand All @@ -190,27 +184,28 @@ def build(self):
Row([self.confirm_button]),
]
)
return self.view

def open_explain_addons_dlg(self, e):
"""Open the dialog to explain addons."""
self.page.dialog = self.dlg_explain_addons
self.dlg_explain_addons.open = True
self.page.update()
self.page.show_dialog(self.dlg_explain_addons)

def close_close_explain_addons_dlg(self, e):
"""Close the dialog to explain addons."""
self.dlg_explain_addons.open = False
self.page.update()
self.page.pop_dialog()

def pick_addons_result(self, e: FilePickerResultEvent):
path = ", ".join(map(lambda f: f.name, e.files)) if e.files else "Cancelled!"
async def handle_pick_addons(self, e):
files = await ft.FilePicker().pick_files(
allow_multiple=True,
file_type=ft.FilePickerFileType.CUSTOM,
allowed_extensions=["zip"],
)
path = ", ".join(map(lambda f: f.name, files)) if files else "Cancelled!"
# update the textfield with the name of the file
self.selected_addons.value = (
self.selected_addons.value.split(":")[0] + f": {path}"
)
if e.files:
self.addon_paths = [file.path for file in e.files]
if files:
self.addon_paths = [file.path for file in files]
self.state.addon_paths = self.addon_paths
logger.info(f"Selected addons: {self.addon_paths}")
else:
Expand Down
12 changes: 8 additions & 4 deletions openandroidinstaller/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# If not, see <https://www.gnu.org/licenses/>."""
# Author: Tobias Sterbak
from app_state import AppState
import flet as ft
from flet import Column, Container, Image, Row, VerticalDivider, margin


Expand All @@ -26,15 +27,16 @@ def __init__(self, state: AppState, image: str = "placeholder.png"):
spacing=30
) # , width=self.column_width, height=120)
self.right_view = Column(
alignment="center",
scroll="adaptive", # , width=self.column_width, height=650
alignment=ft.MainAxisAlignment.CENTER,
scroll=ft.ScrollMode.ADAPTIVE, # , width=self.column_width, height=650
)
self.right_view.bgcolor = ft.Colors.TRANSPARENT
# left part of the display: used for displaying the images
self.left_view = Column(
# width=self.column_width,
controls=[Image(src=f"/imgs/{image}", height=600)],
expand=True,
horizontal_alignment="center",
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
)
# main view row
self.view = Container(
Expand All @@ -46,10 +48,12 @@ def __init__(self, state: AppState, image: str = "placeholder.png"):
expand=True, controls=[self.right_view_header, self.right_view]
),
],
alignment="spaceEvenly",
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
),
margin=margin.only(left=10, top=0, right=50, bottom=5),
bgcolor=ft.Colors.TRANSPARENT,
)
self.controls = [self.view]

def clear(
self,
Expand Down
Loading