Project

General

Profile

« Previous | Next » 

Revision c3ffcf58

Added by Leszek Koltunski over 4 years ago

Progress with saving number of runs, plays, name, verified status.

View differences:

src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
28 28
import android.widget.LinearLayout;
29 29

  
30 30
import org.distorted.magic.R;
31
import org.distorted.scores.RubikScores;
31 32
import org.distorted.scores.RubikScoresDownloader;
32 33
import org.distorted.object.RubikObjectList;
33 34

  
......
165 166

  
166 167
    if( allCreated )
167 168
      {
169
      RubikScores scores = RubikScores.getInstance();
168 170
      RubikScoresDownloader downloader = new RubikScoresDownloader();
169
      downloader.download( this,
170
                           "distorted",  // TODO
171
                           mAct.getString(R.string.app_version),
172
                           1 );  // TODO
171
      downloader.download( this, scores.getName(), mAct.getString(R.string.app_version), scores.getNumRuns() );
173 172
      }
174 173

  
175 174
    return mViews[position];
src/main/java/org/distorted/magic/RubikActivity.java
31 31
import org.distorted.effect.BaseEffect;
32 32
import org.distorted.library.main.DistortedLibrary;
33 33

  
34
import org.distorted.scores.RubikScores;
34 35
import org.distorted.scores.RubikScoresDownloader;
35 36
import org.distorted.object.RubikObjectList;
36 37
import org.distorted.uistate.RubikState;
......
41 42

  
42 43
public class RubikActivity extends AppCompatActivity implements View.OnClickListener
43 44
{
45
    private boolean mJustStarted;
46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

  
44 49
    @Override
45 50
    protected void onCreate(Bundle savedState)
46 51
      {
47 52
      super.onCreate(savedState);
48 53
      setTheme(R.style.CustomActivityThemeNoActionBar);
49 54
      setContentView(R.layout.main);
55

  
56
      mJustStarted = true;
50 57
      }
51 58

  
52 59
///////////////////////////////////////////////////////////////////////////////////////////////////
......
74 81
      RubikState.setState(this);
75 82
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
76 83

  
84
      if( mJustStarted )
85
        {
86
        mJustStarted = false;
87
        RubikScores.getInstance().incrementNumRuns();
88
        }
89

  
77 90
      int object = play.getObject();
78 91
      int size   = play.getSize();
79 92
      RubikObjectList obj = RubikObjectList.getObject(object);
src/main/java/org/distorted/magic/RubikRenderer.java
29 29
import org.distorted.library.message.EffectListener;
30 30
import org.distorted.object.RubikObject;
31 31
import org.distorted.object.RubikObjectList;
32
import org.distorted.scores.RubikScores;
32 33
import org.distorted.uistate.RubikState;
33 34
import org.distorted.uistate.RubikStateSolving;
34 35

  
......
307 308
       mCanRotate      = false;
308 309
       mCanUI          = false;
309 310
       mIsSolved       = false;
311
       RubikScores.getInstance().incrementNumPlays();
310 312
       doEffectNow( BaseEffect.Type.SCRAMBLE );
311 313
       }
312 314
     }
src/main/java/org/distorted/scores/RubikScores.java
27 27
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
28 28

  
29 29
///////////////////////////////////////////////////////////////////////////////////////////////////
30
// hold my own scores
30
// hold my own scores, some other statistics.
31 31

  
32 32
public class RubikScores
33 33
  {
......
35 35
  private static RubikScores mThis;
36 36

  
37 37
  private long[][][] mRecords;
38
  private String mName;
39
  private boolean mNameIsVerified;
40
  private int mNumRuns;
41
  private int mNumPlays;
38 42

  
39 43
///////////////////////////////////////////////////////////////////////////////////////////////////
40 44

  
......
48 52
          {
49 53
          mRecords[i][j][k] = NO_RECORD;
50 54
          }
55

  
56
    mName = "";
57
    mNameIsVerified = false;
58
    mNumPlays= -1;
59
    mNumRuns = -1;
51 60
    }
52 61

  
53 62
///////////////////////////////////////////////////////////////////////////////////////////////////
......
92 101
          }
93 102
        }
94 103

  
95
      editor.putString("record"+scramble, builder.toString());
104
      editor.putString("scores_record"+scramble, builder.toString());
96 105
      }
106

  
107
    editor.putString("scores_name"  , mName  );
108
    editor.putBoolean("scores_isVerified", mNameIsVerified);
109
    editor.putInt("scores_numPlays", mNumPlays);
110
    editor.putInt("scores_numRuns" , mNumRuns);
97 111
    }
98 112

  
99 113
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 121
    for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
108 122
      {
109 123
      start = end = 0;
110
      recordStr = preferences.getString("record"+scramble, "");
111

  
112
      //android.util.Log.e("solving", scramble+" record string: "+recordStr);
124
      recordStr = preferences.getString("scores_record"+scramble, "");
113 125

  
114 126
      while( end!=-1 )
115 127
        {
......
149 161
          }
150 162
        }
151 163
      }
164

  
165
    mName           = preferences.getString("scores_name"  , "");
166
    mNameIsVerified = preferences.getBoolean("scores_isVerified", false);
167
    mNumPlays       = preferences.getInt("scores_numPlays", 0);
168
    mNumRuns        = preferences.getInt("scores_numRuns" , 0);
152 169
    }
153 170

  
154 171
///////////////////////////////////////////////////////////////////////////////////////////////////
155 172

  
156
  public void newRecord(int object, int size, int scramble, long timeTaken)
173
  public void setRecord(int object, int size, int scramble, long timeTaken)
157 174
    {
158 175
    int maxsize = RubikObjectList.getObject(object).getSizes().length;
159 176

  
......
167 184
      }
168 185
    }
169 186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

  
189
  public void incrementNumPlays()
190
    {
191
    mNumPlays++;
192
    }
193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

  
196
  public void incrementNumRuns()
197
    {
198
    mNumRuns++;
199
    }
200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
  public void setName(String newName)
204
    {
205
    mName = newName;
206
    }
207

  
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

  
210
  public void verifyName()
211
    {
212
    mNameIsVerified = true;
213
    }
214

  
170 215
///////////////////////////////////////////////////////////////////////////////////////////////////
171 216

  
172 217
  public long getRecord(int object, int size, int scramble)
......
180 225

  
181 226
    return -1;
182 227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
  public int getNumPlays()
232
    {
233
    return mNumPlays;
234
    }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
  public int getNumRuns()
239
    {
240
    return mNumRuns;
241
    }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  public String getName()
246
    {
247
    return mName;
248
    }
249

  
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

  
252
  public boolean isVerified()
253
    {
254
    return mNameIsVerified;
255
    }
183 256
  }
src/main/java/org/distorted/uistate/RubikStateSolving.java
162 162
      int size    = play.getSize();
163 163
      int scramble= play.getPicker();
164 164

  
165
      mScores.newRecord(object, size, scramble, timeTaken);
165
      mScores.setRecord(object, size, scramble, timeTaken);
166 166
      return timeTaken;
167 167
      }
168 168

  

Also available in: Unified diff