Skip to content

Commit 3e2c1b7

Browse files
committed
Add a back-button to the default views
1 parent a5a4d4a commit 3e2c1b7

File tree

8 files changed

+239
-122
lines changed

8 files changed

+239
-122
lines changed

openandroidinstaller/openandroidinstaller.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,22 @@ def __init__(self, state: AppState):
7373

7474
# create default starter views
7575
welcome_view = WelcomeView(
76-
on_confirm=self.confirm,
76+
on_confirm=self.to_next_view,
7777
state=self.state,
7878
)
7979
start_view = StartView(
80-
on_confirm=self.confirm,
80+
on_confirm=self.to_next_view,
81+
on_back=self.to_previous_view,
8182
state=self.state,
8283
)
8384
requirements_view = RequirementsView(
84-
on_confirm=self.confirm,
85+
on_confirm=self.to_next_view,
86+
on_back=self.to_previous_view,
8587
state=self.state,
8688
)
8789
select_files_view = SelectFilesView(
88-
on_confirm=self.confirm,
90+
on_confirm=self.to_next_view,
91+
on_back=self.to_previous_view,
8992
state=self.state,
9093
)
9194
# ordered to allow for pop
@@ -98,15 +101,28 @@ def __init__(self, state: AppState):
98101
# create the final success view
99102
self.final_view = SuccessView(state=self.state)
100103

101-
self.state.default_views = self.default_views
102-
self.state.final_view = self.final_view
104+
# stack of previous default views for the back-button
105+
self.previous_views = []
103106

104107
def build(self):
105108
self.view.controls.append(self.default_views.pop())
106109
return self.view
107110

108-
def confirm(self, e):
111+
def to_previous_view(self, e):
112+
"""Method to display the previous view."""
113+
# store the current view
114+
self.default_views.append(self.view.controls[-1])
115+
# clear the current view
116+
self.view.controls = []
117+
# retrieve the new view and update
118+
self.view.controls.append(self.previous_views.pop())
119+
logger.info("One step back.")
120+
self.view.update()
121+
122+
def to_next_view(self, e):
109123
"""Confirmation event handler to use in views."""
124+
# store the current view
125+
self.previous_views.append(self.view.controls[-1])
110126
# remove all elements from column view
111127
self.view.controls = []
112128
# if there are default views left, display them first
@@ -117,13 +133,13 @@ def confirm(self, e):
117133
StepView(
118134
step=self.state.steps.pop(0),
119135
state=self.state,
120-
on_confirm=self.confirm,
136+
on_confirm=self.to_next_view,
121137
)
122138
)
123139
else:
124140
# display the final view
125141
self.view.controls.append(self.final_view)
126-
logger.info("Confirmed.")
142+
logger.info("Confirmed and moved to next step.")
127143
self.view.update()
128144

129145

@@ -143,13 +159,23 @@ def configure(page: Page):
143159
def log_version_infos(bin_path):
144160
"""Log the version infos of adb, fastboot and heimdall."""
145161
# adb
146-
adbversion = [line for line in run_command("adb", ["version"], bin_path, enable_logging=False)]
162+
adbversion = [
163+
line for line in run_command("adb", ["version"], bin_path, enable_logging=False)
164+
]
147165
logger.info(f"{adbversion[1].strip()}")
148166
# fastboot
149-
fbversion = [line for line in run_command("fastboot", ["--version"], bin_path, enable_logging=False)]
167+
fbversion = [
168+
line
169+
for line in run_command(
170+
"fastboot", ["--version"], bin_path, enable_logging=False
171+
)
172+
]
150173
logger.info(f"{fbversion[1].strip()}")
151174
# heimdall
152-
hdversion = [line for line in run_command("heimdall", ["info"], bin_path, enable_logging=False)]
175+
hdversion = [
176+
line
177+
for line in run_command("heimdall", ["info"], bin_path, enable_logging=False)
178+
]
153179
logger.info(f"Heimdall version: {hdversion[1].strip()}")
154180

155181

openandroidinstaller/tooling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
PLATFORM = sys.platform
3333

3434

35-
def run_command(tool: str, command: List[str], bin_path: Path, enable_logging: bool = True) -> CompletedProcess:
35+
def run_command(
36+
tool: str, command: List[str], bin_path: Path, enable_logging: bool = True
37+
) -> CompletedProcess:
3638
"""Run a command with a tool (adb, fastboot, heimdall)."""
3739
yield f"${' '.join([tool] + command )}"
3840
if tool not in ["adb", "fastboot", "heimdall"]:

openandroidinstaller/views/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ def __init__(self, state: AppState, image: str = "placeholder.png"):
5252
],
5353
alignment="spaceEvenly",
5454
)
55+
56+
def clear(
57+
self,
58+
):
59+
"""Clear the right view."""
60+
self.right_view.controls = []
61+
self.right_view_header.controls = []

0 commit comments

Comments
 (0)