package Ġorg . opp ia . android . app . activity Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . res . Configuration Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Persist able Bundle Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġorg . opp ia . android . app . fragment . Fragment Component Ċ import Ġorg . opp ia . android . app . fragment . Fragment Component Builder Injector Ċ import Ġorg . opp ia . android . app . fragment . Fragment Component Factory Ċ import Ġorg . opp ia . android . app . translation . App Language Activity Injector Ċ import Ġorg . opp ia . android . app . translation . App Language Activity Injector Provider Ċ import Ġorg . opp ia . android . app . translation . App Language Application Injector Provider Ċ Ċ /** Ċ Ġ* ĠAn Ġ[ AppCompatActivity ] Ġthat Ġfacilit ates Ġfield Ġinjection Ġto Ġchild Ġactivities Ġand Ġconst it uent Ċ Ġ* Ġfragments Ġthat Ġextend Ġ[ org . opp ia . android . app . fragment . Injectable Fragment ]. Ċ Ġ*/ Ċ abstract Ġclass ĠInjectable AppCompatActivity Ġ: ĊĠ ĠAppCompatActivity (), ĠFragment Component Factory , ĠApp Language Activity Injector Provider Ġ{ ĊĠ Ġ/** ĊĠĠ Ġ* ĠThe Ġ[ Activity Component ] Ġcorresponding Ġto Ġthis Ġactivity . ĠThis Ġcannot Ġbe Ġused Ġbefore ĊĠĠ Ġ* Ġ[ attach Base Context ] Ġis Ġcalled , Ġand Ġcan Ġbe Ġused Ġto Ġinject Ġlateinit Ġfields Ġin Ġchild Ġactivities ĊĠĠ Ġ* Ġduring Ġactivity Ġcreation Ġ( which Ġis Ġrecommended Ġto Ġbe Ġdone Ġin Ġan Ġoverride Ġof Ġ[ onCreate ]). ĊĠĠ Ġ*/ ĊĠ Ġlateinit Ġvar Ġactivity Component : ĠActivity Component ĊĊĠ Ġoverride Ġfun Ġattach Base Context ( new Base : ĠContext ?) Ġ{ ĊĠĠĠ Ġval Ġapplication Context Ġ= ĠcheckNotNull ( new Base ?. application Context ) Ġ{ ĊĠĠĠĠĠ Ġ" Expected Ġattached ĠContext Ġto Ġhave Ġan Ġapplication Ġcontext Ġdefined ." ĊĠĠĠ Ġ} ĊĠĠĠ Ġon Initialize Activity Component ( application Context ) ĊĠĠĠ Ġval Ġnew Configuration Ġ= Ġon Initialize Localization ( application Context , Ġnew Base ) ĊĠĠĠ Ġsuper . attach Base Context ( new Base ?. create Configuration Context ( new Configuration )) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠ Ġensure Layout Direction () ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?, Ġpersistent State : ĠPers ist able Bundle ?) Ġ{ ĊĠĠĠ Ġensure Layout Direction () ĊĠĠĠ Ġsuper . onCreate ( savedInstanceState , Ġpersistent State ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġcreate Fragment Component ( fragment : ĠFragment ): ĠFragment Component Ġ{ ĊĠĠĠ Ġval Ġbuilder Injector Ġ= Ġactivity Component Ġas ĠFragment Component Builder Injector ĊĠĠĠ Ġreturn Ġbuilder Injector . get Fragment Component Builder Provider (). get (). set Fragment ( fragment ). build () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget App Language Activity Injector (): ĠApp Language Activity Injector Ġ= Ġactivity Component ĊĊĠ Ġprivate Ġfun Ġon Initialize Activity Component ( application Context : ĠContext ) Ġ{ ĊĠĠĠ Ġval Ġcomponent Factory Ġ= Ġapplication Context Ġas ĠActivity Component Factory ĊĠĠĠ Ġactivity Component Ġ= Ġcomponent Factory . create Activity Component ( this ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġon Initialize Localization ( ĊĠĠĠ Ġapplication Context : ĠContext , ĊĠĠĠ Ġnew Base : ĠContext ? ĊĠ Ġ): ĠConfiguration Ġ{ ĊĠĠĠ Ġ// ĠGiven Ġhow ĠData Providers Ġwork Ġ( i . e . Ġby Ġresolving Ġdata Ġr aces Ġusing Ġevent ual Ġconsistency ), Ġit 's ĊĠĠĠ Ġ// Ġpossible Ġto Ġmiss Ġsome Ġupdates Ġin Ġreally Ġunlikely Ġsituations . ĠNo Ġadditional Ġwork Ġwill Ġbe Ġdone ĊĠĠĠ Ġ// Ġto Ġprevent Ġthese Ġdata Ġr aces Ġunless Ġthey 're Ġactually Ġhit Ġby Ġusers . ĠIt Ġshouldn 't , Ġin Ġpractice , ĊĠĠĠ Ġ// Ġbe Ġpossible Ġsince Ġit Ġrequires Ġchanging Ġthe Ġsystem Ġlanguage Ġbetween Ġactivity Ġtransitions , Ġand ĊĠĠĠ Ġ// Ġin Ġmost Ġcases Ġthat Ġshould Ġresult Ġin Ġan Ġactivity Ġre creation Ġby Ġthe Ġmixin , Ġanyway . ĊĠĠĠ Ġval Ġapp Language App Injector Provider Ġ= ĊĠĠĠĠĠ Ġapplication Context Ġas ĠApp Language Application Injector Provider ĊĠĠĠ Ġval Ġapp Language App Injector Ġ= Ġapp Language App Injector Provider . getApp Language Application Injector () ĊĠĠĠ Ġval Ġapp Language Activity Injector Ġ= Ġactivity Component Ġas ĠApp Language Activity Injector ĊĠĠĠ Ġval Ġapp Language Locale Handler Ġ= Ġapp Language App Injector . getApp Language Handler () ĊĠĠĠ Ġval Ġapp Language Watcher Mixin Ġ= Ġapp Language Activity Injector . getApp Language Watcher Mixin () ĊĠĠĠ Ġapp Language Watcher Mixin . initialize () ĊĠĠĠ Ġreturn ĠConfiguration ( new Base ?. resources ?. configuration ). also Ġ{ Ġnew Configuration Ġ-> ĊĠĠĠĠĠ Ġapp Language Locale Handler . initialize Locale For Activity ( new Configuration ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġensure Layout Direction () Ġ{ ĊĠĠĠ Ġ// ĠEnsure Ġthe Ġroot Ġdecor Ġview Ġhas Ġthe Ġcorrect Ġlayout Ġdirect Ġsetup Ġper Ġthe Ġbase Ġcontext . ĠIn Ġsome ĊĠĠĠ Ġ// Ġcases , ĠAndroid Ġwill Ġlet Ġthe Ġapp Ġrecreate Ġthe Ġactivity Ġ& Ġproperly Ġupdate Ġthe Ġlayout Ġdirection ĊĠĠĠ Ġ// Ġof Ġthe Ġbase Ġcontext 's Ġconfiguration Ġbased Ġon Ġthe Ġselected ĠLocale Ġbut Ġnot Ġupdate Ġthe Ġdecor ĊĠĠĠ Ġ// Ġview . ĠThis Ġensures Ġthat Ġviews Ġuse Ġthe Ġcorrect Ġlayout Ġin Ġthese Ġsituations . ĊĠĠĠ Ġwindow . decor View . layout Direction Ġ= Ġbase Context . resources . configuration . layout Direction ĊĠ Ġ} Ċ } Ċ