Skip to content

Commit f4c4a25

Browse files
committed
Enable the continue button only if the previous call was successful
1 parent 58b1e8a commit f4c4a25

File tree

3 files changed

+86
-67
lines changed

3 files changed

+86
-67
lines changed

openandroidinstaller/openandroidinstaller.py

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,40 @@
2121
from typing import Callable, Optional
2222

2323
import flet
24-
from flet import (AlertDialog, AppBar, Banner, Checkbox, Column, Container,
25-
Divider, ElevatedButton, FilePicker, FilePickerResultEvent,
26-
FilledButton, Icon, Image, Page, ProgressBar, ProgressRing,
27-
Row, Text, TextButton, TextField, UserControl,
28-
VerticalDivider, colors, icons)
24+
from flet import (
25+
AlertDialog,
26+
AppBar,
27+
Banner,
28+
Checkbox,
29+
Column,
30+
Container,
31+
Divider,
32+
ElevatedButton,
33+
FilePicker,
34+
FilePickerResultEvent,
35+
FilledButton,
36+
Icon,
37+
Image,
38+
Page,
39+
ProgressBar,
40+
ProgressRing,
41+
Row,
42+
Text,
43+
TextButton,
44+
TextField,
45+
UserControl,
46+
VerticalDivider,
47+
colors,
48+
icons,
49+
)
2950
from installer_config import InstallerConfig, Step
3051
from loguru import logger
3152
from tool_utils import call_tool_with_command, search_device
3253
from widgets import call_button, confirm_button, get_title
3354

3455
# Toggle to True for development purposes
3556
DEVELOPMENT = False
36-
DEVELOPMENT_CONFIG = "a3y17lte" # "sargo"
57+
DEVELOPMENT_CONFIG = "sargo" # "a3y17lte" # "sargo"
3758

3859

