commit e9397ae9352e41f235d6a2c6c893f36bdbbfa411
Author: leszek <leszek@koltunski.pl>
Date:   Tue Nov 14 17:04:36 2023 +0100

    Progress with the generic PlayActivity.

diff --git a/src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java b/src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
index 23c81fc2..f7904624 100644
--- a/src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
+++ b/src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
@@ -18,9 +18,8 @@ import android.view.View;
 import android.widget.TextView;
 
 import org.distorted.main.R;
-import org.distorted.main_old.RubikActivity;
 import org.distorted.external.RubikScores;
-import org.distorted.screens.ScreenList;
+import org.distorted.playui.PlayActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -36,25 +35,29 @@ public class RubikDialogNewRecord extends RubikDialogAbstract
 
   public void positiveAction()
     {
-    RubikActivity act = (RubikActivity)getActivity();
     RubikScores scores = RubikScores.getInstance();
     String name = scores.getName();
     Bundle bundle = new Bundle();
-    ScreenList.switchScreen(act, ScreenList.PLAY);
+    PlayActivity act = (PlayActivity)getActivity();
 
-    if( name.length()>0 )
+    if( act!=null )
       {
-      bundle.putString("argument", "true");
-      RubikDialogScores scoresDiag = new RubikDialogScores();
-      scoresDiag.setArguments(bundle);
-      scoresDiag.show(act.getSupportFragmentManager(), null);
-      }
-    else
-      {
-      bundle.putString("argument", name );
-      RubikDialogSetName nameDiag = new RubikDialogSetName();
-      nameDiag.setArguments(bundle);
-      nameDiag.show(act.getSupportFragmentManager(), null);
+      if(name.length()>0)
+        {
+        bundle.putString("argument", "true");
+        RubikDialogScores scoresDiag = new RubikDialogScores();
+        scoresDiag.setArguments(bundle);
+        scoresDiag.show(act.getSupportFragmentManager(), null);
+        }
+      else
+        {
+        bundle.putString("argument", name);
+        RubikDialogSetName nameDiag = new RubikDialogSetName();
+        nameDiag.setArguments(bundle);
+        nameDiag.show(act.getSupportFragmentManager(), null);
+        }
+
+      act.finish();
       }
     }
 
@@ -62,8 +65,8 @@ public class RubikDialogNewRecord extends RubikDialogAbstract
 
   public void negativeAction()
     {
-    RubikActivity act = (RubikActivity)getActivity();
-    ScreenList.switchScreen(act, ScreenList.PLAY);
+    PlayActivity act = (PlayActivity)getActivity();
+    if( act!=null ) act.finish();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/playui/PlayActivity.java b/src/main/java/org/distorted/playui/PlayActivity.java
index 67d78430..0262b576 100644
--- a/src/main/java/org/distorted/playui/PlayActivity.java
+++ b/src/main/java/org/distorted/playui/PlayActivity.java
@@ -59,6 +59,7 @@ public class PlayActivity extends AppCompatActivity
     private boolean mObjectLocal;
     private int mObjectOrdinal;
     private boolean mModeFree;
+    private boolean mJustStarted;
     private FirebaseAnalytics mFirebaseAnalytics;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -71,6 +72,7 @@ public class PlayActivity extends AppCompatActivity
       setTheme(R.style.MaterialThemeNoActionBar);
       setContentView(R.layout.play);
 
+      mJustStarted = true;
       mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
 
       Bundle b = getIntent().getExtras();
@@ -211,23 +213,23 @@ public class PlayActivity extends AppCompatActivity
       super.onResume();
       DistortedLibrary.onResume(ACTIVITY_NUMBER);
       PlayView view = findViewById(R.id.playView);
+      ObjectControl control = view.getObjectControl();
       view.onResume();
 
       ScreenList.switchScreen(this, mModeFree ? ScreenList.FREE : ScreenList.SCRA );
-
       SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
       restorePreferences(preferences);
       restoreMoves(preferences);
 
+      mJustStarted = false;
+
       if( mObjectName.length()>0 )
         {
-        changeIfDifferent(mObjectName,mObjectLocal,mObjectOrdinal,view.getObjectControl());
+        changeIfDifferent(mObjectName,mObjectLocal,mObjectOrdinal,control);
         }
 
       if( !mModeFree )
         {
-        android.util.Log.e("D", "scrambles: "+mNumScrambles);
-        ObjectControl control = getControl();
         control.scrambleObject(mNumScrambles);
         }
       }
@@ -280,7 +282,7 @@ public class PlayActivity extends AppCompatActivity
       ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
       }
 
-    ScreenList.restorePreferences(preferences);
+    if( !mJustStarted ) ScreenList.restorePreferences(preferences);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/playui/PlayLibInterface.java b/src/main/java/org/distorted/playui/PlayLibInterface.java
index 5964fe18..e9c616c8 100644
--- a/src/main/java/org/distorted/playui/PlayLibInterface.java
+++ b/src/main/java/org/distorted/playui/PlayLibInterface.java
@@ -202,8 +202,7 @@ public class PlayLibInterface implements ObjectLibInterface
         @Override
         public void run()
           {
-          ScreenScrambling screen = (ScreenScrambling)ScreenList.SCRA.getScreenClass();
-          screen.setReady();
+          ScreenList.switchScreen(act,ScreenList.READ);
           ObjectControl control = act.getControl();
           control.unblockEverything();
           }
