Project

General

Profile

« Previous | Next » 

Revision d8aa4ba8

Added by Leszek Koltunski over 4 years ago

Downloading High Scores: optimizations

View differences:

src/main/java/org/distorted/magic/RubikScoresViewPager.java
45 45

  
46 46
///////////////////////////////////////////////////////////////////////////////////////////////////
47 47

  
48
  public void receive(final String scores)
48
  public void receive(final String[][][][] scores)
49 49
    {
50 50
    mAct.runOnUiThread(new Runnable()
51 51
      {
......
54 54
        {
55 55
        for(int i=0; i<RubikSize.LENGTH; i++)
56 56
          {
57
          mViews[i].prepareView(mAct);
58
          }
59

  
60
        int begin=-1 ,end, len = scores.length();
61

  
62
        while( begin<len )
63
          {
64
          end = scores.indexOf('\n', begin+1);
65
          if( end<0 ) end = len;
66
          sendRow(scores.substring(begin+1,end));
67
          begin = end;
57
          mViews[i].prepareView(mAct,scores[i]);
68 58
          }
69 59
        }
70 60
      });
71 61
    }
72 62

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75
  private void sendRow(String row)
76
    {
77
    int s1 = row.indexOf(' ');
78
    int s2 = row.indexOf(' ',s1+1);
79
    int s3 = row.indexOf(' ',s2+1);
80
    int s4 = row.indexOf(' ',s3+1);
81
    int s5 = row.indexOf(' ',s4+1);
82
    int s6 = row.length();
83

  
84
    if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 )
85
      {
86
      int size       = Integer.valueOf( row.substring(   0,s1) );
87
      int levl       = Integer.valueOf( row.substring(s1+1,s2) );
88
      String place   = row.substring(s2+1, s3);
89
      String name    = row.substring(s3+1, s4);
90
      int time       = Integer.valueOf( row.substring(s4+1,s5) );
91
      String country = row.substring(s5+1, s6);
92

  
93
      if( size>=0 && size< RubikSize.LENGTH )
94
        {
95
        mViews[size].fillRow(mAct, levl, place, time, name, country);
96
        }
97
      else
98
        {
99
        android.util.Log.e("receive", "row invalid: size invalid: "+row);
100
        }
101
      }
102
    else
103
      {
104
      android.util.Log.e("receive", "row invalid: "+row);
105
      }
106
    }
107

  
108 63
///////////////////////////////////////////////////////////////////////////////////////////////////
109 64

  
110 65
  @Override

Also available in: Unified diff