@@ -5,8 +5,6 @@ if (! Array.isArray(data.rows)) {
55 require ( "Storage" ) . writeJSON ( "mtnclock.json" , data ) ;
66}
77
8- let showingSettings = false ;
9- let clockinfosSettings = [ ] ;
108let clockinfosMain = { } ;
119let clockinfos = require ( "clock_info" ) . load ( ) ;
1210
@@ -236,7 +234,6 @@ function draw(color) {
236234}
237235
238236function setWeather ( ) {
239- if ( showingSettings ) return ;
240237 var a = { } ;
241238 //clear day/night is default weather
242239 if ( ( data . code >= 800 && data . code <= 802 ) || data . code == undefined ) {
@@ -398,60 +395,6 @@ global.GB = (event) => {
398395 if ( _GB ) setTimeout ( _GB , 0 , event ) ;
399396} ;
400397
401- function drawClkinfoSettings ( ) {
402- if ( drawTimeout ) clearTimeout ( drawTimeout ) ;
403- g . clear ( ) ;
404- g . setColor ( g . theme . fg ) ;
405- g . setFont ( "Vector" , py ( 10 ) ) . setFontAlign ( - 1 , - 1 ) . drawString ( "<Back" , px ( 2 ) , py ( 9 ) ) ;
406- g . drawRect ( 1 , 1 , px ( 33 ) , px ( 25 ) - 1 ) ;
407- g . setFont ( "Vector" , py ( 10 ) ) . setFontAlign ( 0 , - 1 ) . drawString ( "-" , px ( 50 ) , py ( 9 ) ) ;
408- g . drawRect ( px ( 33 ) , 1 , px ( 67 ) , px ( 25 ) - 1 ) ;
409- g . setFont ( "Vector" , py ( 10 ) ) . setFontAlign ( 0 , - 1 ) . drawString ( "+" , px ( 83 ) , py ( 9 ) ) ;
410- g . drawRect ( px ( 67 ) , 1 , px ( 100 ) - 1 , px ( 25 ) - 1 ) ;
411-
412- data . rows . forEach ( function ( row , r ) {
413- let a = row . menuA ;
414- let b = row . menuB ;
415- let ci = clockinfos [ a ] . items [ b ] ;
416- if ( clockinfosMain [ a ] && clockinfosMain [ a ] [ b ] ) {
417- clockinfosMain [ a ] [ b ] = false ;
418- ci . hide ( ) ;
419- ci . removeListener ( "redraw" , clockinfoRedraw ) ;
420- }
421- addClockinfo ( r )
422- } ) ;
423- clockinfosMain = { } ;
424- }
425-
426- function addClockinfo ( r ) {
427- let dr = data . rows [ r ] ;
428- // Check if the saved clockinfo indices still exist
429- let ma = ( dr && dr . menuA && clockinfos [ dr . menuA ] ) ? dr . menuA : 0 ;
430- let mb = ( ma && dr && dr . menuB && clockinfos [ ma ] . items [ dr . menuB ] ) ? dr . menuB : 0 ;
431- clockinfosSettings [ r ] = require ( "clock_info" ) . addInteractive ( clockinfos , {
432- x : 2 , y : py ( ( r + 1 ) * 25 ) + 1 , w : px ( 100 ) - 4 , h : py ( 25 ) - 2 ,
433- menuA : ma ,
434- menuB : mb ,
435- draw : ( itm , info , options ) => {
436- g . reset ( ) . clearRect ( options . x - 1 , options . y , options . x + options . w + 1 , options . y + options . h ) ;
437- if ( options . focus ) g . drawRect ( options . x - 1 , options . y , options . x + options . w + 1 , options . y + options . h ) ;
438- g . setFont ( "Vector" , py ( 10 ) ) . setFontAlign ( - 1 , 0 ) . drawString ( info . text , options . x , options . y + options . h / 2 ) ;
439- }
440- } ) ;
441- }
442-
443- function saveClockinfos ( ) {
444- data . rows = [ ] ;
445- clockinfosSettings . forEach ( function ( row , r ) {
446- data . rows [ r ] = {
447- menuA : row . menuA ,
448- menuB : row . menuB
449- }
450- row . remove ( ) ;
451- } ) ;
452- require ( "Storage" ) . writeJSON ( "mtnclock.json" , data ) ;
453- }
454-
455398var drawTimeout ;
456399var redrawTimeout ;
457400
@@ -477,41 +420,6 @@ function queueDraw() {
477420 } , 60000 - ( Date . now ( ) % 60000 ) ) ;
478421}
479422
480- function checkTouchBack ( xy ) {
481- return xy . x <= px ( 33 ) && xy . y < py ( 25 ) ;
482- }
483-
484- function checkTouchMinus ( xy ) {
485- return xy . x > px ( 33 ) && xy . x < px ( 67 ) && xy . y < px ( 25 ) ;
486- }
487-
488- function checkTouchPlus ( xy ) {
489- return xy . x >= px ( 67 ) && xy . y < px ( 25 ) ;
490- }
491-
492- Bangle . on ( 'touch' , function ( b , xy ) {
493- // Bangle.js 2 supports long touch (type 2)
494- // On other devices, any touch will show the settings
495- if ( ! showingSettings && ( xy . type == 2 || process . env . HWVERSION != 2 ) ) {
496- drawClkinfoSettings ( ) ;
497- showingSettings = true ;
498- } else if ( checkTouchBack ( xy ) ) {
499- showingSettings = false ;
500- saveClockinfos ( ) ;
501- queueDraw ( ) ;
502- // call setWeather after a timeout because for some reason a clockinfo
503- // can still draw for a little bit despite calling remove() on it
504- setTimeout ( setWeather , 100 ) ;
505- } else if ( checkTouchMinus ( xy ) && clockinfosSettings . length > 0 ) {
506- let cl = clockinfosSettings [ clockinfosSettings . length - 1 ] ;
507- cl . remove ( ) ;
508- g . reset ( ) . clearRect ( cl . x , cl . y , cl . x + cl . w - 2 , cl . y + cl . h - 1 ) ;
509- clockinfosSettings . pop ( ) ;
510- } else if ( checkTouchPlus ( xy ) && clockinfosSettings . length < 3 ) {
511- addClockinfo ( clockinfosSettings . length )
512- }
513- } ) ;
514-
515423queueDraw ( ) ;
516424readWeather ( ) ;
517425setWeather ( ) ;
0 commit comments