@@ -351,31 +351,29 @@ function showMessagesScroller(msg) {
351351 if ( scrollIdx > shownScrollIdxLast ) { shownScrollIdxLast = scrollIdx ; }
352352 } ,
353353 select : function ( scrollIdx , touch ) {
354- for ( let i = firstTitleLinePerMsg . length - 1 ; i >= 0 ; i -- ) {
355- if ( scrollIdx >= firstTitleLinePerMsg [ i ] ) {
356- if ( touch && touch . type === 2 ) { return ; }
357- const MSG_SELECTED = MESSAGES [ i ] ;
358- WU && WU . show ( ) ;
359- print ( process . memory ( ) ) ;
360- E . showScroller ( ) ;
361- print ( process . memory ( ) ) ;
362- updateReadMessages ( ) ;
363- delete titleLines , allLines ;
364- if ( touch && touch . type . back ) {
365- returnToMain ( ) ;
366- } else if ( ! touch || touch . type === 0 ) {
367- setTimeout ( ( ) => {
368- showMessageSettings ( MSG_SELECTED )
369- } , 0 ) ;
370- }
371- //print(touch)
372- if ( touch && touch . type . swipeLR ) {
373- //print("select swipe")
374- if ( touch . type . swipeLR > 0 && posHandler ) { posHandler ( MSG_SELECTED ) ; }
375- if ( touch . type . swipeLR < 0 && negHandler ) { negHandler ( MSG_SELECTED ) ; }
376- }
377- break ;
378- }
354+ if ( touch && touch . type === 2 ) { return ; }
355+ const MSG_SELECTED = findSelectedMsg ( scrollIdx ) ;
356+ WU && WU . show ( ) ;
357+
358+ print ( process . memory ( ) . free ) ;
359+ E . showScroller ( ) ;
360+ Bangle . removeListener ( "swipe" , Bangle . swipeHandler ) ;
361+ Bangle . removeListener ( "touch" , touchHandler ) ;
362+ print ( process . memory ( ) . free ) ;
363+ updateReadMessages ( ) ;
364+ delete titleLines , allLines ;
365+ if ( touch && touch . type . back ) {
366+ returnToMain ( ) ;
367+ } else if ( ! touch || touch . type === 0 ) {
368+ setTimeout ( ( ) => {
369+ showMessageSettings ( MSG_SELECTED )
370+ } , 0 ) ;
371+ }
372+ //print(touch)
373+ if ( touch && touch . type . swipeLR ) {
374+ //print("select swipe")
375+ if ( touch . type . swipeLR > 0 && posHandler ) { posHandler ( MSG_SELECTED ) ; }
376+ if ( touch . type . swipeLR < 0 && negHandler ) { negHandler ( MSG_SELECTED ) ; }
379377 }
380378 } ,
381379 back : function ( ) {
@@ -385,6 +383,15 @@ function showMessagesScroller(msg) {
385383 }
386384 } ) ;
387385
386+ // helper function for message selection
387+ let findSelectedMsg = function ( scrollIdx ) {
388+ for ( let i = firstTitleLinePerMsg . length - 1 ; i >= 0 ; i -- ) {
389+ if ( scrollIdx >= firstTitleLinePerMsg [ i ] ) {
390+ return MESSAGES [ i ] ;
391+ }
392+ }
393+ }
394+
388395 // Add an external back touch handler.
389396 let touchHandler = ( button , xy ) => {
390397 // if ((left side of Banlge 1 screen) || (top left corner of Bangle 2 screen))
0 commit comments