package Ġcom . test . images app . binding Ċ Ċ import Ġandroid . graphics . drawable . Bitmap Drawable Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . ImageView Ċ import Ġandroid . widget . ProgressBar Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . databinding . Binding Adapter Ċ import Ġcom . squareup . pic asso . Pic asso Ċ import Ġcom . test . images app . R Ċ import Ġcom . test . images app . data . model . Photo Ċ import Ġcom . test . images app . data . model . sizes . Label Ċ import Ġcom . test . images app . data . model . sizes . Size Ċ import Ġcom . test . images app . functions . interfaces . On Saved Changed Ċ import Ġcom . test . images app . functions . pic asso Callback Ċ import Ġcom . test . images app . network . exceptions . No Connectivity Exception Ċ import Ġcom . test . images app . ui . base . fragment . Base Fragment Ċ import Ġcom . test . images app . ui . views . Favorite Image Ċ Ċ @ Binding Adapter (" is Progress ") Ċ fun Ġbind Process ( progress Bar : ĠProgress Bar , Ġis Progress : ĠBoolean ) Ġ{ ĊĠĠĠ ĠprogressBar . visibility Ġ= Ġif Ġ( is Progress ) ĠView . VISIBLE Ġelse ĠView . GONE Ċ } Ċ Ċ @ Binding Adapter (" photo ", Ġ" pic asso ", Ġ" is Details ", Ġ" sizes ", Ġrequire All Ġ= Ġfalse ) Ċ fun Ġbind Photo Image ( ĊĠĠĠ ĠimageView : ĠImageView , ĊĠĠĠ Ġphoto : ĠPhoto , ĊĠĠĠ Ġpic asso : ĠPic asso , ĊĠĠĠ Ġis Details : ĠBoolean Ġ= Ġfalse , ĊĠĠĠ Ġsizes : ĠList < Size >? Ġ= Ġnull Ċ ) Ġ{ ĊĊĠĠĠ Ġif Ġ( is Details ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġneeded Photo Size Ġ= Ġ( sizes Ġ?: Ġphoto . sizes )?. find Ġ{ Ġit . label Enum Ġ== ĠLabel . MEDIUM Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġplaceholder Drawable Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBitmap Drawable ( imageView . resources , Ġphoto . low Quality Placeholder ) ĊĊĠĠĠĠĠĠĠ Ġpic asso . load ( needed Photo Size ?. url ). placeholder ( placeholder Drawable ). into ( imageView ) ĊĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( imageView Ġis ĠF avorite Image Ġ&& Ġphoto . photo Fragment Type Ġ== ĠBase Fragment . Fragment Type . POP ULAR ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠimageView . is Draw Favorite Ġ= Ġphoto . is Saved ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġpic asso . load ( photo . url ). into ( imageView , Ġpic asso Callback Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( imageView Ġas ? ĠF avorite Image )?. is Image Draw n Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ @ Binding Adapter (" saved ", Ġ" listener ") Ċ fun Ġbind Saved Photo ( imageView : ĠImageView , Ġis Saved : ĠBoolean , Ġlistener : ĠOn Saved Changed ) Ġ{ ĊĠĠĠ Ġval Ġdrawable Id Ġ= Ġif Ġ( is Saved ) ĠR . drawable . ic _ favorites Ġelse ĠR . drawable . ic _ favorites _ outline ĊĠĠĠ Ġval Ġdrawable Ġ= ĠContext Compat . get Drawable ( imageView . context , Ġdrawable Id ) ĊĊĠĠĠ Ġlistener . onChange ( is Saved ) ĊĊĠĠĠ ĠimageView . setImage Drawable ( drawable ) Ċ } Ċ Ċ @ Binding Adapter (" toast ") Ċ fun Ġbind Failed Toast ( progress Bar : ĠProgress Bar , Ġthrowable : ĠThrowable ?) Ġ{ ĊĠĠĠ Ġthrowable ?. let Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontext Ġ= ĠprogressBar . context ĊĠĠĠĠĠĠĠ Ġval Ġresources Ġ= Ġcontext . resources ĊĊĠĠĠĠĠĠĠ Ġval Ġtext Ġ= Ġwhen Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠNo Connectivity Exception Ġ-> Ġresources . getString ( R . string . failed _ connection ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġresources . getString ( R . string . failed _ to _ load ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠToast . makeText ( context , Ġtext , ĠToast . LENGTH _ SHORT ). show () ĊĠĠĠ Ġ} Ċ } Ċ