Skip to content

Instantly share code, notes, and snippets.

@dbrova15
Last active March 6, 2023 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrova15/fc221679f210d047e52d69149ec1558b to your computer and use it in GitHub Desktop.
Save dbrova15/fc221679f210d047e52d69149ec1558b to your computer and use it in GitHub Desktop.
from __future__ import annotations
from typing import Optional
from kivy import platform
class SingletonMeta(type):
_instance: Optional[Singleton] = None
def __call__(self) -> Singleton:
if self._instance is None:
self._instance = super().__call__()
return self._instance
class Singleton(metaclass=SingletonMeta):
def __init__(self):
if platform == "ios":
from pyobjus import autoclass
self.banner_ad = autoclass("adSwitch").alloc().init()
self.interstitial_ad = autoclass("adInterstitial").alloc().init()
def show_interstitial(self):
print("show_interstitial python")
if platform == "ios":
self.interstitial_ad.InterstitialView()
def show_banner(self):
print("show_banner python")
if platform == "ios":
self.banner_ad.show_ads()
def hide_banner(self):
print("hide_ads python")
if platform == "ios":
self.banner_ad.hide_ads()
if __name__ == "__main__":
s1 = Singleton()
s2 = Singleton()
if id(s1) == id(s2):
print("Singleton works, both variables contain the same instance.")
else:
print("Singleton failed, variables contain different instances.")
@dbrova15
Copy link
Author

dbrova15 commented Nov 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment