/* Ċ Ġ* ĠCreated Ġby ĠO rc hex tra Ċ Ġ* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 1 7 ĠG ig igo ĠMobile ĠServices ĠSL Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . g ig igo . orche x tra . core . domain . actions . action exec utors . notification Ċ Ċ import Ġandroid . app . Notification Channel Ċ import Ġandroid . app . Notification Manager Ċ import Ġandroid . app . Pending Intent Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Context . NOTIFICATION _ SERVICE Ċ import Ġandroid . content . Intent Ċ import Ġandroid . graphics . Color Ċ import Ġandroid . os . Build . VERSION Ċ import Ġandroid . os . Build . VERSION _ CODES Ċ import Ġandroidx . core . app . Notification Compat Ċ import Ġandroid . util . Log Ċ import Ġcom . g ig igo . orche x tra . core . O rc hex tra Ċ import Ġcom . g ig igo . orche x tra . core . R Ċ import Ġcom . g ig igo . orche x tra . core . domain . datas ources . Db DataSource Ċ import Ġcom . g ig igo . orche x tra . core . domain . entities . Action Ċ import Ġcom . g ig igo . orche x tra . core . domain . entities . Notification Ċ Ċ class ĠNotification Action Executor ( private Ġval Ġcontext : ĠContext , ĊĠĠĠ Ġprivate Ġval Ġdb DataSource : ĠDb DataSource ) Ġ{ ĊĊĠ Ġfun Ġshow Notification ( notification : ĠNotification , Ġaction : ĠAction ) Ġ{ ĊĊĠĠĠ ĠLog . d ( TAG , Ġ" show Notification () ") ĊĊĠĠĠ Ġif Ġ( O rc hex tra . is Activity Running ()) Ġ{ ĊĠĠĠĠĠ ĠLog . d ( TAG , Ġ" show Dialog () ") ĊĠĠĠĠĠ Ġshow Dialog ( context , Ġnotification , Ġaction ) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġshow Bar Notification ( notification , Ġaction ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshow Dialog ( context : ĠContext , Ġnotification : ĠNotification , Ġaction : ĠAction ) Ġ= Ġwith ( ĊĠĠĠĠĠ Ġnotification ) Ġ{ ĊĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠNotification Activity . open ( context , Ġnotification , Ġaction ) ĊĠĠĠ Ġ} Ġcatch Ġ( exception : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġexception . printStackTrace () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshow Bar Notification ( notification : ĠNotification , Ġaction : ĠAction ) Ġ= Ġwith ( notification ) Ġ{ ĊĊĠĠĠ Ġval Ġmanager Ġ= Ġcontext . getSystem Service ( NOTIFICATION _ SERVICE ) Ġas ĠNotification Manager ĊĊĠĠĠ Ġif Ġ( VERSION . SDK _ INT Ġ>= ĠVERSION _ CODES . O ) Ġ{ ĊĠĠĠĠĠ Ġval Ġchan 1 Ġ= ĠNotification Channel ( PRIMARY _ CHANNEL , Ġcontext . getString ( R . string . app _ name ), ĊĠĠĠĠĠĠĠĠĠ ĠNotification Manager . IMPORT ANCE _ DEFAULT ) ĊĠĠĠĠĠ Ġchan 1 . light Color Ġ= ĠColor . RED ĊĠĠĠĠĠ Ġchan 1 . lock screen Visibility Ġ= Ġandroid . app . Notification . VIS IBILITY _ PRIVATE ĊĠĠĠĠĠ Ġmanager . create Notification Channel ( chan 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġnotification Builder Ġ= ĠNotification Compat . Builder ( context , ĠPRIMARY _ CHANNEL ) ĊĠĠĠĠĠĠĠ Ġ. set Small Icon ( R . drawable . ox _ notification _ alpha _ small _ icon ) ĊĠĠĠĠĠĠĠ Ġ. setContent Title ( title ) ĊĠĠĠĠĠĠĠ Ġ. setContent Text ( body ) ĊĊĠĠĠ Ġval Ġnotification Intent Ġ= ĠNotification Activity . get Intent ( context , Ġnotification , Ġaction ) ĊĠĠĠ Ġval Ġnotification Activity Name Ġ= Ġdb DataSource . get Notification Activity Name () ĊĊĠĠĠ Ġval Ġpending Intent Ġ= Ġif Ġ( notification Activity Name . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠ Ġval Ġcls Ġ= ĠClass . forName ( notification Activity Name ) ĊĠĠĠĠĠ Ġval Ġback Intent Ġ= ĠIntent ( context , Ġcls ) ĊĠĠĠĠĠ Ġback Intent . add Flags ( Intent . FLAG _ ACTIVITY _ NEW _ TASK ) ĊĊĠĠĠĠĠ ĠPending Intent . get Activities ( context , Ġ 0 x 7 3 , ĊĠĠĠĠĠĠĠĠĠ ĠarrayOf ( back Intent , Ġnotification Intent ), ĠPending Intent . FLAG _ ONE _ SHOT ) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ ĠPending Intent . getActivity ( context , Ġ 0 x 7 3 , Ġnotification Intent , ĠPending Intent . FLAG _ ONE _ SHOT ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġnotification Builder . setContent Intent ( pending Intent ) ĊĠĠĠ Ġnotification Builder . setAuto Cancel ( true ) ĊĊĠĠĠ Ġval Ġm Notification Id Ġ= Ġ 1 ĊĊĠĠĠ Ġmanager . notify ( m Notification Id , Ġnotification Builder . build ()) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject ĠFactory Ġ{ ĊĊĠĠĠ Ġprivate Ġconst Ġval ĠTAG Ġ= Ġ" Notification Action " ĊĠĠĠ Ġprivate Ġconst Ġval ĠPRIMARY _ CHANNEL Ġ= Ġ" default " ĊĊĠĠĠ Ġfun Ġcreate ( context : ĠContext ): ĠNotification Action Executor Ġ= ĠNotification Action Executor ( ĊĠĠĠĠĠĠĠ Ġcontext , ĠDb DataSource . create ( context )) ĊĠ Ġ} Ċ }