package Ġcom . far uk . ml k its ample . activity Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 7 . app . AppCompatActivity Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . EditText Ċ import Ġcom . google . firebase . ml . natur all anguage . Firebase Natural Language Ċ import Ġcom . google . firebase . ml . natur all anguage . smart reply . Firebase Text Message Ċ import Ġcom . google . firebase . ml . natur all anguage . smart reply . Smart Reply Suggestion Result Ċ import Ġcom . far uk . ml k its ample . R Ċ import Ġcom . far uk . ml k its ample . model . Smart Reply Conversation Model Ċ import Ġcom . far uk . ml k its ample . Adapter . Smart Reply Adapter Ċ import Ġkotlinx . android . synt hetic . main . activity _ smart _ reply .* Ċ import Ġkotlinx . android . synt hetic . main . content _ smart _ reply .* Ċ Ċ class ĠSmart Reply Activity Ġ: ĠAppCompatActivity (), ĠView . OnClickListener Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġsmart Reply Conversation Ġ= ĠArrayList < Smart Reply Conversation Model >() ĊĠĠĠ Ġprivate Ġval Ġfirebase Smart Reply Conversation Ġ= ĠArrayList < Firebase Text Message >() ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ smart _ reply ) ĊĠĠĠĠĠĠĠ Ġset Support ActionBar ( toolbar ) ĊĠĠĠĠĠĠĠ Ġsupport ActionBar ?. set Display Home As Up Enabled ( true ) ĊĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . layout Manager Ġ= ĠLinearLayoutManager ( this ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . adapter Ġ= ĠSmart Reply Adapter ( this , Ġsmart Reply Conversation ) ĊĊĠĠĠĠĠĠĠ Ġsmart _ reply _ him _ her _ send _ button . setOnClickListener ( this ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ you _ send _ button . setOnClickListener ( this ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 1 . setOnClickListener ( this ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 2 . setOnClickListener ( this ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 3 . setOnClickListener ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonClick ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen Ġ( view . id ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . smart _ reply _ him _ her _ send _ button Ġ-> Ġon Send Button Clicked ( false , Ġsmart _ reply _ him _ her _ edit _ text ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . smart _ reply _ you _ send _ button Ġ-> Ġon Send Button Clicked ( true , Ġsmart _ reply _ you _ edit _ text ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . smart _ reply _ reply _ button 1 Ġ-> Ġon Smart Reply Button Clicked ( smart _ reply _ reply _ button 1 . text . trim (). toString ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . smart _ reply _ reply _ button 2 Ġ-> Ġon Smart Reply Button Clicked ( smart _ reply _ reply _ button 2 . text . trim (). toString ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . smart _ reply _ reply _ button 3 Ġ-> Ġon Smart Reply Button Clicked ( smart _ reply _ reply _ button 3 . text . trim (). toString ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Send Button Clicked ( is Local User : ĠBoolean , Ġedit Text : ĠEditText ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġedit Text . text . trim (). toString () ĊĊĠĠĠĠĠĠĠ Ġ// Ġadd Ġmessage Ġto Ġsmart Reply Conversation ĊĠĠĠĠĠĠĠ Ġsmart Reply Conversation . add ( Smart Reply Conversation Model ( is Local User , Ġmessage )) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . adapter ?. notify Item Inserted ( smart Reply Conversation . size Ġ- Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . scrollTo Position ( smart Reply Conversation . size Ġ- Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġedit Text . text . clear () ĊĠĠĠĠĠĠĠ Ġ// Ġadd Ġmessage Ġto Ġfirebase Smart Reply Conversation ĊĠĠĠĠĠĠĠ Ġif Ġ( is Local User ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfirebase Smart Reply Conversation . add ( Firebase Text Message . create For Local User ( message , ĠSystem . currentTimeMillis ())) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfirebase Smart Reply Conversation . add ( Firebase Text Message . create For Remote User ( message , ĠSystem . currentTimeMillis (), Ġ" him _ her _ 0 0 7 ")) ĊĠĠĠĠĠĠĠ Ġ// Ġget Ġsmart Ġreplies ĊĠĠĠĠĠĠĠ ĠFirebase Natural Language . getInstance (). smart Reply . suggest Rep lies ( firebase Smart Reply Conversation ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add On Success Listener Ġ{ Ġresult Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( result . status Ġ== ĠSmart Reply Suggestion Result . STATUS _ SUCCESS Ġ&& Ġresult . suggestions . size Ġ== Ġ 3 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ replies _ linear _ layout . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 1 . text Ġ= Ġresult . suggestions [ 0 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 2 . text Ġ= Ġresult . suggestions [ 1 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 3 . text Ġ= Ġresult . suggestions [ 2 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġsmart _ reply _ replies _ linear _ layout . visibility Ġ= ĠView . IN VISIBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Smart Reply Button Clicked ( message : ĠString ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġadd Ġmessage Ġto Ġsmart Reply Conversation ĊĠĠĠĠĠĠĠ Ġsmart Reply Conversation . add ( Smart Reply Conversation Model ( true , Ġmessage )) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . adapter ?. notify Item Inserted ( smart Reply Conversation . size Ġ- Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġsmart _ reply _ recycler _ view . scrollTo Position ( smart Reply Conversation . size Ġ- Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġ// Ġadd Ġmessage Ġto Ġfirebase Smart Reply Conversation ĊĠĠĠĠĠĠĠ Ġfirebase Smart Reply Conversation . add ( Firebase Text Message . create For Local User ( message , ĠSystem . currentTimeMillis ())) ĊĠĠĠĠĠĠĠ Ġ// Ġget Ġsmart Ġreplies ĊĠĠĠĠĠĠĠ ĠFirebase Natural Language . getInstance (). smart Reply . suggest Rep lies ( firebase Smart Reply Conversation ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. add On Success Listener Ġ{ Ġresult Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( result . status Ġ== ĠSmart Reply Suggestion Result . STATUS _ SUCCESS Ġ&& Ġresult . suggestions . size Ġ== Ġ 3 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ replies _ linear _ layout . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 1 . text Ġ= Ġresult . suggestions [ 0 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 2 . text Ġ= Ġresult . suggestions [ 1 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsmart _ reply _ reply _ button 3 . text Ġ= Ġresult . suggestions [ 2 ]. text ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġsmart _ reply _ replies _ linear _ layout . visibility Ġ= ĠView . IN VISIBLE ĊĠĠĠ Ġ} Ċ } Ċ