package Ġnet . m E mo Zz . y ts . kotlin . ui . detail Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . content . Intent Ċ import Ġandroid . graphics . Color Ċ import Ġandroid . net . Uri Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager . HORIZONTAL Ċ import Ġandroid . view . View Ċ import Ġcom . af ol le st ad . material dialogs . Material Dialog Ċ import Ġcom . jak ew h art on . r xb ind ing 2 . view . Rx View Ċ import Ġcom . t br uy elle . rx permissions 2 . Rx Permissions Ċ import Ġkotlinx . android . synt hetic . main . activity _ details . coll ap sing _ toolbar Ċ import Ġkotlinx . android . synt hetic . main . activity _ details . detail _ frame _ thumb Ċ import Ġkotlinx . android . synt hetic . main . activity _ details . detail _ iv _ toolbar _ tr ailer _ thumb Ċ import Ġkotlinx . android . synt hetic . main . activity _ details . toolbar Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ card _ view Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ constraint Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ divider 1 Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ divider 2 Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ iv _ background Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ iv _ poster Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ pager _ screenshots Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ progress _ bar Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ recycler _ cast Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ cast Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ genre Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ overview Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ rate Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ res _ 1 0 8 0 Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ res _ 3 d Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ res _ 7 2 0 Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ screenshots Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ syn opsis Ċ import Ġkotlinx . android . synt hetic . main . content _ details . detail _ tv _ year Ċ import Ġkotlinx . android . synt hetic . main . dialog _ download . view . dialog _ download _ iv _ quality Ċ import Ġkotlinx . android . synt hetic . main . dialog _ download . view . dialog _ download _ tv _ size Ċ import Ġnet . m E mo Zz . y ts . kotlin . R Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . Quality Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . Quality . Q _ 1 0 8 0 P Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . Quality . Q _ 3 D Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . Quality . Q _ 7 2 0 P Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . bus . Movie Data Ċ import Ġnet . m E mo Zz . y ts . kotlin . data . network . Urls Ċ import Ġnet . m E mo Zz . y ts . kotlin . ui . base . Base Activity Ċ import Ġnet . m E mo Zz . y ts . kotlin . ui . detail . Detail Contract . Presenter Ċ import Ġnet . m E mo Zz . y ts . kotlin . ui . detail . adapters . pager . Screenshots Adapter Ċ import Ġnet . m E mo Zz . y ts . kotlin . ui . detail . adapters . recycler . Cast Adapter Ċ import Ġnet . m E mo Zz . y ts . kotlin . ui . main . adapters . Movies Adapter Ċ import Ġnet . m E mo Zz . y ts . kotlin . utilities . Dialog Util Ċ import Ġnet . m E mo Zz . y ts . kotlin . utilities . G lide Util Ċ import Ġnet . m E mo Zz . y ts . kotlin . utilities . Toast Util Ċ import Ġtim ber . log . Tim ber Ċ Ċ /** Ċ Ġ* ĠAuth ored Ġby ĠM oh amed ĠF athy Ġon Ġ 0 8 ĠMar , Ġ 2 0 1 8 . Ċ Ġ* ĠContact : Ġmu h amed . g end y @ gmail . com Ċ Ġ*/ Ċ Ċ class ĠDetails Activity Ġ: ĠBase Activity (), ĠDetail Contract . View Ġ{ ĊĊĠ Ġprivate Ġvar Ġpresenter : ĠPres enter ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġdialog Util : ĠDialog Util ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġdialog : ĠMaterial Dialog ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġdata : ĠMovie Data ? Ġ= Ġnull ĊĠ Ġprivate Ġvar Ġyoutube Code : ĠString ? Ġ= Ġnull ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ ĠsetContentView ( R . layout . activity _ details ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġinit Presenter () Ġ{ ĊĠĠĠ ĠDetail Presenter (). on Attach ( this , ĠDetail Interactor Impl ()) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Destroy () Ġ{ ĊĠĠĠ Ġpresenter !!. on Destroy () ĊĠĠĠ Ġsuper . on Destroy () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Presenter ( presenter : ĠDetail Contract . Presenter ) Ġ{ ĊĠĠĠ Ġthis . presenter Ġ= Ġpresenter ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset ActionBar () Ġ{ ĊĠĠĠ Ġset Support ActionBar ( toolbar ) ĊĠĠĠ Ġval Ġaction Bar Ġ= Ġsupport ActionBar ĊĠĠĠ Ġaction Bar ?. set Display Home As Up Enabled ( true ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġreceive Data () Ġ{ ĊĠĠĠ Ġval Ġdata Ġ= Ġintent ĊĠĠĠ Ġif Ġ( data Ġ!= Ġnull Ġ&& Ġdata . extras Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġthis . data Ġ= Ġdata . get Parcelable Extra ( Movies Adapter . KEY _ MOV IE _ DATA ) ĊĠĠĠĠĠ Ġif Ġ( this . data Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġyoutube Code Ġ= Ġthis . data !!. youtube Code ĊĠĠĠĠĠĠĠ Ġtitle Ġ= Ġthis . data !!. movie Name ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġsetup Recycler () Ġ{ ĊĠĠĠ Ġdetail _ recycler _ cast !!. layout Manager Ġ= ĠLinearLayoutManager ( context !! , ĠH ORIZONTAL , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġinit Dialog () Ġ{ ĊĠĠĠ Ġdialog Util Ġ= ĠDialog Util ( context !! ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġload Details () Ġ{ ĊĠĠĠ Ġif Ġ( data Ġ!= Ġnull ) Ġpresenter !!. load Movie Details ( context !! , Ġdata !!. movie Id ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġload Images ( t ube Url : ĠString , Ġposter Url : ĠString , Ġbackground Url : ĠString ) Ġ{ ĊĠĠĠ ĠG lide Util . load YouTube Thumb ( context !! , Ġcol lap sing _ toolbar !! , Ġdetail _ iv _ toolbar _ tr ailer _ thumb !! , ĊĠĠĠĠĠĠĠ Ġt ube Url ) ĊĠĠĠ ĠG lide Util . load Post er ( context !! , Ġdetail _ card _ view !! , Ġdetail _ iv _ poster !! , Ġposter Url ) ĊĠĠĠ ĠG lide Util . load Img ( context !! , Ġbackground Url , Ġdetail _ iv _ background !! ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Info ( year : ĠString , Ġgenre : ĠString , Ġrate : ĠString , Ġdescription : ĠString ) Ġ{ ĊĠĠĠ Ġdetail _ tv _ year !!. text Ġ= Ġyear ĊĠĠĠ Ġdetail _ tv _ genre !!. text Ġ= Ġgenre ĊĠĠĠ Ġdetail _ tv _ rate !!. text Ġ= ĠgetString ( R . string . detail _ vote , Ġrate ) ĊĠĠĠ Ġdetail _ tv _ overview !!. text Ġ= Ġdescription ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Pager Adapter ( adapter : ĠScreenshots Adapter ) Ġ{ ĊĠĠĠ Ġdetail _ pager _ screenshots !!. adapter Ġ= Ġadapter ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġset Cast Recycler Adapter ( adapter : ĠCast Adapter ) Ġ{ ĊĠĠĠ Ġdetail _ recycler _ cast !!. adapter Ġ= Ġadapter ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow ProgressBar () Ġ{ ĊĠĠĠ Ġdetail _ progress _ bar !!. visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide ProgressBar () Ġ{ ĊĠĠĠ Ġdetail _ progress _ bar !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Main View () Ġ{ ĊĠĠĠ Ġdetail _ constraint !!. visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Year () Ġ{ ĊĠĠĠ Ġdetail _ tv _ year !!. visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Year () Ġ{ ĊĠĠĠ Ġdetail _ tv _ year !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Gen res () Ġ{ ĊĠĠĠ Ġdetail _ tv _ genre !!. visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Gen res () Ġ{ ĊĠĠĠ Ġdetail _ tv _ genre !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Rate () Ġ{ ĊĠĠĠ Ġdetail _ tv _ rate !!. visibility Ġ= ĠView . VISIBLE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Rate () Ġ{ ĊĠĠĠ Ġdetail _ tv _ rate !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġenable 3 D () Ġ{ ĊĠĠĠ Ġdetail _ tv _ res _ 3 d !!. isEnabled Ġ= Ġtrue ĊĠĠĠ Ġdetail _ tv _ res _ 3 d !!. setTextColor ( Color . WHITE ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġenable 7 2 0 p () Ġ{ ĊĠĠĠ Ġdetail _ tv _ res _ 7 2 0 !!. isEnabled Ġ= Ġtrue ĊĠĠĠ Ġdetail _ tv _ res _ 7 2 0 !!. setTextColor ( Color . WHITE ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġenable 1 0 8 0 p () Ġ{ ĊĠĠĠ Ġdetail _ tv _ res _ 1 0 8 0 !!. isEnabled Ġ= Ġtrue ĊĠĠĠ Ġdetail _ tv _ res _ 1 0 8 0 !!. setTextColor ( Color . WHITE ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Syn opsis () Ġ{ ĊĠĠĠ Ġdetail _ divider 1 !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ tv _ overview !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ tv _ syn opsis !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Screenshots () Ġ{ ĊĠĠĠ Ġdetail _ divider 1 !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ tv _ screenshots !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ pager _ screenshots !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġhide Cast () Ġ{ ĊĠĠĠ Ġdetail _ divider 2 !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ tv _ cast !!. visibility Ġ= ĠView . GONE ĊĠĠĠ Ġdetail _ recycler _ cast !!. visibility Ġ= ĠView . GONE ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Progress Dialog () Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= Ġdialog Util !!. build Progress Dialog ( ĊĠĠĠĠĠĠĠ ĠgetString ( R . string . dialog _ title _ download ing ), ĊĠĠĠĠĠĠĠ ĠgetString ( R . string . dialog _ wait ) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuilder . cancel able ( false ) ĊĠĠĠ Ġdialog Ġ= Ġbuilder . build () ĊĠĠĠ Ġdialog !!. show () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġdismiss Progress Dialog () Ġ{ ĊĠĠĠ Ġif Ġ( dialog Ġ!= Ġnull ) Ġdialog !!. dismiss () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow File Saved Toast () Ġ{ ĊĠĠĠ ĠToast Util . show Long Toast ( context !! , ĠgetString ( R . string . msg _ download _ success )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow File Not Saved Toast () Ġ{ ĊĠĠĠ ĠToast Util . show Long Toast ( context !! , ĠgetString ( R . string . msg _ download _ failed )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Copy Confirm Toast () Ġ{ ĊĠĠĠ ĠToast Util . show Short Toast ( context !! , ĠgetString ( R . string . msg _ mag net _ copied )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow No Connection Toast () Ġ{ ĊĠĠĠ ĠToast Util . show Short Toast ( context !! , ĠgetString ( R . string . no _ network )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġshow Permission Not Granted Toast () Ġ{ ĊĠĠĠ ĠToast Util . show Long Toast ( context !! , ĠgetString ( R . string . perm _ not _ gr anted )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġinit Click s () Ġ{ ĊĠĠĠ ĠRx View . click s ( detail _ frame _ thumb ). subscribe ({ ĊĠĠĠĠĠ Ġval Ġyou Tube Uri Ġ= ĠUri . parse ( Urls . get YouTube Url ( youtube Code )) ĊĠĠĠĠĠ ĠstartActivity ( Intent ( Intent . ACTION _ VIEW , Ġyou Tube Uri )) ĊĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠ Ġ}) ĊĠĠĠ ĠRx View . click s ( detail _ tv _ res _ 3 d ). subscribe ({ ĊĠĠĠĠĠ Ġshow Torrent Info Dialog ( Quality . Q _ 3 D ) ĊĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠ Ġ}) ĊĠĠĠ ĠRx View . click s ( detail _ tv _ res _ 7 2 0 ). subscribe ({ ĊĠĠĠĠĠ Ġshow Torrent Info Dialog ( Quality . Q _ 7 2 0 P ) ĊĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠ Ġ}) ĊĠĠĠ ĠRx View . click s ( detail _ tv _ res _ 1 0 8 0 ). subscribe ({ ĊĠĠĠĠĠ Ġshow Torrent Info Dialog ( Quality . Q _ 1 0 8 0 P ) ĊĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġshow Torrent Info Dialog ( quality : ĠQuality ) Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= Ġdialog Util !!. build Dialog ( R . layout . dialog _ download ) ĊĠĠĠ Ġbuilder . title ( getString ( R . string . dialog _ download _ torrent )) ĊĠĠĠ Ġsetup Info Dialog Buttons ( builder , Ġquality ) ĊĠĠĠ Ġval Ġmat Dialog Ġ= Ġbuilder . build () ĊĠĠĠ Ġmat Dialog . set Cancel able ( true ) ĊĠĠĠ Ġval Ġdialog View Ġ= Ġmat Dialog . view ĊĊĠĠĠ Ġwhen Ġ( quality ) Ġ{ ĊĠĠĠĠĠ ĠQ _ 3 D Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ iv _ quality . setImage Drawable ( get Drawable ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . drawable . ic _ 3 d _ quality ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ tv _ size . text Ġ= Ġpresenter !!. get Movie Size ( Quality . Q _ 3 D ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠQ _ 7 2 0 P Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ iv _ quality . setImage Drawable ( get Drawable ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . drawable . ic _ 7 2 0 p _ quality ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ tv _ size . text Ġ= Ġpresenter !!. get Movie Size ( Quality . Q _ 7 2 0 P ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠQ _ 1 0 8 0 P Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ iv _ quality . setImage Drawable ( get Drawable ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . drawable . ic _ 1 0 8 0 p _ quality ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ Ġdialog View . dialog _ download _ tv _ size . text Ġ= Ġpresenter !!. get Movie Size ( Quality . Q _ 1 0 8 0 P ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġmat Dialog . show () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup Info Dialog Buttons ( builder : ĠMaterial Dialog . Builder , Ġquality : ĠQuality ) Ġ{ ĊĠĠĠ Ġbuilder . positive Text ( getString ( R . string . dialog _ download )) ĊĠĠĠ Ġbuilder . on Positive Ġ{ Ġ_, Ġ_ Ġ-> Ġrequest Permission ( quality ) Ġ} ĊĊĠĠĠ Ġbuilder . neutral Text ( getString ( R . string . dialog _ copy _ mag net )) ĊĠĠĠ Ġbuilder . on Neutral Ġ{ Ġ_, Ġ_ Ġ-> Ġpresenter !!. copy Mag net ( builder . context , Ġquality ) Ġ} ĊĊĠĠĠ Ġbuilder . negative Text ( R . string . dialog _ dismiss ) ĊĠĠĠ Ġbuilder . on Negative Ġ{ Ġdialog , Ġ_ Ġ-> Ġdialog . dismiss () Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrequest Permission ( quality : ĠQuality ) Ġ{ ĊĠĠĠ Ġval Ġrx Permissions Ġ= ĠRx Permissions ( context !! ) ĊĠĠĠ Ġrx Permissions . request ( Manifest . permission . WRITE _ EXTERNAL _ STORAGE ) ĊĠĠĠĠĠĠĠ Ġ. subscribe ({ Ġgranted Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġpresenter !!. on Perm Granted ( context !! , Ġquality , Ġgranted !! ) ĊĠĠĠĠĠĠĠ Ġ}, Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠTim ber . e ( it ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠ Ġ} Ċ } Ċ