package Ġde . r ki . cor on aw arn app . contact di ary . ui . exporter Ċ Ċ import Ġandroid . content . Context Ċ import Ġdagger . Re usable Ċ import Ġde . r ki . cor on aw arn app . R Ċ import Ġde . r ki . cor on aw arn app . contact di ary . model . Contact Di ary Location Visit Ċ import Ġde . r ki . cor on aw arn app . contact di ary . model . Contact Di ary Person Encounter Ċ import Ġde . r ki . cor on aw arn app . ui . duration picker . to Readable Duration Ċ import Ġde . r ki . cor on aw arn app . util . Time And Date Extensions . to LocalDate Utc Ċ import Ġde . r ki . cor on aw arn app . util . TimeStamp er Ċ import Ġde . r ki . cor on aw arn app . util . coroutine . Dispatcher Provider Ċ import Ġde . r ki . cor on aw arn app . util . di . AppContext Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġorg . joda . time . LocalDate Ċ import Ġjava . util . Locale Ċ import Ġjavax . inject . Inject Ċ Ċ @ Re usable Ċ class ĠContact Di ary Exporter Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġ@ AppContext Ġprivate Ġval Ġcontext : ĠContext , ĊĠĠĠ Ġprivate Ġval Ġtime Stamp er : ĠTime Stamp er , ĊĠĠĠ Ġprivate Ġval Ġdispatcher Provider : ĠDispatcher Provider Ċ ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġprefix Phone Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ prefix _ phone ) ĊĠĠĠ Ġprivate Ġval Ġprefix EM ail Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ prefix _ email ) ĊĊĠĠĠ Ġprivate Ġval Ġtext Duration LessThan 1 5 Min Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ dur ations _ less _ than _ 1 5 min ) ĊĠĠĠ Ġprivate Ġval Ġtext Duration Long er Than 1 5 Min Ġ= ĊĠĠĠĠĠĠĠ Ġcontext . getString ( R . string . contact _ di ary _ export _ dur ations _ long er _ than _ 1 5 min ) ĊĊĠĠĠ Ġprivate Ġval Ġtext With Mask Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ we aring _ mask ) ĊĠĠĠ Ġprivate Ġval Ġtext No Mask Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ we aring _ no _ mask ) ĊĊĠĠĠ Ġprivate Ġval Ġtext Was Out do ors Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ out door ) ĊĠĠĠ Ġprivate Ġval Ġtext Was In door Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ indo or ) ĊĊĠĠĠ Ġprivate Ġval Ġduration Prefix Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ location _ duration _ prefix ) ĊĠĠĠ Ġprivate Ġval Ġduration Suffix Ġ= Ġcontext . getString ( R . string . contact _ di ary _ export _ location _ duration _ suffix ) ĊĊĠĠĠ Ġsuspend Ġfun Ġcreate Export ( ĊĠĠĠĠĠĠĠ Ġperson En counters : ĠList < Contact Di ary Person Encounter >, ĊĠĠĠĠĠĠĠ Ġlocation Vis its : ĠList < Contact Di ary Location Visit >, ĊĠĠĠĠĠĠĠ ĠnumberOf Last Days To Export : ĠInt ĊĠĠĠ Ġ): ĠString Ġ= Ġwith Context ( dispatcher Provider . Default ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdates To Export Ġ= Ġgenerate Dates To Export ( numberOf Last Days To Export ) ĊĊĠĠĠĠĠĠĠ ĠStringBuilder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. append Intro ( dates To Export ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. append Pers ons And Locations ( person En counters , Ġlocation Vis its , Ġdates To Export ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. toString () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġgenerate Dates To Export ( numberOf Last Days To Export : ĠInt ) Ġ= ĊĠĠĠĠĠĠĠ Ġ( 0 Ġuntil ĠnumberOf Last Days To Export ). map Ġ{ Ġtime Stamp er . now UTC . to LocalDate Utc (). minus Days ( it ) Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠStringBuilder . append Intro ( dates To Export : ĠList < LocalDate >) Ġ= Ġapply Ġ{ ĊĠĠĠĠĠĠĠ Ġappend Line ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontext . getString ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . contact _ di ary _ export _ intro _ one , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdates To Export . last (). to Formatted String (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdates To Export . first (). to Formatted String () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġappend Line ( context . getString ( R . string . contact _ di ary _ export _ intro _ two )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠStringBuilder . append Pers ons And Locations ( ĊĠĠĠĠĠĠĠ Ġperson En counters : ĠList < Contact Di ary Person Encounter >, ĊĠĠĠĠĠĠĠ Ġlocation Vis its : ĠList < Contact Di ary Location Visit >, ĊĠĠĠĠĠĠĠ Ġdates To Export : ĠList < LocalDate > ĊĠĠĠ Ġ) Ġ= Ġapply Ġ{ ĊĊĠĠĠĠĠĠĠ Ġif Ġ( person En counters . isNotEmpty () Ġ|| Ġlocation Vis its . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġappend Line () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġgrouped Person En counters Ġ= Ġperson En counters . groupBy Ġ{ Ġit . date Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġgrouped Location Vis its Ġ= Ġlocation Vis its . groupBy Ġ{ Ġit . date Ġ} ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( date Ġin Ġdates To Export ) Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠAccording Ġto Ġtech Ġspec Ġpersons Ġfirst Ġand Ġthen Ġlocations ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgrouped Person En counters [ date ] ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . sorted By Ġ{ ĠgetString To Sort By ( it . contact Di ary Person . fullName ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . map Ġ{ Ġit . get Export Info ( it . date ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . forEach Ġ{ Ġappend Line ( it ) Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġgrouped Location Vis its [ date ] ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . sorted By Ġ{ ĠgetString To Sort By ( it . contact Di ary Location . location Name ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . map Ġ{ Ġit . get Export Info ( it . date ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . forEach Ġ{ Ġappend Line ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠgetString To Sort By ( name : ĠString ) Ġ= Ġname . toLowerCase ( Locale . ROOT ) ĊĊĠĠĠ Ġprivate Ġfun ĠContact Di ary Person Encounter . get Export Info ( date : ĠLocalDate ) Ġ= ĠlistOf NotNull ( ĊĠĠĠĠĠĠĠ Ġdate . to Formatted String WithName ( contact Di ary Person . fullName ), ĊĠĠĠĠĠĠĠ Ġcontact Di ary Person . phoneNumber ?. let Ġ{ Ġget Phone With Prefix ( it ) Ġ}, ĊĠĠĠĠĠĠĠ Ġcontact Di ary Person . email Address ?. let Ġ{ Ġget EM ail With Prefix ( it ) Ġ}, ĊĠĠĠĠĠĠĠ Ġduration Classification ?. let Ġ{ Ġget Duration Classification String ( it ) Ġ}, ĊĠĠĠĠĠĠĠ Ġwith Mask ?. let Ġ{ Ġif Ġ( it ) Ġtext With Mask Ġelse Ġtext No Mask Ġ}, ĊĠĠĠĠĠĠĠ Ġwas Outside ?. let Ġ{ Ġif Ġ( it ) Ġtext Was Out do ors Ġelse Ġtext Was In door Ġ}, ĊĠĠĠĠĠĠĠ Ġcircumstances ĊĠĠĠ Ġ). join ToString ( separator Ġ= Ġ"; Ġ") ĊĊĠĠĠ Ġprivate Ġfun ĠContact Di ary Location Visit . get Export Info ( date : ĠLocalDate ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf NotNull ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdate . to Formatted String WithName ( contact Di ary Location . location Name ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontact Di ary Location . phoneNumber ?. let Ġ{ Ġget Phone With Prefix ( it ) Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcontact Di ary Location . email Address ?. let Ġ{ Ġget EM ail With Prefix ( it ) Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġduration ?. to Readable Duration ( duration Prefix , Ġduration Suffix ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcircumstances ĊĠĠĠĠĠĠĠ Ġ). join ToString ( separator Ġ= Ġ"; Ġ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠLocalDate . to Formatted String WithName ( name : ĠString ) Ġ= Ġ"${ to Formatted String ()} Ġ$ name " ĊĊĠĠĠ Ġprivate Ġfun Ġget Phone With Prefix ( phone : ĠString ) Ġ= Ġif Ġ( phone . isNotBlank ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġ"$ prefix Phone Ġ$ phone " ĊĠĠĠ Ġ} Ġelse Ġnull ĊĊĠĠĠ Ġprivate Ġfun Ġget EM ail With Prefix ( e Mail : ĠString ) Ġ= Ġif Ġ( e Mail . isNotBlank ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġ"$ prefix EM ail Ġ$ e Mail " ĊĠĠĠ Ġ} Ġelse Ġnull ĊĊĠĠĠ Ġprivate Ġfun Ġget Duration Classification String ( duration : ĠContact Di ary Person Encounter . Duration Classification ) Ġ= ĊĠĠĠĠĠĠĠ Ġwhen Ġ( duration ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠContact Di ary Person Encounter . Duration Classification . LESS _ THAN _ 1 5 _ MIN UTES Ġ-> Ġtext Duration LessThan 1 5 Min ĊĠĠĠĠĠĠĠĠĠĠĠ ĠContact Di ary Person Encounter . Duration Classification . MORE _ THAN _ 1 5 _ MIN UTES Ġ-> Ġtext Duration Long er Than 1 5 Min ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠAccording Ġto Ġtech Ġspec Ġger man Ġlocale Ġonly ĊĠĠĠ Ġprivate Ġfun ĠLocalDate . to Formatted String (): ĠString Ġ= ĠtoString (" dd . MM . yyyy ", ĠLocale . GER MAN ) Ċ } Ċ