Project

General

Profile

« Previous | Next » 

Revision c02235d5

Added by Leszek Koltunski about 1 year ago

progress

View differences:

src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.java
66 66

  
67 67
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
68 68
    {
69
    int objectOrdinal = RubikObjectList.getOrdinal(mArgument);
69
    int objectOrdinal = Integer.parseInt(mArgument);
70 70

  
71 71
    if( objectOrdinal<0 )
72 72
      {
src/main/java/org/distorted/dialogs/RubikDialogScores.java
33 33

  
34 34
  private RubikDialogScoresPagerAdapter mPagerAdapter;
35 35

  
36
  public interface ScoresInvoker
37
    {
38
    int getObjectOrdinal();
39
    }
40

  
36 41
///////////////////////////////////////////////////////////////////////////////////////////////////
37 42

  
38 43
  @Override
......
73 78
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,mArgument.equals("true"), this);
74 79
    tabLayout.setupWithViewPager(viewPager);
75 80

  
76
    viewPager.setCurrentItem(RubikObjectList.getCurrObject());
81
    ScoresInvoker si = (ScoresInvoker) act;
82
    int objectOrdinal = si.getObjectOrdinal();
83

  
84
    viewPager.setCurrentItem(objectOrdinal);
77 85
    int numObjects = RubikObjectList.getNumObjects();
78 86
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
79 87

  
src/main/java/org/distorted/dialogs/RubikDialogTutorialSingle.java
77 77
    {
78 78
    mDialog = dialog;
79 79

  
80
    int objectOrdinal = RubikObjectList.getOrdinal(mArgument);
81

  
82
    android.util.Log.e("D", "dialog tutorial: object "+mArgument);
80
    int objectOrdinal = Integer.parseInt(mArgument);
83 81

  
84 82
    if( objectOrdinal<0 )
85 83
      {
86 84
      android.util.Log.e("D", "object "+mArgument+" not found");
87 85
      return;
88 86
      }
87

  
89 88
    RubikObject robject = RubikObjectList.getObject(objectOrdinal);
90 89
    InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act);
91 90
    String[][] tutorials=null;
src/main/java/org/distorted/external/RubikNetwork.java
796 796
    {
797 797
    mRunning = false;
798 798
    mUpdateeList.clear();
799
    mUpdatesState = UPDATES_RUNNING;
800 799
    }
801 800

  
802 801
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/helpers/MovesController.java
163 163
      StringBuilder moves = new StringBuilder();
164 164
      int numMoves = getNumMoves();
165 165

  
166

  
167
      android.util.Log.e("D", "saving moves: "+numMoves);
168

  
169 166
      for(int m=0; m<numMoves; m++)
170 167
        {
171 168
        Move move = mMoves.get(m);
......
193 190
        String[] tokens = objects.split(" ");
194 191
        int length = tokens.length/3;
195 192

  
196
        android.util.Log.e("D", "restoring moves: "+length);
197

  
198 193
        for(int m=0; m<length; m++)
199 194
          {
200 195
          String axis  = tokens[3*m  ];
src/main/java/org/distorted/main/MainActivity.java
53 53

  
54 54
///////////////////////////////////////////////////////////////////////////////////////////////////
55 55

  
56
public class MainActivity extends AppCompatActivity implements RubikNetwork.Updatee
56
public class MainActivity extends AppCompatActivity implements RubikNetwork.Updatee, RubikDialogScores.ScoresInvoker
57 57
{
58 58
    public static final float RATIO_BAR = 0.080f;
59 59
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
......
69 69
    private int mScreenWidth;
70 70
    private TextView mBubbleUpdates;
71 71
    private int mNumUpdates;
72
    private int mCurrentObject;
72 73
    private MainScrollGrid mGrid;
73 74

  
74 75
///////////////////////////////////////////////////////////////////////////////////////////////////
......
81 82
      setContentView(R.layout.main);
82 83
      hideNavigationBar();
83 84

  
85
      mCurrentObject = 0;
84 86
      mJustStarted = true;
85 87
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
86 88

  
......
89 91

  
90 92
      mCurrVersion = getAppVers();
91 93

  
94
      mBubbleUpdates = findViewById(R.id.bubbleUpdates);
95
      mBubbleUpdates.setVisibility(View.INVISIBLE);
96
      mNumUpdates = 0;
97

  
92 98
      Thread thread = new Thread()
93 99
        {
94 100
        public void run()
......
239 245
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
240 246
      restorePreferences(preferences,mJustStarted);
241 247

  
242
      mBubbleUpdates = findViewById(R.id.bubbleUpdates);
243
      mBubbleUpdates.setVisibility(View.INVISIBLE);
244
      mNumUpdates = 0;
248
      RubikNetwork network = RubikNetwork.getInstance();
249
      network.signUpForUpdates(this);
245 250

  
246 251
      if( mJustStarted )
247 252
        {
248 253
        mJustStarted = false;
249 254

  
250
        RubikNetwork network = RubikNetwork.getInstance();
251
        network.signUpForUpdates(this);
252 255
        network.downloadUpdates(this);
253 256
        RubikScores scores = RubikScores.getInstance();
254 257
        scores.incrementNumRuns();
......
359 362
      return mFirebaseAnalytics;
360 363
      }
361 364

  
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

  
367
    public int getObjectOrdinal()
368
      {
369
      return mCurrentObject;
370
      }
371

  
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

  
374
    public void setCurrentObject(int current)
375
      {
376
      mCurrentObject = current;
377
      }
378

  
362 379
///////////////////////////////////////////////////////////////////////////////////////////////////
363 380

  
364 381
    public void switchToTutorial(int objectOrdinal)
src/main/java/org/distorted/main/MainScrollGrid.java
58 58
        @Override
59 59
        public void onClick(View v)
60 60
          {
61
          act.setCurrentObject(ordinal);
61 62
          int w = displaymetrics.widthPixels;
62 63
          int h = displaymetrics.heightPixels;
63 64
          MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h);
src/main/java/org/distorted/objects/RubikObjectList.java
17 17

  
18 18
import org.distorted.external.RubikFiles;
19 19
import org.distorted.external.RubikScores;
20
import org.distorted.objectlib.signature.ObjectConstants;
21 20
import org.distorted.objectlib.main.ObjectType;
22 21

  
23 22
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
......
30 29
  public static final boolean SHOW_IAP_DEBUG        = false;
31 30
  public static final boolean USE_IAP               = false;
32 31

  
33
  public static final int DEF_OBJECT= ObjectConstants.CUBE_3;
34 32
  private static RubikObjectList mThis;
35 33
  private static int mNumObjects;
36 34
  private static int mNumExtras;
37 35
  private static ArrayList<RubikObject> mObjects;
38
  private static int mObject = DEF_OBJECT;
39 36

  
40 37
  public static class DownloadedObject
41 38
    {
......
58 55
    }
59 56

  
60 57
  private static ArrayList<DownloadedObject> mDownloadedObjects;
61

  
62 58
  private static String mBoughtObjects;
63 59

  
64 60
///////////////////////////////////////////////////////////////////////////////////////////////////
......
285 281

  
286 282
  public static void savePreferences(SharedPreferences.Editor editor)
287 283
    {
288
    RubikObject obj = getObject(mObject);
289
    if( obj!=null ) editor.putString("rol_objName", obj.getUpperName() );
290

  
291 284
    int numDownloaded = mDownloadedObjects.size();
292 285

  
293 286
    if( numDownloaded>0 )
......
336 329
      }
337 330
    }
338 331

  
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

  
341
  public static void savePreferencesMinimal(SharedPreferences.Editor editor)
342
    {
343
    RubikObject obj = getObject(mObject);
344
    if( obj!=null ) editor.putString("rol_objName", obj.getUpperName() );
345
    }
346

  
347 332
///////////////////////////////////////////////////////////////////////////////////////////////////
348 333

  
349 334
  public static void restorePreferences(Context context, SharedPreferences preferences, boolean justStarted)
......
397 382
        }
398 383
      }
399 384

  
400
    RubikObject object = getObject(DEF_OBJECT);
401
    String defName = object==null ? "CUBE_3" : object.getUpperName();
402
    String objName= preferences.getString("rol_objName",defName);
403
    mObject = getOrdinal(objName);
404
    if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
405

  
406 385
    if( USE_IAP && justStarted ) restoreFreedObjects(preferences);
407 386
    }
408 387

  
......
473 452
    mBoughtObjects += add;
474 453
    }
