@@ -2643,7 +2643,8 @@ class uniList {
2643
2643
char * m_name = NULL ;
2644
2644
char * m_buff = NULL ;
2645
2645
char * m_txt[10 ] = {0 };
2646
- char * m_ext[10 ] = {0 };
2646
+ char * m_ext1[10 ] = {0 };
2647
+ char * m_ext2[10 ] = {0 };
2647
2648
bool m_enabled = false ;
2648
2649
2649
2650
public:
@@ -2655,7 +2656,7 @@ class uniList {
2655
2656
~uniList (){
2656
2657
if (m_name){free (m_name); m_name = NULL ;}
2657
2658
if (m_buff){free (m_buff); m_buff = NULL ;}
2658
- for (int i = 0 ; i < 10 ; i++){if (m_txt[i]) free (m_txt[i]); if (m_ext [i]) free (m_ext [i]);}
2659
+ for (int i = 0 ; i < 10 ; i++){if (m_txt[i]) free (m_txt[i]); if (m_ext1 [i]) free (m_ext1[i]); if (m_ext2[i]) free (m_ext2 [i]);}
2659
2660
}
2660
2661
void begin (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fontSize){
2661
2662
m_x = x; // x pos
@@ -2669,26 +2670,39 @@ class uniList {
2669
2670
}
2670
2671
void setMode (uint8_t mode){
2671
2672
if (mode == RADIO) {m_mode = RADIO; m_insert = 10 ;}
2672
- if (mode == PLAYER) m_mode = PLAYER;
2673
- if (mode == DLNA) m_mode = DLNA;
2673
+ if (mode == PLAYER) m_mode = PLAYER;
2674
+ if (mode == DLNA) { m_mode = DLNA; m_insert = 10 ;}
2674
2675
}
2675
2676
void clearList (){
2676
2677
tft.fillRect (m_x, m_y, m_w, m_h, m_bgColor);
2677
2678
for (int i = 0 ; i < 10 ; i++){
2678
- free (m_txt[i]); m_txt[i] = strdup (" " );
2679
- free (m_ext[i]); m_ext[i] = strdup (" " );
2679
+ free (m_txt[i]); m_txt[i] = NULL ;
2680
+ free (m_ext1[i]); m_ext1[i] = NULL ;
2681
+ free (m_ext2[i]); m_ext2[i] = NULL ;
2680
2682
m_nr[i] = -1 ;
2681
2683
}
2682
2684
}
2683
- void drawLine (uint8_t pos, const char * txt, const char * ext , const char * color = ANSI_ESC_WHITE, int16_t nr = -1 ){
2685
+ void drawLine (uint8_t pos, const char * txt, const char * ext1 = NULL , const char * ext2 = NULL , const char * color = ANSI_ESC_WHITE, int16_t nr = -1 ){
2684
2686
if (pos > 9 ) return ;
2687
+ if (!txt) return ;
2685
2688
tft.setFont (m_fontSize);
2686
2689
if (m_mode == RADIO){
2687
2690
sprintf (m_buff, ANSI_ESC_YELLOW " %03d %s%s" , nr, color, txt);
2688
- if (txt){free (m_txt[pos]); m_txt[pos] = strdup (txt);}
2689
- if (ext){free (m_ext[pos]); m_ext[pos] = strdup (ext);}
2691
+ if (txt ){free (m_txt[pos]); m_txt[pos] = strdup (txt);}
2692
+ if (ext1){free (m_ext1[pos]); m_ext1[pos] = strdup (ext1);}
2693
+ if (ext2){free (m_ext2[pos]); m_ext2[pos] = strdup (ext2);}
2690
2694
m_nr[pos] = nr;
2691
2695
}
2696
+ if (m_mode == DLNA){
2697
+ if (!txt) {log_e (" txt is NULL" ); return ;}
2698
+ if (!ext1) sprintf (m_buff, " %s%s" , color, txt);
2699
+ else if (ext1[0 ] == ' \0 ' ) sprintf (m_buff, " %s%s" , color, txt);
2700
+ else sprintf (m_buff, " %s%s " ANSI_ESC_CYAN " (%s)" , color, txt, ext1);
2701
+ m_insert = pos? 20 : 10 ;
2702
+ if (txt) {free (m_txt[pos]); m_txt[pos] = strdup (txt); m_nr[pos] = 1 ;}
2703
+ if (ext1){free (m_ext1[pos]); m_ext1[pos] = strdup (ext1);}
2704
+ if (ext2){free (m_ext2[pos]); m_ext2[pos] = strdup (ext2);}
2705
+ }
2692
2706
tft.writeText (m_buff, m_insert, m_y + pos *m_lineHight, m_w - 10 , m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true , true );
2693
2707
}
2694
2708
void colourLine (uint8_t pos, const char * color = ANSI_ESC_WHITE) {
@@ -2705,6 +2719,15 @@ class uniList {
2705
2719
int16_t getNumberByPos (uint8_t pos){
2706
2720
return m_nr[pos];
2707
2721
}
2722
+ void drawTriangeUp (){
2723
+ auto triangleUp = [&](int16_t x, int16_t y, uint8_t s) { tft.fillTriangle (x + s, y + 0 , x + 0 , y + 2 * s, x + 2 * s, y + 2 * s, TFT_RED); };
2724
+ triangleUp (0 , m_y + (1 * m_lineHight), m_lineHight / 3.5 );
2725
+ }
2726
+ void drawTriangeDown (){
2727
+ auto triangleDown = [&](int16_t x, int16_t y, uint8_t s) { tft.fillTriangle (x + 0 , y + 0 , x + 2 * s, y + 0 , x + s, y + 2 * s, TFT_RED); };
2728
+ triangleDown (0 , m_y + (9 * m_lineHight), m_lineHight / 3.5 );
2729
+ }
2730
+
2708
2731
};
2709
2732
extern uniList myList;
2710
2733
// ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
@@ -2746,6 +2769,8 @@ class dlnaList : public RegisterTable {
2746
2769
bool m_enabled = false ;
2747
2770
bool m_clicked = false ;
2748
2771
bool m_state = false ;
2772
+ bool m_isAudio = false ;
2773
+ bool m_isURL = false ;
2749
2774
char * m_name = NULL ;
2750
2775
char * m_pathBuff = NULL ;
2751
2776
char * m_chptr = NULL ;
@@ -2853,18 +2878,15 @@ class dlnaList : public RegisterTable {
2853
2878
private:
2854
2879
void dlnaItemsList (){
2855
2880
uint8_t pos = 0 ;
2856
-
2857
- auto triangleUp = [&](int16_t x, int16_t y, uint8_t s) { tft.fillTriangle (x + s, y + 0 , x + 0 , y + 2 * s, x + 2 * s, y + 2 * s, TFT_RED); };
2858
- auto triangleDown = [&](int16_t x, int16_t y, uint8_t s) { tft.fillTriangle (x + 0 , y + 0 , x + 2 * s, y + 0 , x + s, y + 2 * s, TFT_RED); };
2859
-
2860
- tft.fillRect (m_x, m_y, m_w, m_h, m_bgColor);
2861
- tft.setFont (m_fontSize);
2862
- tft.setTextColor (TFT_ORANGE);
2863
- tft.writeText (m_dlnaHistory[*m_dlnaLevel].name , 10 , m_y, m_w - 10 , m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true , true );
2881
+ myList.setMode (DLNA);
2882
+ myList.clearList ();
2883
+ myList.drawLine (0 , m_dlnaHistory[*m_dlnaLevel].name , NULL , ANSI_ESC_ORANGE);
2864
2884
tft.setTextColor (TFT_WHITE);
2865
2885
for (pos = 1 ; pos < 10 ; pos++) {
2866
- if (pos == 1 && m_viewPoint > 0 ) { triangleUp (0 , m_y + (pos * m_lineHight), m_lineHight / 3.5 ); }
2867
- if (pos == 9 && m_viewPoint + 9 < m_dlnaMaxItems - 1 ) { triangleDown (0 , m_y + (pos * m_lineHight), m_lineHight / 3.5 ); }
2886
+ if (pos == 1 && m_viewPoint > 0 ) { myList.drawTriangeUp ();}
2887
+ if (pos == 9 && m_viewPoint + 9 < m_dlnaMaxItems - 1 ) { myList.drawTriangeDown ();}
2888
+ if (*m_dlnaLevel == 0 && pos > m_dlnaServer.size ) {/* log_e("pos too high %i", pos);*/ break ;} // guard
2889
+ if (*m_dlnaLevel > 0 && pos > m_srvContent.size ) {/* log_e("pos too high %i", pos);*/ break ;} // guard
2868
2890
drawItem (pos);
2869
2891
}
2870
2892
sprintf (m_buff, " %i-%i/%i" , m_viewPoint + 1 , m_viewPoint + (pos - 1 ), m_dlnaMaxItems); // shows the current items pos e.g. "30-39/210"
@@ -2878,32 +2900,40 @@ class dlnaList : public RegisterTable {
2878
2900
if (pos < 0 || pos > 9 ) {log_e (" pos oor %i" , pos); return ;} // guard
2879
2901
if (*m_dlnaLevel == 0 && pos > m_dlnaServer.size ) {/* log_e("pos too high %i", pos);*/ return ;} // guard
2880
2902
if (*m_dlnaLevel > 0 && pos > m_srvContent.size ) {/* log_e("pos too high %i", pos);*/ return ;} // guard
2903
+ char extension[15 ] = {0 };
2904
+ char dummy[] = " " ;
2881
2905
bool isAudio = false ;
2882
2906
bool isURL = false ;
2883
- const char * item = NULL ; char * duration = NULL ; const char * itemURL = NULL ; (void )itemURL;
2884
- char color[20 ];
2885
- uint16_t posX = m_x + 20 , posY = m_y + pos * m_lineHight, width = m_w - 20 , height = m_lineHight;
2907
+ const char *item = dummy, *duration = dummy, *itemURL = dummy, *color = ANSI_ESC_WHITE; (void )itemURL;
2886
2908
int32_t itemSize = 0 ;
2887
2909
int16_t childCount = 0 ;
2888
- tft.setFont (m_fontSize);
2889
2910
if (pos == 0 ){
2890
- if (pos + m_viewPoint == m_currItemNr[*m_dlnaLevel] + 1 ) strcpy (color, ANSI_ESC_MAGENTA); else strcpy (color, ANSI_ESC_ORANGE);
2891
- if (selectedLine) strcpy (color, ANSI_ESC_CYAN);
2892
- sprintf (m_buff, " %s%s" , color, m_dlnaHistory[*m_dlnaLevel].name );
2893
- tft.writeText (m_buff, 10 , posY , m_w - 10 , m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true , true );
2911
+ if (pos + m_viewPoint == m_currItemNr[*m_dlnaLevel] + 1 ) color = ANSI_ESC_MAGENTA; else color = ANSI_ESC_ORANGE;
2912
+ if (selectedLine) color = ANSI_ESC_CYAN;
2913
+ myList.drawLine (pos, m_dlnaHistory[*m_dlnaLevel].name , " " , " " , color, 1 );
2894
2914
return ;
2895
2915
}
2896
- if (*m_dlnaLevel == 0 ) {item = m_dlnaServer.friendlyName [pos - 1 ];}
2897
- else { item = m_srvContent.title [pos - 1 ]; itemSize = m_srvContent.itemSize [pos - 1 ]; childCount = m_srvContent.childCount [pos -1 ]; duration = m_srvContent.duration [pos - 1 ];
2898
- itemURL = m_srvContent.itemURL [pos -1 ]; isAudio = m_srvContent.isAudio [pos - 1 ]; if (startsWith (m_srvContent.itemURL [pos -1 ], " http" )) isURL = true ;}
2916
+ if (*m_dlnaLevel == 0 ) {
2917
+ if (m_dlnaServer.friendlyName [pos - 1 ]) item = m_dlnaServer.friendlyName [pos - 1 ];
2918
+ }
2919
+ else {
2920
+ if (m_srvContent.title [pos - 1 ]) item = m_srvContent.title [pos - 1 ];
2921
+ itemSize = m_srvContent.itemSize [pos - 1 ];
2922
+ childCount = m_srvContent.childCount [pos -1 ];
2923
+ if (m_srvContent.duration [pos - 1 ]) duration = m_srvContent.duration [pos - 1 ];
2924
+ isAudio = m_srvContent.isAudio [pos - 1 ];
2925
+ if (startsWith (m_srvContent.itemURL [pos -1 ], " http" )) {isURL = true ; itemURL = m_srvContent.itemURL [pos -1 ];}
2926
+ }
2899
2927
2900
- if ((pos - 1 ) + m_viewPoint == m_currItemNr[*m_dlnaLevel]) {strcpy (color, ANSI_ESC_MAGENTA);} else if (isURL && isAudio) {strcpy (color, ANSI_ESC_YELLOW);} else {strcpy (color, ANSI_ESC_WHITE);}
2901
- if (selectedLine) strcpy (color, ANSI_ESC_CYAN);
2902
- sprintf (m_buff, " %s%s" , color, item);
2903
- if (childCount) sprintf (m_buff + strlen (m_buff), ANSI_ESC_CYAN " (%i)" , childCount);
2904
- if (isURL && isAudio) {if (strcmp (duration, " 0:00:00" ) == 0 ) sprintf (m_buff + strlen (m_buff), ANSI_ESC_CYAN " (%li)" , itemSize); else sprintf (m_buff + strlen (m_buff), ANSI_ESC_CYAN " (%s)" , duration);}
2905
- if (isURL && !isAudio) sprintf (m_buff + strlen (m_buff), ANSI_ESC_CYAN " (%li)" , itemSize);
2906
- tft.writeText (m_buff, posX, posY, width, height, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true , true );
2928
+ if ((pos - 1 ) + m_viewPoint == m_currItemNr[*m_dlnaLevel]){ color = ANSI_ESC_MAGENTA;}
2929
+ else if (isURL && isAudio) { color = ANSI_ESC_YELLOW;}
2930
+ else { color = ANSI_ESC_WHITE;}
2931
+ if (selectedLine) { color = ANSI_ESC_CYAN;}
2932
+
2933
+ if (childCount) {sprintf (extension, " %i" , childCount);}
2934
+ if (itemSize) {sprintf (extension, " %li" , itemSize);}
2935
+ if (duration[0 ] != ' ?' ){if (strcmp (duration, " 0:00:00" ) != 0 ) sprintf (extension, " %s" , duration);}
2936
+ myList.drawLine (pos, item, extension, itemURL, color, 1 );
2907
2937
}
2908
2938
2909
2939
void hasReleased (uint16_t x, uint16_t y){
@@ -3134,6 +3164,10 @@ class dlnaList : public RegisterTable {
3134
3164
m_dlnaHistory[*m_dlnaLevel].maxItems = m_dlnaMaxItems;
3135
3165
// log_e("m_dlnaMaxItems %i, level %i", m_dlnaMaxItems, (*m_dlnaLevel)); // level 2, 3, 4...
3136
3166
dlnaItemsList ();
3167
+ if (!m_dlnaMaxItems) { // folder is empty
3168
+ m_currItemNr[*m_dlnaLevel]--;
3169
+ drawItem (m_currItemNr[*m_dlnaLevel] + 0 - m_viewPoint + 1 ); // make magenta
3170
+ }
3137
3171
return NULL ;
3138
3172
}
3139
3173
if (startsWith (m_srvContent.itemURL [m_currItemNr[*m_dlnaLevel] - m_viewPoint], " http" ) != 0 ){ // ---------------------------------- choose file
@@ -3680,7 +3714,7 @@ class stationsList : public RegisterTable {
3680
3714
3681
3715
m_staNameToDraw = staMgnt.getStationName (pos + m_firstStationsLineNr + 1 ); // the station name
3682
3716
m_staNrToDraw = pos + m_firstStationsLineNr + 1 ; // the station number
3683
- myList.drawLine (pos, m_staNameToDraw, " " , m_colorToDraw, m_staNrToDraw);
3717
+ myList.drawLine (pos, m_staNameToDraw, NULL , NULL , m_colorToDraw, m_staNrToDraw);
3684
3718
}
3685
3719
xSemaphoreGive (mutex_display);
3686
3720
}
0 commit comments