commit 5bda8973905a772ea09594d8c0f7da523ecdcdb9
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Aug 4 15:00:37 2022 +0200

    New way to store records, comopletely independent on the number of scrambles.
    Do away with the weird 'getDBLevel' thing.

diff --git a/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java b/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
index 50242996..99dc04ee 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
@@ -40,10 +40,33 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
+  private void prepareView()
     {
-    if( level>RubikScreenPlay.LEVELS_SHOWN ) level=RubikScreenPlay.LEVELS_SHOWN;
+    mAct.runOnUiThread(new Runnable()
+      {
+      @Override
+      public void run()
+        {
+        for(int i=0; i<mNumTabs; i++)
+          {
+          mViews[i].prepareView(mAct);
+          }
+        }
+      });
+    try
+      {
+      Thread.sleep(150);
+      }
+    catch( InterruptedException ignored)
+      {
 
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
+    {
     String title = level==RubikScreenPlay.LEVELS_SHOWN ?
                    mAct.getString(R.string.levelM) :
                    mAct.getString(R.string.lv_placeholder,level+1);
@@ -71,24 +94,24 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void getNext(int currentTab, int[] toDoTab, int[] lastTab)
+  private void getNext(int currentTab, int[] toDoTab)
     {
-    int MAX = RubikScreenPlay.LEVELS_SHOWN+1;
+    int MAX = RubikScreenPlay.LEVELS_SHOWN;
 
-    if( toDoTab[currentTab]<MAX )
+    if( toDoTab[currentTab]<=MAX )
       {
       mToDoTab = currentTab;
-      mToDoLvl = toDoTab[currentTab]<MAX-1 ? toDoTab[currentTab] : lastTab[currentTab]-1;
+      mToDoLvl = toDoTab[currentTab];
       toDoTab[currentTab]++;
       }
     else
       {
       for(int tab=0; tab<mNumTabs; tab++)
         {
-        if( toDoTab[tab]<MAX )
+        if( toDoTab[tab]<=MAX )
           {
           mToDoTab = tab;
-          mToDoLvl = toDoTab[tab]<MAX-1 ? toDoTab[tab] : lastTab[tab]-1;
+          mToDoLvl = toDoTab[tab];
           toDoTab[tab]++;
           break;
           }
@@ -101,14 +124,11 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork
   public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
     {
     prepareView();
-
     int toDo=0;
     int[] toDoTab = new int[mNumTabs];
-    int[] lastTab = new int[mNumTabs];
 
     for(int i=0; i<mNumTabs; i++)
       {
-      lastTab[i]= RubikObjectList.getDBLevel(i);
       toDoTab[i]= 0;
       toDo += (RubikScreenPlay.LEVELS_SHOWN+1);
       }
@@ -116,7 +136,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork
     while( toDo>0 )
       {
       toDo--;
-      getNext(mViewPager.getCurrentItem(), toDoTab, lastTab);
+      getNext(mViewPager.getCurrentItem(), toDoTab);
       addSection( mToDoTab, mToDoLvl, mViews[mToDoTab], country[mToDoTab][mToDoLvl], name[mToDoTab][mToDoLvl], time[mToDoTab][mToDoLvl]);
       }
     }
@@ -165,31 +185,6 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void prepareView()
-    {
-    mAct.runOnUiThread(new Runnable()
-      {
-      @Override
-      public void run()
-        {
-        for(int i=0; i<mNumTabs; i++)
-          {
-          mViews[i].prepareView(mAct);
-          }
-        }
-      });
-    try
-      {
-      Thread.sleep(150);
-      }
-    catch( InterruptedException ignored)
-      {
-
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag)
diff --git a/src/main/java/org/distorted/external/RubikNetwork.java b/src/main/java/org/distorted/external/RubikNetwork.java
index 3c418e55..e1529092 100644
--- a/src/main/java/org/distorted/external/RubikNetwork.java
+++ b/src/main/java/org/distorted/external/RubikNetwork.java
@@ -30,8 +30,8 @@ import org.distorted.library.main.DistortedLibrary;
 import org.distorted.objectlib.json.JsonWriter;
 import org.distorted.objects.RubikObjectList;
 
-import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
 import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG;
+import static org.distorted.screens.RubikScreenPlay.LEVELS_SHOWN;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -128,10 +128,10 @@ public class RubikNetwork
     {
     int newNum = RubikObjectList.getNumObjects();
 
-    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][MAX_LEVEL][MAX_PLACES];
-    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][MAX_LEVEL][MAX_PLACES];
-    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][MAX_LEVEL][MAX_PLACES];
-    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][MAX_LEVEL];
+    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
+    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
+    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][LEVELS_SHOWN+1][MAX_PLACES];
+    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][LEVELS_SHOWN+1];
 
     if( mUpdates==null ) mUpdates = new RubikUpdates();
 
@@ -185,7 +185,7 @@ public class RubikNetwork
       }
 
     for(int i=0; i<mNumObjects; i++)
-      for(int j=0; j<MAX_LEVEL; j++)
+      for(int j=0; j<=LEVELS_SHOWN; j++)
         {
         mPlaces[i][j] = 0;
         }
@@ -234,7 +234,9 @@ public class RubikNetwork
 
         if( country.equals("do") ) country = "dm"; // see RubikScores.setCountry()
 
-        if(level>=0 && level<MAX_LEVEL)
+        if( level>LEVELS_SHOWN ) level = LEVELS_SHOWN;
+
+        if(level>=0)
           {
           int p = mPlaces[object][level];
           mPlaces[object][level]++;
diff --git a/src/main/java/org/distorted/external/RubikScores.java b/src/main/java/org/distorted/external/RubikScores.java
index f2f93d41..2e453e7a 100644
--- a/src/main/java/org/distorted/external/RubikScores.java
+++ b/src/main/java/org/distorted/external/RubikScores.java
@@ -19,16 +19,18 @@ import android.telephony.TelephonyManager;
 import com.google.firebase.crashlytics.FirebaseCrashlytics;
 
 import org.distorted.main.BuildConfig;
+import org.distorted.objectlib.main.ObjectType;
 import org.distorted.objects.RubikObject;
 import org.distorted.objects.RubikObjectList;
 
-import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
+import static org.distorted.objectlib.main.ObjectType.MAX_SCRAMBLES;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // hold my own scores, and some other statistics.
 
 public class RubikScores
   {
+  public static final int MAX_RECORD = 10;
   public static final int MULT = 1000000;
   public static final long NO_RECORD = Long.MAX_VALUE;
   private static RubikScores mThis;
@@ -324,7 +326,7 @@ public class RubikScores
     int numObjects = RubikObjectList.getNumObjects();
     StringBuilder builder = new StringBuilder();
 
-    for(int level=0; level<MAX_LEVEL; level++)
+    for(int level=0; level<=MAX_RECORD; level++)
       {
       builder.setLength(0);
 
@@ -361,15 +363,16 @@ public class RubikScores
   public synchronized void restorePreferences(SharedPreferences preferences)
     {
     String recordStr, subStr, nameStr, timeStr, submStr, errorStr="";
-    int start, end, equals, comma, object, subm;
+    int start, end, equals, comma, ordinal, subm;
     long time;
     boolean thereWasError = false;
     int numObjects = RubikObjectList.getNumObjects();
 
-    for(int level=0; level<MAX_LEVEL; level++)
+    for(int level=0; level<=MAX_SCRAMBLES; level++)
       {
+      recordStr = preferences.getString("scores_record"+level, null);
+      if( recordStr==null ) continue;
       start = end = 0;
-      recordStr = preferences.getString("scores_record"+level, "");
 
       while( end!=-1 )
         {
@@ -389,17 +392,30 @@ public class RubikScores
           timeStr = subStr.substring(equals+1,comma);
           submStr = subStr.substring(comma+1);
 
-          object = RubikObjectList.getOrdinal(nameStr);
+          ordinal = RubikObjectList.getOrdinal(nameStr);
 
-          if( object>=0 && object<numObjects )
+          if( ordinal>=0 && ordinal<numObjects )
             {
             time = Long.parseLong(timeStr);
             subm = Integer.parseInt(submStr);
 
             if( subm>=0 && subm<=1 )
               {
+              int staticNumScrambles = ObjectType.getStaticNumScrambles(ordinal);
+
+              if( level==MAX_RECORD )
+                {
+                android.util.Log.e("D", "object: "+nameStr+" level="+level+" RECORD DETECTED!");
+                }
+
+              if( level>=staticNumScrambles )
+                {
+                android.util.Log.e("D", "object: "+nameStr+" level="+level+" RECORD DETECTED!");
+                level = MAX_RECORD;
+                }
+
               MapValue value = new MapValue(time,subm);
-              int key = mapKey(object,level);
+              int key = mapKey(ordinal,level);
               mMap.put(key,value);
               }
             else
@@ -410,7 +426,7 @@ public class RubikScores
             }
           else
             {
-            errorStr += ("error2: object="+object+" obj: "+nameStr+"\n");
+            errorStr += ("error2: object="+ordinal+" obj: "+nameStr+"\n");
             thereWasError = true;
             }
           }
diff --git a/src/main/java/org/distorted/objects/RubikObjectList.java b/src/main/java/org/distorted/objects/RubikObjectList.java
index 03d0e89c..4c4ff9ab 100644
--- a/src/main/java/org/distorted/objects/RubikObjectList.java
+++ b/src/main/java/org/distorted/objects/RubikObjectList.java
@@ -29,8 +29,6 @@ import static org.distorted.main.RubikActivity.SHOW_DOWNLOADED_DEBUG;
 public class RubikObjectList
 {
   public static final int DEF_OBJECT= ObjectSignatures.CUBE_3;
-  public static int MAX_LEVEL;
-
   private static RubikObjectList mThis;
   private static int mNumObjects;
   private static int mNumExtras;
@@ -59,19 +57,6 @@ public class RubikObjectList
 
   private static ArrayList<DownloadedObject> mDownloadedObjects;
 
-  static
-    {
-    int max = Integer.MIN_VALUE;
-
-    for (int i=0; i<NUM_OBJECTS; i++)
-      {
-      int cur = getDBLevel(i);
-      if( cur>max ) max = cur;
-      }
-
-    MAX_LEVEL = max;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private RubikObjectList()
@@ -147,49 +132,6 @@ public class RubikObjectList
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// historically older versions of the app had lower 'maxScrambles' in case of several objects and
-// those got remembered in the server-side DB already, so we need to keep using them. This function
-// provides a map between 'maxScramble' of an object and its 'dbLevel'. All new objects will have
-// those two values the same.
-//
-// all of those need to be > RubikStatePlay.LEVELS_SHOWN.
-
-  public static int getDBLevel(int ordinal)
-    {
-    if( ordinal== ObjectSignatures.CUBE_3 ) return 16;
-    if( ordinal== ObjectSignatures.CUBE_4 ) return 20;
-    if( ordinal== ObjectSignatures.CUBE_5 ) return 24;
-    if( ordinal== ObjectSignatures.BAN2_3 ) return 16;
-    if( ordinal== ObjectSignatures.BAN4_3 ) return 16;
-    if( ordinal== ObjectSignatures.PYRA_4 ) return 15;
-    if( ordinal== ObjectSignatures.PYRA_5 ) return 20;
-    if( ordinal== ObjectSignatures.MEGA_5 ) return 35;
-    if( ordinal== ObjectSignatures.DIAM_2 ) return 10;
-    if( ordinal== ObjectSignatures.DIAM_3 ) return 18;
-    if( ordinal== ObjectSignatures.REDI_3 ) return 14;
-    if( ordinal== ObjectSignatures.HELI_3 ) return 18;
-    if( ordinal== ObjectSignatures.SKEW_3 ) return 17;
-    if( ordinal== ObjectSignatures.REX_3  ) return 16;
-    if( ordinal== ObjectSignatures.MIRR_3 ) return 16;
-    if( ordinal== ObjectSignatures.IVY_2  ) return  9;
-    if( ordinal== ObjectSignatures.DIN4_3 ) return  9;
-
-    // in 1.9.6 & 1.9.7 there is a bug with downloadable objects (in this very function!):
-    // All of those have DBLevel equal to CUBE_3's DBlevel (in 1.9.7!), i.e. 17.
-    // This will be a problem when we release a new version of the app which has some of the
-    // previously downloadable objects built-in. Thus: in case of those, we need to keep using
-    // 17.
-
-    if( ObjectType.wasDownloadableButNowIsBuiltIn(ordinal) )
-      {
-      return 17;
-      }
-
-    return ObjectType.getObject(ordinal).getNumScramble();
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public static boolean addDownloadedObject(Context context, String shortName, int numScrambles, int objectMinor,
                                          int extrasMinor, boolean icon, boolean object, boolean extras)