475 454

  
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

  
478
  public static boolean setCurrObject(int ordinal)
479
    {
480
    if( mObject!=ordinal )
481
      {
482
      mObject = ordinal;
483
      return true;
484
      }
485

  
486
    return false;
487
    }
488

  
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

  
491
  public static int getCurrObject()
492
    {
493
    return mObject;
494
    }
495

  
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

  
498
  public static String getCurrentName()
499
    {
500
    RubikObject object = mObjects.get(mObject);
501
    return object==null ? "" : object.getUpperName();
502
    }
503

  
504 455
///////////////////////////////////////////////////////////////////////////////////////////////////
505 456

  
506 457
  public static RubikObject getObject(int ordinal)
src/main/java/org/distorted/patternui/PatternActivity.java
189 189
      view.onResume();
190 190

  
191 191
      createObject();
192
      RubikObjectList.setCurrObject(mObjectOrdinal);
193 192
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
194 193
      restorePreferences(preferences);
195 194
      ScreenList.setScreen(this);
......
278 277
      return mScreenHeight;
279 278
      }
280 279

  
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

  
282
    public int getObjectOrdinal()
283
      {
284
      return mObjectOrdinal;
285
      }
286

  
281 287
///////////////////////////////////////////////////////////////////////////////////////////////////
282 288

  
283 289
    public void createObject()