@@ -244,20 +243,24 @@ public class PlayLibInterface implements ObjectLibInterface
 
   public void onBeginRotation()
     {
-    if( ScreenList.getCurrentScreen()==ScreenList.SCRA )
+    if( ScreenList.getCurrentScreen()==ScreenList.READ )
       {
       ScreenSolving solving = (ScreenSolving) ScreenList.SOLV.getScreenClass();
       solving.resetElapsed();
       PlayActivity act = mAct.get();
+      ScreenList.switchScreen( act,ScreenList.SOLV );
 
+      /*
       act.runOnUiThread(new Runnable()
         {
         @Override
         public void run()
           {
-          ScreenList.switchScreen( act,ScreenList.SOLV );
+
           }
         });
+
+       */
       }
     }
 
diff --git a/src/main/java/org/distorted/playui/ScreenList.java b/src/main/java/org/distorted/playui/ScreenList.java
index 01f975f3..7679b019 100644
--- a/src/main/java/org/distorted/playui/ScreenList.java
+++ b/src/main/java/org/distorted/playui/ScreenList.java
@@ -10,6 +10,7 @@
 package org.distorted.playui;
 
 import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
+import static org.distorted.objectlib.main.ObjectControl.MODE_NOTHING;
 import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
 
 import android.content.SharedPreferences;
@@ -19,7 +20,8 @@ import android.content.SharedPreferences;
 public enum ScreenList
   {
   FREE ( null , MODE_ROTATE , new ScreenFree()       ),
-  SCRA ( null , MODE_ROTATE , new ScreenScrambling() ),
+  SCRA ( null , MODE_NOTHING, new ScreenScrambling() ),
+  READ ( null , MODE_ROTATE , new ScreenReady()      ),
   SOLV ( null , MODE_ROTATE , new ScreenSolving()    ),
   DONE ( null , MODE_DRAG   , new ScreenDone()       ),
   ;
diff --git a/src/main/java/org/distorted/playui/ScreenReady.java b/src/main/java/org/distorted/playui/ScreenReady.java
new file mode 100644
index 00000000..0f338924
--- /dev/null
+++ b/src/main/java/org/distorted/playui/ScreenReady.java
@@ -0,0 +1,100 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2023 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Magic Cube.                                                              //
+//                                                                                               //
+// Magic Cube is proprietary software licensed under an EULA which you should have received      //
+// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.playui;
+
+import android.content.SharedPreferences;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.distorted.helpers.TransparentImageButton;
+import org.distorted.main.R;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class ScreenReady extends ScreenAbstract
+  {
+  private TransparentImageButton mBackButton;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void leaveScreen(PlayActivity act)
+    {
+
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void enterScreen(final PlayActivity act)
+    {
+    float width = act.getScreenWidthInPixels();
+    float titleSize = width*PlayActivity.TITLE_TEXT_SIZE;
+    LayoutInflater inflater = act.getLayoutInflater();
+
+    // TOP ////////////////////////////
+    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
+    layoutTop.removeAllViews();
+    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
+    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
+    label.setText(R.string.ready);
+    layoutTop.addView(label);
+
+    // BOT ////////////////////////////
+    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
+    layoutBot.removeAllViews();
+
+    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
+    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,2);
+
+    LinearLayout layoutLeft = new LinearLayout(act);
+    layoutLeft.setLayoutParams(paramsL);
+    LinearLayout layoutRight = new LinearLayout(act);
+    layoutRight.setLayoutParams(paramsR);
+
+    setupBackButton(act);
+
+    layoutRight.addView(mBackButton);
+    layoutBot.addView(layoutLeft);
+    layoutBot.addView(layoutRight);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void setupBackButton(final PlayActivity act)
+    {
+    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
+    mBackButton = new TransparentImageButton(act,R.drawable.ui_back,params);
+
+    mBackButton.setOnClickListener( new View.OnClickListener()
+      {
+      @Override
+      public void onClick(View v)
+        {
+        ScreenList.goBack(act);
+        }
+      });
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void savePreferences(SharedPreferences.Editor editor)
+    {
+
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void restorePreferences(SharedPreferences preferences)
+    {
+
+    }
+  }
diff --git a/src/main/java/org/distorted/playui/ScreenScrambling.java b/src/main/java/org/distorted/playui/ScreenScrambling.java
index b631db98..94d38370 100644
--- a/src/main/java/org/distorted/playui/ScreenScrambling.java
+++ b/src/main/java/org/distorted/playui/ScreenScrambling.java
@@ -10,11 +10,8 @@
 package org.distorted.playui;
 
 import android.content.SharedPreferences;
-import android.util.TypedValue;
-import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.LinearLayout;
-import android.widget.TextView;
 
 import org.distorted.helpers.TransparentImageButton;
 import org.distorted.main.R;
@@ -24,7 +21,6 @@ import org.distorted.main.R;
 public class ScreenScrambling extends ScreenAbstract
   {
   private TransparentImageButton mBackButton;
-  private TextView mLabel;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -37,16 +33,9 @@ public class ScreenScrambling extends ScreenAbstract
 
   void enterScreen(final PlayActivity act)
     {
-    float width = act.getScreenWidthInPixels();
-    float titleSize = width*PlayActivity.TITLE_TEXT_SIZE;
-    LayoutInflater inflater = act.getLayoutInflater();
-
     // TOP ////////////////////////////
     LinearLayout layoutTop = act.findViewById(R.id.upperBar);
     layoutTop.removeAllViews();
-    mLabel = (TextView)inflater.inflate(R.layout.upper_text, null);
-    mLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
-    layoutTop.addView(mLabel);
 
     // BOT ////////////////////////////
     LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
@@ -67,13 +56,6 @@ public class ScreenScrambling extends ScreenAbstract
     layoutBot.addView(layoutRight);
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  void setReady()
-    {
-    mLabel.setText(R.string.ready);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void setupBackButton(final PlayActivity act)
