Project

General

Profile

« Previous | Next » 

Revision 8ab435b9

Added by Leszek Koltunski about 3 years ago

1. Remove 'db level' from objectlib (this belongs to the app!)
2. change ScreenPlay's 'mObject' to be an ObjectType.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
38 38
import org.distorted.main.R;
39 39
import org.distorted.main.RubikActivity;
40 40
import org.distorted.network.RubikScores;
41
import org.distorted.objectlib.main.ObjectType;
41 42
import org.distorted.screens.ScreenList;
42 43
import org.distorted.screens.RubikScreenPlay;
43 44

  
......
79 80
        if( name.length()>0 )
80 81
          {
81 82
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
82
          int object = play.getObject();
83
          ObjectType object = play.getObject();
83 84

  
84
          bundle.putInt("tab", object );
85
          bundle.putInt("tab", object.ordinal() );
85 86
          bundle.putBoolean("submitting", true);
86 87

  
87 88
          RubikDialogScores scoresDiag = new RubikDialogScores();
src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
109 109
    {
110 110
    prepareView();
111 111

  
112
    ObjectType[] types = ObjectType.values();
112 113
    int MAX = RubikScreenPlay.LEVELS_SHOWN;
113 114
    int toDo=0;
114 115
    int[] toDoTab = new int[mNumTabs];
......
117 118

  
118 119
    for(int i=0; i<mNumTabs; i++)
119 120
      {
120
      lastTab[i]= ObjectType.getDBLevel(i);
121
      lastTab[i]= RubikScreenPlay.getDBLevel(types[i]);
121 122
      maxTab[i] = Math.min(lastTab[i],MAX);
122 123
      toDoTab[i]= 0;
123 124

  
src/main/java/org/distorted/dialogs/RubikDialogSetName.java
148 148
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
149 149

  
150 150
          Bundle bundle = new Bundle();
151
          bundle.putInt("tab", play.getObject() );
151
          bundle.putInt("tab", play.getObject().ordinal() );
152 152
          bundle.putBoolean("submitting", true);
153 153

  
154 154
          RubikDialogScores scores = new RubikDialogScores();
src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java
76 76
    String packageName = act.getPackageName();
77 77

  
78 78
    TutorialList list  = TutorialList.getObject(position);
79
    ObjectType objList = list.getObjectList();
79
    ObjectType objType = list.getObject();
80 80

  
81 81
    View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
82 82
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
......
92 92

  
93 93
      int countryID = res.getIdentifier( coun, "drawable", packageName);
94 94

  
95
      View row = createRow(ract,countryID,desc,url,auth,widthT,objList);
95
      View row = createRow(ract,countryID,desc,url,auth,widthT,objType);
96 96
      layout.addView(row);
97 97
      }
98 98

  
src/main/java/org/distorted/main/RubikActivity.java
272 272
        scores.setCountry(this);
273 273
        }
274 274

  
275
      boolean success = false;
276 275
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
277
      int object = play.getObject();
278

  
279
      if( object>=0 && object< ObjectType.NUM_OBJECTS )
280
        {
281
        success = true;
282
        ObjectType nextObj = ObjectType.values()[object];
283
        view.getPreRender().changeObject(nextObj);
284
        }
285

  
286
      if( !success )
287
        {
288
        ObjectType obj = ObjectType.getObject(RubikScreenPlay.DEF_OBJECT);
289
        play.setObject(this,obj);
290
        view.getPreRender().changeObject(obj);
291
        }
292

  
276
      ObjectType object = play.getObject();
277
      view.getPreRender().changeObject(object);
278
      
293 279
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
294 280
      }
295 281
    
src/main/java/org/distorted/main/RubikObjectStateActioner.java
81 81

  
82 82
  private void reportRecord(TwistyActivity act, String debug, int scrambleNum)
