package Ġjp . co . sor am its u . feature _ account _ impl . presentation . node . details Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . live Data Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġjp . co . sor am its u . common . resources . Clipboard Manager Ċ import Ġjp . co . sor am its u . common . resources . ResourceManager Ċ import Ġjp . co . sor am its u . common . utils . map Ċ import Ġjp . co . sor am its u . common . utils . require Exception Ċ import Ġjp . co . sor am its u . common . utils . setValue If New Ċ import Ġjp . co . sor am its u . feature _ account _ api . domain . interfaces . Account Interactor Ċ import Ġjp . co . sor am its u . feature _ account _ impl . R Ċ import Ġjp . co . sor am its u . feature _ account _ impl . data . map pers . map Node To Node Model Ċ import Ġjp . co . sor am its u . feature _ account _ impl . presentation . Account Router Ċ import Ġjp . co . sor am its u . feature _ account _ impl . presentation . node . Node Details Root ViewModel Ċ import Ġjp . co . sor am its u . feature _ account _ impl . presentation . node . model . Node Model Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠNode Details ViewModel ( ĊĠĠĠ Ġprivate Ġval Ġinter actor : ĠAccount Interactor , ĊĠĠĠ Ġprivate Ġval Ġrouter : ĠAccount Router , ĊĠĠĠ Ġprivate Ġval ĠnodeId : ĠInt , ĊĠĠĠ Ġprivate Ġval Ġis Selected : ĠBoolean , ĊĠĠĠ Ġprivate Ġval Ġclipboard Manager : ĠClip board Manager , ĊĠĠĠ Ġprivate Ġval Ġresource Manager : ĠResourceManager Ċ ) Ġ: ĠNode Details Root ViewModel ( resource Manager ) Ġ{ ĊĊĠĠĠ Ġval Ġnode Model LiveData Ġ= Ġlive Data Ġ{ ĊĠĠĠĠĠĠĠ Ġemit ( getNode ( nodeId )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġname Edit Enabled Ġ= Ġnode Model LiveData . map (:: map NodeName Edit State ) ĊĠĠĠ Ġval Ġhost Edit Enabled Ġ= Ġnode Model LiveData . map (:: map Node Host Edit State ) ĊĊĠĠĠ Ġprivate Ġval Ġ_ update Button Enabled Ġ= ĠMutable LiveData < Boolean >() ĊĠĠĠ Ġval Ġupdate Button Enabled : ĠLive Data < Boolean > Ġ= Ġ_ update Button Enabled ĊĊĠĠĠ Ġfun Ġback Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġrouter . back () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġnode Details Edited () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ update Button Enabled . setValue If New ( true ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcopy Node Host Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġnode Model LiveData . value ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclipboard Manager . addTo Clipboard ( it . link ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġshow Message ( resource Manager . getString ( R . string . common _ copied )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġupdate Clicked ( name : ĠString , Ġhost Url : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġinter actor . update Node ( nodeId , Ġname , Ġhost Url ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( result . is Success ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrouter . back () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġhandle Node Exception ( result . require Exception ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun ĠgetNode ( nodeId : ĠInt ): ĠNode Model Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnode Ġ= Ġinter actor . getNode ( nodeId ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġmap Node To Node Model ( node ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmap NodeName Edit State ( node : ĠNode Model ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ! node . is Default ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmap Node Host Edit State ( node : ĠNode Model ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ! node . is Default Ġ&& Ġ! isSelected ĊĠĠĠ Ġ} Ċ }