package Ġmy . ch aster . extension . fitness . step sper period Ċ Ċ import Ġcom . vaadin . flow . component . Text Ċ import Ġcom . vaadin . flow . component . UI Ċ import Ġcom . vaadin . flow . component . button . Button Ċ import Ġcom . vaadin . flow . component . ordered layout . Flex Component Ċ import Ġcom . vaadin . flow . component . ordered layout . Horizontal Layout Ċ import Ġcom . vaadin . flow . component . ordered layout . Vertical Layout Ċ import Ġcom . vaadin . flow . component . text field . IntegerField Ċ import Ġcom . vaadin . flow . router . Before Enter Event Ċ import Ġcom . vaadin . flow . router . Before Enter Observer Ċ import Ġcom . vaadin . flow . router . Page Title Ċ import Ġcom . vaadin . flow . router . Route Ċ import Ġcom . vaadin . flow . server . V aad in Session Ċ import Ġmy . ch aster . extension . fitness . step sper period . work around . config . Steps Per Period Config Ċ import Ġmy . ch aster . extension . fitness . step sper period . work around . config . Steps Per Period Config Repository Ċ import Ġmy . ch aster . fitness . Google Fitness Service Ċ import Ġmy . ch aster . views . Main Layout Ċ import Ġmy . ch aster . views . Notification Ext Ċ import Ġmy . ch aster . views . get Ch aster Lock Id Ċ import Ġjava . time . Duration Ċ Ċ @ Route ( value Ġ= ĠSteps Per Period Config View . ROUTE , Ġlayout Ġ= ĠMain Layout :: class ) Ċ @ Page Title (" Steps ĠPer ĠPeriod ĠConfig ") Ċ class ĠSteps Per Period Config View ( Ċ ĉ private Ġval Ġgoogle Fitness Service : ĠGoogle Fitness Service , Ċ ĉ private Ġval Ġsteps Per Period Service : ĠSteps Per Period Service , Ċ ĉ private Ġval Ġsteps Per Period Config Repository : ĠSteps Per Period Config Repository , Ċ ) Ġ: ĠVertical Layout (), ĠBefore Enter Observer Ġ{ ĊĊ ĉ private Ġval Ġperiod Field : ĠInteger Field Ċ ĉ private Ġval Ġrequired Steps Field : ĠInteger Field Ċ ĉ private Ġval Ġpenalty Field : ĠInteger Field ĊĊ ĉ init Ġ{ Ċĉ ĉ add ClassName (" steps - per - period - config - view ") Ċĉ ĉ default Horizontal Component Alignment Ġ= ĠFlex Component . Alignment . CENTER ĊĊĉ ĉ period Field Ġ= Ġcreate IntegerField ( Ċĉĉ ĉ " Period Ġin Ġhours ", Ċĉĉ ĉ min Ġ= Ġ 1 , Ċĉĉ ĉ max Ġ= Ġ 9 9 9 , Ċĉĉ ĉ default Ġ= Ġ 2 4 , Ċĉ ĉ ) Ċĉ ĉ required Steps Field Ġ= Ġcreate IntegerField ( Ċĉĉ ĉ " Required ĠSteps Ġper ĠPeriod ", Ċĉĉ ĉ min Ġ= Ġ 1 0 0 , Ċĉĉ ĉ max Ġ= Ġ 1 0 _ 0 0 0 _ 0 0 0 , Ċĉĉ ĉ step Ġ= Ġ 1 0 0 , Ċĉĉ ĉ default Ġ= Ġ 5 0 0 0 , Ċĉ ĉ ) Ċĉ ĉ penalty Field Ġ= Ġcreate IntegerField ( Ċĉĉ ĉ " Pen alty Ġin Ġhours ", Ċĉĉ ĉ min Ġ= Ġ 1 , Ċĉĉ ĉ max Ġ= Ġ 9 9 9 , Ċĉĉ ĉ default Ġ= Ġ 6 , Ċĉ ĉ ) Ċĉ ĉ add ( Horizontal Layout ( period Field , Ġrequired Steps Field , Ġpenalty Field )) ĊĊĉ ĉ val Ġsave Button Ġ= ĠButton (" Save ") Ċĉ ĉ save Button . add ClickListener Ġ{ Ġsave Config () Ġ} Ċĉ ĉ add ( save Button ) ĊĊĉ ĉ add ( Text (" You Ġwill Ġnot Ġbe Ġable Ġto Ġchange Ġthe Ġconfiguration Ġafter Ġyou Ġsaved Ġit . ĠS aving Ġthe Ġconfiguration Ġwill Ġforward Ġyou Ġto Ġthe Ġoverview Ġof Ġyour Ġcurrent Ġlock . ĠIt Ġmay Ġrequire Ġa Ġgoogle Ġauthentication Ġfirst Ġso Ġthat Ġyour Ġsteps Ġcan Ġget Ġtracked .")) Ċ ĉ } ĊĊ ĉ override Ġfun Ġbefore Enter ( event : ĠBefore Enter Event ) Ġ{ Ċĉ ĉ val Ġexisting Config Ġ= Ġsteps Per Period Config Repository . findBy Ch aster Lock Id ( V aad in Session . getCurrent (). get Ch aster Lock Id ()) Ċĉ ĉ if Ġ( existing Config Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ event . forward To ( Steps Per Period View :: class . java ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġcreate IntegerField ( label : ĠString , Ġmin : ĠInt , Ġmax : ĠInt , Ġdefault : ĠInt , Ġstep : ĠInt Ġ= Ġ 1 ): ĠInteger Field Ġ{ Ċĉ ĉ val Ġinteger Field Ġ= ĠInteger Field ( label ) Ċĉ ĉ integer Field . set Has Controls ( true ) Ċĉ ĉ integer Field . min Ġ= Ġmin Ċĉ ĉ integer Field . max Ġ= Ġmax Ċĉ ĉ integer Field . step Ġ= Ġstep Ċĉ ĉ integer Field . value Ġ= Ġdefault Ċĉ ĉ integer Field . width Ġ= Ġ" 1 0 em " Ċĉ ĉ integer Field . add Value ChangeListener Ġ{ Ġif Ġ( it . hasValue . isEmpty ) Ġit . source . is Invalid Ġ= Ġtrue Ġ} ĊĊĉ ĉ return Ġinteger Field Ċ ĉ } ĊĊ ĉ private Ġfun Ġsave Config () Ġ{ Ċĉ ĉ if Ġ( period Field . is Invalid Ġ|| Ġrequired Steps Field . is Invalid Ġ|| Ġpenalty Field . is Invalid ) Ġ{ Ċĉĉ ĉ Notification Ext . error (" Input Ġis Ġinvalid ") Ċĉĉ ĉ return Ċĉ ĉ } ĊĊĉ ĉ steps Per Period Config Repository . save ( Ċĉĉ ĉ Steps Per Period Config ( Ċĉĉĉ ĉ V aad in Session . getCurrent (). get Ch aster Lock Id (), Ċĉĉĉ ĉ Duration . of Hours ( period Field . value . to Long ()), Ċĉĉĉ ĉ required Steps Field . value , Ċĉĉĉ ĉ Duration . of Hours ( penalty Field . value . to Long ()), Ċĉĉ ĉ ), Ċĉ ĉ ) ĊĊĉ ĉ UI . getCurrent (). navigate ( Steps Per Period View :: class . java ) Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ const Ġval ĠROUT E Ġ= Ġ" steps - per - period - config " Ċ ĉ } Ċ }