2023-10-18 13:01:48 +00:00
|
|
|
from typing import Callable
|
|
|
|
|
2023-05-17 16:44:43 +00:00
|
|
|
from module.base.base import ModuleBase
|
2023-10-16 10:40:49 +00:00
|
|
|
from module.logger import logger
|
2023-10-18 04:00:48 +00:00
|
|
|
from tasks.base.assets.assets_base_page import BACK, CLOSE
|
2023-05-17 16:44:43 +00:00
|
|
|
from tasks.base.assets.assets_base_popup import *
|
|
|
|
|
|
|
|
|
|
|
|
class PopupHandler(ModuleBase):
|
2023-10-18 04:00:48 +00:00
|
|
|
def handle_reward(self, interval=5, click_button: ButtonWrapper = None) -> bool:
|
2023-05-17 16:44:43 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
interval:
|
2023-10-16 10:40:49 +00:00
|
|
|
click_button: Set a button to click
|
2023-05-17 16:44:43 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
2023-10-16 10:40:49 +00:00
|
|
|
if click_button is None:
|
|
|
|
if self.appear_then_click(GET_REWARD, interval=interval):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
if self.appear(GET_REWARD, interval=interval):
|
|
|
|
logger.info(f'{GET_REWARD} -> {click_button}')
|
|
|
|
self.device.click(click_button)
|
|
|
|
return True
|
2023-05-17 16:44:43 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def handle_battle_pass_notification(self, interval=5) -> bool:
|
|
|
|
"""
|
|
|
|
Popup notification that you enter battle pass the first time.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(BATTLE_PASS_NOTIFICATION, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2023-05-21 01:38:41 +00:00
|
|
|
|
2023-07-02 07:31:42 +00:00
|
|
|
def handle_monthly_card_reward(self, interval=1) -> bool:
|
2023-05-21 01:38:41 +00:00
|
|
|
"""
|
|
|
|
Popup at 04:00 server time if you have purchased the monthly card.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(MONTHLY_CARD_REWARD, interval=interval):
|
|
|
|
return True
|
|
|
|
if self.appear_then_click(MONTHLY_CARD_GET_ITEM, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2023-09-12 17:37:06 +00:00
|
|
|
|
2023-09-16 21:00:16 +00:00
|
|
|
def handle_popup_cancel(self, interval=2) -> bool:
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(POPUP_CANCEL, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def handle_popup_confirm(self, interval=2) -> bool:
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(POPUP_CONFIRM, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2023-09-12 17:37:06 +00:00
|
|
|
def handle_popup_single(self, interval=2) -> bool:
|
|
|
|
"""
|
|
|
|
Popup with one single confirm button in the middle.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(POPUP_SINGLE, interval=interval):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2023-10-18 04:00:48 +00:00
|
|
|
|
2023-10-18 13:01:48 +00:00
|
|
|
def handle_ui_close(self, appear_button: ButtonWrapper | Callable, interval=2) -> bool:
|
2023-10-18 04:00:48 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
appear_button: Click if button appears
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
2023-10-18 13:01:48 +00:00
|
|
|
if callable(appear_button):
|
2023-10-18 13:43:26 +00:00
|
|
|
if self.interval_is_reached(appear_button, interval=interval) and appear_button():
|
2023-10-18 13:01:48 +00:00
|
|
|
logger.info(f'{appear_button.__name__} -> {CLOSE}')
|
|
|
|
self.device.click(CLOSE)
|
2023-10-18 13:43:26 +00:00
|
|
|
self.interval_reset(appear_button, interval=interval)
|
2023-10-18 13:01:48 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
if self.appear(appear_button, interval=interval):
|
|
|
|
logger.info(f'{appear_button} -> {CLOSE}')
|
|
|
|
self.device.click(CLOSE)
|
|
|
|
return True
|
2023-10-18 04:00:48 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2023-10-18 13:01:48 +00:00
|
|
|
def handle_ui_back(self, appear_button: ButtonWrapper | Callable, interval=2) -> bool:
|
2023-10-18 04:00:48 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
appear_button: Click if button appears
|
|
|
|
interval:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
If handled.
|
|
|
|
"""
|
2023-10-18 13:01:48 +00:00
|
|
|
if callable(appear_button):
|
2023-10-18 13:43:26 +00:00
|
|
|
if self.interval_is_reached(appear_button, interval=interval) and appear_button():
|
2023-10-18 13:01:48 +00:00
|
|
|
logger.info(f'{appear_button.__name__} -> {BACK}')
|
|
|
|
self.device.click(BACK)
|
2023-10-18 13:43:26 +00:00
|
|
|
self.interval_reset(appear_button, interval=interval)
|
2023-10-18 13:01:48 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
if self.appear(appear_button, interval=interval):
|
|
|
|
logger.info(f'{appear_button} -> {BACK}')
|
|
|
|
self.device.click(BACK)
|
|
|
|
return True
|
2023-10-18 04:00:48 +00:00
|
|
|
|
|
|
|
return False
|