commit 4c9947bd21ee48afdbb4ce656bec37a3b33d014c
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Oct 13 16:14:33 2021 +0200

    1. Do not restore object scrambling if we freshly upgraded from some version older than 1.9.0
    2. Bugfix for a recently introduced crasher in the Play screen.

diff --git a/src/main/java/org/distorted/main/RubikActivity.java b/src/main/java/org/distorted/main/RubikActivity.java
index c947b306..9e5d234f 100644
--- a/src/main/java/org/distorted/main/RubikActivity.java
+++ b/src/main/java/org/distorted/main/RubikActivity.java
@@ -23,6 +23,8 @@ import java.util.Locale;
 
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.LocaleList;
@@ -263,6 +265,21 @@ public class RubikActivity extends AppCompatActivity
       super.onDestroy();
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private String getAppVers()
+    {
+    try
+      {
+      PackageInfo pInfo = getPackageManager().getPackageInfo( getPackageName(), 0);
+      return pInfo.versionName;
+      }
+    catch (PackageManager.NameNotFoundException e)
+      {
+      return "unknown";
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     private void savePreferences()
@@ -271,6 +288,7 @@ public class RubikActivity extends AppCompatActivity
       SharedPreferences.Editor editor = preferences.edit();
 
       editor.putBoolean("policyAccepted", mPolicyAccepted);
+      editor.putString("appVersion", getAppVers() );
 
       for (int i=0; i<BaseEffect.Type.LENGTH; i++)
         {
@@ -296,6 +314,7 @@ public class RubikActivity extends AppCompatActivity
       SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
 
       mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
+      String oldVersion = preferences.getString("appVersion","");
 
       for (int i=0; i< BaseEffect.Type.LENGTH; i++)
         {
@@ -310,7 +329,20 @@ public class RubikActivity extends AppCompatActivity
       ScreenList.restorePreferences(preferences);
 
       RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
-      view.getObjectControl().restorePreferences(preferences);
+
+      // Versions <= 1.8.6 did not save their 'appVersion' to preferences, therefore in their
+      // case the 'mOldVersion' - version of the app which saved the preferences on the last
+      // go - is empty.
+      // Between versions 1.8.6 and 1.9.0, the order of the cubits in TwistyCube has changed.
+      // If someone has scrambled the cube with v. 1.8.6, then upgraded to 1.9.0 and re-started
+      // the app, because of the different order of the cubits - his cube would be messed up.
+      // So in such case, i.e. on fresh upgrade from version<=1.8.6 to version>=1.9.0, do not
+      // restore the object scrambling.
+
+      if( !oldVersion.equals("") )
+        {
+        view.getObjectControl().restorePreferences(preferences);
+        }
 
       RubikScores scores = RubikScores.getInstance();
 
diff --git a/src/main/java/org/distorted/screens/RubikScreenPlay.java b/src/main/java/org/distorted/screens/RubikScreenPlay.java
index 8ff60bb0..e9514594 100644
--- a/src/main/java/org/distorted/screens/RubikScreenPlay.java
+++ b/src/main/java/org/distorted/screens/RubikScreenPlay.java
@@ -289,7 +289,7 @@ public class RubikScreenPlay extends RubikScreenBase
             {
             mObject = type;
             act.changeObject(type, true);
-            adjustLevels(act);
+            if( mPlayLayout!=null ) adjustLevels(act);
             mMovesController.clearMoves(act);
             }
 
