/* Ċ Ġ* ĠCreated Ġby ĠAnd ri i ĠK oval ch uk Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 2 . Ġro ove Ċ Ġ* Ċ Ġ* ĠThis Ġprogram Ġis Ġfree Ġsoftware : Ġyou Ġcan Ġredistribute Ġit Ġand / or Ġmodify Ċ Ġ* Ġit Ġunder Ġthe Ġterms Ġof Ġthe ĠGNU ĠGeneral ĠPublic ĠLicense Ġas Ġpublished Ġby Ċ Ġ* Ġthe ĠFree ĠSoftware ĠFoundation , Ġeither Ġversion Ġ 3 Ġof Ġthe ĠLicense , Ġor Ċ Ġ* Ġ( at Ġyour Ġoption ) Ġany Ġlater Ġversion . Ċ Ġ* Ċ Ġ* ĠThis Ġprogram Ġis Ġdistributed Ġin Ġthe Ġhope Ġthat Ġit Ġwill Ġbe Ġuseful , Ċ Ġ* Ġbut ĠWITHOUT ĠANY ĠWARRANTY ; Ġwithout Ġeven Ġthe Ġimplied Ġwarranty Ġof Ċ Ġ* ĠMERCHANTABILITY Ġor ĠFITNESS ĠFOR ĠA ĠPARTICULAR ĠPURPOSE . Ġ ĠSee Ġthe Ċ Ġ* ĠGNU ĠGeneral ĠPublic ĠLicense Ġfor Ġmore Ġdetails . Ċ Ġ* Ċ Ġ* ĠYou Ġshould Ġhave Ġreceived Ġa Ġcopy Ġof Ġthe ĠGNU ĠGeneral ĠPublic ĠLicense Ċ Ġ* Ġalong Ġwith Ġthis Ġprogram . Ġ ĠIf Ġnot , Ġsee Ġhttps :// www . gnu . org / licenses Ċ Ġ*/ Ċ Ċ package Ġcom . mm dev . ro ove . ui . chat Ċ Ċ import Ġandroid . app . Activity . RESULT _ OK Ċ import Ġandroid . content . Intent Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Environment Ċ import Ġandroid . provider . Media Store Ċ import Ġandroid . text . format . DateFormat Ċ import Ġandroid . view . Gravity Ċ import Ġandroid . view . View Ċ import Ġandroid . view . animation . Animation Utils Ċ import Ġandroidx . core . content . File Provider Ċ import Ġandroidx . core . widget . do On TextChanged Ċ import Ġandroidx . fragment . app . view Models Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . google . android . material . dialog . Material AlertDialog Builder Ċ import Ġcom . mm dev . domain . Pagination Direction .* Ċ import Ġcom . mm dev . domain . chat . Message Item Ċ import Ġcom . mm dev . domain . con versations . Conversation Item Ċ import Ġcom . mm dev . domain . pairs . Matched User Item Ċ import Ġcom . mm dev . domain . photo . Photo Item Ċ import Ġcom . mm dev . domain . user . data . Base UserInfo Ċ import Ġcom . mm dev . domain . user . data . Report Type .* Ċ import Ġcom . mm dev . domain . user . data . User Item Ċ import Ġcom . mm dev . ro ove . R Ċ import Ġcom . mm dev . ro ove . core . permissions . App Permission Ċ import Ġcom . mm dev . ro ove . core . permissions . App Permission . Permission Code Ċ import Ġcom . mm dev . ro ove . core . permissions . handle Permission Ċ import Ġcom . mm dev . ro ove . core . permissions . on Request Permissions Result Received Ċ import Ġcom . mm dev . ro ove . core . permissions . request App Permissions Ċ import Ġcom . mm dev . ro ove . databinding . Fragment Chat Binding Ċ import Ġcom . mm dev . ro ove . ui . MainActivity Ċ import Ġcom . mm dev . ro ove . ui . common . base . Base Fragment Ċ import Ġcom . mm dev . ro ove . ui . profile . Remote Repo ViewModel Ċ import Ġcom . mm dev . ro ove . utils . extensions . hide Keyboard Ċ import Ġcom . mm dev . ro ove . utils . extensions . observe Once Ċ import Ġcom . mm dev . ro ove . utils . extensions . show Toast Text Ċ import Ġdagger . h ilt . android . Android EntryPoint Ċ import Ġio . grpc . android . Build Config Ċ import Ġjava . io . File Ċ import Ġjava . util .* ĊĊ Ċ /** Ċ Ġ* ĠThis Ġis Ġthe Ġdocumentation Ġblock Ġabout Ġthe Ġclass Ċ Ġ*/ Ċ Ċ @ Android EntryPoint Ċ class ĠChat Fragment Ġ: ĠBase Fragment < Chat ViewModel , ĠFragment Chat Binding >( Ċ ĉ layout Id Ġ= ĠR . layout . fragment _ chat Ċ ) Ġ{ ĊĉĊ ĉ override Ġval Ġm ViewModel : ĠChat ViewModel Ġby Ġview Models () Ċ ĉ private Ġval Ġremote Repo ViewModel : ĠRemote Repo ViewModel Ġby Ġview Models () ĊĊ ĉ private Ġvar Ġreceived Partner City Ġ= Ġ"" Ċ ĉ private Ġvar Ġreceived Partner Gender Ġ= Ġ"" Ċ ĉ private Ġvar Ġreceived Partner Id Ġ= Ġ"" Ċ ĉ private Ġvar Ġreceived Conversation Id Ġ= Ġ"" ĊĉĊ ĉ private Ġvar Ġis Reported : ĠBoolean Ġ= Ġfalse ĊĊ ĉ private Ġlateinit Ġvar Ġcurrent Conversation : ĠCon versation Item Ċ ĉ private Ġlateinit Ġvar Ġcurrent Partner : ĠUser Item ĊĊ ĉ private Ġval Ġm Chat Adapter : ĠChat Adapter Ġ= ĠChat Adapter (). apply Ġ{ Ċĉ ĉ // set Ġcurrent Ġuser Ġid Ġto Ġunderstand Ġleft / right Ġmessage Ċĉ ĉ setCurrent UserId ( MainActivity . currentUser !!. base UserInfo . userId ) ĊĉĉĊĉ ĉ set Load Prev Listener Ġ{ Ġmessage Ġ-> Ċĉĉ ĉ m ViewModel . load Messages ( current Conversation , Ġmessage , ĠNEXT ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ // ĠFile Ċ ĉ private Ġlateinit Ġvar Ġm FilePath Image Camera : ĠFile ĊĊĉ ĊĊ ĉ // static Ġfields Ċ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ private Ġconst Ġval ĠPART NER _ C ITY _ KEY Ġ= Ġ" PART NER _ C ITY " Ċĉ ĉ private Ġconst Ġval ĠPART NER _ G ENDER _ KEY Ġ= Ġ" PART NER _ G ENDER " Ċĉ ĉ private Ġconst Ġval ĠPART NER _ ID _ KEY Ġ= Ġ" PART NER _ ID " Ċĉ ĉ private Ġconst Ġval ĠCON VER S ATION _ ID _ KEY Ġ= Ġ" CONVER S ATION _ ID " ĊĊ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) ĊĊĉ ĉ // deep Ġlink Ġfrom Ġnotification Ċĉ ĉ arguments ?. let Ġ{ Ġhandle Deep Link ( it ) Ġ} ĊĉĉĊĉ ĉ // setup Ċĉ ĉ remote Repo ViewModel . retrie ved User Item . observe Once ( this , Ġ{ Ċĉĉ ĉ current Partner Ġ= Ġit Ċĉĉ ĉ m ViewModel . partner Name . value Ġ= Ġit . base UserInfo . name . split (" Ġ" )[ 0 ] Ċĉĉ ĉ m ViewModel . partner Photo . value Ġ= Ġit . base UserInfo . main Photo Url Ċĉ ĉ }) ĊĉĉĊĉ ĉ remote Repo ViewModel . report Submit ting Status . observe Once ( this , Ġ{ Ċĉĉ ĉ is Reported Ġ= Ġit Ċĉĉ ĉ require Context (). show Toast Text ( getString ( R . string . toast _ text _ report _ success )) Ċĉ ĉ }) ĊĉĉĊĉ ĉ shared ViewModel . conversation Selected . observe Once ( this , Ġ{ Ċĉĉ ĉ current Conversation Ġ= Ġit Ċĉĉ ĉ remote Repo ViewModel . get Requested UserInfo ( it . partner ) Ċĉĉ ĉ // start Ġlistening Ġfor Ġnew Ġmessages Ċĉĉ ĉ m ViewModel . observe New Messages ( it ) Ċĉĉ ĉ // m ViewModel . observe Partner Online ( it . conversation Id ) Ċĉĉ ĉ // init Ġloading Ġchat Ġmessages Ċĉĉ ĉ m ViewModel . load Messages ( it , ĠMessage Item (), ĠINITIAL ) Ċĉ ĉ }) Ċĉ ĉ // set Ġinit Ġmessages Ġlist Ġin Ġadapter Ċĉ ĉ observe Init Messages () Ċĉ ĉ observe Prev Messages () Ċĉ ĉ observe New Message () Ċ ĉ } ĊĉĊ ĉ private Ġfun Ġobserve Init Messages () Ġ= Ġm ViewModel . init Messages . observe Once ( this , Ġ{ Ċĉ ĉ m Chat Adapter . set New Data ( it ) Ċ ĉ }) ĊĉĊ ĉ private Ġfun Ġobserve Prev Messages () Ġ= Ġm ViewModel . next Messages . observe ( this , Ġ{ Ċĉ ĉ m Chat Adapter . insert Prev ( it ) Ċ ĉ }) ĊĉĊ ĉ private Ġfun Ġobserve New Message () Ġ= Ġm ViewModel . new Message . observe ( this , Ġ{ Ċĉ ĉ m Chat Adapter . new Message ( it ) Ċĉ ĉ binding . rv Message List . scrollTo Position ( 0 ) Ċ ĉ }) ĊĉĊ ĉ private Ġfun Ġhandle Deep Link ( bundle : ĠBundle ) Ġ{ Ċĉ ĉ received Partner City Ġ= Ġbundle . getString ( PART NER _ C ITY _ KEY , Ġ"") Ċĉ ĉ received Partner Gender Ġ= Ġbundle . getString ( PART NER _ G ENDER _ KEY , Ġ"") Ċĉ ĉ received Partner Id Ġ= Ġbundle . getString ( PART NER _ ID _ KEY , Ġ"") Ċĉ ĉ received Conversation Id Ġ= Ġbundle . getString ( CONVER S ATION _ ID _ KEY , Ġ"") Ċĉ ĉ if Ġ( received Partner City . isNotEmpty () Ġ&& Ċĉĉ ĉ received Partner Gender . isNotEmpty () Ġ&& Ċĉĉ ĉ received Partner Id . isNotEmpty () Ġ&& Ċĉĉ ĉ received Conversation Id . isNotEmpty () Ċĉ ĉ ) Ġ{ ĊĉĉĉĊĉĉ ĉ // if Ġit Ġwas Ġa Ġdeep Ġlink Ġnavigation Ġthen Ġcreate ĠCon versation Item Ġ" on Ġa Ġflight " ĊĉĉĉĊĉĉ ĉ shared ViewModel . matched User ItemSelected . value Ġ= Ċĉĉĉ ĉ Matched User Item ( Ċĉĉĉĉ ĉ base UserInfo Ġ= ĠBase UserInfo ( userId Ġ= Ġreceived Partner Id ), Ċĉĉĉĉ ĉ conversation Id Ġ= Ġreceived Conversation Id , Ċĉĉĉĉ ĉ conversation Started Ġ= Ġtrue Ċĉĉĉ ĉ ) Ċĉĉ ĉ shared ViewModel . conversation Selected . value Ġ= Ċĉĉĉ ĉ Conversation Item ( Ċĉĉĉĉ ĉ partner Ġ= ĠBase UserInfo ( userId Ġ= Ġreceived Partner Id ), Ċĉĉĉĉ ĉ conversation Id Ġ= Ġreceived Conversation Id , Ċĉĉĉĉ ĉ conversation Started Ġ= Ġtrue Ċĉĉĉ ĉ ) Ċĉ ĉ } ĊĉĉĊ ĉ } ĊĊ ĉ override Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ= Ġbinding . run Ġ{ ĊĉĉĊĉ ĉ ed Text Message Input . do On TextChanged Ġ{ Ġtext , Ġstart , Ġbefore , Ġcount Ġ-> Ċĉĉ ĉ btn SendMessage . is Activated Ġ= Ġtext ?. trim (). isNull Or Blank () Ċĉ ĉ } ĊĊĉ ĉ btn SendMessage . setOnClickListener Ġ{ ĠsendMessage Click () Ġ} ĊĊĉ ĉ // show Ġattachment Ġdialog Ġpicker Ċĉ ĉ btn Send Attachment . setOnClickListener Ġ{ Ċĉĉ ĉ Material AlertDialog Builder ( require Context ()) Ċĉĉĉ ĉ . set Items ( Ċĉĉĉĉ ĉ array Of ( Ċĉĉĉĉĉ ĉ getString ( R . string . material _ dialog _ picker _ camera ), Ċĉĉĉĉĉ ĉ getString ( R . string . material _ dialog _ picker _ gallery ) Ċĉĉĉĉ ĉ ) Ċĉĉĉ ĉ ) Ġ{ Ġ_, Ġitem Index Ġ-> Ċĉĉĉĉ ĉ when Ġ( item Index ) Ġ{ Ċĉĉĉĉĉĉ 0 Ġ-> Ġphoto Camera Click () Ċĉĉĉĉĉĉ 1 Ġ-> Ġphoto Gallery Click () Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉĉ ĉ . create () Ċĉĉĉ ĉ . apply Ġ{ Ġwindow ?. attributes ?. gravity Ġ= ĠGr avity . BOTTOM Ġ} Ċĉĉĉ ĉ . show () Ċĉ ĉ } ĊĊĉ ĉ // if Ġmessage Ġcontains Ġphoto Ġthen Ġit Ġopens Ġin Ġfullscreen Ġdialog Ċĉ ĉ m Chat Adapter . setOn Attached Photo ClickListener Ġ{ Ġview , Ġposition , Ġphoto Item Ġ-> Ċĉĉ ĉ photo Item ?. file Url ?. let Ġ{ Ċĉĉĉ ĉ FullScreen Dialog Fragment . newInstance ( it ) Ċĉĉĉĉ ĉ . show ( child FragmentManager , ĠFull Screen Dialog Fragment :: class . java . canonical Name ) Ċĉĉ ĉ } Ċĉ ĉ } ĊĉĉĊĉĉĊĉ ĉ rv Message List . apply Ġ{ Ċĉĉ ĉ adapter Ġ= Ġm Chat Adapter Ċĉĉ ĉ layout Manager Ġ= ĠLinearLayoutManager ( context , ĠRecyclerView . VERTICAL , Ġtrue ) Ċĉĉ ĉ setOn Touch Listener Ġ{ Ġv , Ġ_ Ġ-> Ċĉĉĉ ĉ v . perform Click () Ċĉĉĉ ĉ v . hide Keyboard ( ed Text Message Input ) Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ toolbar Chat . set Navigation OnClickListener Ġ{ Ġon Back Pressed () Ġ} ĊĊĉ ĉ toolbar Chat . setOn MenuItem ClickListener Ġ{ Ġitem Ġ-> Ċĉĉ ĉ when Ġ( item . itemId ) Ġ{ Ċĉĉĉ ĉ R . id . chat _ action _ report Ġ-> Ġ{ Ġif Ġ(! is Reported ) Ġshow Report Dialog () Ġ} Ċĉĉ ĉ } Ċĉĉ ĉ return @ setOn MenuItem ClickListener Ġtrue Ċĉ ĉ } ĊĊĉ ĉ toolbar Inner Container . setOnClickListener Ġ{ Ċĉĉ ĉ nav Controller . navigate ( R . id . action _ chat _ to _ profile Fragment ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠSend Ġplain Ġtext Ġmsg Ġto Ġchat Ġif Ġedit Text Ġis Ġnot Ġempty Ċĉ Ġ* Ġelse Ġsh ake Ġanimation Ċĉ Ġ*/ Ċ ĉ private Ġfun ĠsendMessage Click () Ġ= Ġbinding . run Ġ{ ĊĉĉĊĉ ĉ if Ġ( ed Text Message Input . text . toString (). trim (). isNotEmpty ()) Ġ{ Ċĉĉ ĉ val Ġtext Ġ= Ġed Text Message Input . text . toString (). trim () ĊĉĉĉĊĉĉ ĉ val Ġmessage Ġ= Ġm ViewModel . sendMessage ( text , Ġcurrent Conversation ) ĊĉĉĉĊĉĉ ĉ // update Ġlocal Ġappearance Ġ( to Ġavoid Ġback Ġpressure ) Ċĉĉ ĉ // there Ġis Ġno Ġguarantee Ġthat Ġmessage Ġwill Ġbe Ġdelivered Ċĉĉ ĉ m Chat Adapter . new Message ( message ) Ċĉĉ ĉ rv Message List . scrollTo Position ( 0 ) Ċĉĉ ĉ ed Text Message Input . text ?. clear () Ċĉ ĉ } Ċĉ ĉ else Ġed Text Message Input . start Animation ( Animation Utils . load Animation ( context , ĠR . anim . horizontal _ shake )) ĊĊ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠChecks Ġif Ġthe Ġapp Ġhas Ġpermissions Ġto ĠOPEN ĠCAM ERA Ġand Ġtake Ġphotos Ċĉ Ġ* ĠIf Ġthe Ġapp Ġdoes Ġnot Ġhas Ġpermission Ġthen Ġthe Ġuser Ġwill Ġbe Ġpromp ted Ġto Ġgrant Ġpermissions Ċĉ Ġ* Ġelse Ġopen Ġcamera Ġintent Ċĉ Ġ*/ Ċ ĉ private Ġfun Ġphoto Camera Click () Ġ= Ġhandle Permission ( Ċĉ ĉ App Permission . CAMERA , Ċĉ ĉ on Granted Ġ= Ġ{ Ġstart Camera Intent () Ġ}, Ċĉ ĉ on Denied Ġ= Ġ{ Ġrequest App Permissions ( it ) Ġ}, Ċĉ ĉ on Explanation Needed Ġ= Ġ{ Ġit . explanation MessageId Ġ} Ċ ĉ ) ĊĊ ĉ // take Ġphoto Ġdirectly Ġby Ġcamera Ċ ĉ private Ġfun Ġstart Camera Intent () Ġ{ Ċĉ ĉ val Ġname Photo Ġ= ĠDate Format . format (" yyyy - MM - dd _ hh mm ss ", ĠDate ()). toString () Ċĉ ĉ m FilePath Image Camera Ġ= ĠFile ( Ċĉĉ ĉ require Context (). get External Files Dir ( Environment . DIRECTORY _ PI CTURE S ), Ġname Photo Ġ+ Ġ" camera . jpg ") Ċĉ ĉ val Ġphoto URI Ġ= ĠFile Provider . get Uri For File ( Ċĉĉ ĉ require Context (), Ċĉĉ ĉ Build Config . APPLICATION _ ID Ġ+ Ġ". provider ", Ċĉĉ ĉ m FilePath Image Camera Ċĉ ĉ ) Ċĉ ĉ val Ġintent Ġ= ĠIntent ( Media Store . ACTION _ IMAGE _ CAPTURE ). apply Ġ{ Ċĉĉ ĉ putExtra ( Media Store . EXTRA _ OUTPUT , Ġphoto URI ) Ċĉ ĉ } Ċĉ ĉ startActivity For Result ( intent , ĠPermission Code . REQUEST _ CODE _ CAMERA . code ) Ċ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠChecks Ġif Ġthe Ġapp Ġhas Ġpermissions Ġto ĠREAD Ġuser Ġfiles Ċĉ Ġ* ĠIf Ġthe Ġapp Ġdoes Ġnot Ġhas Ġpermission Ġthen Ġthe Ġuser Ġwill Ġbe Ġpromp ted Ġto Ġgrant Ġpermissions Ċĉ Ġ* Ġelse Ġopen Ġgallery Ġto Ġchoose Ġphoto Ċĉ Ġ*/ Ċ ĉ private Ġfun Ġphoto Gallery Click () Ġ= Ġhandle Permission ( Ċĉ ĉ App Permission . G ALL ERY , Ċĉ ĉ on Granted Ġ= Ġ{ Ġstart Gallery Intent () Ġ}, Ċĉ ĉ on Denied Ġ= Ġ{ Ġrequest App Permissions ( it ) Ġ}, Ċĉ ĉ on Explanation Needed Ġ= Ġ{ Ġit . explanation MessageId Ġ} Ċ ĉ ) Ċĉ ĊĊ ĉ // open Ġgallery Ġcho oser Ċ ĉ private Ġfun Ġstart Gallery Intent () Ġ{ Ċĉ ĉ val Ġintent Ġ= ĠIntent (). apply Ġ{ Ċĉĉ ĉ action Ġ= ĠIntent . ACTION _ GET _ CONTENT Ċĉĉ ĉ type Ġ= Ġ" image /* " Ċĉ ĉ } Ċĉ ĉ startActivity For Result ( Intent . create Chooser ( intent , Ġ" Select Ġimage "), ĠPermission Code . REQUEST _ CODE _ G ALL ERY . code ) Ċ ĉ } ĊĊ ĉ // Ġstart Ġafter Ġpermissions Ġwas Ġgranted Ċ ĉ // ĠIf Ġrequest Ġis Ġcancelled , Ġthe Ġresult Ġarrays Ġare Ġempty . Ċ ĉ override Ġfun Ġon Request Permissions Result ( request Code : ĠInt , Ġpermissions : ĠArray < String >, Ġgrant Results : ĠInt Array ) Ġ{ Ċĉ ĉ super . on Request Permissions Result ( request Code , Ġpermissions , Ġgrant Results ) Ċĉ ĉ on Request Permissions Result Received ( Ċĉĉ ĉ request Code , Ċĉĉ ĉ grant Results , Ċĉĉ ĉ on Permission Granted Ġ= Ġ{ Ċĉĉĉ ĉ when Ġ( it ) Ġ{ Ċĉĉĉĉ ĉ App Permission . CAMERA Ġ-> Ġstart Camera Intent () Ċĉĉĉĉ ĉ App Permission . G ALL ERY Ġ-> Ġstart Gallery Intent () Ċĉĉĉĉ ĉ else Ġ-> Ġ{} Ċĉĉĉ ĉ } Ċĉĉ ĉ }, Ċĉĉ ĉ on Permission Denied Ġ= Ġ{ Ċĉĉĉ ĉ require Context (). show Toast Text ( getString ( it . den ied MessageId )) Ċĉĉ ĉ } Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Activity Result ( request Code : ĠInt , ĠresultCode : ĠInt , Ġdata : ĠIntent ?) Ġ{ Ċĉ ĉ super . on Activity Result ( request Code , ĠresultCode , Ġdata ) Ċĉ ĉ // check Ġif Ġresponse Ġwith Ġstatus Ġ' OK ' Ċĉ ĉ if Ġ( result Code Ġ== ĠRESULT _ OK ) Ġ{ ĊĉĉĉĊĉĉ ĉ // check Ġwhich Ġrequest Ġthat Ġwas Ċĉĉ ĉ val Ġlocal Uri Ġ= Ġwhen Ġ( request Code ) Ġ{ Ċĉĉĉ ĉ Permission Code . REQUEST _ CODE _ G ALL ERY . code Ġ-> Ġ{ ĊĉĉĉĉĉĊĉĉĉĉ ĉ val Ġgallery Uri Ġ= Ġdata ?. data . toString () Ċĉĉĉĉ ĉ // Ġsend Ġphoto Ġfrom Ġgallery Ċĉĉĉĉ ĉ m ViewModel . send Photo ( gallery Uri , Ġcurrent Conversation ) ĊĉĉĉĉĉĊĉĉĉĉ ĉ gallery Uri Ċĉĉĉ ĉ } ĊĉĉĉĉĊĉĉĉ ĉ Permission Code . REQUEST _ CODE _ CAMERA . code Ġ-> Ġ{ Ċĉĉĉĉ ĉ if Ġ( m FilePath Image Camera . exists ()) Ġ{ Ċĉĉĉĉĉ ĉ val Ġcamera Uri Ġ= ĠUri . from File ( m FilePath Image Camera ). toString () Ċĉĉĉĉĉ ĉ // Ġsend Ġphoto Ġtaken Ġby Ġcamera Ċĉĉĉĉĉ ĉ m ViewModel . send Photo ( camera Uri , Ġcurrent Conversation ) ĊĉĉĉĉĉĉĊĉĉĉĉĉ ĉ camera Uri Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ else Ġ{ Ġrequire Context (). show Toast Text (" filePath Image Camera Ġis Ġnull Ġor ĠfilePath Image Camera Ġisn 't Ġexists ") Ċĉĉĉĉĉ ĉ "" Ċĉĉĉĉ ĉ } ĊĉĉĉĉĉĊĉĉĉ ĉ } Ċĉĉĉ ĉ else Ġ-> Ġ{ Ġ"" Ġ} Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ val Ġphoto Message Ġ= ĠMessage Item ( Ċĉĉĉ ĉ sender Ġ= ĠMainActivity . currentUser !!. base UserInfo , Ċĉĉĉ ĉ recipient Id Ġ= Ġcurrent Conversation . partner . userId , Ċĉĉĉ ĉ photo Item Ġ= ĠPhoto Item ( file Url Ġ= Ġlocal Uri ), Ċĉĉĉ ĉ conversation Id Ġ= Ġcurrent Conversation . conversation Id Ċĉĉ ĉ ) Ċĉĉ ĉ m Chat Adapter . new Message ( photo Message ). also Ġ{ Ċĉĉĉ ĉ binding . rv Message List . scrollTo Position ( 0 ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ else Ġ{ Ċĉĉ ĉ require Context (). show Toast Text ( result Code . toString ()) Ċĉ ĉ } ĊĉĉĊ ĉ } ĊĊ ĉ private Ġfun Ġshow Report Dialog () Ġ= ĠMaterial AlertDialog Builder ( require Context ()) Ċĉ ĉ . set Items ( Ċĉĉ ĉ array Of ( Ċĉĉĉ ĉ getString ( R . string . report _ cho oser _ photos ), Ċĉĉĉ ĉ getString ( R . string . report _ cho oser _ behavior ), Ċĉĉĉ ĉ getString ( R . string . report _ cho oser _ fake ) Ċĉĉ ĉ ) Ċĉ ĉ ) Ġ{ Ġ_, Ġitem Index Ġ-> Ċĉĉ ĉ when Ġ( item Index ) Ġ{ Ċĉĉĉĉ 0 Ġ-> Ġremote Repo ViewModel . submit Report ( IN EL IG IBLE _ PH OT OS , Ġcurrent Partner . base UserInfo ) Ċĉĉĉĉ 1 Ġ-> Ġremote Repo ViewModel . submit Report ( DIS RES PECT FUL _ BE HAV IOR , Ġcurrent Partner . base UserInfo ) Ċĉĉĉĉ 2 Ġ-> Ġremote Repo ViewModel . submit Report ( FA KE , Ġcurrent Partner . base UserInfo ) ĊĉĉĉĉĊĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ . create () Ċĉ ĉ . apply Ġ{ Ġwindow ?. attributes ?. gravity Ġ= ĠGr avity . CENTER Ġ} Ċĉ ĉ . show () ĊĉĊ ĉ /** Ċĉ Ġ* Ġif Ġwe Ġenter Ġchat Ġfrom Ġpairs Ġfragment Ġand Ġstart Ġthe Ġconversation Ġwe Ġshould Ġgo Ġback Ċĉ Ġ* Ġnot Ġto Ġpairs Ġfragment Ġbut Ġto Ġconversations Ċĉ Ġ* Ġif Ġconversation Ġis Ġnot Ġstarted Ġso Ġreturn Ġto Ġprofile Ġand Ġthen Ġto Ġpairs Ċĉ Ġ*/ Ċ ĉ override Ġfun Ġon Back Pressed () Ġ{ Ċĉ ĉ if Ġ( m ViewModel . chat IsEmpty . value Ġ== Ġfalse ) Ġ{ Ċĉĉ ĉ nav Controller . navigate ( R . id . action _ chat _ to _ con versations Fragment ) Ċĉ ĉ } Ċĉ ĉ else Ġnav Controller . navigate Up () Ċ ĉ } Ċ Ċ } Ċ