Project

General

Profile

« Previous | Next » 

Revision 9333086d

Added by Leszek Koltunski over 2 years ago

Correct a recently introduced bug with restoring records.
Slightely simplify ObjectType.

View differences:

src/main/java/org/distorted/network/RubikScores.java
59 59
    mRecords   = new long[NUM_OBJECTS][MAX_LEVEL];
60 60
    mSubmitted = new int [NUM_OBJECTS][MAX_LEVEL];
61 61

  
62
    for(int i=0; i<NUM_OBJECTS; i++)
63
      for(int j=0; j<MAX_LEVEL; j++)
62
    for(int object=0; object<NUM_OBJECTS; object++)
63
      for(int level=0; level<MAX_LEVEL; level++)
64 64
        {
65
        mRecords[i][j]   = NO_RECORD;
66
        mSubmitted[i][j] = 0;
65
        mRecords[object][level]   = NO_RECORD;
66
        mSubmitted[object][level] = 0;
67 67
        }
68 68

  
69 69
    mName = "";
......
103 103
    {
104 104
    mNameIsVerified = true;
105 105

  
106
    for(int i=0; i<NUM_OBJECTS; i++)
107
      for(int j=0; j<MAX_LEVEL; j++)
106
    for(int object=0; object<NUM_OBJECTS; object++)
107
      for(int level=0; level<MAX_LEVEL; level++)
108 108
        {
109
        mSubmitted[i][j]=1;
109
        mSubmitted[object][level]=1;
110 110
        }
111 111
    }
112 112

  
......
122 122
  synchronized boolean thereAreUnsubmittedRecords()
123 123
    {
124 124
    for(int object=0; object<NUM_OBJECTS; object++)
125
      {
126 125
      for(int level=0; level<MAX_LEVEL; level++)
127 126
        {
128 127
        if( mSubmitted[object][level]==0 && mRecords[object][level]<NO_RECORD ) return true;
129 128
        }
130
      }
131 129

  
132 130
    return false;
133 131
    }
......
155 153
            builderLvl.append(',');
156 154
            builderTim.append(',');
157 155
            }
158
          else
159
            {
160
            first=false;
161
            }
156
          first=false;
162 157

  
163 158
          builderObj.append(name);
164 159
          builderLvl.append(level);
......
179 174
    return (obj>=0 && obj<NUM_OBJECTS && level>=0 && level<MAX_LEVEL) ? mRecords[obj][level] : -1;
180 175
    }
181 176

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
  public synchronized boolean isSubmitted(int obj, int level)
185
    {
186
    return obj>=0 && obj<NUM_OBJECTS && level>=0 && level<MAX_LEVEL && mSubmitted[obj][level]==1;
187
    }
188

  
189 177
///////////////////////////////////////////////////////////////////////////////////////////////////
190 178

  
191 179
  public boolean isVerified()
......
293 281

  
294 282
  public static RubikScores getInstance()
295 283
    {
296
    if( mThis==null )
297
      {
298
      mThis = new RubikScores();
299
      }
300

  
284
    if( mThis==null ) mThis = new RubikScores();
301 285
    return mThis;
302 286
    }
303 287

  
......
338 322

  
339 323
  public synchronized void restorePreferences(SharedPreferences preferences)
340 324
    {
341
    String recordStr, subStr, nameStr, sizeStr, timeStr, submStr, errorStr="";
342
    int start, end, equals, underscore, comma, object, subm;
325
    String recordStr, subStr, nameStr, timeStr, submStr, errorStr="";
326
    int start, end, equals, comma, object, subm;
343 327
    long time;
344 328
    boolean thereWasError = false;
345 329

  
......
357 341

  
358 342
        start = end+1;
359 343

  
360
        underscore = subStr.indexOf("_");
361 344
        equals = subStr.indexOf("=");
362
        comma = subStr.indexOf(",");
345
        comma  = subStr.indexOf(",");
363 346

  
364
        if( underscore>=0 && equals>=0 && comma>=0 )
347
        if( equals>=0 && comma>=0 )
365 348
          {
366
          nameStr = subStr.substring(0,underscore);
367
          sizeStr = subStr.substring(underscore+1, equals);
349
          nameStr = subStr.substring(0,equals);
368 350
          timeStr = subStr.substring(equals+1,comma);
369 351
          submStr = subStr.substring(comma+1);
370 352

  
......
382 364
              }
383 365
            else
384 366
              {
385
              errorStr += ("error1: subm="+subm+" obj: "+nameStr+" size: "+sizeStr+"\n");
367
              errorStr += ("error1: subm="+subm+" obj: "+nameStr+"\n");
386 368
              thereWasError= true;
387 369
              }
388 370
            }
389 371
          else
390 372
            {
391
            errorStr += ("error2: object="+object+" obj: "+nameStr+" size: "+sizeStr+"\n");
373
            errorStr += ("error2: object="+object+" obj: "+nameStr+"\n");
392 374
            thereWasError = true;
393 375
            }
394 376
          }

Also available in: Unified diff