mirror of
				https://github.com/liberatedsystems/Sideband_CE.git
				synced 2024-09-03 04:13:27 +02:00 
			
		
		
		
	Added notification support
This commit is contained in:
		
							parent
							
								
									db91946114
								
							
						
					
					
						commit
						ff47102b92
					
				| @ -3,10 +3,12 @@ import LXMF | |||||||
| import time | import time | ||||||
| import sys | import sys | ||||||
| import os | import os | ||||||
|  | import plyer | ||||||
| 
 | 
 | ||||||
| from kivy.logger import Logger, LOG_LEVELS | from kivy.logger import Logger, LOG_LEVELS | ||||||
| # Logger.setLevel(LOG_LEVELS["debug"]) | # TODO: Reset | ||||||
| Logger.setLevel(LOG_LEVELS["error"]) | Logger.setLevel(LOG_LEVELS["debug"]) | ||||||
|  | # Logger.setLevel(LOG_LEVELS["error"]) | ||||||
| 
 | 
 | ||||||
| if RNS.vendor.platformutils.get_platform() != "android": | if RNS.vendor.platformutils.get_platform() != "android": | ||||||
|     local = os.path.dirname(__file__) |     local = os.path.dirname(__file__) | ||||||
| @ -27,6 +29,8 @@ if RNS.vendor.platformutils.get_platform() == "android": | |||||||
|     from ui.messages import Messages, ts_format |     from ui.messages import Messages, ts_format | ||||||
|     from ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem |     from ui.helpers import ContentNavigationDrawer, DrawerList, IconListItem | ||||||
| 
 | 
 | ||||||
|  |     from android.permissions import request_permissions, check_permission | ||||||
|  | 
 | ||||||
| else: | else: | ||||||
|     from .sideband.core import SidebandCore |     from .sideband.core import SidebandCore | ||||||
| 
 | 
 | ||||||
| @ -62,19 +66,47 @@ class SidebandApp(MDApp): | |||||||
|         self.lxmf_sync_dialog_open = False |         self.lxmf_sync_dialog_open = False | ||||||
|         self.sync_dialog = None |         self.sync_dialog = None | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         Window.softinput_mode = "below_target" |         Window.softinput_mode = "below_target" | ||||||
|         self.icon = self.sideband.asset_dir+"/images/icon.png" |         self.icon = self.sideband.asset_dir+"/icon.png" | ||||||
|  |         self.notification_icon = self.sideband.asset_dir+"/notification_icon.png" | ||||||
| 
 | 
 | ||||||
|     def start_core(self, dt): |     def start_core(self, dt): | ||||||
|         self.sideband.start() |         self.sideband.start() | ||||||
|         self.open_conversations() |         self.open_conversations() | ||||||
|         Clock.schedule_interval(self.jobs, 1) |         Clock.schedule_interval(self.jobs, 1) | ||||||
| 
 | 
 | ||||||
|  |         def dismiss_splash(dt): | ||||||
|  |             from android import loadingscreen | ||||||
|  |             loadingscreen.hide_loading_screen() | ||||||
|  | 
 | ||||||
|  |         if RNS.vendor.platformutils.get_platform() == "android": | ||||||
|  |             Clock.schedule_once(dismiss_splash, 0) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     ################################################# |     ################################################# | ||||||
|     # General helpers                               # |     # General helpers                               # | ||||||
|     ################################################# |     ################################################# | ||||||
| 
 | 
 | ||||||
|  |     def notify(self, title, content): | ||||||
|  |         notifications_enabled = True | ||||||
|  | 
 | ||||||
|  |         if notifications_enabled: | ||||||
|  |             if RNS.vendor.platformutils.get_platform() == "android": | ||||||
|  |                 notifications_permitted = False | ||||||
|  |                 if check_permission("android.permission.POST_NOTIFICATIONS"): | ||||||
|  |                     notifications_permitted = True | ||||||
|  |                 else: | ||||||
|  |                     RNS.log("Requesting notification permission") | ||||||
|  |                     request_permissions(["android.permission.POST_NOTIFICATIONS"]) | ||||||
|  |             else: | ||||||
|  |                 notifications_permitted = True | ||||||
|  | 
 | ||||||
|  |             if notifications_permitted: | ||||||
|  |                 if RNS.vendor.platformutils.get_platform() == "android": | ||||||
|  |                     plyer.notification.notify(title, content, notification_icon=self.notification_icon) | ||||||
|  |                 else: | ||||||
|  |                     plyer.notification.notify(title, content) | ||||||
|  | 
 | ||||||
|     def build(self): |     def build(self): | ||||||
|         FONT_PATH = self.sideband.asset_dir+"/fonts" |         FONT_PATH = self.sideband.asset_dir+"/fonts" | ||||||
|         self.theme_cls.theme_style = "Dark" |         self.theme_cls.theme_style = "Dark" | ||||||
|  | |||||||
| @ -58,7 +58,7 @@ class SidebandCore(): | |||||||
|     CONV_GROUP     = 0x02 |     CONV_GROUP     = 0x02 | ||||||
|     CONV_BROADCAST = 0x03 |     CONV_BROADCAST = 0x03 | ||||||
| 
 | 
 | ||||||
|     MAX_ANNOUNCES  = 64 |     MAX_ANNOUNCES  = 48 | ||||||
| 
 | 
 | ||||||
|     aspect_filter = "lxmf.delivery" |     aspect_filter = "lxmf.delivery" | ||||||
|     def received_announce(self, destination_hash, announced_identity, app_data): |     def received_announce(self, destination_hash, announced_identity, app_data): | ||||||
| @ -80,8 +80,7 @@ class SidebandCore(): | |||||||
|         if not os.path.isdir(self.app_dir+"/app_storage"): |         if not os.path.isdir(self.app_dir+"/app_storage"): | ||||||
|             os.makedirs(self.app_dir+"/app_storage") |             os.makedirs(self.app_dir+"/app_storage") | ||||||
| 
 | 
 | ||||||
|         self.asset_dir     = self.app_dir+"/assets" |         self.asset_dir     = self.app_dir+"/app/assets" | ||||||
|         self.kv_dir        = self.app_dir+"/views/kv" |  | ||||||
|         self.config_path   = self.app_dir+"/app_storage/sideband_config" |         self.config_path   = self.app_dir+"/app_storage/sideband_config" | ||||||
|         self.identity_path = self.app_dir+"/app_storage/primary_identity" |         self.identity_path = self.app_dir+"/app_storage/primary_identity" | ||||||
|         self.db_path       = self.app_dir+"/app_storage/sideband.db" |         self.db_path       = self.app_dir+"/app_storage/sideband.db" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user