Skip to content

Commit

Permalink
android polishing and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Dec 2, 2023
1 parent 0e15df6 commit 2a5e976
Show file tree
Hide file tree
Showing 50 changed files with 657 additions and 452 deletions.
88 changes: 44 additions & 44 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.30 (build 21639, api 8, 2023-11-30)
### 1.7.30 (build 21652, api 8, 2023-12-01)
- Continued work on the big 1.7.28 update.
- Got the Android version back up and running. There's been lots of cleanup and
simplification on the Android layer, cleaning out years of cruft. This should
Expand Down
9 changes: 9 additions & 0 deletions src/assets/ba_data/python/babase/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ def postinit(self) -> None:
self.lang = LanguageSubsystem()
self.plugins = PluginSubsystem()

@property
def active(self) -> bool:
"""Whether the app is currently front and center.
This will be False when the app is hidden, other activities
are covering it, etc. (depending on the platform).
"""
return _babase.app_is_active()

@property
def aioloop(self) -> asyncio.AbstractEventLoop:
"""The logic thread's asyncio event loop.
Expand Down
48 changes: 34 additions & 14 deletions src/assets/ba_data/python/baclassic/_ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from __future__ import annotations

import time
import asyncio
import logging
from typing import TYPE_CHECKING

import babase
Expand Down Expand Up @@ -31,6 +33,7 @@ def __init__(self) -> None:
self.last_in_game_ad_remove_message_show_time: float | None = None
self.last_ad_completion_time: float | None = None
self.last_ad_was_short = False
self._fallback_task: asyncio.Task | None = None

def do_remove_in_game_ads_message(self) -> None:
"""(internal)"""
Expand Down Expand Up @@ -181,36 +184,53 @@ def call_after_ad(self, call: Callable[[], Any]) -> None:

# If we're *still* cleared to show, actually tell the system to show.
if show:
# As a safety-check, set up an object that will run
# the completion callback if we've returned and sat for 10 seconds
# (in case some random ad network doesn't properly deliver its
# completion callback).
# As a safety-check, we set up an object that will run the
# completion callback if we've returned and sat for several
# seconds (in case some random ad network doesn't properly
# deliver its completion callback).
class _Payload:
def __init__(self, pcall: Callable[[], Any]):
self._call = pcall
self._ran = False

def run(self, fallback: bool = False) -> None:
"""Run fallback call (and issue a warning about it)."""
"""Run the payload."""
assert app.classic is not None
if not self._ran:
if fallback:
lanst = app.classic.ads.last_ad_network_set_time
print(
'ERROR: relying on fallback ad-callback! '
'last network: '
+ app.classic.ads.last_ad_network
+ ' (set '
+ str(int(time.time() - lanst))
+ 's ago); purpose='
+ app.classic.ads.last_ad_purpose
logging.error(
'Relying on fallback ad-callback! '
'last network: %s (set %s seconds ago);'
' purpose=%s.',
app.classic.ads.last_ad_network,
time.time() - lanst,
app.classic.ads.last_ad_purpose,
)
babase.pushcall(self._call)
self._ran = True

payload = _Payload(call)

# Set up our backup.
with babase.ContextRef.empty():
babase.apptimer(5.0, lambda: payload.run(fallback=True))
# Note to self: Previously this was a simple 5 second
# timer because the app got totally suspended while ads
# were showing (which delayed the timer), but these days
# the app may continue to run, so we need to be more
# careful and only fire the fallback after we see that
# the app has been front-and-center for several seconds.
async def add_fallback_task() -> None:
activesecs = 5
while activesecs > 0:
if babase.app.active:
activesecs -= 1
await asyncio.sleep(1.0)
payload.run(fallback=True)

_fallback_task = babase.app.aioloop.create_task(
add_fallback_task()
)
self.show_ad('between_game', on_completion_call=payload.run)
else:
babase.pushcall(call) # Just run the callback without the ad.
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 21639
TARGET_BALLISTICA_BUILD = 21652
TARGET_BALLISTICA_VERSION = '1.7.30'


Expand Down
6 changes: 4 additions & 2 deletions src/assets/ba_data/python/bauiv1lib/specialoffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ def show_offer() -> bool:
if bui.native_review_request_supported():
bui.native_review_request()
else:
feedback.ask_for_rating()
if app.ui_v1.available:
feedback.ask_for_rating()
else:
SpecialOfferWindow(app.classic.special_offer)
if app.ui_v1.available:
SpecialOfferWindow(app.classic.special_offer)

app.classic.special_offer = None
return True
Expand Down
Loading

0 comments on commit 2a5e976

Please sign in to comment.