@@ -274,6 +274,93 @@ function showMessageScroller(msg) {
274274 } ) ;
275275}
276276
277+ function showMessageScroller2 ( msg , initAtEndOfMsg ) {
278+
279+ cancelReloadTimeout ( ) ;
280+
281+ let msgIdx = MESSAGES . findIndex ( ( m ) => m . id == msg . id )
282+ //print("msgIdx",msgIdx);
283+
284+ let startIdx = Math . max ( msgIdx - 1 , 0 ) ;
285+ let endIdx = Math . min ( msgIdx + 2 , MESSAGES . length ) ;
286+
287+ active = "scroller" ;
288+ var bodyFont = fontBig ;
289+ g . setFont ( bodyFont ) ;
290+ var allLines = [ ] ;
291+ var titleLines = [ ] ;
292+ var j = MESSAGES . length - 1 ;
293+ var initScroll = 0 ;
294+ var messagesWrapped = [ ] ;
295+ for ( let j = startIdx ; j < endIdx ; j ++ ) {
296+ let msgLocal = MESSAGES [ j ] ;
297+ var lines = [ ] ;
298+ if ( msgLocal . title ) {
299+ lines = g . wrapString ( msgLocal . title , g . getWidth ( ) - 10 ) ;
300+ for ( let i = 0 ; i < lines . length ; i ++ ) {
301+ titleLines . push ( i + ( messagesWrapped [ 0 ] ?messagesWrapped [ 0 ] . length :0 ) + ( messagesWrapped [ 1 ] ?messagesWrapped [ 1 ] . length :0 ) ) ;
302+ }
303+ }
304+ var titleCnt = lines . length ;
305+ if ( titleCnt ) lines . push ( "" ) ; // add blank line after title
306+ lines = lines . concat ( g . wrapString ( msgLocal . body , g . getWidth ( ) - 10 ) , [ "------" ] ) ;
307+ messagesWrapped . push ( lines ) ;
308+ //print(lines);
309+ // allLines = allLines.concat(lines);
310+ } ;
311+ allLines . push ( "" ) ;
312+ allLines . push ( "" ) ;
313+ let allLines2 = [ ] ;
314+ for ( let i = 0 ; i < messagesWrapped . length ; i ++ ) {
315+ allLines2 = allLines2 . concat ( messagesWrapped [ i ] ) ;
316+ }
317+ initScroll = messagesWrapped [ 0 ] . length ;
318+ if ( msgIdx == 0 ) initScroll = 0 ;
319+ if ( ! ! initAtEndOfMsg ) {
320+ let i = msgIdx == 0 ?0 :1 ;
321+ initScroll += messagesWrapped [ i ] . length > 8 ?messagesWrapped [ i ] . length - 8 :0 ;
322+ }
323+
324+ //print(allLines);
325+ //print("titleLines:\n", titleLines);
326+ //print("allLines2:\n",allLines2);
327+ //print("messagesWrapped:\n",messagesWrapped);
328+
329+ E . showScroller ( {
330+ scroll : initScroll * g . getFontHeight ( ) ,
331+ h : g . getFontHeight ( ) , // height of each menu item in pixels
332+ c : allLines2 . length , // number of menu items
333+ // a function to draw a menu item
334+ draw : function ( idx , r ) {
335+ //print(idx); // FIXME: Remove this print.
336+ // FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12
337+ g . setBgColor ( titleLines . find ( ( e ) => e == idx ) !== undefined ? g . theme . bg2 : g . theme . bg ) .
338+ setColor ( titleLines . find ( ( e ) => e == idx ) !== undefined ? g . theme . fg2 : g . theme . fg ) .
339+ clearRect ( r . x , r . y , r . x + r . w , r . y + r . h ) ;
340+ g . setFont ( bodyFont ) . setFontAlign ( 0 , - 1 ) . drawString ( allLines2 [ idx ] , r . x + r . w / 2 , r . y ) ;
341+ if ( idx >= allLines2 . length - 1 && msgIdx < MESSAGES . length - 1 ) {
342+ setTimeout ( ( ) => {
343+ showMessageScroller2 ( MESSAGES [ msgIdx + 1 ] , true ) ;
344+ } , 50 )
345+ }
346+ if ( idx == 0 && msgIdx > 0 ) {
347+ setTimeout ( ( ) => {
348+ showMessageScroller2 ( MESSAGES [ msgIdx - 1 ] , false ) ;
349+ } , 50 )
350+ }
351+ } , select : function ( idx , touch ) {
352+ if ( touch . type == 0 ) {
353+ showMessage ( msg . id , true )
354+ }
355+ if ( touch . type == 2 ) {
356+ showMessageSettings ( msg )
357+ }
358+ //showMessage(msg.id, true);
359+ } ,
360+ back : ( ) => showMessage ( messages [ idx ] . id , true )
361+ } ) ;
362+ }
363+
277364function showMessagesScroller ( messages , offsetToMessageNumber ) {
278365 print ( messages ) ;
279366 cancelReloadTimeout ( ) ;
@@ -330,7 +417,7 @@ function showMessageSettings(msg) {
330417 } ;
331418
332419 if ( msg . id != "music" )
333- menu [ /*LANG*/ "View Message" ] = ( ) => showMessageScroller ( msg ) ;
420+ menu [ /*LANG*/ "View Message" ] = ( ) => showMessageScroller2 ( msg ) ;
334421
335422 if ( msg . reply && reply ) {
336423 menu [ /*LANG*/ "Reply" ] = ( ) => {
@@ -503,7 +590,7 @@ function showMessage(msgid, persist) {
503590 ] } ,
504591 { type :"txt" , font :bodyFont , label :body , fillx :1 , filly :1 , pad :2 , cb :( ) => {
505592 // allow tapping to show a larger version
506- showMessageScroller ( msg ) ;
593+ showMessageScroller2 ( msg ) ;
507594 } } ,
508595 { type :"h" , fillx :1 , c : footer }
509596 ] } , { back :goBack } ) ;
@@ -549,7 +636,8 @@ function checkMessages(options) {
549636 // If we have a new message, show it
550637 if ( ! options . ignoreUnread && newMessages . length ) {
551638 delete newMessages [ 0 ] . show ; // stop us getting stuck here if we're called a second time
552- showMessage ( newMessages [ 0 ] . id , false ) ;
639+ //showMessage(newMessages[0].id, false);
640+ showMessageScroller2 ( MESSAGES [ 2 ] , false ) ;
553641 // buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
554642 if ( global . BUZZ_ON_NEW_MESSAGE ) {
555643 // this is set if we entered the messages app by loading `messagegui.new.js`
@@ -664,6 +752,6 @@ Bangle.on('lock',locked => {
664752 require ( "messages" ) . stopBuzz ( ) ;
665753} ) ;
666754
667- setTimeout ( ( ) => {
668- showMessagesScroller ( MESSAGES ) ;
669- } , 11 ) ;
755+ // setTimeout(() => {
756+ // showMessageScroller2 (MESSAGES[2], false );
757+ // }, 11);
0 commit comments