package Ġcom . eric amp ire . android . android study case . util . extension Ċ Ċ import Ġandroid . content . Clip Data Ċ import Ġandroid . content . Clipboard Manager Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Environment Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . core . app . Share Compat Ċ import Ġandroidx . core . content . File Provider Ċ import Ġcom . downloader . Error Ċ import Ġcom . downloader . On Download Listener Ċ import Ġcom . downloader . PR Downloader Ċ import Ġcom . downloader . utils . Utils Ċ import Ġorg . zx connect . android . bes er ve . util . R Ċ import Ġjava . io . File ĊĊ Ċ fun ĠContext . download And Share ( ĊĠ Ġurl : ĠString , ĊĠ ĠonSuccess : Ġ() Ġ-> ĠUnit , ĊĠ ĠonError : Ġ( String ?) Ġ-> ĠUnit Ċ ) Ġ{ ĊĊĠ Ġval Ġdir Path Ġ= Ġget External Files Dir ( Environment . DIRECTORY _ DOWNLOAD S ). toString () ĊĠ Ġval ĠfileName Ġ= Ġurl . substring After Last ("/") ĊĠ Ġval ĠfilePath Ġ= ĠUtils . getPath ( dir Path , ĠfileName ) ĊĠ Ġval Ġdownload Request Ġ= ĠPR Downloader . download ( url , Ġdir Path , ĠfileName ). build () ĊĊĠ Ġdownload Request . start ( object Ġ: ĠOn Download Listener Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġon Download Complete () Ġ{ ĊĠĠĠĠĠ Ġshare File ( filePath ) ĊĠĠĠĠĠ ĠonSuccess () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonError ( error : ĠError ) Ġ{ ĊĠĠĠĠĠ ĠonError ( error . server ErrorMessage ) ĊĠĠĠ Ġ} ĊĠ Ġ}) Ċ } Ċ Ċ fun ĠContext . copy Text To Clipboard ( text : ĠString ) Ġ{ ĊĠ Ġval Ġclipboard Manager Ġ= Ġget System Service ( Context . CLIP BOARD _ SERVICE ) Ġas ĠClip board Manager ĊĠ Ġval Ġclip Data Ġ= ĠClip Data . new Plain Text (" text ", Ġtext ) ĊĠ Ġclipboard Manager . set Primary Clip ( clip Data ) ĊĠ ĠToast . makeText ( this , Ġ" Link Ġcopied Ġto Ġclipboard ", ĠToast . LENGTH _ LONG ). show () Ċ } Ċ Ċ private Ġfun ĠContext . share File ( filePath : ĠString ) Ġ{ ĊĠ Ġval Ġfile Ġ= ĠFile ( filePath ) ĊĠ Ġval Ġfile Uri Ġ= ĠFile Provider . get Uri For File ( ĊĠĠĠ Ġthis , ĊĠĠĠ Ġthis . application Context . packageName . toString () Ġ+ Ġ". provider ", ĊĠĠĠ Ġfile ĊĠ Ġ) ĊĊĠ Ġval Ġshare Intent Ġ= ĠShare Compat . Intent Builder ( this ) ĊĠĠĠ Ġ. set Chooser Title ( getString ( org . zx connect . android . bes er ve . i 1 8 n . R . string . txt _ share _ lott ie _ file )) ĊĠĠĠ Ġ. set Stream ( file Uri ) ĊĠĠĠ Ġ. setType (" application / pdf ") ĊĠĠĠ Ġ. create Chooser Intent () ĊĊĠ ĠstartActivity ( share Intent ) Ċ }