commit 3e5ad4615f741ee0cff33a82de906c371e2bbc48
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Sep 10 21:33:32 2020 +0100

    Improve the Scores dialog: now level sections are added one-by-one.

diff --git a/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java b/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
index 9b87a024..7c085e66 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
@@ -44,37 +44,84 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
   private ViewPager mViewPager;
   private int mNumTabs;
   private boolean mIsSubmitting;
+  private int mToDoTab, mToDoLvl;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
+  private void addSection(int tab, int level, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
     {
-    prepareView();
+    final LinearLayout section = view.createSection(mAct, tab, level, country, name, time);
 
-    boolean[] tabDone = new boolean[mNumTabs];
-    for(int i=0; i<mNumTabs; i++) tabDone[i] = false;
-    int toDo, doneTabs=0;
+    mAct.runOnUiThread(new Runnable()
+      {
+      @Override
+      public void run()
+        {
+        view.addSection(section);
+        }
+      });
 
-    while( doneTabs<mNumTabs )
+    try
       {
-      toDo = mViewPager.getCurrentItem();
+      Thread.sleep(50);
+      }
+    catch( InterruptedException ignored)
+      {
+
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-      if( tabDone[toDo] )
+  private void getNext(int currentTab, int[] toDoTab, int[] maxTab)
+    {
+    if( toDoTab[currentTab]<maxTab[currentTab] )
+      {
+      mToDoTab = currentTab;
+      mToDoLvl = toDoTab[currentTab];
+      toDoTab[currentTab]++;
+      }
+    else
+      {
+      for(int tab=0; tab<mNumTabs; tab++)
         {
-        for(int i=0; i<mNumTabs; i++)
+        if( toDoTab[tab]<maxTab[tab] )
           {
-          if( !tabDone[i] )
-            {
-            toDo = i;
-            break;
-            }
+          mToDoTab = tab;
+          mToDoLvl = toDoTab[tab];
+          toDoTab[tab]++;
+          break;
           }
         }
+      }
+    }
 
-      addPage(toDo, mViews[toDo],country[toDo],name[toDo],time[toDo]);
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-      doneTabs++;
-      tabDone[toDo] = true;
+  public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
+    {
+    prepareView();
+
+    int toDo=0;
+    int[] toDoTab = new int[mNumTabs];
+    int[] maxTab  = new int[mNumTabs];
+
+    for(int i=0; i<mNumTabs; i++)
+      {
+      int object   = RubikObjectList.unpackObject(i);
+      int sizeIndex= RubikObjectList.unpackSizeIndex(i);
+      maxTab[i]    = RubikObjectList.getMaxLevel(object, sizeIndex);
+      toDoTab[i]   = 0;
+
+      toDo += maxTab[i];
+      }
+
+    while( toDo>0 )
+      {
+      toDo--;
+      getNext(mViewPager.getCurrentItem(),toDoTab,maxTab);
+      addSection( mToDoTab,mToDoLvl, mViews[mToDoTab],
+                  country[mToDoTab][mToDoLvl],name[mToDoTab][mToDoLvl],time[mToDoTab][mToDoLvl]);
       }
     }
 
@@ -147,38 +194,6 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time)
-    {
-    int object   = RubikObjectList.unpackObject(tab);
-    int sizeIndex= RubikObjectList.unpackSizeIndex(tab);
-    int maxLevel = RubikObjectList.getMaxLevel(object, sizeIndex);
-
-    for(int i=0; i<maxLevel; i++)
-      {
-      final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]);
-
-      mAct.runOnUiThread(new Runnable()
-        {
-        @Override
-        public void run()
-          {
-          view.addSection(section);
-          }
-        });
-
-      try
-        {
-        Thread.sleep(50);
-        }
-      catch( InterruptedException ignored)
-        {
-
-        }
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag)
