Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 68 additions & 28 deletions android_notify/internal/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
Also For Reference of Available Methods
"""

from enum import IntFlag, auto
from android_notify.internal.logger import logger


class Bundle:
def putString(self, key, value):
logger.debug(f"[MOCK] Bundle.putString called with key={key}, value={value}")
Expand All @@ -19,11 +21,16 @@ def __new__(cls, value):
return str.__new__(cls, value)


class Intent:
FLAG_ACTIVITY_NEW_TASK = 'FACADE_FLAG_ACTIVITY_NEW_TASK'
CATEGORY_DEFAULT = 'FACADE_FLAG_CATEGORY_DEFAULT'


class Intent(IntFlag):
NONE = 0
FLAG_ACTIVITY_CLEAR_TOP = auto()
FLAG_ACTIVITY_NEW_TASK = auto()
FLAG_ACTIVITY_SINGLE_TOP = auto()

def __init__(self, context='', activity=''):
self.IS = "FACADE"
self.obj = {}
logger.debug(f"[MOCK] Intent initialized with context={context}, activity={activity}")

Expand Down Expand Up @@ -132,12 +139,13 @@ def getId(self):
def setSound(self, sound_uri, _):
logger.debug(f"[MOCK] NotificationChannel.setSound called, sound_uri={sound_uri}")

def enableVibration(self,state):
def enableVibration(self, state):
logger.debug(f"[MOCK] NotificationChannel.enableVibration called, state={state}")

def setVibrationPattern(self,list_of_numbers):
def setVibrationPattern(self, list_of_numbers):
logger.debug(f"[MOCK] NotificationChannel.setVibrationPattern called, list_of_numbers={list_of_numbers}")


class IconCompat:
@classmethod
def createWithBitmap(cls, bitmap):
Expand Down Expand Up @@ -175,13 +183,15 @@ class NotificationManagerCompat:
IMPORTANCE_MIN = ''
IMPORTANCE_NONE = ''


class AndroidNotification:
DEFAULT_ALL = 3
PRIORITY_HIGH = 4
PRIORITY_DEFAULT = ''
PRIORITY_LOW = ''
PRIORITY_MIN = ''


class NotificationCompat:
DEFAULT_ALL = 3
PRIORITY_HIGH = 4
Expand All @@ -201,76 +211,97 @@ def __init__(self, context, channel_id):
self.mActions = MActions()
logger.debug(f"[MOCK] NotificationCompatBuilder initialized with context={context}, channel_id={channel_id}")

def setProgress(self, max_value, current_value, endless):
@classmethod
def setProgress(cls, max_value, current_value, endless):
logger.debug(f"[MOCK] setProgress called with max={max_value}, current={current_value}, endless={endless}")

def setStyle(self, style):
@classmethod
def setStyle(cls, style):
logger.debug(f"[MOCK] setStyle called with style={style}")

def setContentTitle(self, title):
@classmethod
def setContentTitle(cls, title):
logger.debug(f"[MOCK] setContentTitle called with title={title}")

def setContentText(self, text):
@classmethod
def setContentText(cls, text):
logger.debug(f"[MOCK] setContentText called with text={text}")

def setSmallIcon(self, icon):
@classmethod
def setSmallIcon(cls, icon):
logger.debug(f"[MOCK] setSmallIcon called with icon={icon}")

def setLargeIcon(self, icon):
@classmethod
def setLargeIcon(cls, icon):
logger.debug(f"[MOCK] setLargeIcon called with icon={icon}")

def setAutoCancel(self, auto_cancel: bool):
@classmethod
def setAutoCancel(cls, auto_cancel: bool):
logger.debug(f"[MOCK] setAutoCancel called with auto_cancel={auto_cancel}")

def setPriority(self, priority):
@classmethod
def setPriority(cls, priority):
logger.debug(f"[MOCK] setPriority called with priority={priority}")

def setDefaults(self, defaults):
@classmethod
def setDefaults(cls, defaults):
logger.debug(f"[MOCK] setDefaults called with defaults={defaults}")

def setOngoing(self, persistent: bool):
@classmethod
def setOngoing(cls, persistent: bool):
logger.debug(f"[MOCK] setOngoing called with persistent={persistent}")

def setOnlyAlertOnce(self, state):
@classmethod
def setOnlyAlertOnce(cls, state):
logger.debug(f"[MOCK] setOnlyAlertOnce called with state={state}")

def build(self):
@classmethod
def build(cls):
logger.debug("[MOCK] build called")

def setContentIntent(self, pending_action_intent: PendingIntent):
@classmethod
def setContentIntent(cls, pending_action_intent: PendingIntent):
logger.debug(f"[MOCK] setContentIntent called with {pending_action_intent}")

def addAction(self, icon_int, action_text, pending_action_intent):
@classmethod
def addAction(cls, icon_int, action_text, pending_action_intent):
logger.debug(
f"[MOCK] addAction called with icon={icon_int}, text={action_text}, intent={pending_action_intent}"
)

def setShowWhen(self, state):
@classmethod
def setShowWhen(cls, state):
logger.debug(f"[MOCK] setShowWhen called with state={state}")

def setWhen(self, time_ms):
@classmethod
def setWhen(cls, time_ms):
logger.debug(f"[MOCK] setWhen called with time_ms={time_ms}")

def setCustomContentView(self, layout):
@classmethod
def setCustomContentView(cls, layout):
logger.debug(f"[MOCK] setCustomContentView called with layout={layout}")

def setCustomBigContentView(self, layout):
@classmethod
def setCustomBigContentView(cls, layout):
logger.debug(f"[MOCK] setCustomBigContentView called with layout={layout}")

def setSubText(self, text):
@classmethod
def setSubText(cls, text):
logger.debug(f"[MOCK] setSubText called with text={text}")

def setColor(self, color: Color) -> None:
@classmethod
def setColor(cls, color: Color) -> None:
logger.debug(f"[MOCK] setColor called with color={color}")

def setVibrate(self, state) -> None:
@classmethod
def setVibrate(cls, state) -> None:
logger.debug(f"[MOCK] setVibrate called with state={state}")


class NotificationCompatBigTextStyle:
def bigText(self, body):
def bigText(cls, body):
logger.debug(f"[MOCK] NotificationCompatBigTextStyle.bigText called with body={body}")
return self
return cls

def setBigContentTitle(self, title):
logger.debug(f"[MOCK] NotificationCompatBigTextStyle.setBigContentTitle called with title={title}")
Expand Down Expand Up @@ -334,6 +365,15 @@ def mActivity():
logger.debug("[MOCK] mActivity used")
return MActivity()

@staticmethod
def startForeground(notification_id, builder_build, foreground_type):
logger.debug(
f"[MOCK] startForeground called with notification_id={notification_id}, builder.build()={builder_build}, foreground_type={foreground_type}")

def setAutoRestartService(self):
logger.debug("[MOCK] setAutoRestartService called")
return self


class DummyIcon:
icon = 101
Expand Down
11 changes: 9 additions & 2 deletions android_notify/sword.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def setData(self, data_object:dict):
:param data_object:
:return:
"""
if not on_android_platform():
return
self.__called_set_data = True
self.data_object = data_object
action_name = str(self.name or self.__id)
Expand Down Expand Up @@ -413,7 +415,7 @@ def send(self, silent: bool = False, persistent=False, close_on_click=True):
"""
self.silent = silent or self.silent
if on_android_platform():
self.start_building(persistent, close_on_click)
self.fill_args(persistent=persistent, close_on_click=close_on_click)
dispatch_notification(notification_id=self.__id, builder=self.builder, passed_check=self.passed_check)

self.__send_logs()
Expand All @@ -426,6 +428,7 @@ def send_(self, silent: bool = False, persistent=False, close_on_click=True):
persistent (bool): True To not remove Notification When User hits clears All notifications button
close_on_click (bool): True if you want Notification to be removed when clicked
"""
# TODO: Remove this method - Check if Device is Android 12 or less and log to use regular .send()
self.passed_check = True
self.send(silent, persistent, close_on_click)

