package Ġcom . anna . spe aking timer . ui . main Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . text . Sp ann able String Ċ import Ġandroid . text . Sp anned Ċ import Ġandroid . text . style . ForegroundColor Span Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . lifecycle . ViewModel Provider Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġcom . anna . spe aking timer . R Ċ import Ġcom . anna . spe aking timer . model . Result Ċ import Ġcom . anna . spe aking timer . util . SharedPreferences Util Ċ import Ġcom . github . mike phil . chart ing . components . Legend Ċ import Ġcom . github . mike phil . chart ing . data . Pie Data Ċ import Ġcom . github . mike phil . chart ing . data . Pie DataSet Ċ import Ġcom . github . mike phil . chart ing . data . Pie Entry Ċ import Ġkotlinx . android . synt hetic . main . results _ fragment .* Ċ import Ġkotlinx . android . synt hetic . main . results _ fragment . count _ pie _ chart Ċ import Ġkotlinx . android . synt hetic . main . results _ fragment . time _ pie _ chart ĊĊ Ċ class ĠResults Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġshared Preferences Util : ĠSharedPreferences Util Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠSharedPreferences Util ( require Activity (). application ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠResults ViewModel Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ ĠViewModel Provider ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠResults ViewModel . Factory ( application Ġ= Ġrequire Activity (). application ) ĊĠĠĠĠĠĠĠ Ġ). get ( Results ViewModel :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , ĊĠĠĠĠĠĠĠ Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . results _ fragment , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġback _ button . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfind Nav Controller (). navigate Up () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġrestart _ button . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġshared Preferences Util . clear SharedPreferences () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfind Nav Controller (). navigate Up () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠviewModel . result . observe ( view Lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠsetData For Chart ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsp ann able String W omen Ġ= ĠSp ann able String ("${ it . percent W omen Count }% Ġof Ġspeak ers Ġwere Ġwomen Ġand Ġthey Ġspo ke Ġ${ it . percent W omen Time }% Ġof Ġthe Ġtime .") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsp ann able String W omen . set Span ( ForegroundColor Span ( resources . getColor ( R . color . w omen )), Ġ 0 , Ġ 3 , ĠSp anned . SPAN _ INCL USIVE _ INCL USIVE ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsp ann able String W omen . set Span ( ForegroundColor Span ( resources . getColor ( R . color . w omen )), Ġ 4 2 , Ġ 4 5 , ĠSp anned . SPAN _ INCL USIVE _ INCL USIVE ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwomen _ results . text Ġ= Ġsp ann able String W omen ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsp ann able String Men Ġ= ĠSp ann able String ("${ it . percent Men Count }% Ġof Ġspeak ers Ġwere Ġmen Ġand Ġthey Ġspo ke Ġ${ it . percent Men Time }% Ġof Ġthe Ġtime .") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsp ann able String Men . set Span ( ForegroundColor Span ( resources . getColor ( R . color . men )), Ġ 0 , Ġ 3 , ĠSp anned . SPAN _ INCL USIVE _ INCL USIVE ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsp ann able String Men . set Span ( ForegroundColor Span ( resources . getColor ( R . color . men )), Ġ 4 0 , Ġ 4 3 , ĠSp anned . SPAN _ INCL USIVE _ INCL USIVE ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmen _ results . text Ġ= Ġsp ann able String Men ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠsetData For Chart ( result : ĠResult ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġpie Entry List Count : ĠMutable List < Pie Entry > Ġ= Ġempty List < Pie Entry >(). to Mutable List () ĊĠĠĠĠĠĠĠ Ġpie Entry List Count . add ( Pie Entry ( result . percent Men Count . toFloat (), Ġ" Men ")) ĊĠĠĠĠĠĠĠ Ġpie Entry List Count . add ( Pie Entry ( result . percent W omen Count . toFloat (), Ġ" W omen ")) ĊĠĠĠĠĠĠĠ Ġval Ġcolor List : ĠMutable List < Int > Ġ= Ġempty List < Int >(). to Mutable List () ĊĠĠĠĠĠĠĠ Ġcolor List . add ( resources . getColor ( R . color . men )) ĊĠĠĠĠĠĠĠ Ġcolor List . add ( resources . getColor ( R . color . w omen )) ĊĠĠĠĠĠĠĠ Ġval Ġpie DataSet Count Ġ= ĠP ie DataSet ( pie Entry List Count , Ġ"") ĊĠĠĠĠĠĠĠ Ġpie DataSet Count . set Draw Icons ( false ) ĊĊĠĠĠĠĠĠĠ Ġpie DataSet Count . colors Ġ= Ġcolor List ĊĠĠĠĠĠĠĠ Ġval Ġpie Data Count Ġ= ĠP ie Data ( pie DataSet Count ) ĊĠĠĠĠĠĠĠ Ġpie Data Count . setValue Text Size ( 1 3 f ) ĊĠĠĠĠĠĠĠ Ġpie Data Count . setValue TextColor ( resources . getColor ( R . color . white )) ĊĠĠĠĠĠĠĠ Ġcount _ pie _ chart . data Ġ= Ġpie Data Count ĊĠĠĠĠĠĠĠ Ġcount _ pie _ chart . set Draw Entry Labels ( false ) ĊĠĠĠĠĠĠĠ Ġcount _ pie _ chart . set Use Percent Values ( true ) ĊĠĠĠĠĠĠĠ Ġcount _ pie _ chart . description . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġval Ġcount Legend Ġ= Ġcount _ pie _ chart . legend ĊĠĠĠĠĠĠĠ Ġcount Legend . direction Ġ= ĠLegend . Legend Direction . RIGHT _ TO _ LEFT ĊĊĠĠĠĠĠĠĠ Ġ// ĠFor Ġtime Ġpie Ġchart ĊĠĠĠĠĠĠĠ Ġval Ġpie Entry List Time : ĠMutable List < Pie Entry > Ġ= Ġempty List < Pie Entry >(). to Mutable List () ĊĠĠĠĠĠĠĠ Ġpie Entry List Time . add ( Pie Entry ( result . percent Men Time . toFloat (), Ġ" Men ")) ĊĠĠĠĠĠĠĠ Ġpie Entry List Time . add ( Pie Entry ( result . percent W omen Time . toFloat (), Ġ" W omen ")) ĊĠĠĠĠĠĠĠ Ġval Ġpie DataSet Time Ġ= ĠP ie DataSet ( pie Entry List Time , Ġ"") ĊĠĠĠĠĠĠĠ Ġpie DataSet Time . set Draw Icons ( false ) ĊĊĠĠĠĠĠĠĠ Ġpie DataSet Time . colors Ġ= Ġcolor List ĊĠĠĠĠĠĠĠ Ġval Ġpie Data Time Ġ= ĠP ie Data ( pie DataSet Time ) ĊĠĠĠĠĠĠĠ Ġpie Data Time . setValue Text Size ( 1 3 f ) ĊĠĠĠĠĠĠĠ Ġpie Data Time . setValue TextColor ( resources . getColor ( R . color . white )) ĊĠĠĠĠĠĠĠ Ġtime _ pie _ chart . data Ġ= Ġpie Data Time ĊĠĠĠĠĠĠĠ Ġtime _ pie _ chart . set Draw Entry Labels ( false ) ĊĠĠĠĠĠĠĠ Ġtime _ pie _ chart . set Use Percent Values ( true ) ĊĠĠĠĠĠĠĠ Ġtime _ pie _ chart . description . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġval Ġtime Legend Ġ= Ġtime _ pie _ chart . legend ĊĠĠĠĠĠĠĠ Ġtime Legend . direction Ġ= ĠLegend . Legend Direction . RIGHT _ TO _ LEFT ĊĊĊĠĠĠ Ġ} Ċ Ċ }