Project

General

Profile

« Previous | Next » 

Revision 7fe62d1f

Added by Leszek Koltunski about 2 years ago

Download the icons only once and save to local storage.

View differences:

src/main/java/org/distorted/external/RubikNetwork.java
29 29
import java.security.MessageDigest;
30 30
import java.security.NoSuchAlgorithmException;
31 31

  
32
import android.content.Context;
32 33
import android.content.pm.PackageInfo;
33 34
import android.content.pm.PackageManager;
34 35
import android.graphics.Bitmap;
......
55 56

  
56 57
  public interface IconReceiver
57 58
    {
58
    void iconDownloaded(int ordinal, Bitmap bitmap);
59
    void iconDownloaded(int ordinal, Bitmap bitmap, boolean downloaded);
59 60
    }
60 61

  
61 62
  public interface Updatee
......
693 694

  
694 695
///////////////////////////////////////////////////////////////////////////////////////////////////
695 696

  
696
  private void iconThread(IconReceiver receiver)
697
  private void iconThread(Context context, IconReceiver receiver)
697 698
    {
698 699
    int numC = mUpdates.getCompletedNumber();
699 700
    int numS = mUpdates.getStartedNumber();
......
704 705

  
705 706
      if( iconPresent!=0 )
706 707
        {
707
        Bitmap icon = mUpdates.getCompletedIcon(c);
708
        boolean downloaded = false;
709
        Bitmap icon = mUpdates.getCompletedIcon(context,c);
708 710

  
709 711
        if( icon==null )
710 712
          {
711 713
          String url = mUpdates.getCompletedURL(c);
712 714
          icon = downloadIcon(url);
715
          downloaded = true;
713 716
          }
714 717
        if( icon!=null )
715 718
          {
716 719
          mUpdates.setCompletedIcon(c,icon);
717
          receiver.iconDownloaded(c,icon);
720
          receiver.iconDownloaded(c,icon,downloaded);
718 721
          }
719 722
        }
720 723
      }
......
725 728

  
726 729
      if( iconPresent!=0 )
727 730
        {
728
        Bitmap icon = mUpdates.getStartedIcon(s);
731
        boolean downloaded = false;
732
        Bitmap icon = mUpdates.getStartedIcon(context,s);
729 733

  
730 734
        if( icon==null )
731 735
          {
732 736
          String url = mUpdates.getStartedURL(s);
733 737
          icon = downloadIcon(url);
738
          downloaded = true;
734 739
          }
735 740
        if( icon!=null )
736 741
          {
737 742
          mUpdates.setStartedIcon(s,icon);
738
          receiver.iconDownloaded(numC+s,icon);
743
          receiver.iconDownloaded(numC+s,icon,downloaded);
739 744
          }
740 745
        }
741 746
      }
......
905 910

  
906 911
///////////////////////////////////////////////////////////////////////////////////////////////////
907 912

  
908
  public void downloadIcons(final IconReceiver receiver)
913
  public void downloadIcons(final Context context, final IconReceiver receiver)
909 914
    {
910 915
    initializeStatics();
911 916

  
......
913 918
      {
914 919
      public void run()
915 920
        {
916
        iconThread(receiver);
921
        iconThread(context,receiver);
917 922
        }
918 923
      };
919 924

  

Also available in: Unified diff