Skip to content

Commit

Permalink
Add a back-button to the default views
Browse files Browse the repository at this point in the history
  • Loading branch information
tsterbak committed Feb 2, 2023
1 parent a5a4d4a commit 3e2c1b7
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 122 deletions.
50 changes: 38 additions & 12 deletions openandroidinstaller/openandroidinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,22 @@ def __init__(self, state: AppState):

# create default starter views
welcome_view = WelcomeView(
on_confirm=self.confirm,
on_confirm=self.to_next_view,
state=self.state,
)
start_view = StartView(
on_confirm=self.confirm,
on_confirm=self.to_next_view,
on_back=self.to_previous_view,
state=self.state,
)
requirements_view = RequirementsView(
on_confirm=self.confirm,
on_confirm=self.to_next_view,
on_back=self.to_previous_view,
state=self.state,
)
select_files_view = SelectFilesView(
on_confirm=self.confirm,
on_confirm=self.to_next_view,
on_back=self.to_previous_view,
state=self.state,
)
# ordered to allow for pop
Expand All @@ -98,15 +101,28 @@ def __init__(self, state: AppState):
# create the final success view
self.final_view = SuccessView(state=self.state)

self.state.default_views = self.default_views
self.state.final_view = self.final_view
# stack of previous default views for the back-button
self.previous_views = []

def build(self):
self.view.controls.append(self.default_views.pop())
return self.view

def confirm(self, e):
def to_previous_view(self, e):
"""Method to display the previous view."""
# store the current view
self.default_views.append(self.view.controls[-1])
# clear the current view
self.view.controls = []
# retrieve the new view and update
self.view.controls.append(self.previous_views.pop())
logger.info("One step back.")
self.view.update()

def to_next_view(self, e):
"""Confirmation event handler to use in views."""
# store the current view
self.previous_views.append(self.view.controls[-1])
# remove all elements from column view
self.view.controls = []
# if there are default views left, display them first
Expand All @@ -117,13 +133,13 @@ def confirm(self, e):
StepView(
step=self.state.steps.pop(0),
state=self.state,
on_confirm=self.confirm,
on_confirm=self.to_next_view,
)
)
else:
# display the final view
self.view.controls.append(self.final_view)
logger.info("Confirmed.")
logger.info("Confirmed and moved to next step.")
self.view.update()


Expand All @@ -143,13 +159,23 @@ def configure(page: Page):
def log_version_infos(bin_path):
"""Log the version infos of adb, fastboot and heimdall."""
# adb
adbversion = [line for line in run_command("adb", ["version"], bin_path, enable_logging=False)]
adbversion = [
line for line in run_command("adb", ["version"], bin_path, enable_logging=False)
]
logger.info(f"{adbversion[1].strip()}")
# fastboot
fbversion = [line for line in run_command("fastboot", ["--version"], bin_path, enable_logging=False)]
fbversion = [
line
for line in run_command(
"fastboot", ["--version"], bin_path, enable_logging=False
)
]
logger.info(f"{fbversion[1].strip()}")
# heimdall
hdversion = [line for line in run_command("heimdall", ["info"], bin_path, enable_logging=False)]
hdversion = [
line
for line in run_command("heimdall", ["info"], bin_path, enable_logging=False)
]
logger.info(f"Heimdall version: {hdversion[1].strip()}")


Expand Down
4 changes: 3 additions & 1 deletion openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
PLATFORM = sys.platform


def run_command(tool: str, command: List[str], bin_path: Path, enable_logging: bool = True) -> CompletedProcess:
def run_command(
tool: str, command: List[str], bin_path: Path, enable_logging: bool = True
) -> CompletedProcess:
"""Run a command with a tool (adb, fastboot, heimdall)."""
yield f"${' '.join([tool] + command )}"
if tool not in ["adb", "fastboot", "heimdall"]:
Expand Down
7 changes: 7 additions & 0 deletions openandroidinstaller/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def __init__(self, state: AppState, image: str = "placeholder.png"):
],
alignment="spaceEvenly",
)

def clear(
self,
):
"""Clear the right view."""
self.right_view.controls = []
self.right_view_header.controls = []
Loading

0 comments on commit 3e2c1b7

Please sign in to comment.