11package com .alleit .alleinfo ;
22
3+ import java .util .Arrays ;
34import java .util .Calendar ;
5+ import java .util .List ;
46import java .util .Locale ;
57
68import com .actionbarsherlock .app .ActionBar ;
@@ -330,52 +332,65 @@ private void makeNewsSub() {
330332 rubrik .setText (listData [0 ].headline );
331333 info .setText (listData [0 ].description );
332334 desc .setText (listData [0 ].longDescription );
333-
334- if (listData [0 ].handler .contains (Html .fromHtml (Karlista .Ename ). toString (). toUpperCase ( Locale . ENGLISH )) )
335- {
335+
336+ if (listData [0 ].handler .contains (Html .fromHtml (Karlista .Ename )
337+ . toString (). toUpperCase ( Locale . ENGLISH ))) {
336338 Pic .setImageDrawable (getResources ().getDrawable (
337339 R .drawable .elevkaren ));
338340 separator .setBackgroundColor (Color .parseColor (Karlista .Ecolor ));
339- } else if (listData [0 ].handler .contains (Html .fromHtml (Karlista .PRname ).toString ().toUpperCase (Locale .ENGLISH )))
340- {
341- Pic .setImageDrawable (getResources ().getDrawable (
342- R .drawable .pr ));
343- separator .setBackgroundColor (Color .parseColor (Karlista .PRcolor ));
344-
345- } else if (listData [0 ].handler .contains (Html .fromHtml (Karlista .Fname ).toString ().toUpperCase (Locale .ENGLISH )))
346- {
341+ } else if (listData [0 ].handler .contains (Html
342+ .fromHtml (Karlista .PRname ).toString ()
343+ .toUpperCase (Locale .ENGLISH ))) {
344+ Pic .setImageDrawable (getResources ().getDrawable (R .drawable .pr ));
345+ separator
346+ .setBackgroundColor (Color .parseColor (Karlista .PRcolor ));
347+
348+ } else if (listData [0 ].handler .contains (Html
349+ .fromHtml (Karlista .Fname ).toString ()
350+ .toUpperCase (Locale .ENGLISH ))) {
347351 Pic .setImageDrawable (getResources ().getDrawable (
348352 R .drawable .festare ));
349353 separator .setBackgroundColor (Color .parseColor (Karlista .Fcolor ));
350-
351- } else if (listData [0 ].handler .contains (Html .fromHtml (Karlista .spexname ).toString ().toUpperCase (Locale .ENGLISH )))
352- {
353- Pic .setImageDrawable (getResources ().getDrawable (
354- R .drawable .spex ));
355- separator .setBackgroundColor (Color .parseColor (Karlista .spexcolor ));
356-
357- } else if (listData [0 ].handler .contains (Html .fromHtml (Karlista .IFname ).toString ().toUpperCase (Locale .ENGLISH )))
358- {
354+
355+ } else if (listData [0 ].handler .contains (Html
356+ .fromHtml (Karlista .spexname ).toString ()
357+ .toUpperCase (Locale .ENGLISH ))) {
358+ Pic .setImageDrawable (getResources ()
359+ .getDrawable (R .drawable .spex ));
360+ separator .setBackgroundColor (Color
361+ .parseColor (Karlista .spexcolor ));
362+
363+ } else if (listData [0 ].handler .contains (Html
364+ .fromHtml (Karlista .IFname ).toString ()
365+ .toUpperCase (Locale .ENGLISH ))) {
359366 Pic .setImageDrawable (getResources ().getDrawable (
360367 R .drawable .skolif ));
361- separator .setBackgroundColor (Color .parseColor (Karlista .IFcolor ));
362-
363- } else if (listData [0 ].handler .contains (Html .fromHtml (Karlista .ITname ).toString ().toUpperCase (Locale .ENGLISH )))
364- {
368+ separator
369+ .setBackgroundColor (Color .parseColor (Karlista .IFcolor ));
370+
371+ } else if (listData [0 ].handler .contains (Html
372+ .fromHtml (Karlista .ITname ).toString ()
373+ .toUpperCase (Locale .ENGLISH ))) {
365374 Pic .setImageDrawable (getResources ().getDrawable (
366375 R .drawable .alleit ));
367- separator .setBackgroundColor (Color .parseColor (Karlista .ITcolor ));
368-
376+ separator
377+ .setBackgroundColor (Color .parseColor (Karlista .ITcolor ));
378+
369379 } else {
370- Toast .makeText (getApplicationContext (), Html .fromHtml ("Nyheten kunde inte läsas in" ), Toast .LENGTH_SHORT ).show ();
371- makeNews ();
380+ Toast .makeText (getApplicationContext (),
381+ Html .fromHtml ("Ingen ansvarig elevförening kunde hittas" ),
382+ Toast .LENGTH_SHORT ).show ();
372383 }
373384
374-
375385 but .setText ("Mer info" );
376386
377387 String url = listData [0 ].butURL ;
378388
389+ if (url .length () == 0 )
390+ {
391+ but .setVisibility (View .INVISIBLE );
392+ }
393+
379394 final String finURL = url ;
380395
381396 but .setOnClickListener (new OnClickListener () {
@@ -608,12 +623,22 @@ private void prepFeed() {
608623 @ Override
609624 public void run () {
610625
611- listData = Webber .getTinyNewsFeed ();
626+ List <NewsInfo > temp = Arrays .asList (Webber .getTinyNewsFeed ());
627+
628+ if (temp .isEmpty ()) {
629+ listData = new NewsInfo [0 ];
630+ } else {
631+ int i = 0 ;
632+ listData = new NewsInfo [temp .size ()];
633+ for (NewsInfo NI : temp ) {
634+ listData [i ] = NI ;
635+ i ++;
636+ }
637+ }
612638
613639 runOnUiThread (new Runnable () {
614640 public void run () {
615- if (listData .length == 0 )
616- {
641+ if (listData .length == 0 ) {
617642 listData = new NewsInfo [1 ];
618643 listData [0 ] = new NewsInfo ();
619644 listData [0 ].headline = "Inga nyheter hittades" ;
@@ -636,7 +661,7 @@ public void onItemClick(AdapterView<?> parent, View view,
636661 if (listData [position ].contentType == 1 ) {
637662 makeNews ();
638663 } else {
639- if (listData [position ].contentType != -1 )
664+ if (listData [position ].contentType != -1 )
640665 ShowSpecNews (listData [position ].uniqeIdentifier );
641666 }
642667 }
@@ -648,12 +673,23 @@ public void onItemClick(AdapterView<?> parent, View view,
648673 @ Override
649674 public void run () {
650675
651- listData = Webber .getNews ("" , Mode .All );
676+ List <NewsInfo > temp = Arrays .asList (Webber .getNews ("" ,
677+ Mode .All ));
678+
679+ if (temp .isEmpty ()) {
680+ listData = new NewsInfo [0 ];
681+ } else {
682+ int i = 0 ;
683+ listData = new NewsInfo [temp .size ()];
684+ for (NewsInfo NI : temp ) {
685+ listData [i ] = NI ;
686+ i ++;
687+ }
688+ }
652689
653690 runOnUiThread (new Runnable () {
654691 public void run () {
655- if (listData .length == 0 )
656- {
692+ if (listData .length == 0 ) {
657693 listData = new NewsInfo [1 ];
658694 listData [0 ] = new NewsInfo ();
659695 listData [0 ].headline = "Inga nyheter hittades" ;
@@ -689,7 +725,19 @@ private void ShowSpecNews(final String uniqeIdentifier) {
689725 @ Override
690726 public void run () {
691727
692- listData = Webber .getNews (uniqeIdentifier , Mode .Specific );
728+ List <NewsInfo > temp = Arrays .asList (Webber .getNews (
729+ uniqeIdentifier , Mode .Specific ));
730+
731+ if (temp .isEmpty ()) {
732+ listData = new NewsInfo [0 ];
733+ } else {
734+ int i = 0 ;
735+ listData = new NewsInfo [temp .size ()];
736+ for (NewsInfo NI : temp ) {
737+ listData [i ] = NI ;
738+ i ++;
739+ }
740+ }
693741
694742 runOnUiThread (new Runnable () {
695743 public void run () {
@@ -698,7 +746,7 @@ public void run() {
698746 } else {
699747 Toast .makeText (
700748 getApplicationContext (),
701- Html .fromHtml ("Nyheten kunde inte hittas.<br>Laddar om " ),
749+ Html .fromHtml ("Nyheten kunde inte hittas." ),
702750 Toast .LENGTH_SHORT ).show ();
703751 prepFeed ();
704752 }
0 commit comments