src/main/java/org/distorted/patternui/ScreenPattern.java
125 125

  
126 126
  private void showDialog(final PatternActivity act)
127 127
    {
128
    int ordinal = act.getObjectOrdinal();
128 129
    Bundle bundle = new Bundle();
129
    bundle.putString("argument",RubikObjectList.getCurrentName());
130
    bundle.putString("argument", String.valueOf(ordinal) );
130 131
    RubikDialogPatternSingle diag = new RubikDialogPatternSingle();
131 132
    diag.setArguments(bundle);
132 133
    diag.show( act.getSupportFragmentManager(), RubikDialogPatternSingle.getDialogTag() );
src/main/java/org/distorted/playui/PlayActivity.java
26 26

  
27 27
import com.google.firebase.analytics.FirebaseAnalytics;
28 28

  
29
import org.distorted.dialogs.RubikDialogScores;
29 30
import org.distorted.library.main.DistortedLibrary;
30 31
import org.distorted.objectlib.main.InitAssets;
31 32
import org.distorted.objectlib.main.ObjectControl;
......
40 41

  
41 42
///////////////////////////////////////////////////////////////////////////////////////////////////
42 43

  
43
public class PlayActivity extends AppCompatActivity
44
public class PlayActivity extends AppCompatActivity implements RubikDialogScores.ScoresInvoker
44 45
{
45 46
    public static final int FLAGS            = MainActivity.FLAGS;
46 47
    public static final float TITLE_TEXT_SIZE= 0.060f;
......
344 345
        InitAssets asset = new InitAssets(jsonStream, meshStream, os);
345 346
        control.changeIfDifferent(ordinal, upperName, iconMode, asset);
346 347
        }
347

  
348
      RubikObjectList.setCurrObject(ordinal);
349 348
      }
350 349

  
351 350
///////////////////////////////////////////////////////////////////////////////////////////////////
......
385 384
      return mLevel;
386 385
      }
387 386

  
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388

  
389
    public int getObjectOrdinal()
390
      {
391
      return mObjectOrdinal;
392
      }
393

  
388 394
///////////////////////////////////////////////////////////////////////////////////////////////////
389 395

  
390 396
    public ObjectControl getControl()
src/main/java/org/distorted/playui/PlayLibInterface.java
96 96
  private void reportRecord(PlayActivity act, long startTime, long endTime, String debug, int scrambleNum)
97 97
    {
98 98
    RubikScores scores  = RubikScores.getInstance();
99
    int object  = RubikObjectList.getCurrObject();
99
    int objectOrdinal = act.getObjectOrdinal();
100 100
    String name = scores.getName();
101
    RubikObject obj = RubikObjectList.getObject(object);
101
    RubikObject obj = RubikObjectList.getObject(objectOrdinal);
102 102
    String objName = obj==null ? "NULL" : obj.getUpperName();
103 103

  
104 104
    String record = objName+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+scrambleNum;
......
249 249
      solving.resetElapsed();
250 250
      PlayActivity act = mAct.get();
251 251
      ScreenList.switchScreen( act,ScreenList.SOLV );
252

  
253
      /*
254
      act.runOnUiThread(new Runnable()
255
        {
256
        @Override
257
        public void run()
258
          {
259

  
260
          }
261
        });
262

  
263
       */
264 252
      }
