commit 72d3d38386f3fef7828c6681586ba38bda2dbd35
Author: leszek <leszek@koltunski.pl>
Date:   Wed Nov 15 16:33:20 2023 +0100

    progress with PlayActivity - colors of the level buttons.

diff --git a/src/main/java/org/distorted/main/MainActivity.java b/src/main/java/org/distorted/main/MainActivity.java
index 1b2295fb..91f93d17 100644
--- a/src/main/java/org/distorted/main/MainActivity.java
+++ b/src/main/java/org/distorted/main/MainActivity.java
@@ -243,13 +243,13 @@ public class MainActivity extends AppCompatActivity implements RubikNetwork.Upda
       mBubbleUpdates.setVisibility(View.INVISIBLE);
       mNumUpdates = 0;
 
-      RubikNetwork network = RubikNetwork.getInstance();
-      network.signUpForUpdates(this);
-      network.downloadUpdates(this);
-
       if( mJustStarted )
         {
         mJustStarted = false;
+
+        RubikNetwork network = RubikNetwork.getInstance();
+        network.signUpForUpdates(this);
+        network.downloadUpdates(this);
         RubikScores scores = RubikScores.getInstance();
         scores.incrementNumRuns();
         scores.setCountry(this);
diff --git a/src/main/java/org/distorted/main/MainObjectPopup.java b/src/main/java/org/distorted/main/MainObjectPopup.java
index 9bb5b6a4..859e9f62 100644
--- a/src/main/java/org/distorted/main/MainObjectPopup.java
+++ b/src/main/java/org/distorted/main/MainObjectPopup.java
@@ -12,6 +12,8 @@ package org.distorted.main;
 import static android.view.View.GONE;
 
 import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.Resources;
 import android.util.TypedValue;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -21,6 +23,7 @@ import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 import android.widget.TextView;
 
+import org.distorted.external.RubikScores;
 import org.distorted.objects.RubikObject;
 import org.distorted.objects.RubikObjectList;
 
@@ -37,7 +40,7 @@ public class MainObjectPopup
 
   private final PopupWindow mPopup;
   private final int mMenuTextSize;
-  private Button[] mLevel;
+  private final int mObjectOrdinal;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -49,6 +52,7 @@ public class MainObjectPopup
     mPopup.setContentView(layout);
     mPopup.setFocusable(true);
 
+    mObjectOrdinal = ordinal;
     boolean firstButtonShown = false;
 
     mMenuTextSize = (int)(height*MENU_TEXT_SIZE);
@@ -156,6 +160,11 @@ public class MainObjectPopup
 
   private void setupLevelButtons(MainActivity act, RubikObject object, View layout, int width,int padding, int margin)
     {
+    RubikScores scores = RubikScores.getInstance();
+    Resources res = act.getResources();
+    ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
+    ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
+
     int layoutWidth = (int)(width*MENU_WIDTH);
     int levelHeight = (int)(width*BUTTON_HEIGHT);
     int levelWidth  = (layoutWidth-4*padding)/3;
@@ -163,44 +172,49 @@ public class MainObjectPopup
     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(levelWidth,levelHeight);
     params.setMargins(margin,-margin,margin,-margin);
 
-    mLevel = new Button[LEVELS_SHOWN+1];
+    Button[] level = new Button[LEVELS_SHOWN+1];
 
-    mLevel[0] = layout.findViewById(R.id.level0);
-    mLevel[1] = layout.findViewById(R.id.level1);
-    mLevel[2] = layout.findViewById(R.id.level2);
-    mLevel[3] = layout.findViewById(R.id.level3);
-    mLevel[4] = layout.findViewById(R.id.level4);
-    mLevel[5] = layout.findViewById(R.id.level5);
-    mLevel[6] = layout.findViewById(R.id.level6);
-    mLevel[7] = layout.findViewById(R.id.level7);
-    mLevel[8] = layout.findViewById(R.id.levelM);
+    level[0] = layout.findViewById(R.id.level0);
+    level[1] = layout.findViewById(R.id.level1);
+    level[2] = layout.findViewById(R.id.level2);
+    level[3] = layout.findViewById(R.id.level3);
+    level[4] = layout.findViewById(R.id.level4);
+    level[5] = layout.findViewById(R.id.level5);
+    level[6] = layout.findViewById(R.id.level6);
+    level[7] = layout.findViewById(R.id.level7);
+    level[8] = layout.findViewById(R.id.levelM);
 
     int numScramble  = object==null ? 1 : object.getNumScramble();
     int min = Math.min(numScramble,LEVELS_SHOWN);
 
     if( numScramble>=1 && numScramble<=7 )
       {
-      mLevel[numScramble].setText(R.string.levelM);
-      for(int i=numScramble+1; i<=8; i++) mLevel[i].setVisibility(GONE);
+      level[numScramble].setText(R.string.levelM);
+      for(int i=numScramble+1; i<=8; i++) level[i].setVisibility(GONE);
       }
 
-    for(int i=0; i<=min; i++)
+    for(int l=0; l<=min; l++)
       {
-      mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
-      mLevel[i].setLayoutParams(params);
-      mLevel[i].setPadding(0,0,0,0);
+      level[l].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
+      level[l].setLayoutParams(params);
+      level[l].setPadding(0,0,0,0);
+
+      boolean isSolved = scores.isSolved(mObjectOrdinal,l);
+      level[l].setBackgroundTintList( isSolved ? colorG : colorD);
 
-      final int ii=i;
-      boolean free = i==0;
-      int scrambles = (i>0 && i<min) ? i : numScramble;
+      final int ll=l;
+      boolean free = l==0;
+      int scrambles = (l>0 && l<min) ? l : numScramble;
 
-      mLevel[i].setOnClickListener( new View.OnClickListener()
+      level[l].setOnClickListener( new View.OnClickListener()
         {
         @Override
         public void onClick(View v)
           {
           mPopup.dismiss();
-          act.switchToPlay(object,scrambles,free,ii);
+          if( ll==0 ) scores.setRecord(mObjectOrdinal,0,0); // remember we've entered the 'Free'
+                                                            // so that the button turns green
+          act.switchToPlay(object,scrambles,free,ll);
           }
         });
       }
@@ -208,54 +222,7 @@ public class MainObjectPopup
     int index = (numScramble>=1 && numScramble<=7) ? numScramble : LEVELS_SHOWN;
     LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(levelWidth,levelHeight);
     params2.setMargins(margin,-margin,margin,margin);
-    mLevel[index].setLayoutParams(params2);
-
-    setupLevelButtonVisibilityAndColor(act);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void setupLevelButtonVisibilityAndColor(MainActivity act)
-    {
-    /*
-    int currObject = RubikObjectList.getCurrObject();
-    RubikObject object = RubikObjectList.getObject(currObject);
-    int numScramble = object==null ? 1 : object.getNumScramble();
-    RubikScores scores = RubikScores.getInstance();
-    Resources res = act.getResources();
-    ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
-    ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
-
-    for(int level=0; level<=LEVELS_SHOWN; level++)
-      {
-      boolean isSolved = scores.isSolved(currObject,level);
-      mLevel[level].setBackgroundTintList( isSolved ? colorG : colorD);
-      }
-
-    if( numScramble<=LEVELS_SHOWN || mOldNumScramble<=LEVELS_SHOWN )
-      {
-      if( numScramble<mOldNumScramble )
-        {
-        int max = Math.min(LEVELS_SHOWN,mOldNumScramble-1);
-        for(int level=numScramble; level<=max; level++) mLevel[level].setVisibility(View.INVISIBLE);
-        mLevel[numScramble-1].setText(R.string.levelM);
-        }
-      if( numScramble>mOldNumScramble )
-        {
-        int max = Math.min(LEVELS_SHOWN,numScramble-1);
-        mLevel[mOldNumScramble-1].setText( String.valueOf(mOldNumScramble) );
-
-        for(int level=mOldNumScramble; level<=max; level++)
-          {
-          mLevel[level].setVisibility(View.VISIBLE);
-          if( level<max ) mLevel[level].setText( String.valueOf(level+1) );
-          else            mLevel[level].setText( R.string.levelM );
-          }
-        }
-      }
-
-    mOldNumScramble = numScramble;
-    */
+    level[index].setLayoutParams(params2);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/playui/PlayActivity.java b/src/main/java/org/distorted/playui/PlayActivity.java
index 32896066..ab0d5d20 100644
--- a/src/main/java/org/distorted/playui/PlayActivity.java
+++ b/src/main/java/org/distorted/playui/PlayActivity.java
@@ -344,6 +344,8 @@ public class PlayActivity extends AppCompatActivity
         InitAssets asset = new InitAssets(jsonStream, meshStream, os);
         control.changeIfDifferent(ordinal, upperName, iconMode, asset);
         }
+
+      RubikObjectList.setCurrObject(ordinal);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