Expand Down Expand Up @@ -591,7 +594,11 @@ def setSound(self, res_sound_name):

return set_sound(self.builder, res_sound_name)

def start_building(self, persistent=False, close_on_click=True, silent: bool = False):
def fill_args(self, silent: bool = False, persistent=False, close_on_click=True):
"""Name Makes More sense than start_building"""
return self.start_building(silent, persistent , close_on_click)

def start_building(self, silent: bool = False, persistent=False, close_on_click=True):
# Main use is for foreground service, bypassing .notify in .send method to let service.startForeground(...) send it
self.silent = silent or self.silent
if not on_android_platform():
Expand Down
2 changes: 0 additions & 2 deletions android_notify/tests/test_notification_permission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# android_notify/tests/basic_notification_actions.py

from android_notify import NotificationHandler
from android_notify.internal.permissions import ask_notification_permission
from android_notify.core import asks_permission_if_needed
Expand Down
14 changes: 10 additions & 4 deletions android_notify/widgets/texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from android_notify.config import on_android_platform
from android_notify.internal.java_classes import autoclass, String, NotificationCompatBigTextStyle, NotificationCompatInboxStyle
from android_notify.internal.java_classes import String, NotificationCompatBigTextStyle, NotificationCompatInboxStyle


def set_big_text(builder, body, title="", summary=""):
Expand Down Expand Up @@ -48,8 +48,10 @@ def set_title(builder, title, using_layout=False):
:param title: New Notification Title
:param using_layout: Whether to use layout or not
"""

def log():
logger.info(f'new notification title: {title}')
if not on_android_platform():
log()
return None

if using_layout:
Expand All @@ -58,7 +60,7 @@ def set_title(builder, title, using_layout=False):
else:
builder.setContentTitle(String(title))

logger.info(f'new notification title: {title}')
log()
return None


Expand All @@ -69,8 +71,11 @@ def set_message(builder, message, using_layout=False):
:param message: New Notification message
:param using_layout: Whether to use layout or not
"""
def log():
logger.info(f'new notification message: {message}')

if not on_android_platform():
log()
return None

if using_layout:
Expand All @@ -79,7 +84,7 @@ def set_message(builder, message, using_layout=False):
else:
builder.setContentText(String(message))

logger.info(f'new notification message: {message}')
log()
return None


Expand Down Expand Up @@ -116,6 +121,7 @@ def setLayoutText(layout, text_id, text, color):

def set_custom_colors(builder, title, message, title_color, message_color):
# Load layout
from android_notify.internal.java_classes import autoclass
NotificationCompatDecoratedCustomViewStyle = autoclass(
'android.app.Notification$DecoratedCustomViewStyle')

Expand Down