3960
PLATFORM = sys.platform
@@ -212,9 +233,7 @@ def __init__(
212233
self.selected_recovery = selected_recovery
213234

214235
def build(self):
215-
self.confirm_button = confirm_button(
216-
"If you selected both files you can continue.", self.on_confirm
217-
)
236+
self.confirm_button = confirm_button(self.on_confirm)
218237
self.confirm_button.disabled = True
219238

220239
self.pick_recovery_dialog.on_result = self.enable_button_if_ready
@@ -257,7 +276,8 @@ def build(self):
257276
),
258277
self.selected_recovery,
259278
Divider(),
260-
self.confirm_button,
279+
Text("If you selected both files you can continue."),
280+
Row([self.confirm_button]),
261281
]
262282
)
263283
return self.view
@@ -423,36 +443,50 @@ def __init__(
423443

424444
def build(self):
425445
"""Create the content of a view from step."""
426-
self.right_view.controls = [get_title(f"{self.step.title}"), self.progressbar]
446+
self.right_view.controls = [
447+
get_title(f"{self.step.title}"),
448+
self.progressbar,
449+
Text(f"{self.step.content}"),
450+
]
427451
# basic view depending on step.type
428452
if self.step.type == "confirm_button":
429-
self.right_view.controls.append(
430-
confirm_button(self.step.content, self.on_confirm)
431-
)
453+
self.confirm_button = confirm_button(self.on_confirm)
454+
self.right_view.controls.append(Row([self.confirm_button]))
432455
elif self.step.type == "call_button":
456+
self.confirm_button = confirm_button(self.on_confirm)
457+
self.confirm_button.disabled = True
458+
self.call_button = call_button(
459+
self.call_to_phone, command=self.step.command
460+
)
433461
self.right_view.controls.append(
434-
call_button(
435-
self.step.content, self.call_to_phone, command=self.step.command
436-
)
462+
Row([self.call_button, self.confirm_button])
437463
)
438464
elif self.step.type == "call_button_with_input":
465+
self.confirm_button = confirm_button(self.on_confirm)
466+
self.confirm_button.disabled = True
467+
self.call_button = call_button(
468+
self.call_to_phone, command=self.step.command
469+
)
439470
self.right_view.controls.extend(
440-
[
441-
self.inputtext,
442-
call_button(
443-
self.step.content, self.call_to_phone, command=self.step.command
444-
),
445-
]
471+
[self.inputtext, Row([self.call_button, self.confirm_button])]
446472
)
447-
elif self.step.type == "text":
448-
self.right_view.controls.append(Text(self.step.content))
449-
else:
473+
elif self.step.type != "text":
450474
raise Exception(f"Unknown step type: {self.step.type}")
451475

452476
# if skipping is allowed add a button to the view
453477
if self.step.allow_skip or DEVELOPMENT:
454478
self.right_view.controls.append(
455-
confirm_button("Already done?", self.on_confirm, confirm_text="Skip")
479+
Row(
480+
[
481+
Text("Do you want to skip?"),
482+
ElevatedButton(
483+
"Skip",
484+
on_click=self.on_confirm,
485+
icon=icons.NEXT_PLAN_OUTLINED,
486+
expand=True,
487+
),
488+
]
489+
)
456490
)
457491
return self.view
458492

@@ -477,14 +511,19 @@ def call_to_phone(self, e, command: str):
477511
success = call_tool_with_command(command=command, bin_path=BIN_PATH)
478512
# update the view accordingly
479513
if success:
514+
# pop the progress ring
480515
self.right_view.controls.pop()
481-
self.right_view.controls.append(Text(f"Command {command} failed!"))
482-
else:
483-
sleep(5) # wait to make sure everything is fine
484-
self.right_view.controls.pop() # pop the progress ring
485516
self.right_view.controls.append(
486-
ElevatedButton("Confirm and continue", on_click=self.on_confirm)
517+
Text(
518+
f"Command {command} failed! Try again or make sure everything is setup correctly."
519+
)
487520
)
521+
else:
522+
sleep(5) # wait to make sure everything is fine
523+
# pop the progress ring
524+
self.right_view.controls.pop()
525+
self.confirm_button.disabled = False
526+
self.call_button.disabled = True
488527
self.view.update()
489528

490529

openandroidinstaller/tool_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def call_tool_with_command(command: str, bin_path: Path) -> bool:
2929

3030
logger.info(f"Run command: {command}")
3131
res = call(f"{command}", shell=True)
32-
if res != 0:
32+
if res == 0:
3333
logger.info("Success.")
3434
return True
3535
logger.info(f"Command {command} failed.")

openandroidinstaller/widgets.py

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,24 @@ def get_title(title: str):
3636

3737

3838
def confirm_button(
39-
text: str, confirm_func: Callable, confirm_text: str = "Confirm and continue"
40-
) -> Column:
39+
confirm_func: Callable, confirm_text: str = "Confirm and continue"
40+
) -> ElevatedButton:
4141
"""Get a button, that calls a given function when clicked."""
42-
return Column(
43-
[
44-
Text(f"{text}"),
45-
Row(
46-
[
47-
ElevatedButton(
48-
f"{confirm_text}",
49-
on_click=confirm_func,
50-
icon=icons.NEXT_PLAN_OUTLINED,
51-
expand=True,
52-
)
53-
]
54-
),
55-
],
56-
horizontal_alignment="center",
42+
return ElevatedButton(
43+
f"{confirm_text}",
44+
on_click=confirm_func,
45+
icon=icons.NEXT_PLAN_OUTLINED,
46+
expand=True,
5747
)
5848

5949

6050
def call_button(
61-
text: str, call_func: Callable, command: str, confirm_text: str = "Confirm and run"
62-
) -> Column:
51+
call_func: Callable, command: str, confirm_text: str = "Confirm and run"
52+
) -> ElevatedButton:
6353
"""Get a button, that calls a given function with given command when clicked."""
64-
return Column(
65-
[
66-
Text(f"{text}"),
67-
Row(
68-
[
69-
ElevatedButton(
70-
f"{confirm_text}",
71-
on_click=partial(call_func, command=command),
72-
expand=True,
73-
icon=icons.DIRECTIONS_RUN_OUTLINED,
74-
)
75-
]
76-
),
77-
],
78-
horizontal_alignment="center",
54+
return ElevatedButton(
55+
f"{confirm_text}",
56+
on_click=partial(call_func, command=command),
57+
expand=True,
58+
icon=icons.DIRECTIONS_RUN_OUTLINED,
7959
)

0 commit comments

Comments
 (0)