265 253
    }
266 254

  
......
286 274
    {
287 275
    if( ScreenList.getCurrentScreen()==ScreenList.SOLV )
288 276
      {
277
      PlayActivity act = mAct.get();
278
      int objectOrdinal = act.getObjectOrdinal();
289 279
      ScreenSolving solving = (ScreenSolving)ScreenList.SOLV.getScreenClass();
290 280
      mNewRecord = solving.stopTimerAndGetRecord();
291
      mIsNewRecord = solving.setRecord();
281
      mIsNewRecord = solving.setRecord(objectOrdinal);
292 282
      }
293 283
    }
294 284

  
src/main/java/org/distorted/playui/ScreenSolving.java
181 181

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

  
184
  public int setRecord()
184
  public int setRecord(int object)
185 185
    {
186
    int object = RubikObjectList.getCurrObject();
187 186
    return mScores.setRecord(object, mLevel, (int)mElapsed);
188 187
    }
189 188

  
src/main/java/org/distorted/purchase/PurchaseActivity.java
202 202
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
203 203
      SharedPreferences.Editor editor = preferences.edit();
204 204
      RubikScores scores = RubikScores.getInstance();
205

  
206 205
      scores.savePreferencesMinimal(editor);
207
      RubikObjectList.savePreferencesMinimal(editor);
208 206

  
209 207
      boolean success = editor.commit();
210 208
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
src/main/java/org/distorted/purchase/PurchaseScreenPane.java
274 274
  public void overlayFinished(long id)
275 275
    {
276 276
    PurchaseActivity act = mAct.get();
277

  
278
    if( act!=null )
279
      {
280
      String upperName = mObject.getUpperName();
281
      int ordinal = RubikObjectList.getOrdinal(upperName);
282
      RubikObjectList.setCurrObject(ordinal);
283
      act.finish();
284
      }
277
    if( act!=null ) act.finish();
285 278
    }
286 279
}
src/main/java/org/distorted/solverui/SolverActivity.java
307 307
      return mSolverOrdinal;
308 308
      }
309 309

  
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

  
312
    public int getObjectOrdinal()
313
      {
314
      return mObjectOrdinal;
315
      }
316

  
310 317
///////////////////////////////////////////////////////////////////////////////////////////////////
311 318

  
312 319
    public void createObject()
src/main/java/org/distorted/solverui/SolverObjectLibInterface.java
169 169

  
170 170
  public void onReplaceModeDown(int cubit, int face)
171 171
    {
172
    SolverActivity act = mAct.get();
172 173
    ScreenSolver solver = (ScreenSolver) ScreenList.SVER.getScreenClass();
173 174
    int color = solver.getCurrentColor();
174
    int currObject = RubikObjectList.getCurrObject();
175
    int currObject = act.getObjectOrdinal();
175 176
    mLastCubitColor = SolverMain.cubitIsLocked(currObject,cubit);
176 177
    mLastCubit = cubit;
177 178
    mLastCubitFace = face;
178
    ObjectControl control = mAct.get().getControl();
179
    ObjectControl control = act.getControl();
179 180
    control.setTextureMap( cubit, face, color );
180 181
    }
181 182

  
src/main/java/org/distorted/tutorials/TutorialActivity.java
87 87

  
88 88
    public void showDialog()
89 89
      {
90
      RubikObjectList.setCurrObject(mObjectOrdinal);
91 90
      Bundle bundle = new Bundle();
92
      bundle.putString("argument",RubikObjectList.getCurrentName());
91
      bundle.putString("argument", String.valueOf(mObjectOrdinal) );
93 92
      RubikDialogTutorialSingle diag = new RubikDialogTutorialSingle();
94 93
      diag.setArguments(bundle);
95 94
      diag.show( getSupportFragmentManager(), RubikDialogTutorialSingle.getDialogTag() );

Also available in: Unified diff