@@ -3,7 +3,7 @@ import dayjs from 'dayjs';
33import { App } from '../app' ;
44import { LastUpdated } from '../../models' ;
55import { SmartDisplayController } from '../../smart-display-controller' ;
6- import { StringHelper } from '../../helper' ;
6+ import { StringHelper , DrawHelper } from '../../helper' ;
77import { OpenWeatherMapService } from './services' ;
88import { CityWeatherData , CityWeatherSetting } from './models' ;
99
@@ -46,29 +46,37 @@ export class CityWeatherApp implements App {
4646 // refresh weather data
4747 this . _service
4848 . loadData ( )
49- . then ( data => {
49+ . then ( ( data ) => {
5050 console . log ( 'city weather' , data ) ;
5151 this . _data . value = data ;
5252 } )
53- . catch ( error =>
53+ . catch ( ( error ) =>
5454 console . error ( "can't load openweathermap data" , error )
5555 ) ;
5656 }
5757
5858 render ( ) : void {
59+ this . renderTemperature ( ) ;
60+
61+ DrawHelper . renderPixelProgress (
62+ this . controller ,
63+ this . calcCacheMinutesAge ( ) ,
64+ CityWeatherApp . MaxCacheMinutesAge
65+ ) ;
66+
67+ this . _wasRendered = true ;
68+ }
69+
70+ private renderTemperature ( ) : void {
5971 const temperature = StringHelper . roundToFixed (
6072 this . _data ?. value ?. temperature
6173 ) ;
6274
6375 this . controller . drawText ( {
6476 hexColor : '#4CFF00' ,
6577 text : `${ temperature } °` ,
66- position : { x : 7 , y : 1 }
78+ position : { x : 7 , y : 1 } ,
6779 } ) ;
68-
69- this . showCacheAgeProgressbar ( ) ;
70-
71- this . _wasRendered = true ;
7280 }
7381
7482 private calcCacheMinutesAge ( ) : number | null {
@@ -81,21 +89,4 @@ export class CityWeatherApp implements App {
8189
8290 return diffMinutes ;
8391 }
84-
85- private showCacheAgeProgressbar ( ) : void {
86- const cacheMinutesAge = this . calcCacheMinutesAge ( ) ;
87-
88- if ( cacheMinutesAge == null ) {
89- return ;
90- }
91-
92- const cacheAgePercent =
93- cacheMinutesAge / CityWeatherApp . MaxCacheMinutesAge ;
94- const xPosition = 2 + Math . round ( 26 * cacheAgePercent ) ;
95-
96- this . controller . drawPixel (
97- { x : xPosition , y : 7 } ,
98- '#A0A0A0'
99- ) ;
100- }
10192}
0 commit comments