83 83
    {
84
    RubikActivity ract = (RubikActivity)act;
85
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
86
    RubikScores scores = RubikScores.getInstance();
87

  
88
    int object      = play.getObject();
89
    int level       = play.getLevel();
90
    ObjectType list = ObjectType.getObject(object);
91
    String name     = scores.getName();
92

  
93
    String record = list.name()+" level "+level+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+scrambleNum;
84
    RubikActivity ract  = (RubikActivity)act;
85
    RubikScreenPlay play= (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
86
    RubikScores scores  = RubikScores.getInstance();
87
    ObjectType object   = play.getObject();
88
    int level           = play.getLevel();
89
    String name         = scores.getName();
90

  
91
    String record = object.name()+" level "+level+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+scrambleNum;
94 92

  
95 93
    if( BuildConfig.DEBUG )
96 94
       {
src/main/java/org/distorted/network/RubikNetwork.java
36 36
import org.distorted.library.main.DistortedLibrary;
37 37
import org.distorted.objectlib.main.ObjectType;
38 38

  
39
import static org.distorted.objectlib.main.ObjectType.MAX_LEVEL;
39
import static org.distorted.screens.RubikScreenPlay.MAX_LEVEL;
40 40
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
41 41

  
42 42
///////////////////////////////////////////////////////////////////////////////////////////////////
......
458 458
    return url;
459 459
    }
460 460

  
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

  
463
  private static String getObjectList()
464
    {
465
    StringBuilder list = new StringBuilder();
466
    ObjectType[] objects = ObjectType.values();
467

  
468
    for(int i=0; i<NUM_OBJECTS; i++)
469
      {
470
      if( i>0 ) list.append(',');
471
      list.append(objects[i].name());
472
      }
473

  
474
    return list.toString();
475
    }
476

  
461 477
///////////////////////////////////////////////////////////////////////////////////////////////////
462 478

  
463 479
  private String constructDownloadURL()
......
471 487

  
472 488
    String url="https://distorted.org/magic/cgi-bin/download.cgi";
473 489
    url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d";
474
    url += "&o="+ ObjectType.getObjectList()+"&min=0&max="+MAX_LEVEL+"&l="+MAX_PLACES;
490
    url += "&o="+getObjectList()+"&min=0&max="+MAX_LEVEL+"&l="+MAX_PLACES;
475 491

  
476 492
    return url;
477 493
    }
......
501 517
    String url1="https://distorted.org/magic/cgi-bin/submit.cgi";
502 518
    String url2 = "n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d";
503 519
    url2 += "&d="+renderer+"&s="+version;
504
    url2 += reclist+"&c="+country+"&f="+epoch+"&oo="+ ObjectType.getObjectList();
520
    url2 += reclist+"&c="+country+"&f="+epoch+"&oo="+getObjectList();
505 521
    url2 += "&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES;
506 522
    String hash = computeHash( url2, salt.getBytes() );
507 523

  
src/main/java/org/distorted/network/RubikScores.java
28 28
import com.google.firebase.crashlytics.FirebaseCrashlytics;
29 29

  
30 30
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
31
import static org.distorted.objectlib.main.ObjectType.MAX_LEVEL;
31
import static org.distorted.screens.RubikScreenPlay.MAX_LEVEL;
32 32

  
33 33
import org.distorted.objectlib.main.ObjectType;
34 34

  
src/main/java/org/distorted/patterns/RubikPatternList.java
72 72
// PUBLIC API
73 73
///////////////////////////////////////////////////////////////////////////////////////////////////
74 74

  
75
  public static int getOrdinal(int object)
75
  public static int getOrdinal(ObjectType object)
76 76
    {
77 77
    for(int i=0; i<NUM_OBJECTS; i++)
78 78
      {
79
      if( objects[i].mObject.ordinal() == object )
79
      if( objects[i].mObject == object )
80 80
        {
81 81
        return i;
82 82
        }
src/main/java/org/distorted/screens/RubikScreenAbstract.java
22 22
import android.content.SharedPreferences;
23 23

  
24 24
import org.distorted.main.RubikActivity;
25
import org.distorted.objectlib.main.ObjectType;
25 26
import org.distorted.patterns.RubikPatternList;
26 27
import org.distorted.tutorials.TutorialList;
27 28

  
......
32 33
  int getPatternOrdinal()
33 34
    {
34 35
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
35
    int obj  = play.getObject();
36
    ObjectType obj  = play.getObject();
36 37
    int ret = RubikPatternList.getOrdinal(obj);
37 38

  
38 39
    if( ret<0 )
......
48 49
  int getTutorialOrdinal()
49 50
    {
50 51
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
51
    int obj  = play.getObject();
52
    ObjectType obj  = play.getObject();
52 53

  
53 54
    int ret = TutorialList.getOrdinal(obj);
54 55

  
src/main/java/org/distorted/screens/RubikScreenPattern.java
67 67

  
68 68
    if( !play.setObject(act,object) )
69 69
      {
70
      int objectPlay= play.getObject();
71

  
72
      act.changeObject(ObjectType.getObject(objectPlay),false);
70
      act.changeObject(play.getObject(),false);
73 71
      }
74 72
    }
75 73

  
src/main/java/org/distorted/screens/RubikScreenPlay.java
54 54
  {
55 55
  public static final int NUM_COLUMNS  = 4;
56 56
  public static final int LEVELS_SHOWN = 10;
57
  public static final int DEF_OBJECT= ObjectType.CUBE_3.ordinal();
57
  public static int MAX_LEVEL;
58
  public static final ObjectType DEF_OBJECT= ObjectType.CUBE_3;
58 59

  
59 60
  private static final int[] BUTTON_LABELS = { R.string.scores,
60 61
                                               R.string.patterns,
......
70 71
  private ImageButton mObjButton, mMenuButton, mSolveButton;
71 72
  private Button mPlayButton;
72 73
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
73
  private int mObject = DEF_OBJECT;
74
  private ObjectType mObject = DEF_OBJECT;
74 75
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
75 76
  private int mLevelValue;
76 77
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
......
78 79
  private LinearLayout mPlayLayout;
79 80
  private int mUpperBarHeight;
80 81

  
82
  static
83
    {
84
    ObjectType[] types = ObjectType.values();
85
    int max = Integer.MIN_VALUE;
86

  
87
    for (ObjectType type : types)
88
      {
89
      int cur = getDBLevel(type);
90
      if( cur>max ) max = cur;
91
      }
92

  
93
    MAX_LEVEL = max;
94
    }
95

  
81 96
///////////////////////////////////////////////////////////////////////////////////////////////////
82 97

  
83 98
  void leaveScreen(RubikActivity act)
......
120 135
    createBottomPane(act,width,mSolveButton);
121 136
    }
122 137

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
138
//////////////////////////////////////////////////////////////////////////////////////////////////
124 139

  
125 140
  private void setupObjectButton(final RubikActivity act, final float width)
126 141
    {
......
163 178
          {
164 179
          View popupView = mPlayPopup.getContentView();
165 180
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
166
          final int dbLevel = ObjectType.getDBLevel(mObject);
181
          final int dbLevel = getDBLevel(mObject);
167 182
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
168 183
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
169 184
          final int realHeight = Math.min(popupHeight,maxHeight);
......
258 273
          {
259 274
          if( act.getPreRender().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
260 275
            {
261
            mObject = obj;
276
            mObject = ObjectType.getObject(obj);
262 277
            act.changeObject(list, true);
263 278
            adjustLevels(act);
264 279
            mMovesController.clearMoves(act);
......
344 359
    {
345 360
    switch(button)
346 361
      {
347
      case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
348
              int object = play.getObject();
349
              Bundle sBundle = new Bundle();
350
              sBundle.putInt("tab", object );
362
      case 0: Bundle sBundle = new Bundle();
363
              sBundle.putInt("tab", mObject.ordinal() );
351 364
              sBundle.putBoolean("submitting", false);
352 365
              RubikDialogScores scores = new RubikDialogScores();
353 366
              scores.setArguments(sBundle);
......
403 416

  
404 417
  public void savePreferences(SharedPreferences.Editor editor)
405 418
    {
406
    editor.putInt("statePlay_object", mObject);
419
    editor.putString("statePlay_objName", mObject.name() );
407 420

  
408 421
    if( mObjectPopup!=null )
409 422
      {
......
428 441

  
429 442
  public void restorePreferences(SharedPreferences preferences)
430 443
    {
431
    mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
432
    int dbLevel = ObjectType.getDBLevel(mObject);
433

  
434
    // This means the app has been upgraded to a new version which swapped the
435
    // Object for a new one with larger sizeIndex and now getMaxLevel() returns
436
    // 0. Reset the object to default, otherwise we'll get a crash later on.
437

  
438
    if( dbLevel==0 ) mObject = DEF_OBJECT;
444
    String objName= preferences.getString("statePlay_objName", DEF_OBJECT.name() );
445
    int ordinal = ObjectType.getOrdinal(objName);
446
    mObject = ordinal>=0 ? ObjectType.values()[ordinal] : DEF_OBJECT;
439 447
    }
440 448

  
441 449
///////////////////////////////////////////////////////////////////////////////////////////////////
442 450

  
443 451
  public boolean setObject(RubikActivity act, ObjectType obj)
444 452
    {
445
    if( mObject!=obj.ordinal() )
453
    if( mObject!=obj )
446 454
      {
447
      mObject = obj.ordinal();
455
      mObject = obj;
448 456
      if( mPlayLayout!=null ) adjustLevels(act);
449 457
      return true;
450 458
      }
......
493 501

  
494 502
  private void adjustLevels(final RubikActivity act)
495 503
    {
496
    int dbLevel = ObjectType.getDBLevel(mObject);
497
    int numScrambles = ObjectType.getNumScramble(mObject);
504
    int dbLevel = getDBLevel(mObject);
505
    int numScrambles = ObjectType.getNumScramble(mObject.ordinal());
498 506
    int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
499 507
    String[] levels = new String[numLevel];
500 508

  
......
541 549
      button.setText(levels[i]);
542 550
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
543 551

  
544
      int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
552
      int icon = scores.isSolved(mObject.ordinal(), level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
545 553
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
546 554

  
547 555
      button.setOnClickListener( new View.OnClickListener()
......
564 572
      }
565 573
    }
566 574

  
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
// historically older versions of the app had lower 'maxScrambles' in case of several objects and
577
// those got remembered in the server-side DB already, so we need to keep using them. This function
578
// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have
579
// those two values the same.
580

  
581
  public static int getDBLevel(ObjectType object)
582
    {
583
    switch(object)
584
      {
585
      case CUBE_3: return 16;
586
      case CUBE_4: return 20;
587
      case CUBE_5: return 24;
588
      case PYRA_4: return 14;
589
      case PYRA_5: return 20;
590
      case MEGA_5: return 35;
591
      case DIAM_2: return 10;
592
      case DIAM_3: return 18;
593
      case REDI_3: return 14;
594
      case HELI_3: return 18;
595
      case SKEW_3: return 17;
596
      case REX_3 : return 16;
597
      case MIRR_3: return 16;
598
      default    : return ObjectType.getNumScramble(object.ordinal());
599
      }
600
    }
601

  
567 602
///////////////////////////////////////////////////////////////////////////////////////////////////
568 603

  
569 604
  public int getLevel()
......
573 608

  
574 609
///////////////////////////////////////////////////////////////////////////////////////////////////
575 610

  
576
  public int getObject()
611
  public ObjectType getObject()
577 612
    {
578 613
    return mObject;
579 614
    }
src/main/java/org/distorted/screens/RubikScreenSolving.java
35 35
import org.distorted.main.R;
36 36
import org.distorted.main.RubikActivity;
37 37
import org.distorted.network.RubikScores;
38
import org.distorted.objectlib.main.ObjectType;
38 39

  
39 40
///////////////////////////////////////////////////////////////////////////////////////////////////
40 41

  
......
185 186
      mElapsed = System.currentTimeMillis()-mStartTime;
186 187

  
187 188
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
188
      int object  = play.getObject();
189
      ObjectType object  = play.getObject();
189 190
      int level   = play.getLevel();
190
      boolean isNew = mScores.setRecord(object, level, mElapsed);
191
      boolean isNew = mScores.setRecord(object.ordinal(), level, mElapsed);
191 192

  
192 193
      return isNew ? mElapsed : -mElapsed;
193 194
      }
src/main/java/org/distorted/tutorials/TutorialList.java
443 443

  
444 444
///////////////////////////////////////////////////////////////////////////////////////////////////
445 445

  
446
  public static int getOrdinal(int object)
446
  public static int getOrdinal(ObjectType object)
447 447
    {
448
    if( object== ObjectType.DIN4_3.ordinal() )
448
    if( object== ObjectType.DIN4_3 )
449 449
      {
450
      object= ObjectType.DINO_3.ordinal();
450
      object= ObjectType.DINO_3;
451 451
      }
452 452

  
453 453
    for(int i=0; i<NUM_OBJECTS; i++)
454 454
      {
455
      if( objects[i].mObject.ordinal() == object )
455
      if( objects[i].mObject == object )
456 456
        {
457 457
        return i;
458 458
        }
......
463 463

  
464 464
///////////////////////////////////////////////////////////////////////////////////////////////////
465 465

  
466
  public ObjectType getObjectList()
466
  public ObjectType getObject()
467 467
    {
468 468
    return mObject;
469 469
    }
src/main/java/org/distorted/tutorials/TutorialScreen.java
74 74
      public void onClick(View v)
75 75
        {
76 76
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
77
        int numScrambles = ObjectType.getNumScramble(play.getObject());
77
        int ordinal = play.getObject().ordinal();
78
        int numScrambles = ObjectType.getNumScramble(ordinal);
78 79
        act.getPreRender().scrambleObject(numScrambles);
79 80
        }
80 81
      });

Also available in: Unified diff