commit 2e3488f6abf50df098cfbe8bfa7402e7962134f3
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Apr 1 13:40:41 2022 +0200

    Remember move history in the PLAY and SOLV screens.

diff --git a/src/main/java/org/distorted/helpers/MovesController.java b/src/main/java/org/distorted/helpers/MovesController.java
index 362fa4f3..86de649e 100644
--- a/src/main/java/org/distorted/helpers/MovesController.java
+++ b/src/main/java/org/distorted/helpers/MovesController.java
@@ -22,6 +22,7 @@ package org.distorted.helpers;
 import java.util.ArrayList;
 
 import android.app.Activity;
+import android.content.SharedPreferences;
 import android.view.View;
 import android.widget.LinearLayout;
 
@@ -179,6 +180,63 @@ public class MovesController implements MovesFinished
       });
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void savePreferences(SharedPreferences.Editor editor)
+      {
+      StringBuilder moves = new StringBuilder();
+      int numMoves = getNumMoves();
+
+      for(int m=0; m<numMoves; m++)
+        {
+        Move move = mMoves.get(m);
+
+        if( m>0 ) moves.append(' ');
+        moves.append(move.mAxis);
+        moves.append(' ');
+        moves.append(move.mRow);
+        moves.append(' ');
+        moves.append(move.mAngle);
+        }
+
+      editor.putString("movesController", moves.toString() );
+      editor.apply();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void restorePreferences(Activity act, SharedPreferences preferences)
+      {
+      String objects = preferences.getString("movesController","");
+
+      if( objects.length()>0 )
+        {
+        String[] tokens = objects.split(" ");
+        int length = tokens.length;
+
+        for(int m=0; m<length/3; m++)
+          {
+          String axis  = tokens[3*m  ];
+          String row   = tokens[3*m+1];
+          String angle = tokens[3*m+2];
+
+          try
+            {
+            int axisI = Integer.parseInt(axis);
+            int rowI  = Integer.parseInt(row);
+            int angleI= Integer.parseInt(angle);
+
+            addMove(act,axisI,rowI,angleI);
+            }
+          catch(NumberFormatException ex)
+            {
+            // ignore
+            android.util.Log.e("D", "exception: "+ex.getMessage());
+            }
+          }
+        }
+      }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public TransparentImageButton getButton()
diff --git a/src/main/java/org/distorted/main/RubikActivity.java b/src/main/java/org/distorted/main/RubikActivity.java
index ac0abde3..c40feea2 100644
--- a/src/main/java/org/distorted/main/RubikActivity.java
+++ b/src/main/java/org/distorted/main/RubikActivity.java
@@ -56,6 +56,7 @@ import org.distorted.external.RubikScores;
 import org.distorted.external.RubikNetwork;
 import org.distorted.objects.RubikObject;
 import org.distorted.objects.RubikObjectList;
+import org.distorted.screens.RubikScreenSolving;
 import org.distorted.screens.ScreenList;
 import org.distorted.screens.RubikScreenPlay;
 import org.distorted.tutorials.TutorialActivity;
@@ -251,6 +252,8 @@ public class RubikActivity extends AppCompatActivity
       ScreenList.setScreen(this);
       unblockEverything();
 
+      restoreMoves();
+
       if( mJustStarted )
         {
         mJustStarted = false;
@@ -317,6 +320,19 @@ public class RubikActivity extends AppCompatActivity
       RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
       view.getObjectControl().savePreferences(editor);
 
+      ScreenList curr = ScreenList.getCurrentScreen();
+
+      if( curr==ScreenList.PLAY )
+        {
+        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
+        play.saveMovePreferences(editor);
+        }
+      if( curr==ScreenList.SOLV )
+        {
+        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
+        solv.saveMovePreferences(editor);
+        }
+
       editor.apply();
       }
 
@@ -367,6 +383,25 @@ public class RubikActivity extends AppCompatActivity
         }
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void restoreMoves()
+      {
+      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+      ScreenList curr = ScreenList.getCurrentScreen();
+
+      if( curr==ScreenList.PLAY )
+        {
+        RubikScreenPlay play = (RubikScreenPlay)ScreenList.PLAY.getScreenClass();
+        play.restoreMovePreferences(this,preferences);
+        }
+      if( curr==ScreenList.SOLV )
+        {
+        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
+        solv.restoreMovePreferences(this,preferences);
+        }
+      }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     private void PrivacyPolicy()
diff --git a/src/main/java/org/distorted/screens/RubikScreenBase.java b/src/main/java/org/distorted/screens/RubikScreenBase.java
index dfd24a2f..85eae3f4 100644
--- a/src/main/java/org/distorted/screens/RubikScreenBase.java
+++ b/src/main/java/org/distorted/screens/RubikScreenBase.java
@@ -20,6 +20,7 @@
 package org.distorted.screens;
 
 import android.app.Activity;
+import android.content.SharedPreferences;
 import android.widget.LinearLayout;
 
 import org.distorted.helpers.TransparentImageButton;
@@ -100,4 +101,18 @@ abstract class RubikScreenBase extends RubikScreenAbstract
     ObjectControl control = act.getControl();
     mLockController.reddenLock(act,control);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void saveMovePreferences(SharedPreferences.Editor editor)
+    {
+    mMovesController.savePreferences(editor);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void restoreMovePreferences(Activity act, SharedPreferences preferences)
+    {
+    mMovesController.restorePreferences(act,preferences);
+    }
   }
